import type { Meta, StoryObj } from '@storybook/vue3' import { ref } from 'vue' import FdsSsn from './FdsSsn.vue' const meta: Meta = { title: 'FDS/Form/FdsSsn', component: FdsSsn, tags: ['autodocs'], argTypes: { label: { control: 'text' }, meta: { control: 'text' }, disabled: { control: 'boolean' }, optional: { control: 'boolean' }, valid: { control: 'select', options: [undefined, true, false, null] }, invalidMessage: { control: 'text' }, allowCoordinationNumber: { control: 'boolean' }, allowInterimNumber: { control: 'boolean' }, clearButton: { control: 'boolean' }, maxlength: { control: 'number' }, }, args: { label: 'Personnummer', meta: '', disabled: false, optional: false, valid: undefined, invalidMessage: undefined, allowCoordinationNumber: true, allowInterimNumber: true, clearButton: false, maxlength: undefined, }, } export default meta type Story = StoryObj export const Default: Story = { render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('') const ssnValid = ref(null) return { args, ssn, ssnValid } }, template: `

v-model: {{ ssn || '—' }}

valid: {{ ssnValid }}

`, }), } export const InvalidValue: Story = { args: { valid: false, }, render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('198501011234') return { args, ssn } }, template: ` `, }), } export const InvalidWithoutMessage: Story = { args: { valid: false, invalidMessage: '', }, render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('198501011234') return { args, ssn } }, template: ` `, }), } export const ValidPersonnummer: Story = { render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('198507099805') return { args, ssn } }, template: ` `, }), } export const CoordinationNumber: Story = { args: { allowCoordinationNumber: true, }, render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('198506698805') const ssnValid = ref(null) return { args, ssn, ssnValid } }, template: `

valid: {{ ssnValid }}

`, }), } export const InterimNumber: Story = { args: { allowInterimNumber: true, }, render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('19850709T125') const ssnValid = ref(null) return { args, ssn, ssnValid } }, template: `

valid: {{ ssnValid }}

`, }), } export const WithClearButton: Story = { args: { clearButton: true, maxlength: 12, }, render: (args) => ({ components: { FdsSsn }, setup() { const ssn = ref('198507099805') const ssnValid = ref(null) const cleared = ref(false) const clearInput = () => { cleared.value = true } return { args, ssn, ssnValid, cleared, clearInput } }, template: `

v-model: {{ ssn || '—' }}

valid: {{ ssnValid }}

cleared: {{ cleared }}

`, }), }