Skip to content

Commit 9d0f076

Browse files
committed
[Alert.stories] Better align examples with the DS Alert examples while also demonstrating the unique features implemented via DSR
1 parent 55e237e commit 9d0f076

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

src/components/Alert/Alert.stories.tsx

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/react';
2-
import { Alert, AlertFieldLevel, TextInput } from '~/src/index';
2+
import { ReactNode } from 'react';
3+
import { Alert, AlertFieldLevel, Icon, Link, TextInput } from '~/src/index';
34
import type { TextInputStatusType } from '../TextInput/TextInputStatus';
45

56
type AlertStatusType = TextInputStatusType & ['loading'];
@@ -17,6 +18,25 @@ export default meta;
1718

1819
type Story = StoryObj<typeof meta>;
1920

21+
const AlertMessage = ({ status = 'a warning' }): ReactNode => (
22+
<>
23+
This is a field-level alert with {status} status.{' '}
24+
<Link hasIcon href={window.location.pathname}>
25+
Link to more info <Icon name='external-link' />
26+
</Link>
27+
.
28+
</>
29+
);
30+
31+
const alertExplanation = (type: string): string =>
32+
`This is an optional explanation of the ${type} message.`;
33+
34+
const externalLinkProperties = {
35+
href: '/',
36+
label: 'This is an external link',
37+
isExternal: true
38+
};
39+
2040
export const Information: Story = {
2141
render: arguments_ => <Alert {...arguments_} />,
2242
args: { status: 'info', message: 'A Notification' }
@@ -27,7 +47,8 @@ export const InformationWithExplanation: Story = {
2747
name: 'Information with explanation',
2848
args: {
2949
...Information.args,
30-
children: 'You can also add an explanation to the notification.'
50+
children:
51+
'This is a longer explanation to demonstrate how text wrapping is applied to more extensive alert content.'
3152
}
3253
};
3354

@@ -42,28 +63,42 @@ export const InformationWithLinks: Story = {
4263
href: '/',
4364
label: 'This is a link below the explanation'
4465
},
45-
{
46-
href: '/',
47-
label: 'This is an external link',
48-
isExternal: true
49-
}
66+
externalLinkProperties
5067
]
5168
}
5269
};
5370

5471
export const Success: Story = {
5572
...Information,
56-
args: { ...Information.args, status: 'success', message: '11 results' }
73+
args: {
74+
...Information.args,
75+
status: 'success',
76+
message: '11 results',
77+
links: [externalLinkProperties],
78+
children: <>{alertExplanation('success')}</>
79+
}
5780
};
5881

5982
export const Warning: Story = {
6083
...Information,
61-
args: { ...Information.args, status: 'warning', message: 'No results found.' }
84+
args: {
85+
...Information.args,
86+
status: 'warning',
87+
message: 'No results found.',
88+
links: [externalLinkProperties],
89+
children: <>{alertExplanation('warning')}</>
90+
}
6291
};
6392

6493
export const Error: Story = {
6594
...Information,
66-
args: { ...Information.args, status: 'error', message: 'Page not found.' }
95+
args: {
96+
...Information.args,
97+
status: 'error',
98+
message: 'Page not found.',
99+
links: [externalLinkProperties],
100+
children: <>{alertExplanation('error')}</>
101+
}
67102
};
68103

69104
export const InProgress: Story = {
@@ -92,7 +127,7 @@ export const SuccessFieldLevel: Story = {
92127
name: 'Success (field-level)',
93128
args: {
94129
status: 'success',
95-
message: 'This is a field-level alert with a success status.'
130+
message: <AlertMessage status='a success' />
96131
}
97132
};
98133

@@ -112,7 +147,7 @@ export const WarningFieldLevel: Story = {
112147
name: 'Warning (field-level)',
113148
args: {
114149
status: 'warning',
115-
message: 'This is a field-level alert with a warning status.'
150+
message: <AlertMessage status='a warning' />
116151
}
117152
};
118153

@@ -132,6 +167,6 @@ export const ErrorFieldLevel: Story = {
132167
name: 'Error (field-level)',
133168
args: {
134169
status: 'error',
135-
message: 'This is a field-level alert with an error status.'
170+
message: <AlertMessage status='an error' />
136171
}
137172
};

0 commit comments

Comments
 (0)