Skip to content

Commit dd98e65

Browse files
committed
chore(core): use common button stories
1 parent 6b14048 commit dd98e65

File tree

2 files changed

+10
-125
lines changed

2 files changed

+10
-125
lines changed

packages/plasma-new-hope/.storybook/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const config: StorybookConfig = {
4747
resolve: {
4848
dedupe: ['react', 'react-dom', 'styled-components'],
4949
alias: {
50-
'src': path.resolve(__dirname, '../src'),
51-
}
50+
src: path.resolve(__dirname, '../src'),
51+
'@salutejs/plasma-sb-utils': path.resolve('../../utils/plasma-sb-utils/src'),
52+
},
5253
},
5354
build: {
5455
sourcemap: false,
Lines changed: 7 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,20 @@
11
import * as React from 'react';
22
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';
85

96
import { Button } from './Button';
107
import { config } from './Button.config';
118

12-
const { views, sizes } = getConfigVariations(config);
9+
type ButtonProps = ComponentProps<typeof Button>;
1310

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 });
3512

36-
const meta: Meta<typeof Button> = {
13+
const meta: Meta<ButtonProps> = {
14+
...META,
3715
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-
},
8516
};
8617

8718
export default meta;
8819

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

Comments
 (0)