@pikas-ui/toast

This package contains a toast component that can be used to display notifications.

This library is based on Radix Ui.

Change Log

Requirements

To use this package, you must install the @pikas-ui/styles package.

Installation

You can install this package using npm, yarn, or pnpm.

npm install @pikas-ui/toast
yarn add @pikas-ui/toast
pnpm add @pikas-ui/toast

Usage

ToastProvider

This component is used to provide the toast context.

Props

PropDescriptionTypeDefault
childrenThe content of the component.ReactNode-
durationThe duration of the toast.number5000
labelThe label of the toast provider.string"Notification'
cssThe css of the toast provider.PikasCSS-
swipeThresholdThe swipe threshold of the toast.number-
widthThe width of the toast.number400
positionThe position of the toast.ToastPosition"top'
closeWithSwipeEnable or disable the swipe to close.booleantrue
viewportThe viewport of the toast provider.ToastProviderViewport{ hotkey: ['F8'], label: 'Notifications ({hotkey})' }

Toast

This component is used to display a toast. It is used by the useToast hook.

    import { Toast, useToast, ToastProvider } from '@pikas-ui/toast';
    
    const Child: React.FC = () => {
      const toast = useToast();
    
      const handleClick = () => {
        toast.publish(
          <Toast title="Title" description="Description" variant="success" />
        );
      };
    
      return <button onClick={handleClick}>Show toast</button>;
    };
    
    const Parent: React.FC = () => {
      return (
        <ToastProvider position="top-right">
          <Child />
        </ToastProvider>
      );
    };
    

    Props

    PropDescriptionTypeDefault
    cssCustom css of the custom toastDefaultToastCSS-
    childrenChildren of the custom toastReactNode-
    durationDuration of the custom toastnumber5000
    onOpenChangeCallback when the custom toast is open or close(open: boolean) => void-
    actionAction of the custom toastToastAction-
    typeType of the custom toastToastType"foreground"
    onEscapeKeyDownCallback when the custom toast is escape key down(event: KeyboardEvent) => void-
    onSwipeStartCallback when the custom toast is swipe start(event: SwipeEvent) => void-
    onSwipeMoveCallback when the custom toast is swipe move(event: SwipeEvent) => void-
    onSwipeEndCallback when the custom toast is swipe end(event: SwipeEvent) => void-
    onPauseCallback when the custom toast is pause() => void-
    onResumeCallback when the custom toast is resume() => void-
    forceMountForce mount the custom toasttrue or undefined-
    hasCloseButtonHas close button the custom toastboolean-
    timerHas timer the custom toastbooleantrue
    titleTitle of the custom toaststring-
    descriptionDescription of the custom toaststring-
    variantVariant of the custom toastToastVariant"info"
    widthWidth of the custom toastnumber or string"auto"
    maxWidthMax width of the custom toastnumber or string"100%"
    heightHeight of the custom toastnumber or string"auto"

    DefaultToast

    This component is used to display a default toast. It is used by the useToast hook.

                import { DefaultToast, useToast, ToastProvider } from '@pikas-ui/toast';
                import type { IconProps } from '@pikas-ui/icons';
                import { IconByName } from '@pikas-ui/icons';
                
                const IconExample: React.FC<IconProps> = (props) => {
                  return <IconByName {...props} name="bx:baguette" />;
                };
                
                const Child: React.FC = () => {
                  const toast = useToast();
                
                  const handleClick = () => {
                    toast.publish(
                      <DefaultToast
                        title="Title"
                        description="Description"
                        Icon={IconExample}
                      />
                    );
                  };
                
                  return <button onClick={handleClick}>Show toast</button>;
                };
                
                const Parent: React.FC = () => {
                  return (
                    <ToastProvider position="top-right">
                      <Child />
                    </ToastProvider>
                  );
                };
                

                Props

                PropDescriptionTypeDefault
                cssCustom css of the custom toastDefaultToastCSS-
                childrenChildren of the custom toastReactNode-
                durationDuration of the custom toastnumber5000
                onOpenChangeCallback when the custom toast is open or close(open: boolean) => void-
                actionAction of the custom toastToastAction-
                typeType of the custom toastToastType"foreground"
                onEscapeKeyDownCallback when the custom toast is escape key down(event: KeyboardEvent) => void-
                onSwipeStartCallback when the custom toast is swipe start(event: SwipeEvent) => void-
                onSwipeMoveCallback when the custom toast is swipe move(event: SwipeEvent) => void-
                onSwipeEndCallback when the custom toast is swipe end(event: SwipeEvent) => void-
                onPauseCallback when the custom toast is pause() => void-
                onResumeCallback when the custom toast is resume() => void-
                forceMountForce mount the custom toasttrue or undefined-
                hasCloseButtonHas close button the custom toastboolean-
                timerHas timer the custom toastbooleantrue
                titleTitle of the custom toaststring-
                descriptionDescription of the custom toaststring-
                IconIcon of the custom toastFC<IconProps>-
                widthWidth of the custom toastnumber or string"auto"
                maxWidthMax width of the custom toastnumber or string"100%"
                heightHeight of the custom toastnumber or string"auto"

                CustomToast

                This component is used to display a custom toast. It is used by the useToast hook.

                            import { CustomToast, useToast, ToastProvider } from '@pikas-ui/toast';
                            
                            const Child: React.FC = () => {
                              const toast = useToast();
                            
                              const handleClick = () => {
                                toast.publish(<CustomToast>Hello world</CustomToast>);
                              };
                            
                              return <button onClick={handleClick}>Show toast</button>;
                            };
                            
                            const Parent: React.FC = () => {
                              return (
                                <ToastProvider position="top-right">
                                  <Child />
                                </ToastProvider>
                              );
                            };
                            

                            Props

                            PropDescriptionTypeDefault
                            cssCustom css of the custom toastCustomToastCSS-
                            childrenChildren of the custom toastReactNode-
                            durationDuration of the custom toastnumber5000
                            onOpenChangeCallback when the custom toast is open or close(open: boolean) => void-
                            actionAction of the custom toastToastAction-
                            typeType of the custom toastToastType"foreground"
                            onEscapeKeyDownCallback when the custom toast is escape key down(event: KeyboardEvent) => void-
                            onSwipeStartCallback when the custom toast is swipe start(event: SwipeEvent) => void-
                            onSwipeMoveCallback when the custom toast is swipe move(event: SwipeEvent) => void-
                            onSwipeEndCallback when the custom toast is swipe end(event: SwipeEvent) => void-
                            onPauseCallback when the custom toast is pause() => void-
                            onResumeCallback when the custom toast is resume() => void-
                            forceMountForce mount the custom toasttrue or undefined-
                            hasCloseButtonHas close button the custom toastboolean-
                            timerHas timer the custom toastbooleantrue
                            widthWidth of the custom toastnumber or string"auto"
                            maxWidthMax width of the custom toastnumber or string"100%"
                            heightHeight of the custom toastnumber or string"auto"

                            Contributing

                            This documentation can be edited on GitHub here