import { ref, watch } from 'vue' import { faAlignCenter, faAlignJustify, faAlignLeft, faAlignRight, faArrowLeft, faArrowRight, faBold, faCodeBranch, faEarth, faHeart, faLanguage, faPause, faSearch, faShoppingCart, faSignOut, faStrikethrough, faUnderline, faUser, } from '@fortawesome/free-solid-svg-icons' import { action } from '@storybook/addon-actions' import type { Meta, StoryObj } from '@storybook/vue3' import Button from 'src/components/button/Button.vue' import Dropdown from 'src/components/dropdown/Dropdown.vue' import Icon from 'src/components/icon/Icon.vue' import { countryOptions, fileOptions } from 'src/stories/fixture' import omit from 'src/utils/omit' const meta = { component: Dropdown, parameters: { actions: { argTypesRegex: `^(${(Dropdown.emits as string[])?.join('|')})$`, }, }, argTypes: { default: { table: { category: 'slots', type: { summary: 'VNode' }, }, }, value: { description: 'Current selected value', control: 'text', table: { category: 'props', type: { summary: 'string' }, }, }, values: { description: 'Current selected value (when multiple is enabled)', control: 'array', table: { category: 'props', type: { summary: 'string[]' }, }, }, options: { control: 'array', table: { type: { summary: 'Sem.Option[]', detail: `type Sem.Option { value: V onClick?: (event: Event, value: V) => void text?: string description?: string hidden?: boolean disabled?: boolean divider?: boolean icon?: IconDefinition }`, }, }, }, change: { action: 'changed', table: { category: 'events', }, }, }, args: { value: 'China', options: countryOptions, }, render: (args: Record, { argTypes }) => { const attrs: Record = {} const props: Record = {} const slots: Record = {} const events: Record = {} for (const [k, argType] of Object.entries(argTypes) as any) { const v = args[k] if (k in Dropdown.props) props[k] = v else if (argType.table?.category === 'slots') slots[k] = argType else if (argType.table?.category === 'events' && v) events[k] = v else if (v) attrs[k] = v } return { components: { Dropdown }, props: Object.keys(argTypes), setup: () => ({ action, args }), template: ` args[prop] ? `:${prop}="args.${prop}"` : '').join('\n')} ${Object.keys(attrs).map(attr => args[attr] ? `:${attr}="args.${attr}"` : '').join('\n')} ${Object.keys(events).map(event => `@${event}="action('${event}')"`).join('\n')} > ${Object.entries(slots).map(([nameWithSlot, argTypes]) => ``).join('\n')} `, } }, } satisfies Meta export default meta type Story = StoryObj export const Basic: Story = { decorators: [() => ({ template: `
` })], args: { text: 'File', }, } export const Upward: Story = { decorators: [() => ({ template: `
` })], args: { text: 'File', upward: true, }, } /** * Debug mode will not close dropdown list when focusout document. * (For example, when you want to debug the element style of the dropdown list) */ export const DebugMode: Story = { decorators: [() => ({ template: `
` })], args: { text: 'File', debug: true, }, } export const Slotted: Story = { decorators: [() => ({ template: `
` })], render: () => ({ components: { Dropdown, Button }, setup: () => { const country = ref('') function onChange (option?: Sem.Option) { country.value = option?.text || '' } return { countryOptions, faLanguage, onChange, country } }, template: ` `, }), } export const Compat: Story = { decorators: [() => ({ template: `

The user is come from

`, })], args: { compat: true, text: 'China', options: countryOptions, }, }