Skip to content

Alert

Alerts provide contextual feedback messages for typical user actions.

import { Alert, AlertTitle } from '@truongdq01/ui';
<Alert severity="success">
<AlertTitle>Success</AlertTitle>
Your changes have been saved.
</Alert>;
<Alert variant="standard" severity="info">Standard info</Alert>
<Alert variant="filled" severity="error">Filled error</Alert>
<Alert variant="outlined" severity="warning">Outlined warning</Alert>

Use the useAlert hook to manage the open state and accessibility properties automatically.

import { Alert, Button, useAlert } from '@truongdq01/ui';
const MyAlert = () => {
const { isOpen, close, getAlertProps, getCloseButtonProps } = useAlert({
onClose: () => console.log('Alert closed'),
});
if (!isOpen)
return <Button label="Reset Alert" onPress={() => location.reload()} />;
return (
<Alert severity="info" onClose={close} {...getAlertProps()}>
This alert is managed by a headless hook.
</Alert>
);
};
PropTypeDefaultDescription
severityerror | warning | info | successinfoThe severity of the alert
variantstandard | filled | outlinedstandardThe visual variant
onClose() => void-Callback when close icon is pressed
iconReactNode | false-Custom icon or hide icon
actionReactNode-Action element (e.g. Button)