/* eslint-disable react/jsx-key */ import React, { useEffect, useState } from 'react'; import { faker } from '@faker-js/faker'; import { storybookExcludedControlParams, StoryMetaType, StoryType, } from '@lg-tools/storybook-utils'; import { StoryContext, StoryFn } from '@storybook/react'; import range from 'lodash/range'; import startCase from 'lodash/startCase'; import { Button } from '@leafygreen-ui/button'; import { css } from '@leafygreen-ui/emotion'; import { DarkModeProps } from '@leafygreen-ui/lib'; import { InlineCode, Label, Link } from '@leafygreen-ui/typography'; import { variantIcons } from './InternalToast/VariantIcon'; import { makeToast, makeToastStack } from './ToastContext/utils/makeToast'; import { InternalToast, type InternalToastProps } from './InternalToast'; import { ToastProvider, type ToastProviderProps, useToast, Variant } from '.'; const meta: StoryMetaType = { title: 'Components/Notifications/Toast', component: InternalToast, decorators: [ (Story, meta: StoryContext) => ( ), ], parameters: { default: 'LiveExample', controls: { exclude: [ ...storybookExcludedControlParams, 'as', 'title', 'description', 'dismissible', 'progress', 'variant', ], }, generate: { combineArgs: { darkMode: [false, true], description: [ undefined, 'Lorem ipsum dolor sit amet', This is a Link , ], dismissible: [true, false], variant: Object.values(Variant), progress: [0, 1], actionElement: [undefined, ], }, args: { title: 'This is a toast', className: css` position: relative; `, }, excludeCombinations: [ { progress: 1, variant: [ Variant.Success, Variant.Note, Variant.Warning, Variant.Important, ], }, { actionElement: ); })} {progressToasts && progressToasts.length > 0 && ( <> {progress}
{ const _progress = Number(e.target.value); setProgress(_progress); progressToasts.forEach(([id]) => { updateToast(id, { progress: _progress, }); }); }} type="range" id="progress" min={0} max={1} step={0.1} /> )} ); }; LiveExample.parameters = { chromatic: { disableSnapshot: true }, }; export const WithInitialToasts: StoryFn< InternalToastProps & ToastProviderProps > = (props: Partial) => { const { pushToast, clearStack } = useToast(); return (
); }; WithInitialToasts.parameters = { chromatic: { disableSnapshot: true }, }; WithInitialToasts.args = { initialValue: makeToastStack( range(6).map(_ => makeToast({ title: 'Initial toast', description: faker.lorem.lines(2), variant: faker.helpers.objectValue(Variant), }), ), ), }; export const Basic: StoryType = ( props: Partial & DarkModeProps, ) => { const { pushToast, clearStack } = useToast(); const createRandomToast = () => { const variant = props.variant || faker.helpers.objectValue(Variant); pushToast({ title: `I'm a ${variant} toast`, description: faker.lorem.lines(faker.number.int({ min: 1, max: 2 })), variant, ...props, }); }; return (
); }; Basic.parameters = { chromatic: { disableSnapshot: true }, }; export const Generated = () => {};