How to show Alerts in Lightning Component.
So today we'll learn to use alerts in lightning component. In lightning component we have multiple alerts.
1. Info Alerts
To use info alerts copy and paste below code in your component.
<div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_info" role="alert">
<span class="slds-assistive-text">info</span>
<span class="slds-icon_container slds-icon-utility-user slds-m-right_x-small" title="Description of icon when needed">
<svg class="slds-icon slds-icon_x-small" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#user"></use>
</svg>
</span>
<h2>Logged in as John Smith (johnsmith@acme.com).
<a href="javascript:void(0);">Log out</a>
</h2>
<div class="slds-notify__close">
<button class="slds-button slds-button_icon slds-button_icon-small slds-button_icon-inverse" title="Close">
<svg class="slds-button__icon" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
</svg>
<span class="slds-assistive-text">Close</span>
</button>
</div>
</div>
___________________________________________________________________________2. Warning Alerts
<div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_warning" role="alert">
<span class="slds-assistive-text">warning</span>
<span class="slds-icon_container slds-icon-utility-warning slds-m-right_x-small" title="Description of icon when needed">
<svg class="slds-icon slds-icon_x-small" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#warning"></use>
</svg>
</span>
<h2>Your browser is outdated. Your Salesforce experience may be degraded.
<a href="javascript:void(0);">More Information</a>
</h2>
<div class="slds-notify__close">
<button class="slds-button slds-button_icon slds-button_icon-small" title="Close">
<svg class="slds-button__icon" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
</svg>
<span class="slds-assistive-text">Close</span>
</button>
</div>
</div>
___________________________________________________________________________3. Error Alerts
<div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_error" role="alert">
<span class="slds-assistive-text">error</span>
<span class="slds-icon_container slds-icon-utility-error slds-m-right_x-small" title="Description of icon when needed">
<svg class="slds-icon slds-icon_x-small" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#error"></use>
</svg>
</span>
<h2>Your browser is currently not supported. Your Salesforce may be degraded.
<a href="javascript:void(0);">More Information</a>
</h2>
<div class="slds-notify__close">
<button class="slds-button slds-button_icon slds-button_icon-small slds-button_icon-inverse" title="Close">
<svg class="slds-button__icon" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
</svg>
<span class="slds-assistive-text">Close</span>
</button>
</div>
</div>
______________________________________________________________________________
You can use these alerts on click of a button or on any event you want. You just have
to use <aura:if> tag to show and hide these alerts.
Note : If the svg icons doesn't work for you so please use <lightning:icon> tag to
show icons.
Share this article with your friends if this helps you somehow.
Source : www.lightningdesignsystem.com
2 Comments
How to enable this to work? I have created my component but this is still not visible on the home page
ReplyDeleteHi Sudip, try toast event instead.
Delete