The Alert component displays a callout for user attention with optional title, description, icon, and button. It supports different variants for various alert types.
Info
Renamed from Message in Gravity 12.
Usage
import { Alert } from 'components/lib';
function Component({ ...props }){
return (
<Alert
title="Success!"
description="Your operation was successful."
variant="success"
button={{ text: 'Okay', action: () => alert('You clicked me') }}
/>
);
}
Props
| Prop | Description | Required | Value |
|---|---|---|---|
| button | button object | optional | object |
| className | custom styles | optional | SCSS or Tailwind object |
| description | description text | optional | string |
| icon | override the variant icon | optional | string |
| title | title text | optional | string |
| variant | alert type | optional | string (info/success/warning/error) |
Example
import { Alert } from 'components/lib';
function Example({ ...props }){
return (
<div>
<Alert
title='Information'
description='This is an info alert.'
variant='info'
/>
<Alert
title='Success'
description='This is a success alert.'
variant='success'
/>
<Alert
title='Warning'
description='This is a warning alert.'
variant='warning'
/>
<Alert
title='Error'
description='This is an error alert.'
variant='error'
/>
</div>
);
}
Notes
- The
Alertcomponent uses the Icon and Button components. - The
variantprop determines the styling and default icon for the alert. - Custom styles can be applied using the
classNameprop. - The
buttonprop accepts an object with button properties to render a button within the alert. - For more details, refer to the Shadcn Alert documentation.