Toast
Display a brief notification.
#
Documentation
#
#
Usage
#
Use toaster.create()
along with the Toast
component to add toasts.
import { Button, Toast, ToastTitle, toaster } from "@optiaxiom/react";
export function App() {
return (
<Button
onClick={() =>
toaster.create(
<Toast>
<ToastTitle>This is an example toast message.</ToastTitle>
</Toast>,
)
}
>
Create Toast
</Button>
);
}
#
Appearance
#
Use the colorScheme
prop to select between the different toast types.
import type { ComponentPropsWithRef } from "react";
import { Button, Toast, ToastTitle, toaster } from "@optiaxiom/react";
export function App({
colorScheme,
}: Pick<ComponentPropsWithRef<typeof Toast>, "colorScheme">) {
return (
<Button
onClick={() =>
toaster.create(
<Toast colorScheme={colorScheme}>
<ToastTitle>This is an example toast message.</ToastTitle>
</Toast>,
)
}
>
Create Toast
</Button>
);
}
#
Action
#
Use the ToastAction
component to include a short action button associated with the toast.
Task is in-progress
import {
Button,
Flex,
Text,
Toast,
ToastAction,
ToastTitle,
toaster,
} from "@optiaxiom/react";
import { IconTrash } from "@tabler/icons-react";
import { useState } from "react";
export function App() {
const [status, setStatus] = useState("in-progress");
return (
<Flex flexDirection="row">
<Text w="144">Task is {status}</Text>
<Button
appearance="danger-outline"
disabled={status === "deleted"}
icon={<IconTrash />}
onClick={() => {
setStatus("deleted");
toaster.create(
<Toast>
<ToastTitle>Task Deleted</ToastTitle>
<ToastAction
altText="Undo"
onClick={() => setStatus("in-progress")}
>
Undo
</ToastAction>
</Toast>,
);
}}
>
Delete
</Button>
<Button
disabled={status !== "deleted"}
onClick={() => setStatus("in-progress")}
>
Restore
</Button>
</Flex>
);
}
#
Props
#
#
Toast
#
Supports all Box props in addition to its own.
Name | Type |
---|---|
asChild |
|
colorScheme |
|
defaultOpen |
|
duration |
Time in milliseconds that toast should remain visible for. Overrides value
given to |
forceMount |
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. |
onEscapeKeyDown |
|
onOpenChange |
|
onPause |
|
onResume |
|
onSwipeCancel |
|
onSwipeEnd |
|
onSwipeMove |
|
onSwipeStart |
|
open |
|
type |
|
#
ToastTitle
#
Supports all Box props in addition to its own.
Name | Type |
---|---|
asChild |
|
#
ToastAction
#
Supports all Box props in addition to its own.
Name | Type |
---|---|
altText* |
A short description for an alternate way to carry out the action. For screen reader users who will not be able to navigate to the button easily/quickly. |
asChild |
|
#
ToastProvider
#
Name | Type |
---|---|
asChild |
|
container |
|
duration |
Time in milliseconds that each toast should remain visible for. @defaultValue 5000 |
hotkey |
The keys to use as the keyboard shortcut that will move focus to the toast viewport. @defaultValue [‘F8’] |
label |
An author-localized label for each toast. Used to help screen reader users associate the interruption with a toast. @defaultValue ‘Notification’ |
swipeDirection |
Direction of pointer swipe that should close the toast. @defaultValue ‘right’ |
swipeThreshold |
Distance in pixels that the swipe must pass before a close is triggered. @defaultValue 50 |
toaster |
An instance of toaster returned from the |
#
Changelog
#
#
0.1.0
#
- Added component