Bring attention to important information and updates with the vibrant and customizable messages in JTB_MD.
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.
In JTB_MD, there are two different ways to create and use an alert element in your project:
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.)
<!-- 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 a paragraph element in alert.
<!-- 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>
To make your alert closable, you can add .jtbAlert-closable
class to your alert element.
<!-- Default Alert (Closable) -->
<div class='jtbAlert jtbAlert-closable'>Hello! I'm a closable alert box.</div>
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.
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>
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.
<!-- Alert With Icon -->
<div class='jtbAlert'>
<i class='...'></i>
<span>Success! My precious feedback is here.</span>
</div>
Within JTB_MD, the alert component comes in two distinctive versions:
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.
<!-- 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>
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.
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 ]
.jtbAlert-purple
class..jtbAlert-blue
class..jtbAlert-aqua
class..jtbAlert-green
class..jtbAlert-lime
class..jtbAlert-yellow
class..jtbAlert-orange
class..jtbAlert-volcano
class..jtbAlert-red
class.
<!-- Example colorful jtbAlert (Yellow) -->
<div class='jtbAlert jtbAlert-yellow'>...</div>
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 ]
.jtbAlert-xs
class..jtbAlert-sm
class..jtbAlert-md
class..jtbAlert-lg
class..jtbAlert-xl
class.
<!-- Example sized jtbAlert (size = xs) -->
<div class='jtbAlert jtbAlert-xs'>...</div>
To create a borderless alert element, simply apply the .jtbAlert-borderless
class.
<!-- Borderless Alert -->
<div class='jtbAlert jtbAlert-borderless'>...</div>
To create a rectangular alert (with no border radius), apply the .jtbAlert-rect
class to your alert element.
<!-- Rectangular Alert -->
<div class='jtbAlert jtbAlert-rect'>...</div>
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.
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.
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.
<!-- 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');" |
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.
/*----- Update the alert element -----*/
$('#alertID').jtbAlert('update', {
// Parameters goes here
});
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");
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.
/*----- To Hide alerts -----*/
$("#alertID").jtbAlert("hide");
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.
/*----- To Change visibility of alert -----*/
$("#alertID").jtbAlert("toggle");
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.
/*----- To remove an alert completely -----*/
$("#alertID").jtbAlert("destroy");
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:
jtbAlert()
.
/*----- Toggle Alert and callback -----*/
$("#alertID").jtbAlert("toggle", showProcessDone);
/*------ Define showProcessDone in here -------*/
function showProcessDone(){
alert('Process done boss.');
}
jtbAlert()
.
/*----- 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.
<!-- 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>
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.
<!-- 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.