@k8ordo/ui

Toast

画面の下に一時的に出る通知です。useToastのopenで表示します。

インポート

ts
import { ToastProvider, useToast } from '@k8ordo/ui';

使い方

基本的な使い方

tsx
<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

tsx
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

tsx
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'
PropTypeDefault
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: -
PropTypeDefault
open(tone: Status, message: string, options?: ToastOptions) => string-
close(id: string) => void-
closeAll() => void-
k8ordo

Baselineに入った機能を、制限なく使うReactのライブラリ群。