Skip to content

Commit 72d109f

Browse files
authored
Update storybook documentation inconsistencies (#183)
* Updates stories to have docs where the `Show Code` is exactly as needed to copy and paste. Adding an unused `args` parameter to the custom render function fixes the rendering to not include `render: () =>` * Upgrade storybook version * Adds .displayName to all dot notation components, as without this storybook strips the dot * Disable no unused vars for stories files. this is required for storybook to render as we want. * Correct lint rule, fix other lint issue of hook in story file * Revert package bumps
1 parent 7302751 commit 72d109f

30 files changed

+191
-94
lines changed

.eslintrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"jsx-a11y/anchor-has-content": 0,
3333
"jsx-a11y/alt-text": 0,
3434
"jsx-a11y/heading-has-content": 0,
35-
"react-hooks/exhaustive-deps": 0
36-
}
35+
"react-hooks/exhaustive-deps": 0,
36+
},
37+
"overrides": [{
38+
"files": ["*.stories.tsx"],
39+
"rules": {"@typescript-eslint/no-unused-vars":"off"}
40+
}]
3741
}

stories/Components/Breadcrumb.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const meta: Meta<typeof Breadcrumb> = {
4444
export default meta;
4545
type Story = StoryObj<typeof Breadcrumb>;
4646

47+
Breadcrumb.Item.displayName = 'Breadcrumb.Item';
48+
Breadcrumb.Back.displayName = 'Breadcrumb.Back';
49+
4750
export const Standard: Story = {};
4851

4952
export const OverrideAriaLabel: Story = {

stories/Components/Card.stories.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ const meta: Meta<typeof Card> = {
1111
export default meta;
1212
type Story = StoryObj<typeof Card>;
1313

14+
Card.Content.displayName = 'Card.Content';
15+
Card.Heading.displayName = 'Card.Heading';
16+
Card.Description.displayName = 'Card.Description';
17+
Card.Link.displayName = 'Card.Link';
18+
Card.Image.displayName = 'Card.Image';
19+
Card.Group.displayName = 'Card.Group';
20+
Card.GroupItem.displayName = 'Card.GroupItem';
21+
1422
export const Standard: Story = {
15-
render: () => (
23+
render: (args) => (
1624
<Card>
1725
<Card.Content>
1826
<Card.Heading>If you need help now but it&apos;s not an emergency</Card.Heading>

stories/Components/CareCard.stories.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ const meta: Meta<typeof CareCard> = {
4848
component: CareCard,
4949
};
5050
export default meta;
51+
52+
CareCard.Heading.displayName = 'CareCard.Heading';
53+
CareCard.Content.displayName = 'CareCard.Content';
54+
5155
type Story = StoryObj<typeof CareCard>;
5256
export const NonUrgent: Story = {
53-
render: (): JSX.Element => (
54-
<CareCard type="non-urgent">
57+
args: { type: 'non-urgent' },
58+
render: (args): JSX.Element => (
59+
<CareCard type={args.type}>
5560
<CareCard.Heading>Speak to a GP if:</CareCard.Heading>
5661
<CareCard.Content>
5762
<ul>
@@ -69,8 +74,9 @@ export const NonUrgent: Story = {
6974
};
7075

7176
export const Urgent: Story = {
72-
render: () => (
73-
<CareCard type="urgent">
77+
args: { type: 'urgent' },
78+
render: (args) => (
79+
<CareCard type={args.type}>
7480
<CareCard.Heading>Ask for an urgent GP appointment if:</CareCard.Heading>
7581
<CareCard.Content>
7682
<ul>
@@ -94,8 +100,9 @@ export const Urgent: Story = {
94100
};
95101

96102
export const Immediate: Story = {
97-
render: () => (
98-
<CareCard type="immediate">
103+
args: { type: 'immediate' },
104+
render: (args) => (
105+
<CareCard type={args.type}>
99106
<CareCard.Heading>Call 999 if you have sudden chest pain that:</CareCard.Heading>
100107
<CareCard.Content>
101108
<ul>
@@ -113,8 +120,11 @@ export const Immediate: Story = {
113120
};
114121

115122
export const WithoutVisuallyHiddenText: Story = {
116-
render: () => (
117-
<CareCard type="non-urgent">
123+
args: {
124+
type: 'non-urgent',
125+
},
126+
render: (args) => (
127+
<CareCard type={args.type}>
118128
<CareCard.Heading visuallyHiddenText={false}>Speak to a GP if:</CareCard.Heading>
119129
<CareCard.Content>
120130
<ul>
@@ -135,8 +145,11 @@ export const WithoutVisuallyHiddenText: Story = {
135145
};
136146

137147
export const WithCustomVisuallyHiddenText: Story = {
138-
render: () => (
139-
<CareCard type="non-urgent">
148+
args: {
149+
type: 'non-urgent',
150+
},
151+
render: (args) => (
152+
<CareCard type={args.type}>
140153
<CareCard.Heading visuallyHiddenText="Custom Hidden Text">Speak to a GP if:</CareCard.Heading>
141154
<CareCard.Content>
142155
<ul>

stories/Components/Checkboxes.stories.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ const meta: Meta<typeof Checkboxes> = {
3737
export default meta;
3838
type Story = StoryObj<typeof Checkboxes>;
3939

40+
Checkboxes.Box.displayName = 'Checkboxes.Box';
41+
4042
export const Standard: Story = {
41-
render: () => (
43+
render: (args) => (
4244
<Fieldset aria-describedby="nationality--hint">
4345
<Fieldset.Legend>What is your nationality?</Fieldset.Legend>
4446
<Checkboxes
47+
idPrefix={args.idPrefix}
4548
name="nationality"
4649
id="nationality"
4750
hint="If you have more than 1 nationality, select all options that are relevant to you."
@@ -55,7 +58,7 @@ export const Standard: Story = {
5558
};
5659

5760
export const WithHintText: Story = {
58-
render: () => (
61+
render: (args) => (
5962
<Fieldset>
6063
<Fieldset.Legend isPageHeading>How do you want to sign in?</Fieldset.Legend>
6164
<Checkboxes>
@@ -82,7 +85,7 @@ export const WithHintText: Story = {
8285
};
8386

8487
export const WithDisabledItem: Story = {
85-
render: () => (
88+
render: (args) => (
8689
<Checkboxes id="colours" name="colours">
8790
<Checkboxes.Box value="red">Red</Checkboxes.Box>
8891
<Checkboxes.Box value="green">Green</Checkboxes.Box>
@@ -94,7 +97,7 @@ export const WithDisabledItem: Story = {
9497
};
9598

9699
export const WithConditionalContent: Story = {
97-
render: () => (
100+
render: (args) => (
98101
<Fieldset aria-describedby="waste--hint">
99102
<Fieldset.Legend isPageHeading>
100103
Which types of waste do you transport regularly?
@@ -109,7 +112,7 @@ export const WithConditionalContent: Story = {
109112
};
110113

111114
export const WithLegendAsPageHeading: Story = {
112-
render: () => (
115+
render: (args) => (
113116
<Fieldset aria-describedby="waste--hint">
114117
<Fieldset.Legend isPageHeading>
115118
Which types of waste do you transport regularly?
@@ -124,7 +127,8 @@ export const WithLegendAsPageHeading: Story = {
124127
};
125128

126129
export const WithErrorBoolean: Story = {
127-
render: function WithErrorBooleanRender() {
130+
render: (args) => {
131+
// eslint-disable-next-line react-hooks/rules-of-hooks
128132
const [errorToggle, setErrorToggle] = React.useState(true);
129133
return (
130134
<>
@@ -154,7 +158,8 @@ export const WithErrorBoolean: Story = {
154158
};
155159

156160
export const WithErrorString: Story = {
157-
render: function WithErrorStringRender() {
161+
render: (args) => {
162+
// eslint-disable-next-line react-hooks/rules-of-hooks
158163
const [error, setError] = React.useState('Please select an option');
159164
return (
160165
<>
@@ -176,6 +181,5 @@ export const WithErrorString: Story = {
176181
</>
177182
);
178183
},
179-
180184
name: 'With Error (String)',
181185
};

stories/Components/ContentsList.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ const meta: Meta<typeof ContentsList> = {
4848
export default meta;
4949
type Story = StoryObj<typeof ContentsList>;
5050

51+
ContentsList.Item.displayName = 'ContentsList.Item';
52+
5153
export const Standard: Story = {
52-
render: () => (
54+
render: (args) => (
5355
<ContentsList aria-label="Pages in this guide">
5456
<ContentsList.Item current aria-current="page">
5557
What is AMD?

stories/Components/Details.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const meta: Meta<typeof Details> = {
5050
export default meta;
5151
type Story = StoryObj<typeof Details>;
5252

53+
Details.Summary.displayName = 'Details.Summary';
54+
Details.Text.displayName = 'Details.Text';
55+
Details.ExpanderGroup.displayName = 'Details.ExpanderGroup';
56+
5357
export const Standard: Story = {
5458
argTypes: { expander: { table: { disable: true } } },
5559
render: ({ expander }) => (
@@ -125,7 +129,7 @@ export const Expander: Story = {
125129
};
126130

127131
export const ExpanderGroup: Story = {
128-
render: () => (
132+
render: (args) => (
129133
<Details.ExpanderGroup>
130134
<Details expander>
131135
<Details.Summary>How to measure your blood glucose levels</Details.Summary>

stories/Components/DoDontList.stories.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ const meta: Meta<typeof DoDontList> = {
4545
export default meta;
4646
type Story = StoryObj<typeof DoDontList>;
4747

48+
DoDontList.Item.displayName = 'DoDontList.Item';
49+
4850
export const Do: Story = {
49-
render: () => (
51+
render: (args) => (
5052
<DoDontList listType="do">
5153
<DoDontList.Item>
5254
cover blisters that are likely to burst with a soft plaster or dressing
@@ -60,7 +62,7 @@ export const Do: Story = {
6062
};
6163

6264
export const Dont: Story = {
63-
render: () => (
65+
render: (args) => (
6466
<DoDontList listType="dont">
6567
<DoDontList.Item>burst a blister yourself</DoDontList.Item>
6668
<DoDontList.Item>peel the skin off a burst blister</DoDontList.Item>

stories/Components/ErrorMessage.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const meta: Meta<typeof ErrorMessage> = {
3232
export default meta;
3333
type Story = StoryObj<typeof ErrorMessage>;
3434

35-
export const Standard: Story = { argTypes: { visuallyHiddenText: { control: false } } };
35+
export const Standard: Story = {
36+
argTypes: { visuallyHiddenText: { control: false } },
37+
};
3638
export const NoVisuallyHiddenText: Story = {
3739
args: { visuallyHiddenText: false },
3840
argTypes: { visuallyHiddenText: { control: false } },

stories/Components/ErrorSummary.stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ const meta: Meta<typeof ErrorSummary> = {
4848
export default meta;
4949
type Story = StoryObj<typeof ErrorSummary>;
5050

51+
ErrorSummary.Title.displayName = 'ErrorSummary.Title';
52+
ErrorSummary.Body.displayName = 'ErrorSummary.Body';
53+
ErrorSummary.List.displayName = 'ErrorSummary.List';
54+
ErrorSummary.Item.displayName = 'ErrorSummary.Item';
55+
5156
export const Standard: Story = {
52-
render: () => (
57+
render: (args) => (
5358
<ErrorSummary aria-labelledby="error-summary-title" role="alert" tabIndex={-1}>
5459
<ErrorSummary.Title id="error-summary-title">There is a problem</ErrorSummary.Title>
5560
<ErrorSummary.Body>

0 commit comments

Comments
 (0)