Alert
Alert messages are meant to provide contextual feedback about important changes in the interface. They are used to convey essential information to the user, ensuring that critical updates or warnings are immediately noticeable.
Name | Type | Description | Default | |
---|---|---|---|---|
closable | boolean | If true, the alert will have a close button that will remove the message from the alert, only in banner and inline modes. The rest of the functionality will depend on the onClose event of each message (e.g. closing the modal alert). | true | |
message | Message | Message[] being {
onClose?: () => void;
text: React.ReactNode;
} | List of messages to be displayed. Each message has a close action that will, apart from remove from the alert the current message, call the onClose if it is defined. If the message is an array, the alert will show a navigation bar to move between the messages. The modal mode only allows one message per alert. In this case, the message must be an object and the presence of the onClose attribute is mandatory, since the management of the closing of the alert relies completely on the user. | - | |
mode | 'inline' | 'modal' | 'banner' | The mode of the alert. The possible values are:
| 'inline' | |
primaryAction | {
icon?: (React.ReactNode
& React.SVGProps<SVGSVGElement>);
label: string;
onClick: () => void;
} | Primary action of the alert. | - | |
secondaryAction | {
icon?: (React.ReactNode
& React.SVGProps<SVGSVGElement>);
label: string;
onClick: () => void;
} | Secondary action of the alert. | - | |
semantic | 'error' | 'info' | 'success' | 'warning' | Specifies the semantic meaning of the alert. | 'info' | |
Required title | string | Title of the alert. | - |
() => { return ( <DxcInset space="2rem"> <DxcFlex direction="column" gap="1.5rem"> <DxcAlert title="Auto-saved document" message={{ text: "Your document as been auto-saved. You can continue working without worry, as all changes are being saved automatically." }} /> <DxcAlert title="Read carefully" semantic="warning" message={{ text: "Please read the documents carefully before the submission of the data." }} /> <DxcAlert title="Save failed" semantic="error" message={{ text: "You have unsaved changes in your document. If you navigate away from this page, you will lose any changes you have made." }} /> <DxcAlert title="Saved successfully" semantic="success" message={{ text: "Your document has been saved successfully." }} /> </DxcFlex> </DxcInset> ); }
() => { const messages = [ { text: "Your document as been auto-saved." }, { text: "You can continue working without worrying, as all changes are automatically saved." }, { text: "You can also go back to the previous version of the document." }, ]; return ( <DxcInset space="2rem"> <DxcFlex direction="column" gap="1.5rem"> <DxcAlert title="Auto-saved document" message={messages} primaryAction={{ label: "Continue", onClick: () => {} }} secondaryAction={{ label: "Back", onClick: () => {} }} /> </DxcFlex> </DxcInset> ); }