import { h, ref } from 'vue' import { action } from '@storybook/addon-actions' import type { Meta, StoryObj } from '@storybook/vue3' import Placeholder from 'src/components/placeholder/Placeholder.vue' import Segment from 'src/components/segment/Segment.vue' import { text } from 'src/stories/fixture' import { booleanProp, vNodeSlot } from 'src/stories/story-macro' const meta = { component: Segment, parameters: { actions: { argTypesRegex: `^(${(Segment.emits as string[])?.join('|')})$`, }, }, argTypes: { default: { ...vNodeSlot, }, disabled: { ...booleanProp, description: 'Any interaction events in the Segment are disabled', }, loading: { ...booleanProp, description: 'Show loading indicator and any interaction events in the Segment are disabled', }, raised: { ...booleanProp }, stacked: { ...booleanProp }, tallStacked: { ...booleanProp }, piled: { ...booleanProp }, attached: { ...booleanProp }, borderless: { description: 'Do not add border to Segment', ...booleanProp, }, }, args: { default: text, }, 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 Segment.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: { Segment }, props: Object.keys(argTypes), setup () { return { 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 = {} export const Disabled: Story = { args: { disabled: true, }, } export const Loading: Story = { args: { loading: true, }, } export const Borderless: Story = { args: { borderless: true, }, } export const WithPlaceholder: Story = { render: () => ({ components: { Segment, Placeholder }, template: `

Borderless

`, }), } export const Raised: Story = { args: { raised: true, }, } export const Stacked: Story = { args: { stacked: true, }, } export const TallStacked: Story = { args: { tallStacked: true, }, } export const Piled: Story = { args: { piled: true, }, } export const Colored: Story = { render: () => ({ components: { Segment }, template: ` Red Green Blue Grey `, }), } export const Attached: Story = { render: () => ({ components: { Segment }, setup: () => ({ text }), template: `
Top Middle Pink Orange Olive Violet

Raised

{{ text }} {{ text }}

Stacked

{{ text }} {{ text }}

Tall Stacked

{{ text }} {{ text }}
`, }), } export const Nested: Story = { render: () => ({ components: { Segment }, template: ` Top Nested top Nested bottom Nested top Nested bottom Bottom `, }), }