Toast
A toast inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom of the screen. They shouldn't interrupt the user experience, and they don't require user input to disappear.
| Install | yarn add @diallink-corp/convergo-react-toast |
|---|---|
| Version | 4.1.2 |
| Usage | import {Toast} from '@diallink-corp/convergo-react-toast' |
Example
To start using toasts you need to render a toast container at the root of your app:
<ToastContainer />
<ToastContainer />
<ToastContainer />
Then, you can queue a toast from anywhere:
<Button
onPress={() => ToastQueue.positive('Toast is added!')}
color="primary">
Show toast
</Button>
<Button
onPress={() => ToastQueue.positive('Toast is added!')}
color="primary">
Show toast
</Button>
<Button
onPress={() =>
ToastQueue
.positive(
'Toast is added!'
)}
color="primary"
>
Show toast
</Button>
Content
You can trigger a toast using any of the methods from ToastQueue. A <ToastContainer> element must be rendered at the root of your app in order for it to display the queued toasts.
Toasts are shown according to a priority queue, depending on their variant. Actionable toasts are prioritized over non-actionable toasts, and errors are prioritized over other types of notifications. Only one toast will be displayed at a time.
<ButtonGroup>
<Button
onPress={() => ToastQueue.neutral('Toast available')} color="primary">
Neutral Toast
</Button>
<Button
onPress={() => ToastQueue.positive('Toast is done!')} color="secondary">
Positive Toast
</Button>
<Button
onPress={() => ToastQueue.negative('Toast is burned!')} color="danger">
Negative Toast
</Button>
<Button
onPress={() => ToastQueue.info('Toasting…')} color="primary"
variant="outlined">
Info Toast
</Button>
</ButtonGroup>
<ButtonGroup>
<Button
onPress={() => ToastQueue.neutral('Toast available')} color="primary">
Neutral Toast
</Button>
<Button
onPress={() => ToastQueue.positive('Toast is done!')} color="secondary">
Positive Toast
</Button>
<Button
onPress={() => ToastQueue.negative('Toast is burned!')} color="danger">
Negative Toast
</Button>
<Button
onPress={() => ToastQueue.info('Toasting…')} color="primary"
variant="outlined">
Info Toast
</Button>
</ButtonGroup>
<ButtonGroup>
<Button
onPress={() =>
ToastQueue
.neutral(
'Toast available'
)} color="primary"
>
Neutral Toast
</Button>
<Button
onPress={() =>
ToastQueue
.positive(
'Toast is done!'
)} color="secondary"
>
Positive Toast
</Button>
<Button
onPress={() =>
ToastQueue
.negative(
'Toast is burned!'
)} color="danger"
>
Negative Toast
</Button>
<Button
onPress={() =>
ToastQueue.info(
'Toasting…'
)} color="primary"
variant="outlined"
>
Info Toast
</Button>
</ButtonGroup>
API
| Method | Description |
neutral(
(children: ReactNode,
, options: ToastOptions
)): CloseFunction | Queues a neutral toast. |
positive(
(children: ReactNode,
, options: ToastOptions
)): CloseFunction | Queues a positive toast. |
negative(
(children: ReactNode,
, options: ToastOptions
)): CloseFunction | Queues a negative toast. |
info(
(children: ReactNode,
, options: ToastOptions
)): CloseFunction | Queues an informational toast. |
A ToastContainer renders the queued toasts in an application. It should be placed at the root of the app.
ToastContainerProps