import { useState } from 'react'; import { Title, Subtitle, Description, Stories } from '@storybook/addon-docs/blocks'; import { Meta, StoryObj } from '@storybook/react-webpack5'; import { action } from 'storybook/actions'; import { InfoCircle, Documents, Warning, Home, Globe, People, Link as LinkIcon, } from '@transferwise/icons'; import { lorem10, lorem100, lorem20, lorem5 } from '../../test-utils'; import Modal from '../../modal'; import Link from '../../link'; import List from '../../list'; import Popover from '../../popover'; import { SnackbarConsumer, type SnackbarContextType } from '../../snackbar/SnackbarContext'; import SnackbarProvider from '../../snackbar/SnackbarProvider'; import Tooltip from '../../tooltip'; import { Position } from '../../common'; import { ListItem, type ListItemProps } from '../ListItem'; import { storySourceWithoutNoise } from './helpers'; import { SB_LIST_ITEM_ADDITIONAL_INFO as INFO, SB_LIST_ITEM_CONTROLS as CONTROLS, SB_LIST_ITEM_MEDIA as MEDIA, SB_LIST_ITEM_PROMPTS as PROMPTS, } from './subcomponents'; export default { component: ListItem, title: 'Content/ListItem/Common Scenarios', tags: ['autodocs'], args: { title: lorem5, subtitle: lorem10, media: MEDIA.image, additionalInfo: INFO.nonInteractive, prompt: PROMPTS.interactive, control: CONTROLS.button, }, parameters: { docs: { page: () => ( <> Common scenarios ), }, }, } satisfies Meta; type Story = StoryObj; /** * Aside from using the main control for triggering a [Modal](?path=/docs/dialogs-modal--docs), * it's also possible to toggle it via inline-button as part of the `` * or ``. */ export const WithModals: Story = storySourceWithoutNoise({ parameters: { controls: { disable: true }, }, render: function WithModals(listItemProps) { const [isModalOpen, setIsModalOpen] = useState(false); const handleOpening = () => { setIsModalOpen(true); action('Modal opening')(); }; const handleClosing = () => { setIsModalOpen(false); action('Modal closing')(); }; return ( Open modal } additionalInfo={ This is additional information that contains a } prompt={ {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} This prompt also has a button that opens a modal {' '} for your convenience. } /> ); }, }); /** * The control or inline buttons can trigger a [Popover](?path=/docs/dialogs-popover--docs). */ export const WithPopover: Story = { parameters: { controls: { disable: true }, }, render: (listItemProps) => { return ( } prompt={PROMPTS.nonInteractive} /> ); }, }; /** * The control or inline buttons can trigger a [Tooltip](?path=/docs/dialogs-tooltip--docs). */ export const WithTooltip: Story = { parameters: { controls: { disable: true }, }, render: (listItemProps) => { return ( } prompt={PROMPTS.nonInteractive} /> ); }, }; /** * ListItem is often used as a simple copy and paste button augmented with a [Snackbar](?path=/docs/dialogs-snackbar--docs).
* * **NB** The snippet below uses a simplified example implementation of a clipboard handler, * which may not be suitable or sufficient for your needs. */ export const CopyAndPasteWithSnackbar: Story = storySourceWithoutNoise({ parameters: { controls: { disable: true }, }, args: { prompt: undefined, additionalInfo: undefined, }, render: function CopyAndPaste(listItemProps) { const title = 'Artie Choke'; const subtitle = 'Account holder'; const handleCopy = async (createSnackbar: SnackbarContextType['createSnackbar']) => navigator.clipboard .writeText(`${subtitle}: ${title}`) .catch((err) => { console.error('Failed to copy text: ', err); }) .then(() => { createSnackbar({ text: `${subtitle} copied to clipboard.`, }); }); return ( {({ createSnackbar }) => { return ( handleCopy(createSnackbar)} > ); }} } media={ } /> ); }, }); export const Summary: Story = storySourceWithoutNoise({ parameters: { docs: { canvas: { sourceState: 'shown', }, }, }, render: function Summary() { return ( } control={ } /> } /> } additionalInfo={ console.log('hello') }} /> } /> } additionalInfo={ console.log('hello') }} /> } control={ } /> } /> } /> ); }, });