Use themes
Themes are one of the most important things in BellJs as they give you the opportunity to choose between different designs and find the one that best suits your system. Or create your own.
Using a theme
BellJs does not load the Extra default themes to improve performance. If you want to try all the themes it’s as easy as importing the CSS allThemes.css
or if you want to import just the one you’re going to use light.css
.
To use a theme it is as easy as selecting it. To do this we must modify the theme
property of the third parameter of Bell. Here is an example:
With this done all the alert types will change their design.
Create a theme
Creating themes is an efficient way to customize our alerts without having to change each one. But first of all we must know how these themes work.
- BellJs CSS variables.
- Theme name and restricted names.
- Using the new themes.
BellJs CSS variables
Themes and most of all BellJs works with variables to improve the development environment for both the team and the users who use or modify the library. These are the variables that BellJs uses:
Variable name | Use | Example |
---|---|---|
--b_t | Defines the title color | --b_t: white; |
--b_d | Defines the description color | --b_d: black; |
--b_bg | Defines the alert background color | --b_bg: red; |
--b_svg | Defines the icon color | --b_svg: blue; |
--b_br | Defines the border color | --b_br: gray; |
--b_t | Defines the title color | --b_t: white; |
--b_tm | Defines the animation time of the timeline | --b_tm: 5000ms; |
--b_h | Defines the height of the alert | --b_h: 40px; |
--b_w | Defines the width of the alert | --b_w: 120px; |
With this in mind we can start modifying the variables to create our own theme, remember that we must modify each of the possible types such as info
, error
or others:
Save the CSS file with the name of this new theme.
Theme name and restricted names.
The next step is to give our theme a name, although you should not use restricted names from BellJs to avoid problems, some of them are:
Restricted name | Use |
---|---|
.b_c | Alert container CSS class |
.b_p | Alert container parent CSS class |
.b_close | Remove button CSS class |
.b_i | Icons or svg CSS class |
.b_t-c | Text container CSS class |
.b_t | Title CSS class |
.b_d | Description CSS class |
.b_t_p | Promise title CSS class |
@keyframes b_a-timeline | Timeline animation name |
@keyframes b_a-svg | Promise icon animation name |
We should also not use the name of an existing theme as a theme name. Example: colors
Use created theme
Now with everything already created we can use the created theme, remember to have imported the CSS of the new theme.
Now you can see your new theme created. If you think your theme can help or please other people, what are you waiting for? Send a PR to the BellJs repo and share your creations now.