From bbab6b6d9b05923bdedf71d05e4e1097e46285d0 Mon Sep 17 00:00:00 2001 From: Charles de Dreuille Date: Sun, 23 Mar 2025 14:53:27 +0000 Subject: [PATCH] Update snippets Signed-off-by: Charles de Dreuille --- .../src/app/(docs)/components/box/page.mdx | 4 +- .../app/(docs)/components/checkbox/page.mdx | 7 +- .../app/(docs)/components/container/page.mdx | 4 +- .../src/app/(docs)/components/field/page.mdx | 11 +- .../src/app/(docs)/components/flex/page.mdx | 4 +- .../src/app/(docs)/components/grid/page.mdx | 4 +- .../app/(docs)/components/heading/page.mdx | 12 +-- .../(docs)/components/icon-button/page.mdx | 19 ++-- .../src/app/(docs)/components/icon/page.mdx | 4 +- .../src/app/(docs)/components/input/page.mdx | 6 +- .../src/app/(docs)/components/text/page.mdx | 15 +-- .../src/app/(docs)/theme/typography/page.mdx | 8 +- .../src/app/(playground)/playground/page.tsx | 19 ++-- canon-docs/src/snippets/box.tsx | 32 +++--- canon-docs/src/snippets/checkbox.tsx | 42 +++----- canon-docs/src/snippets/container.tsx | 34 +++--- canon-docs/src/snippets/field.tsx | 34 +++--- canon-docs/src/snippets/flex.tsx | 41 +++---- canon-docs/src/snippets/grid.tsx | 36 +++---- canon-docs/src/snippets/heading.tsx | 52 +++------ canon-docs/src/snippets/icon-button.tsx | 73 ++++--------- canon-docs/src/snippets/icon.tsx | 19 +++- canon-docs/src/snippets/inline.tsx | 47 -------- canon-docs/src/snippets/input.tsx | 43 +++----- canon-docs/src/snippets/text.tsx | 102 +++--------------- .../components/Heading/Heading.stories.tsx | 5 +- packages/canon/src/components/Icon/icons.ts | 2 +- packages/canon/src/components/Icon/types.ts | 5 +- 28 files changed, 238 insertions(+), 446 deletions(-) delete mode 100644 canon-docs/src/snippets/inline.tsx diff --git a/canon-docs/src/app/(docs)/components/box/page.mdx b/canon-docs/src/app/(docs)/components/box/page.mdx index c1413dbe19..1a96ffc621 100644 --- a/canon-docs/src/app/(docs)/components/box/page.mdx +++ b/canon-docs/src/app/(docs)/components/box/page.mdx @@ -2,7 +2,7 @@ import { CodeBlock } from '@/components/CodeBlock'; import { PropsTable } from '@/components/PropsTable'; import { Tabs } from '@/components/Tabs'; import { Snippet } from '@/components/Snippet'; -import { BoxPreview } from '@/snippets/box'; +import { BoxSnippet } from '@/snippets/box'; import { boxPropDefs } from './props'; import { spacingPropDefs } from '../../../../utils/propDefs'; @@ -12,7 +12,7 @@ Box is the lowest-level component in Canon. It provides a consistent API for sty } + preview={} code={` `} diff --git a/canon-docs/src/app/(docs)/components/checkbox/page.mdx b/canon-docs/src/app/(docs)/components/checkbox/page.mdx index fd2ec42e1b..42d67c7857 100644 --- a/canon-docs/src/app/(docs)/components/checkbox/page.mdx +++ b/canon-docs/src/app/(docs)/components/checkbox/page.mdx @@ -1,5 +1,5 @@ import { PropsTable } from '@/components/PropsTable'; -import { CheckboxPreview, CheckboxAllVariants } from '@/snippets/checkbox'; +import { CheckboxSnippet } from '@/snippets/checkbox'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; @@ -11,8 +11,9 @@ import { checkboxPropDefs } from './props'; A checkbox component that can be used to trigger actions. } + preview={} code={``} /> @@ -55,7 +56,7 @@ Here's a view when checkboxes have different variants. align="center" py={4} open - preview={} + preview={} code={` diff --git a/canon-docs/src/app/(docs)/components/container/page.mdx b/canon-docs/src/app/(docs)/components/container/page.mdx index 0dbe0223e5..cd6b2d738d 100644 --- a/canon-docs/src/app/(docs)/components/container/page.mdx +++ b/canon-docs/src/app/(docs)/components/container/page.mdx @@ -2,7 +2,7 @@ import { CodeBlock } from '@/components/CodeBlock'; import { PropsTable } from '@/components/PropsTable'; import { Tabs } from '@/components/Tabs'; import { Snippet } from '@/components/Snippet'; -import { ContainerPreview } from '@/snippets/container'; +import { ContainerSnippet } from '@/snippets/container'; import { containerPropDefs } from './props'; # Container @@ -12,7 +12,7 @@ content on the page. } + preview={} code={` `} diff --git a/canon-docs/src/app/(docs)/components/field/page.mdx b/canon-docs/src/app/(docs)/components/field/page.mdx index 54c091faeb..ceaddcaac5 100644 --- a/canon-docs/src/app/(docs)/components/field/page.mdx +++ b/canon-docs/src/app/(docs)/components/field/page.mdx @@ -2,7 +2,7 @@ import { PropsTable } from '@/components/PropsTable'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; -import { FieldPreview } from '@/snippets/field'; +import { FieldSnippet } from '@/snippets/field'; import { BaseUI } from '@/components/HeadlessBanners/BaseUI'; import { fieldRootPropDefs, @@ -15,7 +15,12 @@ import { A wrapper around `Input` or `Select` component to add label, description and error messages.. -} code={``} /> +} + code={``} +/> @@ -85,7 +90,7 @@ Here's a simple input with a label and description. align="center" py={4} open - preview={} + preview={} code={` Name Visible on your profile diff --git a/canon-docs/src/app/(docs)/components/flex/page.mdx b/canon-docs/src/app/(docs)/components/flex/page.mdx index 0e1a6a1fb8..3d0c22a90b 100644 --- a/canon-docs/src/app/(docs)/components/flex/page.mdx +++ b/canon-docs/src/app/(docs)/components/flex/page.mdx @@ -8,7 +8,7 @@ import { flexAlign, } from '@/snippets/_snippets'; import { Snippet } from '@/components/Snippet'; -import { FlexPreview } from '@/snippets/flex'; +import { FlexSnippet } from '@/snippets/flex'; import { flexPropDefs } from './props'; import { spacingPropDefs } from '../../../../utils/propDefs'; @@ -21,7 +21,7 @@ columns. All values are responsive. } + preview={} code={` diff --git a/canon-docs/src/app/(docs)/components/grid/page.mdx b/canon-docs/src/app/(docs)/components/grid/page.mdx index c57493b114..94f3eaec08 100644 --- a/canon-docs/src/app/(docs)/components/grid/page.mdx +++ b/canon-docs/src/app/(docs)/components/grid/page.mdx @@ -3,7 +3,7 @@ import { PropsTable } from '@/components/PropsTable'; import { Tabs } from '@/components/Tabs'; import { grid } from '@/snippets/_snippets'; import { Snippet } from '@/components/Snippet'; -import { GridPreview } from '@/snippets/grid'; +import { GridSnippet } from '@/snippets/grid'; import { spacingPropDefs } from '../../../../utils/propDefs'; import { gridPropDefs, gridItemPropDefs } from './props'; @@ -14,7 +14,7 @@ more complex ones. } + preview={} code={` diff --git a/canon-docs/src/app/(docs)/components/heading/page.mdx b/canon-docs/src/app/(docs)/components/heading/page.mdx index ad8131cdbd..98bdab6efb 100644 --- a/canon-docs/src/app/(docs)/components/heading/page.mdx +++ b/canon-docs/src/app/(docs)/components/heading/page.mdx @@ -1,9 +1,5 @@ import { PropsTable } from '@/components/PropsTable'; -import { - HeadingPreview, - HeadingAllVariants, - HeadingResponsive, -} from '@/snippets/heading'; +import { HeadingSnippet } from '@/snippets/heading'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; @@ -15,7 +11,7 @@ Headings are used to structure the content of your page. } + preview={} code={`Hello World!`} /> @@ -56,7 +52,7 @@ appearance of the heading. } + preview={} code={` Display Title 1 @@ -74,7 +70,7 @@ on the screen size. } + preview={} code={` Responsive heading `} diff --git a/canon-docs/src/app/(docs)/components/icon-button/page.mdx b/canon-docs/src/app/(docs)/components/icon-button/page.mdx index 28b6eefbf2..d1ea768a62 100644 --- a/canon-docs/src/app/(docs)/components/icon-button/page.mdx +++ b/canon-docs/src/app/(docs)/components/icon-button/page.mdx @@ -2,12 +2,7 @@ import { PropsTable } from '@/components/PropsTable'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; -import { - IconButtonPreview, - IconButtonSizes, - IconButtonDisabled, - IconButtonResponsive, -} from '@/snippets/icon-button'; +import { IconButtonSnippet } from '@/snippets/icon-button'; import { iconButtonVariants } from '@/snippets/_snippets'; import { iconButtonPropDefs } from './props'; @@ -18,11 +13,11 @@ A button component with a single icon that can be used to trigger actions. } + preview={} code={` -`} + `} /> @@ -62,7 +57,7 @@ Here's a view when buttons have different variants. align="center" py={4} open - preview={} + preview={} code={iconButtonVariants} /> @@ -74,7 +69,7 @@ Here's a view when buttons have different sizes. align="center" py={4} open - preview={} + preview={} code={` @@ -89,7 +84,7 @@ Here's a view when buttons are disabled. align="center" py={4} open - preview={} + preview={} code={``} /> @@ -101,6 +96,6 @@ Here's a view when buttons are responsive. align="center" py={4} open - preview={} + preview={} code={``} /> diff --git a/canon-docs/src/app/(docs)/components/icon/page.mdx b/canon-docs/src/app/(docs)/components/icon/page.mdx index 3d8d065374..78d8c85d01 100644 --- a/canon-docs/src/app/(docs)/components/icon/page.mdx +++ b/canon-docs/src/app/(docs)/components/icon/page.mdx @@ -1,5 +1,5 @@ import { PropsTable } from '@/components/PropsTable'; -import { IconPreview } from '@/snippets/icon'; +import { IconSnippet } from '@/snippets/icon'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; @@ -12,7 +12,7 @@ Icons are used to represent an action or a state. } + preview={} code={``} /> diff --git a/canon-docs/src/app/(docs)/components/input/page.mdx b/canon-docs/src/app/(docs)/components/input/page.mdx index 228ef68061..a74862a62e 100644 --- a/canon-docs/src/app/(docs)/components/input/page.mdx +++ b/canon-docs/src/app/(docs)/components/input/page.mdx @@ -2,7 +2,7 @@ import { PropsTable } from '@/components/PropsTable'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; -import { InputPreview, InputSizes } from '@/snippets/input'; +import { InputSnippet } from '@/snippets/input'; import { BaseUI } from '@/components/HeadlessBanners/BaseUI'; import { inputPropDefs } from './props'; @@ -13,7 +13,7 @@ A input component tfor your forms. } + preview={} code={``} /> @@ -55,7 +55,7 @@ Here's a simple input with a label and description. align="center" py={4} open - preview={} + preview={} code={` diff --git a/canon-docs/src/app/(docs)/components/text/page.mdx b/canon-docs/src/app/(docs)/components/text/page.mdx index 9b904f84c4..ef18739199 100644 --- a/canon-docs/src/app/(docs)/components/text/page.mdx +++ b/canon-docs/src/app/(docs)/components/text/page.mdx @@ -1,10 +1,5 @@ import { PropsTable } from '@/components/PropsTable'; -import { - TextPreview, - TextAllVariants, - TextResponsive, - TextAllWeights, -} from '@/snippets/text'; +import { TextSnippet } from '@/snippets/text'; import { Snippet } from '@/components/Snippet'; import { Tabs } from '@/components/Tabs'; import { CodeBlock } from '@/components/CodeBlock'; @@ -16,7 +11,7 @@ The `Text` component is used to display content on your page. } + preview={} code={` A man looks at a painting in a museum and says, “Brothers and sisters I have none, but that man's father is my father's son.” Who is in @@ -60,7 +55,7 @@ appearance of the text. } + preview={} code={` A man looks at a painting in a museum and says, “Brothers and sisters I @@ -92,7 +87,7 @@ appearance of the text. } + preview={} code={` A man looks at a painting in a museum and says, “Brothers and sisters I @@ -114,7 +109,7 @@ on the screen size. } + preview={} code={` Responsive text `} diff --git a/canon-docs/src/app/(docs)/theme/typography/page.mdx b/canon-docs/src/app/(docs)/theme/typography/page.mdx index 74b3144ef6..9ec36d6e8b 100644 --- a/canon-docs/src/app/(docs)/theme/typography/page.mdx +++ b/canon-docs/src/app/(docs)/theme/typography/page.mdx @@ -1,5 +1,5 @@ -import { HeadingAllVariants } from '@/snippets/heading'; -import { TextAllVariants } from '@/snippets/text'; +import { HeadingSnippet } from '@/snippets/heading'; +import { TextSnippet } from '@/snippets/text'; import { Snippet } from '@/components/Snippet'; # Typography @@ -20,7 +20,7 @@ component](?path=/docs/components-heading--docs). } + preview={} code={` Display Title 1 @@ -40,7 +40,7 @@ page. } + preview={} code={` A man looks at a painting in a museum and says, “Brothers and sisters I diff --git a/canon-docs/src/app/(playground)/playground/page.tsx b/canon-docs/src/app/(playground)/playground/page.tsx index 354f07bb25..7184227a0a 100644 --- a/canon-docs/src/app/(playground)/playground/page.tsx +++ b/canon-docs/src/app/(playground)/playground/page.tsx @@ -5,10 +5,10 @@ import { Grid, Flex, Text } from '../../../../../packages/canon'; import { screenSizes } from '@/utils/data'; import { Frame } from '@/components/Frame'; import { usePlayground } from '@/utils/playground-context'; -import { ButtonPlayground } from '@/snippets/button'; -import { CheckboxPlayground } from '@/snippets/checkbox'; -import { HeadingPlayground } from '@/snippets/heading'; -import { TextPlayground } from '@/snippets/text'; +import { ButtonSnippet } from '@/snippets/button'; +import { CheckboxSnippet } from '@/snippets/checkbox'; +import { HeadingSnippet } from '@/snippets/heading'; +import { TextSnippet } from '@/snippets/text'; import styles from './styles.module.css'; @@ -55,16 +55,19 @@ const Content = () => { return ( {selectedComponents.find(c => c === 'button') && ( - } title="Button" /> + } title="Button" /> )} {selectedComponents.find(c => c === 'checkbox') && ( - } title="Checkbox" /> + } + title="Checkbox" + /> )} {selectedComponents.find(c => c === 'heading') && ( - } title="Heading" /> + } title="Heading" /> )} {selectedComponents.find(c => c === 'text') && ( - } title="Text" /> + } title="Text" /> )} {/* {selectedComponents.find(c => c === 'input') && ( } title="Input" /> diff --git a/canon-docs/src/snippets/box.tsx b/canon-docs/src/snippets/box.tsx index 2a99ebee7d..ff7725a5ad 100644 --- a/canon-docs/src/snippets/box.tsx +++ b/canon-docs/src/snippets/box.tsx @@ -1,20 +1,20 @@ 'use client'; -import { Box } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as BoxStories from '../../../packages/canon/src/components/Box/Box.stories'; -export const BoxPreview = () => { - return ( - - ); +export const BoxSnippet = ({ story }: { story: string }) => { + const stories = composeStories(BoxStories); + const [isReady, setIsReady] = useState(false); + + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Preview') return ; + + return null; }; diff --git a/canon-docs/src/snippets/checkbox.tsx b/canon-docs/src/snippets/checkbox.tsx index fe2a5b0219..fe71240d2d 100644 --- a/canon-docs/src/snippets/checkbox.tsx +++ b/canon-docs/src/snippets/checkbox.tsx @@ -1,32 +1,22 @@ 'use client'; -import { Checkbox, Flex, Text } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as CheckboxStories from '../../../packages/canon/src/components/Checkbox/Checkbox.stories'; -export const CheckboxPreview = () => { - return ; -}; +export const CheckboxSnippet = ({ story }: { story: string }) => { + const stories = composeStories(CheckboxStories); + const [isReady, setIsReady] = useState(false); -export const CheckboxAllVariants = () => { - return ( - - - - - - - ); -}; + useEffect(() => { + setIsReady(true); + }, [story]); -export const CheckboxPlayground = () => { - return ( - - All variants - - - - - - - - ); + if (!isReady) return null; + + if (story === 'Default') return ; + if (story === 'AllVariants') return ; + if (story === 'Playground') return ; + + return null; }; diff --git a/canon-docs/src/snippets/container.tsx b/canon-docs/src/snippets/container.tsx index 27c0ba9922..c73988c28e 100644 --- a/canon-docs/src/snippets/container.tsx +++ b/canon-docs/src/snippets/container.tsx @@ -1,24 +1,20 @@ 'use client'; -import { Box, Container } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as ContainerStories from '../../../packages/canon/src/components/Container/Container.stories'; -const DecorativeBox = () => ( - -); +export const ContainerSnippet = ({ story }: { story: string }) => { + const stories = composeStories(ContainerStories); + const [isReady, setIsReady] = useState(false); -export const ContainerPreview = () => { - return ( - - - - ); + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Preview') return ; + + return null; }; diff --git a/canon-docs/src/snippets/field.tsx b/canon-docs/src/snippets/field.tsx index e801d85641..dfe16a80a9 100644 --- a/canon-docs/src/snippets/field.tsx +++ b/canon-docs/src/snippets/field.tsx @@ -1,23 +1,21 @@ 'use client'; -import { Input, Field } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as FieldStories from '../../../packages/canon/src/components/Field/Field.stories'; -export const FieldPreview = () => { - return ( -
- - Name - - Visible on your profile - -
- ); -}; +export const FieldSnippet = ({ story }: { story: string }) => { + const stories = composeStories(FieldStories); + const [isReady, setIsReady] = useState(false); -export const InputPlayground = () => { - return ( -
- -
- ); + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Default') return ; + if (story === 'WithLabelAndDescription') + return ; + return null; }; diff --git a/canon-docs/src/snippets/flex.tsx b/canon-docs/src/snippets/flex.tsx index 8bfab8878e..d020a37537 100644 --- a/canon-docs/src/snippets/flex.tsx +++ b/canon-docs/src/snippets/flex.tsx @@ -1,31 +1,20 @@ 'use client'; -import { Flex } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as FlexStories from '../../../packages/canon/src/components/Flex/Flex.stories'; -const DecorativeBox = () => { - return ( -
- ); -}; +export const FlexSnippet = ({ story }: { story: string }) => { + const stories = composeStories(FlexStories); + const [isReady, setIsReady] = useState(false); -export const FlexPreview = () => { - return ( -
- - - - - -
- ); + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Default') return ; + + return null; }; diff --git a/canon-docs/src/snippets/grid.tsx b/canon-docs/src/snippets/grid.tsx index 87012b7630..8f72e8453c 100644 --- a/canon-docs/src/snippets/grid.tsx +++ b/canon-docs/src/snippets/grid.tsx @@ -1,26 +1,20 @@ 'use client'; -import { Box, Grid } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as GridStories from '../../../packages/canon/src/components/Grid/Grid.stories'; -const FakeBox = () => ( - -); +export const GridSnippet = ({ story }: { story: string }) => { + const stories = composeStories(GridStories); + const [isReady, setIsReady] = useState(false); -export const GridPreview = () => { - return ( - - - - - - ); + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Default') return ; + + return null; }; diff --git a/canon-docs/src/snippets/heading.tsx b/canon-docs/src/snippets/heading.tsx index 484497e7a7..5ec970c4a7 100644 --- a/canon-docs/src/snippets/heading.tsx +++ b/canon-docs/src/snippets/heading.tsx @@ -1,42 +1,24 @@ 'use client'; -import { Heading, Flex, Text } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as HeadingStories from '../../../packages/canon/src/components/Heading/Heading.stories'; -export const HeadingPreview = () => { - return Look mum, no hands!; -}; +export const HeadingSnippet = ({ story }: { story: string }) => { + const stories = composeStories(HeadingStories); + const [isReady, setIsReady] = useState(false); -export const HeadingAllVariants = () => { - return ( - - Display - Title 1 - Title 2 - Title 3 - Title 4 - - ); -}; + useEffect(() => { + setIsReady(true); + }, [story]); -export const HeadingResponsive = () => { - return ( - - - Responsive heading - - - ); -}; + if (!isReady) return null; -export const HeadingPlayground = () => { - return ( - - All variants - Display - Title 1 - Title 2 - Title 3 - Title 4 - - ); + if (story === 'Default') return ; + if (story === 'Title1') return ; + if (story === 'AllVariants') return ; + if (story === 'Responsive') return ; + if (story === 'Playground') return ; + + return null; }; diff --git a/canon-docs/src/snippets/icon-button.tsx b/canon-docs/src/snippets/icon-button.tsx index 2079041456..954822cce6 100644 --- a/canon-docs/src/snippets/icon-button.tsx +++ b/canon-docs/src/snippets/icon-button.tsx @@ -1,57 +1,24 @@ 'use client'; -import { IconButton, Flex, ButtonProps, Text } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as IconButtonStories from '../../../packages/canon/src/components/IconButton/IconButton.stories'; -export const IconButtonPreview = () => { - return ( - - - - - ); -}; - -export const IconButtonSizes = () => { - return ( - - - - - ); -}; - -export const IconButtonDisabled = () => { - return ; -}; - -export const IconButtonResponsive = () => { - return ( - - ); -}; - -export const IconButtonPlayground = () => { - const variants: string[] = ['primary', 'secondary']; - - return ( - - {variants.map(variant => ( - - {variant} - {['small', 'medium'].map(size => ( - - - - ))} - - ))} - - ); +export const IconButtonSnippet = ({ story }: { story: string }) => { + const stories = composeStories(IconButtonStories); + const [isReady, setIsReady] = useState(false); + + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Variants') return ; + if (story === 'Sizes') return ; + if (story === 'Disabled') return ; + if (story === 'Responsive') return ; + if (story === 'Playground') return ; + + return null; }; diff --git a/canon-docs/src/snippets/icon.tsx b/canon-docs/src/snippets/icon.tsx index 126dbaf686..b0557ab2cd 100644 --- a/canon-docs/src/snippets/icon.tsx +++ b/canon-docs/src/snippets/icon.tsx @@ -1,7 +1,20 @@ 'use client'; -import { Icon } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as IconStories from '../../../packages/canon/src/components/Icon/Icon.stories'; -export const IconPreview = () => { - return ; +export const IconSnippet = ({ story }: { story: string }) => { + const stories = composeStories(IconStories); + const [isReady, setIsReady] = useState(false); + + useEffect(() => { + setIsReady(true); + }, [story]); + + if (!isReady) return null; + + if (story === 'Default') return ; + + return null; }; diff --git a/canon-docs/src/snippets/inline.tsx b/canon-docs/src/snippets/inline.tsx deleted file mode 100644 index 43fd56c650..0000000000 --- a/canon-docs/src/snippets/inline.tsx +++ /dev/null @@ -1,47 +0,0 @@ -'use client'; - -import { Box, Flex } from '../../../packages/canon'; - -const fakeBlockList = [ - { width: 45, height: 60 }, - { width: 150, height: 75 }, - { width: 80, height: 50 }, - { width: 120, height: 70 }, - { width: 95, height: 65 }, - { width: 80, height: 32 }, - { width: 130, height: 60 }, - { width: 100, height: 80 }, - { width: 140, height: 45 }, - { width: 85, height: 70 }, - { width: 125, height: 50 }, -]; - -const FakeBox = ({ - width = 120, - height = 80, -}: { - width?: number; - height?: number; -}) => ( - -); - -export const InlinePreview = () => { - return ( - - {fakeBlockList.map((block, index) => ( - - ))} - - ); -}; diff --git a/canon-docs/src/snippets/input.tsx b/canon-docs/src/snippets/input.tsx index 69d0b62b7f..f4536cdde6 100644 --- a/canon-docs/src/snippets/input.tsx +++ b/canon-docs/src/snippets/input.tsx @@ -1,36 +1,21 @@ 'use client'; -import { Input, Grid } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as InputStories from '../../../packages/canon/src/components/Input/Input.stories'; -export const InputPreview = () => { - return ( -
- -
- ); -}; +export const InputSnippet = ({ story }: { story: string }) => { + const stories = composeStories(InputStories); + const [isReady, setIsReady] = useState(false); -export const InputSizes = () => { - return ( - - - - - ); -}; + useEffect(() => { + setIsReady(true); + }, [story]); -export const InputError = () => { - return ( -
- -
- ); -}; + if (!isReady) return null; -export const InputPlayground = () => { - return ( -
- -
- ); + if (story === 'Primary') return ; + if (story === 'Sizes') return ; + + return null; }; diff --git a/canon-docs/src/snippets/text.tsx b/canon-docs/src/snippets/text.tsx index 4d39cbf6dd..e721dcc094 100644 --- a/canon-docs/src/snippets/text.tsx +++ b/canon-docs/src/snippets/text.tsx @@ -1,94 +1,24 @@ 'use client'; -import { Flex, Text } from '../../../packages/canon'; +import { useEffect, useState } from 'react'; +import { composeStories } from '@storybook/react'; +import * as TextStories from '../../../packages/canon/src/components/Text/Text.stories'; -export const TextPreview = () => { - return ( - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is in - the painting? - - ); -}; +export const TextSnippet = ({ story }: { story: string }) => { + const stories = composeStories(TextStories); + const [isReady, setIsReady] = useState(false); -export const TextAllVariants = () => { - return ( - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - ); -}; + useEffect(() => { + setIsReady(true); + }, [story]); -export const TextAllWeights = () => { - return ( - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - ); -}; + if (!isReady) return null; -export const TextResponsive = () => { - return ( - Responsive text - ); -}; + if (story === 'Default') return ; + if (story === 'AllVariants') return ; + if (story === 'AllWeights') return ; + if (story === 'Responsive') return ; + if (story === 'Playground') return ; -export const TextPlayground = () => { - return ( - - Subtitle - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - Body - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - Caption - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - Label - - A man looks at a painting in a museum and says, “Brothers and sisters I - have none, but that man's father is my father's son.” Who is - in the painting? - - - ); + return null; }; diff --git a/packages/canon/src/components/Heading/Heading.stories.tsx b/packages/canon/src/components/Heading/Heading.stories.tsx index 1357bde877..b4c0ab7546 100644 --- a/packages/canon/src/components/Heading/Heading.stories.tsx +++ b/packages/canon/src/components/Heading/Heading.stories.tsx @@ -42,7 +42,7 @@ export const Title1: Story = { export const AllVariants: Story = { render: () => ( - + Display Title 1 Title 2 @@ -70,8 +70,7 @@ export const CustomTag: Story = { export const Playground: Story = { render: () => ( - - All variants + Display Title 1 Title 2 diff --git a/packages/canon/src/components/Icon/icons.ts b/packages/canon/src/components/Icon/icons.ts index 8cc862459c..615c918db7 100644 --- a/packages/canon/src/components/Icon/icons.ts +++ b/packages/canon/src/components/Icon/icons.ts @@ -130,4 +130,4 @@ export const icons: IconMap = { youtube: RiYoutubeLine, 'zoom-in': RiZoomInLine, 'zoom-out': RiZoomOutLine, -}; +} as const; diff --git a/packages/canon/src/components/Icon/types.ts b/packages/canon/src/components/Icon/types.ts index 5cbdb8e147..4870a1afc4 100644 --- a/packages/canon/src/components/Icon/types.ts +++ b/packages/canon/src/components/Icon/types.ts @@ -15,6 +15,7 @@ */ import { ReactNode } from 'react'; +import type { RemixiconComponentType } from '@remixicon/react'; /** @public */ export type IconNames = @@ -74,7 +75,7 @@ export type IconNames = | 'zoom-out'; /** @public */ -export type IconMap = Partial>; +export type IconMap = Partial>; /** @public */ export type IconProps = { @@ -92,5 +93,5 @@ export interface IconContextProps { /** @public */ export interface IconProviderProps { children?: ReactNode; - overrides?: Partial>; + overrides?: Partial>; }