Skip to content

Commit f50536c

Browse files
authored
docs: add dropdown to props table for icons, illustrations, patterns
Updates stories for icons, illustrations, patterns to show a dropdown for the icon, illustration, pattern in playground controls that dynamically updates the one shown in the playground
1 parent 6ba486b commit f50536c

File tree

8 files changed

+137
-26
lines changed

8 files changed

+137
-26
lines changed

packages/styleguide/src/lib/Atoms/Icons/Mini/Mini.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ Our icons by using standardized with a viewBox size of `"0 0 16 16"`. Icons shou
3838

3939
All of our Icons are not minified by default, and optimized by [SVGO](https://github.com/svg/svgo) before build time. We like to preserve the source URL as well as any relevent comments or metadata within these SVGs.
4040

41+
Example usage:
42+
43+
```jsx
44+
import { MiniStarIcon } from '@codecademy/gamut-icons';
45+
46+
<MiniStarIcon />;
47+
```
48+
4149
## Playground
4250

43-
<Canvas sourceState="shown" of={MiniIconStories.Default} />
51+
<Canvas of={MiniIconStories.Default} sourceState="none" />
4452

4553
<Controls />
4654

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
import { MiniStarIcon } from '@codecademy/gamut-icons';
1+
import { GamutIconProps } from '@codecademy/gamut-icons';
2+
// eslint-disable-next-line gamut/import-paths
3+
import * as miniIcons from '@codecademy/gamut-icons/src/icons/mini';
24
import type { Meta, StoryObj } from '@storybook/react';
5+
import React from 'react';
36

4-
const meta: Meta<typeof MiniStarIcon> = {
5-
component: MiniStarIcon,
6-
args: {},
7+
type MiniIconProps = GamutIconProps & {
8+
icon: typeof miniIcons.MiniStarIcon;
9+
};
10+
11+
const MiniIconComponent: React.FC<MiniIconProps> = ({
12+
icon: Icon,
13+
...rest
14+
}) => {
15+
return <Icon {...rest} />;
16+
};
17+
18+
const meta: Meta<typeof MiniIconComponent> = {
19+
component: MiniIconComponent,
20+
argTypes: {
21+
icon: {
22+
options: Object.keys(miniIcons),
23+
mapping: miniIcons,
24+
control: {
25+
type: 'select',
26+
},
27+
},
28+
},
729
};
830

931
export default meta;
10-
type Story = StoryObj<typeof MiniStarIcon>;
32+
type Story = StoryObj<typeof MiniIconComponent>;
1133

1234
export const Default: Story = {
13-
args: {},
35+
args: {
36+
size: 16,
37+
icon: miniIcons.MiniStarIcon,
38+
},
1439
};

packages/styleguide/src/lib/Atoms/Icons/Regular/Regular.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ Our icons are standardized with a viewBox size of `"0 0 24 24"`. Icons should be
3838

3939
All of our Icons are not minified by default, and optimized by [SVGO](https://github.com/svg/svgo) before build time. We like to preserve the source URL as well as any relevent comments or metadata within these SVGs.
4040

41+
Example usage:
42+
43+
```jsx
44+
import { AlertIcon } from '@codecademy/gamut-icons';
45+
46+
<AlertIcon />;
47+
```
48+
4149
## Playground
4250

43-
<Canvas sourceState="shown" of={RegularIconStories.Default} />
51+
<Canvas of={RegularIconStories.Default} sourceState="none" />
4452

4553
<Controls />
4654

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
import { AlertIcon } from '@codecademy/gamut-icons';
1+
import { GamutIconProps } from '@codecademy/gamut-icons';
2+
// eslint-disable-next-line gamut/import-paths
3+
import * as icons from '@codecademy/gamut-icons/src/icons/regular';
24
import type { Meta, StoryObj } from '@storybook/react';
35

4-
const meta: Meta<typeof AlertIcon> = {
5-
component: AlertIcon,
6-
args: {},
6+
type IconProps = GamutIconProps & {
7+
icon: typeof icons.AlertIcon;
8+
};
9+
10+
const IconComponent: React.FC<IconProps> = ({ icon: Icon, ...rest }) => {
11+
return <Icon {...rest} />;
12+
};
13+
14+
const meta: Meta<typeof IconComponent> = {
15+
component: IconComponent,
16+
argTypes: {
17+
icon: {
18+
options: Object.keys(icons),
19+
mapping: icons,
20+
control: {
21+
type: 'select',
22+
},
23+
},
24+
},
725
};
826

927
export default meta;
10-
type Story = StoryObj<typeof AlertIcon>;
28+
type Story = StoryObj<typeof IconComponent>;
1129

1230
export const Default: Story = {
1331
args: {
1432
size: 40,
33+
icon: icons.AlertIcon,
1534
},
1635
};

packages/styleguide/src/lib/Atoms/Illustrations/Illustrations.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export const parameters = {
2828

2929
## Usage
3030

31-
Illustrations are intended to be able to take in props for variants such as color, so despite being SVG-based, they're stored in our code as regular React components.
31+
Illustrations are intended to be able to take in props for variants such as color, so despite being SVG-based, they're stored in our code as regular React components and can be used like so:
32+
33+
```jsx
34+
import { NumberBlocks } from '@codecademy/gamut-illustrations';
35+
36+
<NumberBlocks width="128px" />;
37+
```
3238

3339
## Adding an illustration
3440

@@ -44,7 +50,7 @@ If you cannot find the Illustration you would like in the ones that we have spec
4450

4551
## Playground
4652

47-
<Canvas sourceState="shown" of={IllustrationsStories.Default} />
53+
<Canvas of={IllustrationsStories.Default} sourceState="none" />
4854

4955
<Controls />
5056

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1+
import type { IllustrationProps } from '@codecademy/gamut-illustrations';
12
import * as illustrations from '@codecademy/gamut-illustrations';
23
import type { Meta, StoryObj } from '@storybook/react';
34

4-
const Illustration = illustrations.NumberBlocks;
5+
type IllustrationComponentProps = IllustrationProps & {
6+
illustration: React.ComponentType<IllustrationProps>;
7+
};
8+
9+
const IllustrationComponent: React.FC<IllustrationComponentProps> = ({
10+
illustration: Illustration,
11+
...rest
12+
}) => {
13+
return <Illustration {...rest} />;
14+
};
515

6-
const meta: Meta<typeof Illustration> = {
7-
component: Illustration,
8-
args: {},
16+
const meta: Meta<typeof IllustrationComponent> = {
17+
component: IllustrationComponent,
18+
argTypes: {
19+
illustration: {
20+
options: Object.keys(illustrations),
21+
mapping: illustrations,
22+
control: {
23+
type: 'select',
24+
},
25+
},
26+
},
927
};
1028

1129
export default meta;
12-
type Story = StoryObj<typeof Illustration>;
30+
type Story = StoryObj<typeof IllustrationComponent>;
1331

1432
export const Default: Story = {
1533
args: {
1634
width: 256,
35+
height: 256,
36+
illustration: illustrations.NumberBlocks,
1737
},
1838
};

packages/styleguide/src/lib/Atoms/Patterns/Patterns.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ export const parameters = {
3333

3434
Patterns are intended to be able to take in a color and any system layout, positioning, and spacing props.
3535

36+
```jsx
37+
import { DotsLoose } from '@codecademy/gamut-patterns';
38+
39+
<DotsLoose width="128px" />;
40+
```
41+
3642
## Playground
3743

38-
<Canvas sourceState="shown" of={PatternsStories.Default} />
44+
<Canvas of={PatternsStories.Default} sourceState="none" />
3945

4046
<Controls />
4147

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1+
import type { PatternProps } from '@codecademy/gamut-patterns';
12
import * as patterns from '@codecademy/gamut-patterns';
23
import type { Meta, StoryObj } from '@storybook/react';
34

4-
const Pattern = patterns.DotLoose;
5+
type PatternComponentProps = PatternProps & {
6+
pattern: React.ComponentType<PatternProps>;
7+
};
8+
9+
const PatternComponent: React.FC<PatternComponentProps> = ({
10+
pattern: Pattern,
11+
...rest
12+
}) => {
13+
return <Pattern {...rest} />;
14+
};
515

6-
const meta: Meta<typeof Pattern> = {
7-
component: Pattern,
8-
args: {},
16+
const meta: Meta<typeof PatternComponent> = {
17+
component: PatternComponent,
18+
argTypes: {
19+
pattern: {
20+
options: Object.keys(patterns),
21+
mapping: patterns,
22+
control: {
23+
type: 'select',
24+
},
25+
},
26+
},
927
};
1028

1129
export default meta;
12-
type Story = StoryObj<typeof Pattern>;
30+
type Story = StoryObj<typeof PatternComponent>;
1331

1432
export const Default: Story = {
1533
args: {
1634
height: 200,
35+
pattern: patterns.DotLoose,
1736
},
1837
};

0 commit comments

Comments
 (0)