Skip to content

Commit 5a3648e

Browse files
committed
Configure IconUtils globally for all storybook to save re-register in individual stories
1 parent fbe36b2 commit 5a3648e

5 files changed

Lines changed: 45 additions & 65 deletions

File tree

.storybook/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { withKnobs } from "@storybook/addon-knobs";
44
import { withInfo } from "@storybook/addon-info";
55
import "./storybook.css";
66
import "assets/scss/andculturecode-javascript-react-components.scss";
7+
import { IconUtils } from "utilities/icon-utils";
8+
import { SvgIcons } from "atoms/constants/svg-icons";
9+
10+
IconUtils.register(SvgIcons);
711

812
setDefaults({
913
header: true,

src/assets/scss/6-components/atoms/_buttons.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
width: 100%;
3434
}
3535

36-
&.-medium {
37-
@include padding(11px, 24px);
38-
}
39-
4036
&.-small {
4137
@include padding(7px, 16px);
4238
@include font-style($font-primary, "xsmall", #ffffff, 800, 12px);

src/atoms/anchors/anchor-with-icon.stories.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { select, text } from "@storybook/addon-knobs";
77
import { ButtonSizes } from "../constants/button-sizes";
88
import { ButtonStyles } from "../constants/button-styles";
99
import { Icons } from "../constants/icons";
10-
import { IconUtils } from "../../utilities/icon-utils";
11-
import { SvgIcons } from "../constants/svg-icons";
10+
import { MemoryRouter } from "react-router-dom";
1211

1312
addDecorator(StoryRouter());
1413

@@ -17,10 +16,8 @@ export default {
1716
title: "Atoms | Anchors / AnchorWithIcon",
1817
};
1918

20-
export const anchorIconWithChevronDownIcon = () => {
21-
IconUtils.register(SvgIcons);
22-
23-
return (
19+
export const anchorIconWithChevronDownIcon = () => (
20+
<MemoryRouter>
2421
<AnchorWithIcon
2522
accessibleText="Text for screen reader"
2623
size={ButtonSizes.Medium}
@@ -29,13 +26,11 @@ export const anchorIconWithChevronDownIcon = () => {
2926
to="/test">
3027
{Faker.lorem.words(5)}
3128
</AnchorWithIcon>
32-
);
33-
};
29+
</MemoryRouter>
30+
);
3431

35-
export const anchorIconKnobs = () => {
36-
IconUtils.register(SvgIcons);
37-
38-
return (
32+
export const anchorIconKnobs = () => (
33+
<MemoryRouter>
3934
<AnchorWithIcon
4035
accessibleText={text("accessibleText", "Text for screen reader")}
4136
size={select("size", ButtonSizes, ButtonSizes.Medium)}
@@ -44,5 +39,5 @@ export const anchorIconKnobs = () => {
4439
to="/test">
4540
{text("text", "Anchor text")}
4641
</AnchorWithIcon>
47-
);
48-
};
42+
</MemoryRouter>
43+
);

src/atoms/buttons/button.stories.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { Icon } from "../icons/icon";
66
import { IconSizes } from "../constants/icon-sizes";
77
import { Icons } from "../constants/icons";
88
import React from "react";
9-
import { IconUtils } from "../../utilities/icon-utils";
10-
import { SvgIcons } from "../constants/svg-icons";
119

1210
export default {
1311
title: "Atoms | Buttons",
@@ -24,19 +22,15 @@ export const buttonDefault = () => (
2422
</Button>
2523
);
2624

27-
export const buttonIcon = () => {
28-
IconUtils.register(SvgIcons);
29-
30-
return (
31-
<Button
32-
onClick={() => {}}
33-
size={select("size", ButtonSizes, ButtonSizes.Medium)}
34-
style={select("style", ButtonStyles, ButtonStyles.Primary)}
35-
accessibleText={text("Accessible Text", "Text for screen reader")}>
36-
<Icon
37-
type={select("type", Icons, Icons.Close)}
38-
size={select("icon size", IconSizes, IconSizes.Large)}
39-
/>
40-
</Button>
41-
);
42-
};
25+
export const buttonIcon = () => (
26+
<Button
27+
onClick={() => {}}
28+
size={select("size", ButtonSizes, ButtonSizes.Medium)}
29+
style={select("style", ButtonStyles, ButtonStyles.Primary)}
30+
accessibleText={text("Accessible Text", "Text for screen reader")}>
31+
<Icon
32+
type={select("type", Icons, Icons.Close)}
33+
size={select("icon size", IconSizes, IconSizes.Large)}
34+
/>
35+
</Button>
36+
);

src/atoms/icons/icon.stories.tsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,31 @@ import { IconSizes } from "../constants/icon-sizes";
33
import { Icons } from "../constants/icons";
44
import React from "react";
55
import { select } from "@storybook/addon-knobs";
6-
import { IconUtils } from "../../utilities/icon-utils";
76
import { SvgIcons } from "../constants/svg-icons";
87

98
export default {
109
component: Icon,
1110
title: "Atoms | Icons / Icon",
1211
};
1312

14-
export const icon = () => {
15-
IconUtils.register(SvgIcons);
13+
export const icon = () => (
14+
<Icon
15+
type={select("type", Icons, Icons.Checkmark)}
16+
size={select("icon size", IconSizes, IconSizes.Large)}
17+
/>
18+
);
1619

17-
return (
18-
<Icon
19-
type={select("type", Icons, Icons.Checkmark)}
20-
size={select("icon size", IconSizes, IconSizes.Large)}
21-
/>
22-
);
23-
};
24-
25-
export const IconsAll = () => {
26-
IconUtils.register(SvgIcons);
27-
28-
return (
29-
<React.Fragment>
30-
{SvgIcons.map((i) => (
31-
<div>
32-
<h3>{i.type}</h3>
33-
<h4>Base</h4>
34-
<Icon type={i.type} size={IconSizes.Base} />
35-
<h4>Large</h4>
36-
<Icon type={i.type} size={IconSizes.Large} />
37-
<hr />
38-
</div>
39-
))}
40-
</React.Fragment>
41-
);
42-
};
20+
export const IconsAll = () => (
21+
<React.Fragment>
22+
{SvgIcons.map((i) => (
23+
<div>
24+
<h3>{i.type}</h3>
25+
<h4>Base</h4>
26+
<Icon type={i.type} size={IconSizes.Base} />
27+
<h4>Large</h4>
28+
<Icon type={i.type} size={IconSizes.Large} />
29+
<hr />
30+
</div>
31+
))}
32+
</React.Fragment>
33+
);

0 commit comments

Comments
 (0)