Skip to content

Commit ae1d12a

Browse files
authored
chore(Link): fix stories (#1210)
1 parent bc9224d commit ae1d12a

File tree

3 files changed

+74
-50
lines changed

3 files changed

+74
-50
lines changed

src/components/Link/Link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getTextSize({size, theme}: {size?: TextSize; theme: LinkTheme}) {
5252
return size;
5353
}
5454

55-
const LinkBlock = (props: React.PropsWithChildren<LinkFullProps>) => {
55+
const Link = (props: React.PropsWithChildren<LinkFullProps>) => {
5656
const {
5757
text,
5858
url,
@@ -147,4 +147,4 @@ const LinkBlock = (props: React.PropsWithChildren<LinkFullProps>) => {
147147
);
148148
};
149149

150-
export default LinkBlock;
150+
export default Link;

src/components/Link/__stories__/Link.stories.tsx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,52 @@ import * as React from 'react';
22

33
import {Meta, StoryFn} from '@storybook/react';
44

5-
import {Col, Row} from '../../../grid';
6-
import {LinkProps} from '../../../models';
5+
import {Col, GridAlignItems, Row} from '../../../grid';
76
import Link, {LinkFullProps} from '../Link';
87

98
import data from './data.json';
109

11-
const getSizesTitle = (size: string) => data.themesSizes.title.replace('{{size}}', size);
12-
1310
export default {
1411
component: Link,
1512
title: 'Components/Links and buttons/Link',
1613
} as Meta;
1714

15+
const THEMES_SIZES = ['normal', 'underline', 'back', 'file-link'].map((theme) =>
16+
['s', 'm', 'l'].map((textSize) => ({
17+
theme,
18+
textSize,
19+
...data.themesSizes,
20+
})),
21+
);
22+
1823
const DefaultTemplate: StoryFn<LinkFullProps> = (args) => <Link {...args} />;
1924
const DarkTemplate: StoryFn<LinkFullProps> = (args) => (
2025
<section style={{backgroundColor: '#7ccea0', display: 'inline-block', padding: '0 16px 16px'}}>
2126
<Link {...args} />
2227
</section>
2328
);
24-
const SizesTemplate: StoryFn<LinkFullProps> = (args) => (
25-
<Row>
26-
<Col>{args.theme}</Col>
27-
<Col>
28-
<Link text={getSizesTitle('s')} {...args} textSize="s" />
29-
</Col>
30-
<Col>
31-
<Link text={getSizesTitle('m')} {...args} textSize="m" />
32-
</Col>
33-
<Col>
34-
<Link text={getSizesTitle('l')} {...args} textSize="l" />
35-
</Col>
29+
const SizesTemplate: StoryFn<Record<number, LinkFullProps>> = (args) => (
30+
<Row alignItems={GridAlignItems.End}>
31+
<Col>{args[0].theme}</Col>
32+
{Object.values(args).map((itemArgs, index) => (
33+
<Col key={index}>
34+
<Link {...itemArgs} />
35+
</Col>
36+
))}
3637
</Row>
3738
);
38-
const ThemesSizesTemplate: StoryFn<LinkFullProps> = (args) => (
39+
const ThemesSizesTemplate: StoryFn<Record<number, Record<number, LinkFullProps>>> = (args) => (
3940
<React.Fragment>
4041
<Row>
4142
<Col />
42-
<Col>s</Col>
43-
<Col>m</Col>
44-
<Col>l</Col>
43+
<Col>{args[0][0].textSize}</Col>
44+
<Col>{args[0][1].textSize}</Col>
45+
<Col>{args[0][2].textSize}</Col>
4546
</Row>
46-
<SizesTemplate {...args} theme="normal" />
47-
<SizesTemplate {...args} theme="underline" />
48-
<SizesTemplate {...args} theme="back" />
49-
<SizesTemplate {...args} theme="file-link" />
47+
<SizesTemplate {...args[0]} />
48+
<SizesTemplate {...args[1]} />
49+
<SizesTemplate {...args[2]} />
50+
<SizesTemplate {...args[3]} />
5051
</React.Fragment>
5152
);
5253

@@ -72,17 +73,28 @@ const WithChildrenTemplate: StoryFn<LinkFullProps> = (args) => (
7273
);
7374

7475
export const Default = DefaultTemplate.bind({});
75-
export const ThemesSizes = ThemesSizesTemplate.bind({});
76+
export const ThemesSizes = ThemesSizesTemplate.bind([[]]);
77+
ThemesSizes.parameters = {
78+
controls: {
79+
include: Object.keys(THEMES_SIZES),
80+
},
81+
};
7682
export const NormalWithChildren = WithChildrenTemplate.bind({});
77-
export const NormalArrow = SizesTemplate.bind({});
83+
export const NormalArrow = SizesTemplate.bind([]);
84+
NormalArrow.parameters = {
85+
controls: {
86+
include: Object.keys(data.normalArrows),
87+
},
88+
};
89+
7890
export const NormalForDarkTheme = DarkTemplate.bind({});
7991
export const UnderlineWithChildren = WithChildrenTemplate.bind({});
8092
export const BackWithChildren = WithChildrenTemplate.bind({});
8193

8294
Default.args = data.default.content;
83-
ThemesSizes.args = data.themesSizes.content;
84-
NormalWithChildren.args = data.normalWithChildren.content as LinkProps;
85-
NormalArrow.args = data.normalArrow.content as LinkProps;
86-
NormalForDarkTheme.args = data.normalForDarkTheme.content as LinkProps;
87-
UnderlineWithChildren.args = data.underlineWithChildren.content as LinkProps;
88-
BackWithChildren.args = data.backWithChildren.content as LinkProps;
95+
ThemesSizes.args = THEMES_SIZES as LinkFullProps[][];
96+
NormalWithChildren.args = data.normalWithChildren.content as LinkFullProps;
97+
NormalArrow.args = data.normalArrows as LinkFullProps[];
98+
NormalForDarkTheme.args = data.normalForDarkTheme.content as LinkFullProps;
99+
UnderlineWithChildren.args = data.underlineWithChildren.content as LinkFullProps;
100+
BackWithChildren.args = data.backWithChildren.content as LinkFullProps;
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"backWithChildren": {
3-
"content": {
4-
"url": "#",
5-
"theme": "back"
6-
}
7-
},
82
"default": {
93
"content": {
104
"text": "Default link",
115
"url": "#"
126
}
137
},
8+
"backWithChildren": {
9+
"content": {
10+
"url": "#",
11+
"theme": "back"
12+
}
13+
},
1414
"underlineWithChildren": {
1515
"content": {
1616
"url": "#",
@@ -24,14 +24,29 @@
2424
"theme": "normal"
2525
}
2626
},
27-
"normalArrow": {
28-
"content": {
29-
"text": "Normal link with an arrow",
27+
"normalArrows": [
28+
{
29+
"text": "Normal link with an arrow. Size s",
3030
"url": "#",
3131
"arrow": true,
32-
"theme": "normal"
32+
"theme": "normal",
33+
"textSize": "s"
34+
},
35+
{
36+
"text": "Normal link with an arrow. Size m",
37+
"url": "#",
38+
"arrow": true,
39+
"theme": "normal",
40+
"textSize": "m"
41+
},
42+
{
43+
"text": "Normal link with an arrow. Size l",
44+
"url": "#",
45+
"arrow": true,
46+
"theme": "normal",
47+
"textSize": "l"
3348
}
34-
},
49+
],
3550
"normalForDarkTheme": {
3651
"content": {
3752
"text": "Normal link",
@@ -41,10 +56,7 @@
4156
}
4257
},
4358
"themesSizes": {
44-
"title": "Link size {{size}}",
45-
"content": {
46-
"text": "Link",
47-
"url": "#"
48-
}
59+
"text": "Link",
60+
"url": "#"
4961
}
5062
}

0 commit comments

Comments
 (0)