From 692b4a817d141b7084e1d767b3010ccf4cb4a002 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Fri, 5 Jan 2024 11:55:00 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D(react)=20add=20Toast=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With various examples and how-to guides. --- .../react/src/components/Toast/DocUtils.tsx | 30 ++++++ packages/react/src/components/Toast/index.mdx | 97 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 packages/react/src/components/Toast/DocUtils.tsx create mode 100644 packages/react/src/components/Toast/index.mdx diff --git a/packages/react/src/components/Toast/DocUtils.tsx b/packages/react/src/components/Toast/DocUtils.tsx new file mode 100644 index 0000000..c134e9d --- /dev/null +++ b/packages/react/src/components/Toast/DocUtils.tsx @@ -0,0 +1,30 @@ +import { ReactNode } from "react"; +import { ToastType } from ":/components/Toast/ToastProvider"; +import { ButtonProps } from ":/components/Button"; + +/** + * This function is used for doc purpose only. + */ +export const toast = ({ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + message, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + type, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + options, +}: { + /** Message displayed inside the toast */ + message: string; + /** Type of the toast */ + type?: ToastType; + /** Various options */ + options?: { + duration: number; + icon?: ReactNode; + primaryLabel?: string; + primaryOnClick?: ButtonProps["onClick"]; + primaryProps?: ButtonProps; + }; +}) => { + return {}; +}; diff --git a/packages/react/src/components/Toast/index.mdx b/packages/react/src/components/Toast/index.mdx new file mode 100644 index 0000000..679fd47 --- /dev/null +++ b/packages/react/src/components/Toast/index.mdx @@ -0,0 +1,97 @@ +import { Canvas, Meta, Story, Source, ArgTypes } from '@storybook/blocks'; +import * as Stories from './index.stories'; +import { toast } from './DocUtils'; +import { ToastProvider } from './ToastProvider'; +import { Toast } from './index'; + + + +# Toast + +Cunningham provides a powerful Toast component for displaying any kind of information for a defined amount of time. + + + +## Usage + +Toasts are really simple to use, you need to wrap your app inside `CunninghamProvider`. + + ( + + + +); + `} +/> + +And then simply use the `toast` function from `useToastProvider` hook. + + { + const { toast } = useToastProvider(); + + return ( + + ); +}; +`}/> + +You can also customize the appearance of the toast with the `toast` function. See the API. + + + +## Type + +Toast can be of different types, each type has a different color and icon. + + + + + + + +## Actions + +You can quickly add an action to your toast by passing `primaryLabel` and `primaryOnClick` props to the `toast` function. + + + +## Customize + +You can customize the appearance of the toast by passing `actions` when calling `toast` function. + + + +## Props + +These are the props of `Toast` component which you might not need to create by yourself as the `toast` function does all +the heavy lifting for you. + + + +## Design tokens + +Here a the custom design tokens defined by the Toast. + +| Token | Description | +|--------------- |----------------------------- | +| slide-in-duration | Time the toast takes to slide in | +| slide-out-duration | Time the toast takes to slide out | +| background-color | Default background color | +| color | Color of the content | +| font-weight | Font weight of the content | +| icon-size | Size of the left icon | +| progress-bar-height | Height of the progress bar |