import { html, ref, repeat } from '@microsoft/fast-element'; import { uniqueId } from '@microsoft/fast-web-utilities'; import { LabelPosition } from '../field/field.options.js'; import { type Meta, renderComponent, type StoryArgs, type StoryObj } from '../helpers.stories.js'; import { getStorybookHelpers } from '../../.storybook/wc-toolkit-helpers.js'; import type { Checkbox as FluentCheckbox } from './checkbox.js'; import { CheckboxShape, CheckboxSize } from './checkbox.options.js'; type Story = StoryObj; const { argTypes } = getStorybookHelpers('fluent-checkbox'); const storyTemplate = html>` ${story => story.checkedIndicatorContent?.()} ${story => story.indeterminateIndicatorContent?.()} `; const fieldStoryTemplate = html>` ${story => story.storyContent} `; export default { title: 'Components/Checkbox', render: renderComponent(storyTemplate), args: { disabled: false, }, argTypes, } as Meta; export const Default: Story = {}; export const Checkbox: Story = { render: renderComponent(storyTemplate), args: { id: uniqueId('checkbox-'), }, }; export const Checked: Story = { render: renderComponent(html>` ${repeat(story => story.storyContent, html>`${fieldStoryTemplate}
`)} `), args: { storyContent: [ { storyContent: storyTemplate, slot: 'input', labelPosition: LabelPosition.after, id: uniqueId('checkbox-'), checked: true, label: 'Checked (default)', }, { storyContent: storyTemplate, slot: 'input', labelPosition: LabelPosition.after, id: uniqueId('checkbox-'), checked: true, shape: CheckboxShape.circular, label: 'Checked (circular)', }, ], }, }; export const Indeterminate: Story = { render: renderComponent(html>` ${repeat(story => story.storyContent, html>`${fieldStoryTemplate}
`)} `), args: { storyContent: [ { storyContent: storyTemplate, id: uniqueId('checkbox-'), indeterminate: true, label: 'Indeterminate (default)', labelPosition: LabelPosition.after, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), indeterminate: true, label: 'Indeterminate (circular)', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, ], }, }; export const Disabled: Story = { render: renderComponent(html>` ${repeat(story => story.storyContent, html>`${fieldStoryTemplate}
`)} `), args: { storyContent: [ { storyContent: storyTemplate, id: uniqueId('checkbox-'), disabled: true, label: 'Disabled unchecked', labelPosition: LabelPosition.after, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), disabled: true, label: 'Disabled circular unchecked', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, { storyContent: storyTemplate, checked: true, disabled: true, id: uniqueId('checkbox-'), label: 'Disabled checked', labelPosition: LabelPosition.after, slot: 'input', }, { storyContent: storyTemplate, checked: true, disabled: true, id: uniqueId('checkbox-'), label: 'Disabled circular checked', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, { storyContent: storyTemplate, disabled: true, id: uniqueId('checkbox-'), indeterminate: true, label: 'Disabled indeterminate', labelPosition: LabelPosition.after, slot: 'input', }, { storyContent: storyTemplate, disabled: true, id: uniqueId('checkbox-'), indeterminate: true, label: 'Disabled circular indeterminate', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, ], }, }; export const Required: Story = { render: renderComponent(html>`
${fieldStoryTemplate}
Submit Reset
`), args: { storyContent: storyTemplate, slot: 'input', labelPosition: LabelPosition.after, id: uniqueId('checkbox-'), required: true, label: 'Check this to submit the form', }, }; export const Large: Story = { render: renderComponent(html>` ${repeat(story => story.storyContent, html>`${fieldStoryTemplate}
`)} `), args: { storyContent: [ { storyContent: storyTemplate, id: uniqueId('checkbox-'), label: 'Large checkbox', labelPosition: LabelPosition.after, size: CheckboxSize.large, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), label: 'Large circular', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, size: CheckboxSize.large, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), indeterminate: true, label: 'Large indeterminate', labelPosition: LabelPosition.after, size: CheckboxSize.large, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), indeterminate: true, label: 'Large circular indeterminate', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, size: CheckboxSize.large, slot: 'input', }, ], }, }; export const LabelBefore: Story = { render: renderComponent(fieldStoryTemplate), args: { storyContent: storyTemplate, id: uniqueId('checkbox-'), labelPosition: LabelPosition.before, label: 'Label before', slot: 'input', }, }; export const LabelWrapping: Story = { render: renderComponent(fieldStoryTemplate), args: { storyContent: storyTemplate, id: uniqueId('checkbox-'), labelPosition: LabelPosition.after, label: 'Here is an example of a checkbox with a long label and it starts to wrap to a second line', slot: 'input', }, decorators: [ story => { const storyElement = story() as HTMLElement; storyElement.style.width = '400px'; return storyElement; }, ], }; export const Circular: Story = { render: renderComponent(html>` ${repeat(story => story.storyContent, html>`${fieldStoryTemplate}
`)} `), args: { storyContent: [ { storyContent: storyTemplate, id: uniqueId('checkbox-'), label: 'Circular checkbox', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), label: 'Circular checked', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, checked: true, slot: 'input', }, { storyContent: storyTemplate, id: uniqueId('checkbox-'), indeterminate: true, label: 'Circular indeterminate', labelPosition: LabelPosition.after, shape: CheckboxShape.circular, slot: 'input', }, ], }, };