Snackbar
Snackbar (also known as toasts) are used for brief notifications of processes that have been or will be performed.
The Snackbar component appears themporarily and floats above the UI to provide users with(non-critical) updates on an app’s processes. The demo below inspired by Google keep, shows a basic Snackbar with a text element and two actions:
Preview
Usage
import { Snackbar } from 'archi-ui'
<Snackbar
message='Basic Snackbar'
open={true}
/>
Automatic dismiss
Use the autoHideDuration
prop to automatically trigger the Snackbar’s onClose
function after a set period of time (in milliseconds).
Preview
Customization
Use with Alerts
Use the Alert inside a Snackbar for messages that communicate a certain severity.
Preview
Snackbar with Action
To add the actions to the snackbar use action
prop. If want to add multiple actions, use React.Fragment
.
Preview
Positions
Use the anchorOrigin
prop to control the snackbar’s position on the screen.
When displaying multiple consecutive snackbars using a single parent-rendered <Snackbar />
, add the key
prop to ensure independent treatment of each message. For instance, use <Snackbar key={message} />
. Otherwise, messages might update in place, and features like autoHideDuration
could be affected.
Preview
Snackbar API
API reference docs for the React Snackbar component.
Props
Name | Type | Default | Description |
---|---|---|---|
children | node | - | The content of the component. |
className | string | - | Override or extend the styles applied to the component |
open | bool | - | If true, the component is shown. |
message | node | - | The message to display. |
onClose | func | - | Callback fired when the component requests to be closed. Typically onClose is used to set state in the parent component, which is used to control the Snackbar open prop. Signature: function() => void |
autoHideDuration | number | null | The number of milliseconds to wait before automatically calling the onClose function. onClose should then set the state of the open prop to hide the snackbar. This behavior is disabled by default with the null value. |
action | node | - | The action to display. It renders after the message, at the end of the snackbar. |
anchorOrigin | { horizontal: 'center'|'left'|'right', vertical: 'bottom'|'top' } | { vertical:'bottom', horizontal:'left' } | The anchor of the Snackbar. On smaller screens, the component grows to occupy all the available width, the horizontal alignment is ignored. |
key | any | - | When displaying multiple consecutive snackbars using a single parent-rendered <Snackbar /> , add the key prop to ensure independent treatment of each message. For instance, use <Snackbar key={message} /> . Otherwise, messages might update in place, and features like autoHideDuration could be affected. |