import { InformationIcon } from '@blocksuite/icons/rc'; import type { Meta, StoryFn } from '@storybook/react'; import type { ReactNode } from 'react'; import { useCallback, useState } from 'react'; import { Button } from '../button'; import { Tooltip } from '../tooltip'; import type { MenuItemProps, MenuProps } from './index'; import { Menu, MenuIcon, MenuItem, MenuSeparator, MenuSub, MenuTrigger, } from './index'; export default { title: 'UI/Menu', component: Menu, } satisfies Meta; const Template: StoryFn = args => ( menu trigger ); interface Items { label: ReactNode; type?: MenuItemProps['type']; preFix?: MenuItemProps['preFix']; disabled?: boolean; divider?: boolean; subItems?: Items[]; block?: boolean; } const items: Items[] = [ { label: 'default menu item 1', }, { label: 'menu item with icon', preFix: ( ), }, { label: ( Write, Draw, and Plan All at Once Notion Open Source Alternative One hyper-fused platform for wildly creative minds ), block: true, }, { label: 'default disabled menu item', disabled: true, }, { label: 'danger menu item', type: 'danger', block: true, preFix: ( ), }, { label: 'warning menu item', type: 'warning', divider: true, }, { label: 'menu item with sub menu', subItems: [ { label: 'sub menu item 1', }, { label: 'sub menu item 1', }, ], }, { label: 'menu item with deep sub menu', subItems: [ { label: 'sub menu item 1', }, { label: 'sub menu with sub', subItems: [ { label: 'sub menu item 2-1', }, { label: 'sub menu item 2-2', }, ], }, ], }, ]; export const Default: StoryFn = Template.bind(undefined); const ItemRender = ({ label, divider, subItems, ...otherProps }: Items) => { const onSelect = useCallback(() => { console.log('value', label); }, [label]); if (subItems) { return ( <> ( ))} triggerOptions={otherProps} > {label} {divider ? : null} ); } return ( <> {label} {divider ? : null} ); }; Default.args = { items: items.map((props, i) => { return ; }), }; const selectList = [ { name: 'AFFiNE', value: '1' }, { name: 'blocksuite', value: '2' }, { name: 'octobase', value: '3' }, { name: 'virgo', value: '4' }, ]; const SelectItems = ({ selectedValue, onSelect, }: { selectedValue: string; onSelect: (value: string) => void; }) => { return selectList.map(({ name, value }) => ( onSelect(value)} > {name} )); }; const AsSelectTemplate: StoryFn = () => { const [value, setValue] = useState('1'); const name = selectList.find(item => item.value === value)?.name; return ( }> ); }; export const AsSelect: StoryFn = AsSelectTemplate.bind({});