|
| 1 | +/* eslint-disable react/no-unescaped-entities */ |
| 2 | +import { ArgsTable, Primary, PRIMARY_STORY } from '@storybook/addon-docs' |
| 3 | +import { Meta, StoryObj } from '@storybook/react' |
| 4 | +import { Hero, Section, StoryStage, TableOfContents } from 'pcln-docs-utils' |
| 5 | +import { Flex, ISwatchProps, Swatch, Text, ThemeProvider } from '..' |
1 | 6 | import React, { useState } from 'react' |
2 | | -import Swatch from './Swatch' |
3 | | -import { Box, Flex, Text } from '../' |
4 | 7 |
|
5 | | -export default { |
6 | | - title: 'Swatch', |
7 | | - component: Swatch, |
| 8 | +type SwatchStory = StoryObj<ISwatchProps> |
| 9 | + |
| 10 | +export const Playground: SwatchStory = { |
| 11 | + render: (args) => <Swatch {...args} />, |
| 12 | + args: { |
| 13 | + colors: [ |
| 14 | + '#D50032', |
| 15 | + '#1B7742', |
| 16 | + '#0033A0', |
| 17 | + '#002244', |
| 18 | + '#6244BB', |
| 19 | + '#31225D', |
| 20 | + '#31225D', |
| 21 | + '#FFC658', |
| 22 | + '#4F6F8F', |
| 23 | + ], |
| 24 | + }, |
| 25 | + argTypes: { |
| 26 | + onClick: () => null, |
| 27 | + }, |
| 28 | +} |
| 29 | + |
| 30 | +export const SingleColor: SwatchStory = { |
| 31 | + render: () => ( |
| 32 | + <StoryStage> |
| 33 | + <Swatch colors={['#0033A0']} /> |
| 34 | + </StoryStage> |
| 35 | + ), |
8 | 36 | } |
9 | 37 |
|
10 | | -export const SingleColor = () => <Swatch colors={['#0033A0']} /> |
11 | | - |
12 | | -export const MultipleColors = () => <Swatch colors={['#D50032', '#1B7742', '#0033A0']} /> |
13 | | - |
14 | | -export const Wrap = () => ( |
15 | | - <Box width='100px'> |
16 | | - <Swatch |
17 | | - colors={[ |
18 | | - '#D50032', |
19 | | - '#1B7742', |
20 | | - '#0033A0', |
21 | | - '#002244', |
22 | | - '#6244BB', |
23 | | - '#31225D', |
24 | | - '#31225D', |
25 | | - '#FFC658', |
26 | | - '#4F6F8F', |
27 | | - ]} |
28 | | - /> |
29 | | - </Box> |
30 | | -) |
31 | | - |
32 | | -export const SelectColor = () => { |
| 38 | +export const MultipleColors: SwatchStory = { |
| 39 | + render: () => ( |
| 40 | + <StoryStage> |
| 41 | + <Swatch colors={['#D50032', '#1B7742', '#0033A0']} /> |
| 42 | + </StoryStage> |
| 43 | + ), |
| 44 | +} |
| 45 | + |
| 46 | +const SwatchWithState = () => { |
33 | 47 | const [color, setColor] = useState('#D50032') |
34 | 48 | return ( |
35 | | - <> |
36 | | - <Swatch colors={['#FFFFFF', '#D50032', '#1B7742', '#0033A0']} onClick={(color) => setColor(color)} /> |
| 49 | + <StoryStage> |
| 50 | + <Swatch |
| 51 | + colors={['#FFFFFF', '#D50032', '#1B7742', '#0033A0']} |
| 52 | + onClick={(color) => (typeof color === 'string' ? setColor(color) : undefined)} |
| 53 | + /> |
37 | 54 | <Flex mt='3' flexDirection='row' alignItems='center'> |
38 | 55 | <Text mr={2}>Color:</Text> |
39 | 56 | <Text>{color}</Text> |
40 | 57 | </Flex> |
41 | | - </> |
| 58 | + </StoryStage> |
42 | 59 | ) |
43 | 60 | } |
| 61 | + |
| 62 | +export const SelectColor: SwatchStory = { |
| 63 | + render: () => <SwatchWithState />, |
| 64 | +} |
| 65 | + |
| 66 | +const meta: Meta<typeof Swatch> = { |
| 67 | + title: 'Swatch', |
| 68 | + component: Swatch, |
| 69 | + parameters: { |
| 70 | + docs: { |
| 71 | + page: () => ( |
| 72 | + <ThemeProvider> |
| 73 | + <Hero name='Swatch' img={null}> |
| 74 | + Use the Swatch component to render a group of colors. Clicking one of the color will execute |
| 75 | + onClick callback, that can be passed as a prop. |
| 76 | + </Hero> |
| 77 | + |
| 78 | + <TableOfContents links={['Overview', 'Props']} /> |
| 79 | + |
| 80 | + <Section heading='Overview'> |
| 81 | + <Text textStyle='paragraph'> |
| 82 | + Use the Swatch component to render a group of colors. Clicking one of the color will execute |
| 83 | + onClick callback, that can be passed as a prop. |
| 84 | + </Text> |
| 85 | + </Section> |
| 86 | + |
| 87 | + <Section heading='Props'> |
| 88 | + <Primary /> |
| 89 | + <ArgsTable story={PRIMARY_STORY} /> |
| 90 | + </Section> |
| 91 | + </ThemeProvider> |
| 92 | + ), |
| 93 | + }, |
| 94 | + }, |
| 95 | +} |
| 96 | + |
| 97 | +export default meta |
0 commit comments