Live example
Implementation
Toasts confirm when an action has happened, will happen, or when an action has failed.
Only one toast should be visible at a time. Each new toast must be displayed after the previous one. Any toast with new information can replace an old one immediately.
A standard toast will auto-dismiss. This means that it'll automatically disappear after a defined period. Toasts include a visible backwards loading bar to show how long is left before the disappear.
Add ToastsContainer to your App.
import { ToastContainer } from '@ovotech/element'; // @ovotech/element-native for RN, it has almost same API!
export default App() {
return (
//... rest of the app
<ToastsContainer/>
)
}
Call showToast with needed options.
import { showToast } from '@ovotech/element'; // @ovotech/element-native for RN
export default PasswordResetSuccess() {
useEffect(() => {
showToast({ message: "New password saved" })
}, []);
return (
//... rest of the component
)
}
Properties
ToastsContainer
|
Name |
Values |
Default |
|---|---|---|
|
position |
'bottom-right' | 'top-right' |
'bottom-right’ |
|
reverseOrder |
boolean |
false |
|
gutter (px) |
number |
8 |
showToast
|
Name |
Values |
Default |
|---|---|---|
|
actionTitle |
string |
|
|
bottomOffset |
string |
|
|
dismissible |
boolean |
false |
|
duration (ms) |
number |
5000 |
|
iconLeft |
Extract<IconName, 'check-circle' | 'info'> |
|
|
iconColor |
string |
|
|
message |
string |
|
|
variant |
DEPRECATED |
'default' |
Native Properties
ToastContainer
|
Name |
Values |
Default |
|---|---|---|
|
top |
number |
-80 |
|
left |
number |
|
|
right |
number |
|
|
horizontalInset |
number |
|
|
inModal |
boolean |
false |
|
ComponentProps<typeof Toasts> |
(e.g. providerKey for rendering in modals) |
showToast
|
Name |
Values |
Default |
|---|---|---|
|
message (required) |
string |
|
|
dismissible |
boolean |
false |
|
action |
Function (): void |
|
|
actionTitle |
string |
|
|
duration |
number (ms) |
5000 (ignored when action or dismissible are set) |
|
bottomOffset |
number |
|
|
IconLeft |
Extract<IconName, 'check-circle' | 'info'> |
|
|
iconColor |
string |
|
|
providerKey |
string |
|
|
variant |
DEPRECATED |
|
|
inlineContent |
DEPRECATED |
|
Composition
- Icon
- Heading
- Close button
- Link
- Timer bar
- Dismissible
- Non-dismissible
|
Tokens |
|
|---|---|
|
Background colour |
color.alert.info |
|
Timer bar colour |
color.brand.fixed.dark opacity.transparent |
|
Text and action colour |
color.brand.onbrand |
|
Dismiss icon colour |
color.button.surface.fg |
|
Dismiss button colour |
color.button.surface.bg |
|
Text font weight |
font.family.bold |
|
Action font weight |
font.family.book |
|
Text line height |
font.lineheight.md |
|
Border radius |
border.radius.lg |
|
Padding |
space-100 space-200 space-400 |