import type { Meta, StoryObj } from '@storybook/vue3-vite' import { ref } from 'vue' import SingleSelect from './SingleSelect.vue' // SingleSelect already includes options prop, so no need to extend const meta: Meta = { title: 'Components/Input/SingleSelect', component: SingleSelect, tags: ['autodocs'], argTypes: { label: { control: 'text' }, options: { control: 'object' }, listMaxHeight: { control: 'text', description: 'Maximum height of the dropdown list' }, popoverMinWidth: { control: 'text', description: 'Minimum width of the popover' }, popoverMaxWidth: { control: 'text', description: 'Maximum width of the popover' } }, args: { label: 'Sorting Type', options: [ { name: 'Popular', value: 'popular' }, { name: 'Newest', value: 'newest' }, { name: 'Oldest', value: 'oldest' }, { name: 'A → Z', value: 'az' }, { name: 'Z → A', value: 'za' } ] } } export default meta export type Story = StoryObj const sampleOptions = [ { name: 'Popular', value: 'popular' }, { name: 'Newest', value: 'newest' }, { name: 'Oldest', value: 'oldest' }, { name: 'A → Z', value: 'az' }, { name: 'Z → A', value: 'za' } ] export const Default: Story = { render: (args) => ({ components: { SingleSelect }, setup() { const selected = ref(null) const options = args.options || sampleOptions return { selected, options, args } }, template: `

Selected: {{ selected ?? 'None' }}

` }) } export const WithIcon: Story = { render: () => ({ components: { SingleSelect }, setup() { const selected = ref('popular') const options = sampleOptions return { selected, options } }, template: `

Selected: {{ selected }}

` }) } export const Preselected: Story = { render: () => ({ components: { SingleSelect }, setup() { const selected = ref('newest') const options = sampleOptions return { selected, options } }, template: ` ` }) } export const AllVariants: Story = { render: () => ({ components: { SingleSelect }, setup() { const options = sampleOptions const a = ref(null) const b = ref('popular') const c = ref('az') return { options, a, b, c } }, template: `
` }), parameters: { controls: { disable: true }, actions: { disable: true }, slot: { disable: true } } } export const CustomMaxHeight: Story = { render: () => ({ components: { SingleSelect }, setup() { const selected = ref(null) const manyOptions = Array.from({ length: 20 }, (_, i) => ({ name: `Option ${i + 1}`, value: `option${i + 1}` })) return { selected, manyOptions } }, template: `

Small Height (10rem)

Default Height (28rem)

Large Height (32rem)

` }), parameters: { controls: { disable: true }, actions: { disable: true }, slot: { disable: true } } } export const CustomMinWidth: Story = { render: () => ({ components: { SingleSelect }, setup() { const selected1 = ref(null) const selected2 = ref(null) const selected3 = ref(null) const options = [ { name: 'A', value: 'a' }, { name: 'B', value: 'b' }, { name: 'Very Long Option Name Here', value: 'long' } ] return { selected1, selected2, selected3, options } }, template: `

Auto Width

Min Width 15rem

Min Width 25rem

` }), parameters: { controls: { disable: true }, actions: { disable: true }, slot: { disable: true } } } export const CustomMaxWidth: Story = { render: () => ({ components: { SingleSelect }, setup() { const selected1 = ref(null) const selected2 = ref(null) const selected3 = ref(null) const longOptions = [ { name: 'Short', value: 'short' }, { name: 'This is a very long option name that would normally expand the dropdown', value: 'long1' }, { name: 'Another extremely long option that demonstrates max-width constraint', value: 'long2' } ] return { selected1, selected2, selected3, longOptions } }, template: `

Auto Width

Max Width 15rem

Min 10rem Max 20rem

` }), parameters: { controls: { disable: true }, actions: { disable: true }, slot: { disable: true } } }