インポート
コードをコピー
import { ToastProvider, useToast } from '@k8ordo/ui';使い方
基本的な使い方
縦書きプレビューに切り替え
コードをコピー
<ToastProvider>
<ToastDemo />
</ToastProvider>
function ToastDemo() {
const { open } = useToast();
return (
<div className={styles.actions}>
<Button onClick={() => open('success', 'Operation completed')}>
Success
</Button>
<Button onClick={() => open('info', 'Here is some information')}>
Info
</Button>
<Button onClick={() => open('warning', 'Please check your input')}>
Warning
</Button>
<Button onClick={() => open('error', 'Something went wrong')}>
Error
</Button>
</div>
);
}useToast
コードをコピー
const { open, close, closeAll } = useToast();
// Show a toast
open('success', 'Saved successfully');
// Close a specific toast by the ID open returned
const toastId = open('info', 'Syncing…', {
duration: Number.POSITIVE_INFINITY,
});
close(toastId);
// Close all toasts
closeAll();closeAll
縦書きプレビューに切り替え
コードをコピー
function CloseAllDemo() {
const { open, closeAll } = useToast();
return (
<div className={styles.actions}>
<Button onClick={() => open('info', 'Notification 1')}>
Add Toast
</Button>
<Button onClick={() => open('success', 'Notification 2')}>
Add Another
</Button>
<Button onClick={closeAll}>Close All</Button>
</div>
);
}Props
ToastProvider
children?- Type:
ReactNode - Default: -
portalRef?- Type:
RefObject<HTMLElement | null> - Default:
null position?- Type:
'fixed'|'absolute' - Default:
'fixed'
| Prop | Type | Default |
|---|---|---|
children? | ReactNode | - |
portalRef? | RefObject<HTMLElement | null> | null |
position? | 'fixed'|'absolute' | 'fixed' |
useToast
open- Type:
(tone: Status, message: string, options?: ToastOptions) => string - Default: -
close- Type:
(id: string) => void - Default: -
closeAll- Type:
() => void - Default: -
| Prop | Type | Default |
|---|---|---|
open | (tone: Status, message: string, options?: ToastOptions) => string | - |
close | (id: string) => void | - |
closeAll | () => void | - |