% @side_nav = "css" %>
There are two ways to build alerts in Abstractio 4: with our predefined HTML classes or with our structure and mixins. Building an alert using our predefined class is super-easy, you only need a block-level element with a class of .alert-box
(we usually use a <div>
). You may also include an anchor with a class of .close
to create a close box. Here is the markup you'll need:
For these styles to come across, make sure you have the default Abstractio CSS package or that you've selected alerts from a custom package. These should be linked up following our default HTML page structure.
We've included SCSS mixins used to style alert boxes. To use these mixins, you'll need to have the extension installed or grab _abstractio-global.scss, _global.scss and _alert-boxes.scss from Github and throw them into a Abstractio folder in your project directory. From there, you can import the files at the top of your own SCSS stylesheet, like so:
<%= code_example ' @import "abstractio/abstractio-global", "abstractio/components/global", "abstractio/components/alerts"; ', :css %>If you are using the mixins, you may include the styles on whatever class or ID you'd like, just make sure you follow our markup structure:
<%= code_example ' ', :html %>You can build your alert using our global mixin by including it on your custom class or ID in your stylesheet. The mixin contains options for changing the background color, which also controls the border and text color. The rest of the defaults can be modified using the available variables. The global mixin looks like this:
<%= code_example ' /* Using the default styles */ .your-class-name { @include alert; } /* Using the available options */ .your-class-name { @include alert(#ff6c3c); } ', :css %>Use this mixin to create the base styles for alert boxes. This will include styles that create the basic structure of an alert box.
<%= code_example ' .your-class-name { @include alert-base; } ', :css %>You can control the background, border and text styles for the alert using this mixin. We base the border and text style on the background color you choose using some sweet Sass logic.
<%= code_example ' .your-class-name { @include alert-base; @include alert-style($bg); }', :css %>You can set $bg
color to any of our predefined color variables or any hexadecimal color of your choosing. To set this value to something other than our default, use @include alert-bg(#hexcolor);
You can include a close box with each of the alert boxes by adding an anchor right before the closing </div>
. This anchor should have a class of .close
in order to work with abstractio.alerts.js, which contains the interaction for closing.
We've also created a global radius mixin that you can use to add border-radius to any element you'd like.
<%= code_example ' .your-class-name { @include alert-base; @include alert-style($success-color); @include radius($radius); }', :css %>Note: emCalc();
is a function we wrote to convert px
to em
.
You don't need ths JS to create alert boxes with Abstractio. The only reason you'll need to include abstractio.alerts.js
is if you want to add the ability to close an alert. You'll also need to make sure to include zepto.js
and abstractio.js
above the alert plugin. Above your closing </body>
tag include the following line of code and make sure you have the JS in your directory:
Read how to install Abstractio JavaScript
Required Abstractio Library: abstractio.alerts.js
Then, you'll need to add a data-attribute to make the JS work properly on that element. That looks like:
<%= code_example ' ', :html %>