import type { Meta, StoryObj } from '@storybook/vue3-vite' import { ref } from 'vue' import CpSwitch from '@/components/CpSwitch.vue' import { docCellStyle, docLabelStyle, docRowWrapStyle } from '@/stories/documentationStyles' const switchColors = ['blue', 'purple'] as const const meta = { title: 'Atoms/CpSwitch', component: CpSwitch, argTypes: { autofocus: { control: 'boolean', description: 'Whether to autofocus the switch', }, color: { control: 'select', options: switchColors, description: 'Color variant of the switch', }, disabled: { control: 'boolean', description: 'Whether the switch is disabled', }, groupName: { control: 'text', description: 'Name attribute for the switch', }, helper: { control: 'text', description: 'Helper text to display below the label', }, isRequired: { control: 'boolean', description: 'Whether the switch is required', }, label: { control: 'text', description: 'Label text for the switch', }, modelValue: { control: 'boolean', description: 'The switch state', }, reverseLabel: { control: 'boolean', description: 'Whether to show label before the switch', }, tooltip: { control: 'text', description: 'Tooltip text to display', }, }, } satisfies Meta export default meta type Story = StoryObj /** * Default switch. Use the controls to experiment with each prop in isolation. */ export const Default: Story = { args: { label: 'Label', helper: '', disabled: false, color: 'purple', reverseLabel: false, autofocus: false, isRequired: true, tooltip: '', }, render: (args) => ({ components: { CpSwitch }, setup() { const value = ref(false) return { args, value } }, template: `
`, }), } /* -------------------------------------------------------------------------- */ /* States */ /* -------------------------------------------------------------------------- */ /** * Off, on, disabled off and disabled on compared side by side. */ export const States: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpSwitch }, setup() { return { docCellStyle, docLabelStyle, docRowWrapStyle } }, template: `
Off
On
Disabled off
Disabled on
`, }), } /* -------------------------------------------------------------------------- */ /* Colors */ /* -------------------------------------------------------------------------- */ /** * Color variants rendered side by side. */ export const Colors: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpSwitch }, setup() { return { switchColors, docCellStyle, docLabelStyle, docRowWrapStyle } }, template: `
{{ color }}
`, }), } /* -------------------------------------------------------------------------- */ /* Sizes */ /* -------------------------------------------------------------------------- */ /** * The switch inherits its size from the font-size of its container. Wrap it * inside a `transform: scale()` to obtain smaller or larger switches. */ export const Sizes: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpSwitch }, setup() { const values = ref({ sm: false, md: true, lg: false, }) return { values } }, template: `
`, }), } /* -------------------------------------------------------------------------- */ /* Variants */ /* -------------------------------------------------------------------------- */ /** * Display the label before the switch using `reverseLabel`. */ export const Reversed: Story = { args: { ...Default.args, reverseLabel: true, }, render: (args) => ({ components: { CpSwitch }, setup() { const value = ref(false) return { args, value } }, template: `
`, }), } /** * Add a helper text, a tooltip next to the label, or both. */ export const HelpAndTooltip: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpSwitch }, setup() { const values = ref({ helper: false, tooltip: false, both: false }) return { values, docCellStyle, docLabelStyle, docRowWrapStyle } }, template: `
With helper
With tooltip
With both
`, }), } /* -------------------------------------------------------------------------- */ /* Group */ /* -------------------------------------------------------------------------- */ /** * Multiple switches bound together, sharing the same `groupName`. */ export const SwitchGroup: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpSwitch }, setup() { const switches = ref({ switch1: false, switch2: true, switch3: false, switch4: false, }) return { switches } }, template: `
`, }), }