From a839e9d97e2f824e3e8f9876eca04c72720118ad Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Aug 2023 09:39:46 -0700 Subject: [PATCH] fix: Update M- Components to Storybook CSF3 --- src/components/Menu/Menu.stories.tsx | 89 ++++++++++++++---------- src/components/Menu/MenuItem.stories.tsx | 38 +++++----- src/components/Modal/Modal.stories.tsx | 52 +++++++++----- 3 files changed, 102 insertions(+), 77 deletions(-) diff --git a/src/components/Menu/Menu.stories.tsx b/src/components/Menu/Menu.stories.tsx index 3b61833d..3cfa3eb7 100644 --- a/src/components/Menu/Menu.stories.tsx +++ b/src/components/Menu/Menu.stories.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { StoryObj, Meta } from '@storybook/react'; import { Menu } from './Menu'; import { IconButton } from '../IconButton'; @@ -7,45 +7,60 @@ import { MoreHorizontal } from '@lifeomic/chromicons'; import { MenuItem } from './MenuItem'; import { MenuGroupHeading } from './MenuGroupHeading'; -export default { - title: 'Components/Menu/Menu', +const meta: Meta = { component: Menu, - argTypes: {}, -} as ComponentMeta; - -const Template: ComponentStory = (args) => ; - -export const Default = Template.bind({}); -Default.args = { - 'aria-label': 'Chroma menu options', - anchorElement: ( - - ), - items: [Menu body], + args: { + 'aria-label': 'Chroma menu options', + anchorElement: ( + + ), + items: [ + Option 1, + Option 2, + Option 3, + Option 4, + ], + }, + decorators: [(story) =>
{story()}
], }; +export default meta; +type Story = StoryObj; -export const GroupHeadings = Template.bind({}); -GroupHeadings.args = { - 'aria-label': 'Chroma menu options', - anchorElement: ( - - ), - items: [ - First Section, - Option 1, - Option 2, - Second Section, - Option 3, - Option 4, - ], +export const Default: Story = {}; + +export const GroupHeadings: Story = { + args: { + items: [ + First Section, + Option 1, + Option 2, + Second Section, + Option 3, + Option 4, + ], + }, +}; + +export const Title: Story = { + args: { + title: 'Title', + }, +}; + +export const Placement: Story = { + args: { + placement: 'top-end', + }, +}; + +export const Gutter: Story = { + args: { + gutter: 50, + }, }; -export const Placement = Template.bind({}); -Placement.args = { - 'aria-label': 'Chroma menu options', - anchorElement: ( - - ), - items: [Menu body], - placement: 'top-end', +export const UsePortal: Story = { + args: { + usePortal: true, + }, }; diff --git a/src/components/Menu/MenuItem.stories.tsx b/src/components/Menu/MenuItem.stories.tsx index cb5a2b58..e3faed38 100644 --- a/src/components/Menu/MenuItem.stories.tsx +++ b/src/components/Menu/MenuItem.stories.tsx @@ -1,34 +1,30 @@ -import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { StoryObj, Meta } from '@storybook/react'; import { MenuItem } from './MenuItem'; import { HelpCircle } from '@lifeomic/chromicons'; -export default { - title: 'Components/Menu/MenuItem', +const meta: Meta = { component: MenuItem, + args: { + text: 'Menu Item', + }, argTypes: { onClick: { action: 'clicked' }, }, -} as ComponentMeta; - -const Template: ComponentStory = (args) => ( - -); - -export const Default = Template.bind({}); -Default.args = { - text: 'Menu Item', }; +export default meta; +type Story = StoryObj; -export const SecondaryText = Template.bind({}); -SecondaryText.args = { - text: 'Menu Item', - secondaryText: 'This is secondary text', +export const Default: Story = {}; + +export const SecondaryText: Story = { + args: { + secondaryText: 'This is secondary text', + }, }; -export const Icon = Template.bind({}); -Icon.args = { - text: 'Menu Item', - icon: HelpCircle, +export const Icon: Story = { + args: { + icon: HelpCircle, + }, }; diff --git a/src/components/Modal/Modal.stories.tsx b/src/components/Modal/Modal.stories.tsx index 1029ff3c..f0c60955 100644 --- a/src/components/Modal/Modal.stories.tsx +++ b/src/components/Modal/Modal.stories.tsx @@ -1,17 +1,17 @@ import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { StoryObj, StoryFn, Meta } from '@storybook/react'; import { Modal } from './Modal'; import { Button } from '../Button'; import { Checkbox } from '../Checkbox'; -export default { - title: 'Components/Modal', +const meta: Meta = { component: Modal, - argTypes: {}, -} as ComponentMeta; +}; +export default meta; +type Story = StoryObj; -export const Default: ComponentStory = (args) => { +const Template: StoryFn = (args) => { const [isOpen, setIsOpen] = React.useState(false); return ( @@ -33,13 +33,9 @@ export const Default: ComponentStory = (args) => { ); }; -Default.args = { - title: 'Modal Example', -}; -export const ActionsModal: ComponentStory = (args) => { +const Template2: StoryFn = (args) => { const [isOpen, setIsOpen] = React.useState(false); - return ( <>