From 0f936ec0e7606cb79434d94096b6e113a7ce78eb Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 15 Dec 2023 18:35:16 +0100 Subject: refactor(stories): migrate stories to CSF3 format --- .../labelled-field/labelled-field.stories.tsx | 386 ++++++++++++++------- .../forms/radio-group/radio-group.stories.tsx | 140 ++++---- .../molecules/forms/switch/switch.stories.tsx | 99 ++++-- 3 files changed, 406 insertions(+), 219 deletions(-) (limited to 'src/components/molecules/forms') diff --git a/src/components/molecules/forms/labelled-field/labelled-field.stories.tsx b/src/components/molecules/forms/labelled-field/labelled-field.stories.tsx index 1d1af70..47ded7b 100644 --- a/src/components/molecules/forms/labelled-field/labelled-field.stories.tsx +++ b/src/components/molecules/forms/labelled-field/labelled-field.stories.tsx @@ -1,130 +1,270 @@ -import type { ComponentMeta, ComponentStory } from '@storybook/react'; -import { type ChangeEvent, useState, useCallback } from 'react'; -import { Input, Label } from '../../../atoms'; +import type { Meta, StoryObj } from '@storybook/react'; +import { type ChangeEvent, useCallback, useState } from 'react'; +import { + Checkbox, + type CheckboxProps, + Radio, + type RadioProps, + Input, + type InputProps, + type TextAreaProps, + TextArea, + Label, +} from '../../../atoms'; +import { ControlledSelect } from '../../../atoms/forms/fields/select/select.stories'; import { LabelledField } from './labelled-field'; -/** - * LabelledField - Storybook Meta - */ -export default { - title: 'Molecules/Forms/Field', +const meta = { + title: 'Molecules/Forms/Labelled Field', component: LabelledField, - argTypes: { - className: { - control: { - type: 'text', - }, - description: 'Set additional classnames to the field.', - table: { - category: 'Styles', - }, - type: { - name: 'string', - required: false, - }, - }, - field: { - control: { - type: null, - }, - description: 'A component: Checkbox, Input, Select, Radio or TextArea.', - type: { - name: 'function', - required: true, - }, - }, - label: { - control: { - type: null, - }, - description: 'A Label component.', - type: { - name: 'function', - required: true, - }, - }, - isInline: { - control: { - type: 'boolean', - }, - description: 'Should the label and the field be inlined?', - table: { - category: 'Options', - defaultValue: { summary: false }, - }, - type: { - name: 'boolean', - required: false, - }, - }, - isReversedOrder: { - control: { - type: 'boolean', - }, - description: 'Should the label and the field be reversed?', - table: { - category: 'Options', - defaultValue: { summary: false }, - }, - type: { - name: 'boolean', - required: false, - }, - }, - }, -} as ComponentMeta; - -const Template: ComponentStory = ({ ...args }) => { - const id = 'sunt'; - const [value, setValue] = useState(''); - const updateValue = useCallback((e: ChangeEvent) => { +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +const ControlledCheckbox = ({ + isChecked: checked = false, + ...args +}: CheckboxProps) => { + const [isChecked, setIsChecked] = useState(checked); + + const handleChange = useCallback((e: ChangeEvent) => { + setIsChecked(e.target.checked); + }, []); + + return ; +}; + +const ControlledInput = ({ value: defaultValue, ...args }: InputProps) => { + const [value, setValue] = useState(defaultValue); + + const handleChange = useCallback((e: ChangeEvent) => { + setValue(e.target.value); + }, []); + + return ; +}; + +const ControlledRadio = ({ + isChecked: checked = false, + ...args +}: RadioProps) => { + const [isChecked, setIsChecked] = useState(checked); + + const handleChange = useCallback((e: ChangeEvent) => { + setIsChecked(e.target.checked); + }, []); + + return ; +}; + +const ControlledTextArea = ({ + value: defaultValue, + ...args +}: TextAreaProps) => { + const [value, setValue] = useState(defaultValue); + + const handleChange = useCallback((e: ChangeEvent) => { setValue(e.target.value); }, []); - return ( - - } - label={} - /> - ); -}; - -/** - * Labelled Field Stories - Left - */ -export const Left = Template.bind({}); -Left.args = { - isInline: true, -}; - -/** - * Labelled Field Stories - Right - */ -export const Right = Template.bind({}); -Right.args = { - isInline: true, - isReversedOrder: true, -}; - -/** - * Labelled Field Stories - Top - */ -export const Top = Template.bind({}); -Top.args = {}; - -/** - * Labelled Field Stories - Bottom - */ -export const Bottom = Template.bind({}); -Bottom.args = { - isReversedOrder: true, + return