From f0fb358bf7e324d3fc2d834251c5976ea79000f3 Mon Sep 17 00:00:00 2001 From: mimo Date: Wed, 31 Jan 2024 15:29:14 +0900 Subject: [PATCH 1/2] feat: refactor MultiSelect storyes --- .../__snapshots__/index.story.storyshot | 76 ++--- .../components/MultiSelect/index.story.tsx | 288 ++++++------------ 2 files changed, 128 insertions(+), 236 deletions(-) diff --git a/packages/react/src/components/MultiSelect/__snapshots__/index.story.storyshot b/packages/react/src/components/MultiSelect/__snapshots__/index.story.storyshot index d34a4ac36..06d041bb0 100644 --- a/packages/react/src/components/MultiSelect/__snapshots__/index.story.storyshot +++ b/packages/react/src/components/MultiSelect/__snapshots__/index.story.storyshot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Storybook Tests MultiSelect Default 1`] = ` +exports[`Storybook Tests MultiSelect Basic 1`] = ` .c1 { display: grid; grid-template-columns: auto 1fr; @@ -136,7 +136,7 @@ exports[`Storybook Tests MultiSelect Default 1`] = ` data-dark={false} >
@@ -149,7 +149,7 @@ exports[`Storybook Tests MultiSelect Default 1`] = ` checked={true} className="c2" disabled={false} - name="" + name="name" onChange={[Function]} type="checkbox" value="選択肢1" @@ -166,8 +166,7 @@ exports[`Storybook Tests MultiSelect Default 1`] = `
- 選択肢 - 1 + 選択肢1
@@ -405,7 +401,7 @@ exports[`Storybook Tests MultiSelect Invalid 1`] = ` data-dark={false} >
@@ -418,7 +414,7 @@ exports[`Storybook Tests MultiSelect Invalid 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="name" onChange={[Function]} type="checkbox" value="選択肢1" @@ -435,8 +431,7 @@ exports[`Storybook Tests MultiSelect Invalid 1`] = `
- 選択肢 - 1 + 選択肢1
@@ -673,7 +665,7 @@ exports[`Storybook Tests MultiSelect Overlay 1`] = ` data-dark={false} >
@@ -686,7 +678,7 @@ exports[`Storybook Tests MultiSelect Overlay 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="name" onChange={[Function]} type="checkbox" value="選択肢1" @@ -703,8 +695,7 @@ exports[`Storybook Tests MultiSelect Overlay 1`] = `
- 選択肢 - 1 + 選択肢1
@@ -950,7 +938,7 @@ exports[`Storybook Tests MultiSelect Playground 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="" onChange={[Function]} type="checkbox" value="選択肢1" @@ -980,7 +968,7 @@ exports[`Storybook Tests MultiSelect Playground 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="" onChange={[Function]} type="checkbox" value="選択肢2" @@ -1010,7 +998,7 @@ exports[`Storybook Tests MultiSelect Playground 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="" onChange={[Function]} type="checkbox" value="選択肢3" @@ -1040,7 +1028,7 @@ exports[`Storybook Tests MultiSelect Playground 1`] = ` checked={false} className="c2" disabled={false} - name="defaultName" + name="" onChange={[Function]} type="checkbox" value="選択肢4" diff --git a/packages/react/src/components/MultiSelect/index.story.tsx b/packages/react/src/components/MultiSelect/index.story.tsx index 3de025dc1..8d4887700 100644 --- a/packages/react/src/components/MultiSelect/index.story.tsx +++ b/packages/react/src/components/MultiSelect/index.story.tsx @@ -1,42 +1,18 @@ import { useState } from 'react' -import { Story } from '../../_lib/compat' import styled from 'styled-components' import { MultiSelectGroup, default as MultiSelect } from '.' +import { Meta, StoryObj } from '@storybook/react' + +const StyledMultiSelectGroup = styled(MultiSelectGroup)` + display: grid; + grid-template-columns: 1fr; + gap: 8px; +` export default { title: 'MultiSelect', component: MultiSelect, argTypes: { - name: { - control: { - type: 'text', - }, - }, - label: { - control: { - type: 'text', - }, - }, - selected: { - control: { - type: 'boolean', - }, - }, - disabled: { - control: { - type: 'boolean', - }, - }, - readonly: { - control: { - type: 'boolean', - }, - }, - invalid: { - control: { - type: 'boolean', - }, - }, variant: { control: { type: 'inline-radio', @@ -44,173 +20,101 @@ export default { }, }, }, -} - -type Props = { - name: string - label: string - selected: boolean - onChange: (selected: string[]) => void - disabled?: boolean - readonly?: boolean - invalid?: boolean - variant?: 'default' | 'overlay' - className?: string -} - -const StyledMultiSelectGroup = styled(MultiSelectGroup)` - display: grid; - grid-template-columns: 1fr; - gap: 8px; -` - -const Template: Story = ({ - name, - label, - selected, - onChange, - disabled, - readonly, - invalid, - variant, - className, -}) => { - return ( - - {[1, 2, 3, 4].map((idx) => ( - - 選択肢{idx} - - ))} - - ) -} - -export const Default = Template.bind({}) -Default.args = { - name: '', - label: '', - selected: true, - disabled: false, - readonly: false, - invalid: false, - variant: 'default', - // eslint-disable-next-line no-console - onChange: (selected) => console.log(selected), -} + args: { + variant: 'default', + }, +} as Meta -type PlaygroundProps = { - name: string - label: string - disabled?: boolean - readonly?: boolean - invalid?: boolean - className?: string - variant?: 'default' | 'overlay' +export const Basic: StoryObj = { + render: function Render(args) { + const options = ['選択肢1', '選択肢2', '選択肢3', '選択肢4'] + return ( + { + // eslint-disable-next-line no-console + console.log('click') + }} + selected={['選択肢1', '選択肢3']} + > + {options.map((option) => ( + + {option} + + ))} + + ) + }, } -export const Playground: Story = ({ className, ...props }) => { - const [selected, setSelected] = useState([]) - - return ( - - {[1, 2, 3, 4].map((idx) => ( - - 選択肢{idx} - - ))} - - ) -} -Playground.args = { - name: 'defaultName', - label: '', - disabled: false, - readonly: false, - invalid: false, - variant: 'default', +export const Invalid: StoryObj = { + render: function Render(args) { + const options = ['選択肢1', '選択肢2', '選択肢3', '選択肢4'] + return ( + { + // eslint-disable-next-line no-console + console.log('click') + }} + selected={[]} + invalid + > + {options.map((option) => ( + + {option} + + ))} + + ) + }, } -export const Invalid: Story = ({ className, ...props }) => { - const [selected, setSelected] = useState([]) - - return ( - - {[1, 2, 3, 4].map((idx) => ( - - 選択肢{idx} - - ))} - - ) -} -Invalid.args = { - name: 'defaultName', - label: '', - disabled: false, - readonly: false, - variant: 'default', +export const Overlay: StoryObj = { + render: function Render(args) { + const options = ['選択肢1', '選択肢2', '選択肢3', '選択肢4'] + return ( + { + // eslint-disable-next-line no-console + console.log('click') + }} + selected={[]} + > + {options.map((option) => ( + + {option} + + ))} + + ) + }, + args: { + variant: 'overlay', + }, } -export const Overlay: Story = ({ className, ...props }) => { - const [selected, setSelected] = useState([]) +export const Playground: StoryObj = { + render: function Render(args) { + const [selected, setSelected] = useState([]) - return ( - - {[1, 2, 3, 4].map((idx) => ( - - 選択肢{idx} - - ))} - - ) -} -Overlay.args = { - name: 'defaultName', - label: '', - disabled: false, - readonly: false, + return ( + + {[1, 2, 3, 4].map((idx) => ( + + 選択肢{idx} + + ))} + + ) + }, } From caec7f02c56ee4ef37e6627e2b3d0b2e45baeb15 Mon Sep 17 00:00:00 2001 From: mimo Date: Thu, 8 Feb 2024 17:06:36 +0900 Subject: [PATCH 2/2] chore(react): replace console.log to action) --- .../src/components/MultiSelect/index.story.tsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/react/src/components/MultiSelect/index.story.tsx b/packages/react/src/components/MultiSelect/index.story.tsx index 8d4887700..81ceb67d3 100644 --- a/packages/react/src/components/MultiSelect/index.story.tsx +++ b/packages/react/src/components/MultiSelect/index.story.tsx @@ -2,6 +2,7 @@ import { useState } from 'react' import styled from 'styled-components' import { MultiSelectGroup, default as MultiSelect } from '.' import { Meta, StoryObj } from '@storybook/react' +import { action } from '@storybook/addon-actions' const StyledMultiSelectGroup = styled(MultiSelectGroup)` display: grid; @@ -32,10 +33,7 @@ export const Basic: StoryObj = { { - // eslint-disable-next-line no-console - console.log('click') - }} + onChange={action('click')} selected={['選択肢1', '選択肢3']} > {options.map((option) => ( @@ -55,10 +53,7 @@ export const Invalid: StoryObj = { { - // eslint-disable-next-line no-console - console.log('click') - }} + onChange={action('click')} selected={[]} invalid > @@ -79,10 +74,7 @@ export const Overlay: StoryObj = { { - // eslint-disable-next-line no-console - console.log('click') - }} + onChange={action('click')} selected={[]} > {options.map((option) => (