|
1 | 1 | import * as React from 'react'; |
2 | 2 | import type { ComponentProps } from 'react'; |
3 | | -import type { StoryObj, Meta } from '@storybook/react'; |
4 | | -import { disableProps, getConfigVariations } from '@salutejs/plasma-sb-utils'; |
5 | | - |
6 | | -import { IconMic } from '../../../components/_Icon'; |
7 | | -import { WithTheme } from '../../_helpers'; |
| 3 | +import type { Meta } from '@storybook/react'; |
| 4 | +import { getButtonStories } from '@salutejs/plasma-sb-utils'; |
8 | 5 |
|
9 | 6 | import { Button } from './Button'; |
10 | 7 | import { config } from './Button.config'; |
11 | 8 |
|
12 | | -const { views, sizes } = getConfigVariations(config); |
| 9 | +type ButtonProps = ComponentProps<typeof Button>; |
13 | 10 |
|
14 | | -const stretchingValues = ['auto', 'filled', 'fixed']; |
15 | | -const pinValues = [ |
16 | | - '', |
17 | | - 'square-square', |
18 | | - 'square-clear', |
19 | | - 'clear-square', |
20 | | - 'clear-clear', |
21 | | - 'clear-circle', |
22 | | - 'circle-clear', |
23 | | - 'circle-circle', |
24 | | -]; |
25 | | -const contentPlacingValues = ['default', 'relaxed']; |
26 | | -const sizeMap = { |
27 | | - xxs: '0.75rem', // 12px |
28 | | - xs: '1rem', // 16px |
29 | | - s: '1.5rem', // 24px |
30 | | - m: '1.5rem', // 36px |
31 | | - l: '1.5rem', // 44px |
32 | | - xl: '1.5rem', // 56px |
33 | | - xxl: '1.5rem', // 100px |
34 | | -}; |
| 11 | +const { meta: META, Default } = getButtonStories({ component: Button, componentConfig: config }); |
35 | 12 |
|
36 | | -const meta: Meta<typeof Button> = { |
| 13 | +const meta: Meta<ButtonProps> = { |
| 14 | + ...META, |
37 | 15 | title: 'Data Entry/Button', |
38 | | - decorators: [WithTheme], |
39 | | - component: Button, |
40 | | - args: { |
41 | | - view: 'default', |
42 | | - size: 'm', |
43 | | - contentPlacing: 'default', |
44 | | - stretching: 'auto', |
45 | | - text: 'Hello', |
46 | | - disabled: false, |
47 | | - focused: true, |
48 | | - square: false, |
49 | | - isLoading: false, |
50 | | - }, |
51 | | - argTypes: { |
52 | | - view: { |
53 | | - options: views, |
54 | | - control: { |
55 | | - type: 'select', |
56 | | - }, |
57 | | - }, |
58 | | - size: { |
59 | | - options: sizes, |
60 | | - control: { |
61 | | - type: 'select', |
62 | | - }, |
63 | | - }, |
64 | | - contentPlacing: { |
65 | | - options: contentPlacingValues, |
66 | | - control: { |
67 | | - type: 'select', |
68 | | - }, |
69 | | - }, |
70 | | - stretching: { |
71 | | - options: stretchingValues, |
72 | | - control: { |
73 | | - type: 'select', |
74 | | - }, |
75 | | - }, |
76 | | - pin: { |
77 | | - options: pinValues, |
78 | | - control: { |
79 | | - type: 'select', |
80 | | - }, |
81 | | - table: { defaultValue: { summary: 'bottom' } }, |
82 | | - }, |
83 | | - ...disableProps(['focused', 'pin']), |
84 | | - }, |
85 | 16 | }; |
86 | 17 |
|
87 | 18 | export default meta; |
88 | 19 |
|
89 | | -type StoryPropsDefault = ComponentProps<typeof Button> & { |
90 | | - enableContentLeft: boolean; |
91 | | - enableContentRight: boolean; |
92 | | -}; |
93 | | - |
94 | | -const StoryDefault = ({ enableContentLeft, enableContentRight, size, ...rest }: StoryPropsDefault) => { |
95 | | - return ( |
96 | | - <Button |
97 | | - contentLeft={enableContentLeft ? <IconMic sizeCustomValue={sizeMap[size]} color="inherit" /> : undefined} |
98 | | - contentRight={enableContentRight ? <IconMic sizeCustomValue={sizeMap[size]} color="inherit" /> : undefined} |
99 | | - size={size} |
100 | | - {...rest} |
101 | | - /> |
102 | | - ); |
103 | | -}; |
104 | | - |
105 | | -export const Default: StoryObj<StoryPropsDefault> = { |
106 | | - args: { |
107 | | - enableContentLeft: false, |
108 | | - enableContentRight: false, |
109 | | - }, |
110 | | - render: (args) => <StoryDefault {...args} />, |
111 | | -}; |
112 | | - |
113 | | -export const WithValue: StoryObj<StoryPropsDefault> = { |
114 | | - args: { |
115 | | - value: 'Value', |
116 | | - enableContentLeft: false, |
117 | | - }, |
118 | | - argTypes: { |
119 | | - ...disableProps(['enableContentRight']), |
120 | | - }, |
121 | | - render: (args) => <StoryDefault {...args} />, |
122 | | -}; |
123 | | - |
124 | | -export const AccessibilityWithChildren: StoryObj<ComponentProps<typeof Button>> = { |
125 | | - argTypes: { ...disableProps(['text']) }, |
126 | | - render: (props: ComponentProps<typeof Button>) => { |
127 | | - const args = { ...props, text: undefined }; |
128 | | - |
129 | | - return ( |
130 | | - <Button {...args}> |
131 | | - <IconMic color="inherit" sizeCustomValue={sizeMap[args.size]} /> |
132 | | - <span>Включить микрофон</span> |
133 | | - </Button> |
134 | | - ); |
135 | | - }, |
136 | | -}; |
| 20 | +export { Default }; |
0 commit comments