Home Documents Blog

Alerts

Bring attention to important information and updates with the vibrant and customizable messages in JTB_MD.

About

Alerts in JTB_MD are dynamic elements designed to grab attention and convey important information in a visually striking way. Whether you want to highlight critical updates, notifications, or key messages, our customizable alerts add vibrancy and excitement to your user interface.

With a range of styles and customization options, JTB_MD's alerts empower you to create engaging and user-centric designs. They elevate the impact of your messages, enhance user awareness, and make your content more compelling.

How to use

In JTB_MD, there are two different ways to create and use an alert element in your project:

  • Creating the element via HTML directly,
  • Creating alert via jtbAlert plugin.

To create an alert element via HTML, you just need to create a container element (preferably <div>) and add .jtbAlert class into it. (We will explain the plugin method later on this page.)

Hello! I'm an alert box.
                <!-- Default Alert -->
<div class='jtbAlert'>Hello! I'm an alert box.</div>
            

Alerts in JTB_MD support all content in either plain text or HTML format. However, there is an important consideration when supplying content:

In JTB_MD, alerts are elements that uses flexbox as thier base technology, which means that if you provide content in a format where HTML elements are mixed with plain text, it automatically attempts to arrange them based on it. To avoid this issue, it is highly advisable to wrap all your content with a <span> element if you need to disable the flex features of alerts.

Hello! I'm plain-text content.

Hello! I'm a paragraph element in alert.

Hello! we are mixed content.
                <!-- PlainText -->
<div class='jtbAlert'>Hello! I'm plain-text content.</div>

<!-- HTML Content -->
<div class='jtbAlert'><p>Hello! I'm a paragraph element in alert.</p></div>

<!-- Mixed -> Wrapped with span to disable flex features -->
<div class='jtbAlert'><span>Hello! we <b>are</b> <i>mixed</i> content.</span></div>
            

Closable

To make your alert closable, you can add .jtbAlert-closable class to your alert element.

Hello! I'm a closable alert box.
                    <!-- Default Alert (Closable) -->
<div class='jtbAlert jtbAlert-closable'>Hello! I'm a closable alert box.</div>
                

Multi line

Since alerts in JTB_MB uses flex-inline as their display property, they allow you to manipulate their contents as a flexbox containers. To order your alert elements' content in a top-to-bottom, simply apply the jtbF-column class to them. The library will automatically handle the required adjustments for you.

Hi all!

I'm a multi line alert!

                    <!-- Multi Line Alert -->
<div class='jtbAlert jtbF-column' >
    <h4>Hi all!</h4>
    <p>I'm a multi line alert!</p>
</div>
                

Icon usage

Thanks to flex structure of alerts, there is no additional thing to do while adding icons to your alert elements. The library automatically detects the content and adjusts them for you.

Success! My precious feedback is here.
                    <!-- Alert With Icon -->
<div class='jtbAlert'>
    <i class='...'></i>
    <span>Success! My precious feedback is here.</span>
</div>
                

Versions

Within JTB_MD, the alert component comes in two distinctive versions:

  • Default Version: This is the standard version of alerts, designed with a background to ensure your messages stand out prominently.
  • Inverse Version: In this alternative version, the alert is rendered with a transparent background. Notably, the left border is thicker compared to the default version, providing a sleek and modern appearance.

Regardless of the version you choose, the usage remains consistent. To implement the inverse version, simply apply the .jtbAlert-inverse class to your .jtbAlert element.

Hello, I'm the default version!
Hello, I'm the inverse version!
                <!-- Default Alert -->
<div class='jtbAlert'>Hello, I'm the default version!</div>

<!-- Inverse Alert -->
<div class='jtbAlert jtbAlert-inverse'>Hello, I'm the inverse version!</div>
            

Styling

As you've learned how to provide feedback to users about their actions, let's now explore how to enhance the visual appeal of your feedback messages using pre-defined JTB_MD alert classes.

Never forget that you can leverage all classes from the Utilities section to seamlessly integrate elements with your design. However, the following pre-defined classes within alerts have been crafted to simplify your design workflow.

Colors

JTB_MD enables you to utilize the predefined colors outlined in the Colors section for your alerts. To do so, simply apply the desired color class to your alerts:

.jtbAlert-[ purple | blue | aqua | green | lime | yellow | orange | volcano | red ]

Hello, I have .jtbAlert-purple class.
Hello, I have .jtbAlert-blue class.
Hello, I have .jtbAlert-aqua class.
Hello, I have .jtbAlert-green class.
Hello, I have .jtbAlert-lime class.
Hello, I have .jtbAlert-yellow class.
Hello, I have .jtbAlert-orange class.
Hello, I have .jtbAlert-volcano class.
Hello, I have .jtbAlert-red class.
                                <!-- Example colorful jtbAlert (Yellow) -->
<div class='jtbAlert jtbAlert-yellow'>...</div>
                            

Sizes

In JTB_MD, you can also resize your alert elements. To make your alert larger or smaller than the default, simply apply the relevant size-class to your alert element.

.jtbAlert-[ xs | sm | md | lg | xl ]

Hello I have .jtbAlert-xs class.
Hello I have .jtbAlert-sm class.
Hello I have .jtbAlert-md class.
Hello I have .jtbAlert-lg class.
Hello I have .jtbAlert-xl class.
                                <!-- Example sized jtbAlert (size = xs) -->
<div class='jtbAlert jtbAlert-xs'>...</div>
                            

Removing Borders

To create a borderless alert element, simply apply the .jtbAlert-borderless class.

Hello, I'm a borderless alert.
                    <!-- Borderless Alert -->
<div class='jtbAlert jtbAlert-borderless'>...</div>
                

Rectangular

To create a rectangular alert (with no border radius), apply the .jtbAlert-rect class to your alert element.

Hello, I'm a rectangular alert.
                    <!-- Rectangular Alert -->
<div class='jtbAlert jtbAlert-rect'>...</div>
                

Javascript Plugin

In JTB_MD, the actions and methods that alerts can perform are defined in the jtbAlert plugin. Ensure that you haven't manually removed it from your project to utilize its functionalities properly.

For detailed information on plugins, refer to the JavaScript section.

Methods

With the jtbAlert plugin integrated, you can effortlessly generate and manipulate alerts on-the-fly in your project using JavaScript.

If you prefer to avoid traditional methods, such as creating elements directly in HTML, the following methods will be your best companions.

Create

To dynamically create an alert, use the jtbAlert() function with create method and your desired parameters. The format is $(container).jtbAlert('create', { parameters }, callbackFunction); where:

  • $(container) represents the element in which the alert will be placed,
  • parameters represents the object that holds alert's details such as content and classes,
  • callbackFunction (optional) stands for the function that you want to call after the creation of your alert element.
When creating an alert using plugin, the method returns the freshly created alert element. You can assign it to a variable for further use.
                        <!-- Define Alert Container -->
<div id='createHere'></div>

<!-- Assign Function to Button -->
<button class='jtbButton' onclick='createAlert()'>Create Alert</button>

<!-- Function to Create Alert -->
<script type='text/javascript'>
    function createAlert() {
        $('#createHere').jtbAlert('create', {
            html: "Hello! I'm an alert!",
            classes: "jtbAlert-closable jtbAlert-green jtbMB-0_5",
            // Additional parameters goes here
        });
    }
</script>
                    

For a personalized touch that aligns with your project's design, you can customize the parameters of the jtbAlert() function as outlined below:

Category Name Type Default Value Description Example Usage
Identifiers id String "" ID of the alert element. If not specified the system automatically fills it. "myAlertID"
classes String "" Classes to be applied to alert element. "jtbAlert-lg jtbAlert-rect"
Content html String "" Content to be displayed in alert as HTML or plain-text.
To disable flex adjustments, wrap your whole content with a <span> element.
"This is an example alert!"
Design css String "" Additional CSS codes to style alert element. "font-size:1rem; color:blue;"
Listeners animSpeed Integer 300 Speed of animations for methods. 1000
onUpdate String "" Function that will be called after 'update' method. "myCustomFunc('param1');"
onShow String "" Function that will be called after 'show' method. "myCustomFunc('param1');"
onHide String "" Function that will be called after 'hide' method. "myCustomFunc('param1');"
onToggle String "" Function that will be called after 'toggle' method. "myCustomFunc('param1');"
onDestroy String "" Function that will be called after 'destroy' method. "myCustomFunc('param1');"
Update

After creating an alert element, if you wish to modify any of its defined parameters, you can invoke the jtbAlert() function with update method and your new values.

At this point we need to state that the update method needs to be linked directly to alert element that you want to update instead of the container that holds the alert. The defined format for update is: $(alert).jtbAlert('update', { parameters }, callbackFunction); where:

  • $(alert) represents the alert element that you want to update,
  • parameters represents the object that holds alert's details such as content and classes,
  • callbackFunction (optional) stands for the function that you want to call after the update action.
This is an example alert. click button below to change its content.
                        /*----- Update the alert element -----*/
$('#alertID').jtbAlert('update', {
    // Parameters goes here
});
                    
Show

To make a specific alert visible on your DOM, you can invoke the plugin with the "show" parameter. Unlike the previous two methods, show method has no attribute as parameters. So you can trigger the method as: $(alert).jtbAlert('show', callbackFunction); where:

  • $(alert) represents the alert element that you want to make hidden,
  • callbackFunction (optional) stands for the function that you want to call after the visibility fully changed.
                        /*----- To Show hidden alerts -----*/
$("#alertID").jtbAlert("show");
                    
Hide

To hide a specific alert on your DOM, utilize the jtbAlert() function with the "hide" parameter. Like the "show" method, "hide" has no attribute as parameters. So you can trigger the method as: $(alert).jtbAlert('hide', callbackFunction); where:

  • $(alert) represents the alert element that you want to make visible,
  • callbackFunction (optional) stands for the function that you want to call after the visibility fully changed.
I need to hide, agents after me. Please, quick!
                        /*----- To Hide alerts -----*/
$("#alertID").jtbAlert("hide");
                    
Toggle

To toggle visibility of a specific alert on your DOM (hide if visible and make it visible if hidden), utilize the jtbAlert() function with the "toggle" parameter. Like the previous two methods, "toggle" has no attribute as parameters. So you can trigger the method as: $(alert).jtbAlert('toggle', callbackFunction); where:

  • $(alert) represents the alert element that you want to toggle visibility,
  • callbackFunction (optional) stands for the function that you want to call after the visibility fully changed.
I'm an alert, change my visibility!
                        /*----- To Change visibility of alert -----*/
$("#alertID").jtbAlert("toggle");
                    
Destroy

To permanently remove your alert element from the DOM, use the jtbAlert() function with the "destroy" parameter. Please be aware that after destruction, the element is completely removed from the HTML code and cannot be restored. You can trigger the "destroy" method as: $(alert).jtbAlert('destroy', callbackFunction); where:

  • $(alert) represents the alert element that you want to destroy,
  • callbackFunction (optional) stands for the function that you want to call after the visibility fully changed.
Destroy me senpai, uWu.
                        /*----- To remove an alert completely -----*/
$("#alertID").jtbAlert("destroy");
                    

Callbacks

Throughout the process of creating alerts and using methods via the plugin, you can execute additional functions after the operation by providing additional parameter to the jtbAlert() function.

The jtbAlert plugin offers three ways to specify a callback function. Since one of them is defining the listeners for element as attributes on their html tags such as onUpdate="console.log('updated');" and you've already saw that we do not go over them again. Here are the two additional methods:

  • Create a function elsewhere and call it inside jtbAlert().
I'm an illustrative alert, just for you. ;)
                    /*-----  Toggle Alert and callback -----*/
$("#alertID").jtbAlert("toggle", showProcessDone);

/*------ Define showProcessDone in here -------*/
function showProcessDone(){
	alert('Process done boss.');
}
                
  • Define the function itself inside jtbAlert().
I'm an illustrative alert, just for you. ;)
                    /*----- Toggle Alert and callback -----*/
$("#alertID").jtbAlert("toggle", function(){
	alert("Process done boss.");
});
                

The closing actions of alerts in JTB_MD triggers jtbAlert plugin's destroy method. So if you define onDestroy attribute to your alert element, it automatically calls defined function when a user closes the alert.

Click the close button on the right to see the effect.
                    <!-- Closable Alert with onDestroy Attribute -->
<div class='jtbAlert jtbAlert-jtbAlert-green jtbAlert-closable' onDestroy='showProcessDone();'>...</div>

<script type='text/javascript'>
	/*----- Defining Function In Here ------*/
		function showProcessDone(){
			alert('Process done boss.');
		}
</script>
                

Custom Close Buttons

If you prefer not to use the default close button in your alert, you can customize them using the jtbAlert plugin methods:

Ensure that an alert with a custom close button does not have the .jtbAlert-closable class.

This is the alert content...
                    <!-- Custom close button example -->
<div id='alert-X' class='jtbAlert jtbAlert-green jtbF jtbF-inline jtbW-100 jtbF-align-center'>
	<span class='_x1 jtbF jtbF-align-center'>This is an alert content....</span>
	<button onclick='$("#alert-X").jtbAlert("destroy");' class='jtbButton jtbButton-xs'>I understand</button>
</div>
                

Copyright © 2024 JTBLabs - All rights reserved.