Alert

An Alert component is a UI element used to display important messages or notifications to users. It can convey different types of information such as success, warning, error, or informational messages, typically styled with distinct colors and icons to highlight the message's significance. Alerts are often used to grab the user's attention and provide immediate feedback on actions or events.

Demo

Rendered live, with the same build of the library you install.

Alert!

New version available!

Information!

New version available!

Success!

New version available!

Warning!

New version available!

Error!

New version available!

Usage

Alert.tsx
import { AlertTypes, NAlert } from '@nayan-ui/react';
const Alert = () => {
return (
<div>
<div className="space-y-3">
<NAlert type={AlertTypes.DEFAULT} message="New version available!" onClose={() => console.log('Alert closed')} />
<NAlert type={AlertTypes.INFO} message="New version available!" onClose={() => console.log('Alert closed')} />
<NAlert type={AlertTypes.SUCCESS} message="New version available!" onClose={() => console.log('Alert closed')} />
<NAlert type={AlertTypes.WARNING} message="New version available!" onClose={() => console.log('Alert closed')} />
<NAlert type={AlertTypes.ERROR} title="Error!" message="New version available!" onClose={() => console.log('Alert closed')} />
</div>
</div>
);
};
export default Alert;

Attributes

12 props
NameTypeDefaultDetails
typeAlertTypesRequiredYou can pass type of the alert.
messagestringOptionalYou can pass alert message.
titlestringOptionalYou can pass alert title.
iconReact.ReactNodeOptionalCustom icon for the alert.
actionsReact.ReactNodeOptionalCustom actions for the alert.
classNamestring' 'You can customise by passing tailwind classes.
titleClassNamestring' 'You can customise by passing tailwind classes.
messageClassNamestring' 'You can customise by passing tailwind classes.
closeClassNamestring' 'You can customise by passing tailwind classes.
onClose() => voidOptionalYou can get callback when alert got closed.
role'alert' | 'status'OptionalARIA role for accessibility.
childrenReact.ReactNodeOptionalCustom content for the alert.

Tags

Other components solving nearby problems.