Skip to content

Commit bc8e3d7

Browse files
committed
chore(button): create button common stories
1 parent d696a93 commit bc8e3d7

File tree

6 files changed

+199
-0
lines changed

6 files changed

+199
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
3+
import { getConfigVariations } from '../../helpers';
4+
5+
import { createMeta } from './meta';
6+
import { createDefaultStory } from './stories';
7+
8+
type CreateStoriesProps = {
9+
component: any;
10+
componentConfig: any;
11+
title?: string;
12+
disablePropsList?: [];
13+
defaultArgs?: {};
14+
additionalArgTypes?: {};
15+
};
16+
17+
export const getButtonStories = (config: CreateStoriesProps) => {
18+
const { component, componentConfig, ...rest } = config;
19+
20+
const buttonConfig = getConfigVariations(componentConfig);
21+
22+
const meta = createMeta({
23+
component,
24+
componentConfig: buttonConfig,
25+
...rest,
26+
});
27+
28+
const DefaultStoryComponent = createDefaultStory(component);
29+
30+
const Default = {
31+
render: (args: any) => <DefaultStoryComponent {...args} />,
32+
};
33+
34+
return {
35+
meta,
36+
Default,
37+
};
38+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const stretchingValues = ['auto', 'filled', 'fixed'];
2+
3+
export const pinValues = [
4+
'',
5+
'square-square',
6+
'square-clear',
7+
'clear-square',
8+
'clear-clear',
9+
'clear-circle',
10+
'circle-clear',
11+
'circle-circle',
12+
];
13+
14+
export const contentPlacingValues = ['default', 'relaxed'];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Button';
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { disableProps, InSpacingDecorator } from '../../index';
2+
3+
import { stretchingValues, pinValues, contentPlacingValues } from './fixtures';
4+
5+
type CreateMetaProps = {
6+
component: any;
7+
componentConfig: any;
8+
title?: string;
9+
defaultArgs?: {};
10+
additionalArgTypes?: {};
11+
disablePropsList?: [];
12+
};
13+
14+
export const createMeta = ({
15+
component,
16+
componentConfig,
17+
title = 'Data Entry/Button',
18+
defaultArgs = {},
19+
additionalArgTypes = {},
20+
disablePropsList = [],
21+
}: CreateMetaProps) => {
22+
return {
23+
title,
24+
decorators: [InSpacingDecorator],
25+
component,
26+
args: {
27+
view: 'default',
28+
size: 'm',
29+
contentPlacing: 'default',
30+
stretching: 'auto',
31+
text: 'Button',
32+
value: '',
33+
disabled: false,
34+
focused: true,
35+
square: false,
36+
isLoading: false,
37+
...defaultArgs,
38+
},
39+
argTypes: {
40+
view: {
41+
options: componentConfig.views,
42+
control: { type: 'select' },
43+
table: {
44+
category: 'Appearance',
45+
},
46+
},
47+
size: {
48+
options: componentConfig.sizes,
49+
control: { type: 'select' },
50+
table: {
51+
category: 'Appearance',
52+
},
53+
},
54+
contentPlacing: {
55+
options: contentPlacingValues,
56+
control: { type: 'select' },
57+
table: {
58+
category: 'Other',
59+
},
60+
},
61+
stretching: {
62+
options: stretchingValues,
63+
control: { type: 'select' },
64+
table: {
65+
category: 'Other',
66+
},
67+
},
68+
pin: {
69+
options: pinValues,
70+
control: { type: 'select' },
71+
table: { defaultValue: { summary: 'bottom' }, category: 'Other' },
72+
},
73+
isLoading: {
74+
control: { type: 'boolean' },
75+
table: { defaultValue: { summary: 'false' }, category: 'State' },
76+
},
77+
disabled: {
78+
control: { type: 'boolean' },
79+
table: { defaultValue: { summary: 'false' }, category: 'State' },
80+
},
81+
value: {
82+
control: { type: 'text' },
83+
table: {
84+
category: 'Content',
85+
},
86+
},
87+
text: {
88+
control: { type: 'text' },
89+
table: {
90+
category: 'Content',
91+
},
92+
},
93+
...additionalArgTypes,
94+
...disableProps([
95+
'theme',
96+
'loader',
97+
'onClick',
98+
'onFocus',
99+
'onBlur',
100+
'outlined',
101+
'contentLeft',
102+
'contentRight',
103+
'shiftLeft',
104+
'shiftRight',
105+
'stretch',
106+
'as',
107+
'forwardedAs',
108+
'pin',
109+
'focused',
110+
'blur',
111+
'square',
112+
...disablePropsList,
113+
]),
114+
},
115+
};
116+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { action } from '@storybook/addon-actions';
3+
import { IconMic } from '@salutejs/plasma-icons';
4+
5+
const onClick = action('onClick');
6+
const onFocus = action('onFocus');
7+
const onBlur = action('onBlur');
8+
9+
const getIconSize = (size: string) => (size === 'xs' || size === 'xxs' ? 'xs' : 's');
10+
const shouldShowIcon = (enabled: boolean, size: string) => enabled && size !== 'xxs';
11+
12+
export const createDefaultStory = (Button: any) => {
13+
return ({ enableContentLeft, enableContentRight, size, ...rest }: any) => {
14+
const computedContentSlot = (predicate: boolean) =>
15+
predicate ? <IconMic size={getIconSize(size)} color="inherit" /> : undefined;
16+
17+
return (
18+
<Button
19+
contentLeft={computedContentSlot(shouldShowIcon(enableContentLeft, size))}
20+
contentRight={computedContentSlot(shouldShowIcon(enableContentRight, size))}
21+
size={size}
22+
onClick={onClick}
23+
onFocus={onFocus}
24+
onBlur={onBlur}
25+
{...rest}
26+
/>
27+
);
28+
};
29+
};

utils/plasma-sb-utils/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export { IconPlaceholder } from './IconPlaceholder';
33
export { PaletteGrid } from './PaletteGrid';
44
export { InSpacing as InSpacingDecorator } from './StoryDecorators';
55
export { ThemeColors } from './ThemeColors';
6+
export * from './Button';

0 commit comments

Comments
 (0)