Comments (13)
Overriding the CSS is not a fix for this ticket. It's a workaround. I just want to pass an option with the FontAwesome unicode or icon name.
from toastr.
Why using iconClasses
change the background color?
from toastr.
@coderdave You can still do something like this:
toastr.options = {
iconClasses: {
error: 'fa fa-close',
info: 'fa fa-info',
success: 'something',
warning: 'something'
},
};
It is a bit late, but does this help?
from toastr.
@MaxInMoon
Because it replaces the toastr
container class toast-success
.
You could use it in this way:
toastr.options = {
iconClasses: {
success: 'toast-success fa fa-close'
}
};
The implementation is not quite good because it overrides the class of the whole container instead of adding icon as separate <i class="fa fa-close"/>
tag
from toastr.
You can do this now by overriding the CSS yourself.
Glad you like toastr!
from toastr.
It's been ~2 years since this initial request. FontAwesome is being used in a lot more web applications now. Could toastr be updated so that it accepts a FontAwesome icon classname or unicode?
http://fortawesome.github.io/Font-Awesome/cheatsheet/
I'd like to customize the icon based on the message "category" (email, cart, photo, social brand, etc) and use the warning/info/success/error classes to continue managing the themed colors. Generating static CSS per message type or using Javascript to temporarily override CSS for a single toastr call isn't optimal.
As a potential work around, is it possible/recommend to use jQuery to chain a icon swap after the toastr message is generated but before it's displayed? Thanks.
from toastr.
Font Awesome icons aren't used natively in toastr, but are converted to a base64 representation that is stored within the CSS file. If you'd like to specify additional toast types, you're more than free to modify the toastr.js and toastr.css files to add those additional types.
The existing toastr methods (success, info, etc) already return a jQuery wrapped DOM element reference of the toast that was created by that call.
from toastr.
I can't hide the original icon of the toast. I have tried with an example with this code.
#toast-container > .toast {
background-image: none !important;
}
But doesn't work. Any idea.
from toastr.
@chuynelo - can you please post your question to Stack Overflow?
from toastr.
I found a similar notification jQuery plugin called Lobibox that supports more options (images, sound support, multiple sizes, etc.) I liked the simplicity of Toastr, but found myself continually wishing it were more customization.
from toastr.
@tbragaf's snippet looks like it'll work.
@JamoCA - sorry you felt like Toastr wasn't a good fit. Lobibox seems to have a lot more capabilities that toastr intentionally leaves out of its scope.
from toastr.
@JamoCA wow, Lobibox looks really kewl!
from toastr.
The solution i found:
Download the icon you want in svg format from FontAwesome site, after that, open the file with some text editor and change "<path fill="currentColor"
to "<path fill="#ffffff"
(because the default is black and toastr.js use white icons).
After that use https://www.svgtopng.me/ to convert the svg to png file, in this website you have to resize to 24x24 (is the toastr default size of icon but you can choose what you want), and convert.
Now you can use this png image on toastr notification like so:
#toast-container > .toast-success {
background-image: url('path-to-png-image') !important;
}
or you can encode the png image to base64 using this site: https://www.base64-image.de/
and use it the same way as toastr
#toast-container> .toast-success {
background-image: url('base-64-image') !important;
}
Live example here: https://codepen.io/JoaoHamerski/pen/zYGpdxK
This solution is a little long but is the most consistent way to replace the icons that i found.
from toastr.
Related Issues (20)
- ngx toastr clear on outside click of toastr area
- Add import without links necessity HOT 3
- Travis-CI did not trigger tests
- Correlate a Toast with the one which has Just Hidden HOT 1
- jQuery.easing[jQuery.easing.def] is not a function
- Cannot read property 'extend' of undefined HOT 1
- Can't put two toastrs at two different positions
- timeOut not working
- timeout=0 onclick=function(){} how do I hide the toastr? HOT 1
- Accessibility issues HOT 1
- setAria
- #558 require js loading issue
- XSS Vulnerability "HIGH" due to default escapeHtml=false setting HOT 5
- TypeError: Cannot read properties of undefined (reading 'extend') HOT 2
- Toastr background white HOT 1
- toastr does not work with bootstrap 5 ? HOT 2
- This project is not maintained (2023)
- Target class [toastr] does not exist. HOT 1
- Update a toast message if a toast is already visible
- Icon animation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toastr.