1
1
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' ;
3
4
import type { TextInputStatusType } from '../TextInput/TextInputStatus' ;
4
5
5
6
type AlertStatusType = TextInputStatusType & [ 'loading' ] ;
@@ -17,6 +18,25 @@ export default meta;
17
18
18
19
type Story = StoryObj < typeof meta > ;
19
20
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
+
20
40
export const Information : Story = {
21
41
render : arguments_ => < Alert { ...arguments_ } /> ,
22
42
args : { status : 'info' , message : 'A Notification' }
@@ -27,7 +47,8 @@ export const InformationWithExplanation: Story = {
27
47
name : 'Information with explanation' ,
28
48
args : {
29
49
...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.'
31
52
}
32
53
} ;
33
54
@@ -42,28 +63,42 @@ export const InformationWithLinks: Story = {
42
63
href : '/' ,
43
64
label : 'This is a link below the explanation'
44
65
} ,
45
- {
46
- href : '/' ,
47
- label : 'This is an external link' ,
48
- isExternal : true
49
- }
66
+ externalLinkProperties
50
67
]
51
68
}
52
69
} ;
53
70
54
71
export const Success : Story = {
55
72
...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
+ }
57
80
} ;
58
81
59
82
export const Warning : Story = {
60
83
...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
+ }
62
91
} ;
63
92
64
93
export const Error : Story = {
65
94
...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
+ }
67
102
} ;
68
103
69
104
export const InProgress : Story = {
@@ -92,7 +127,7 @@ export const SuccessFieldLevel: Story = {
92
127
name : 'Success (field-level)' ,
93
128
args : {
94
129
status : 'success' ,
95
- message : 'This is a field-level alert with a success status.'
130
+ message : < AlertMessage status = 'a success' />
96
131
}
97
132
} ;
98
133
@@ -112,7 +147,7 @@ export const WarningFieldLevel: Story = {
112
147
name : 'Warning (field-level)' ,
113
148
args : {
114
149
status : 'warning' ,
115
- message : 'This is a field-level alert with a warning status.'
150
+ message : < AlertMessage status = 'a warning' />
116
151
}
117
152
} ;
118
153
@@ -132,6 +167,6 @@ export const ErrorFieldLevel: Story = {
132
167
name : 'Error (field-level)' ,
133
168
args : {
134
169
status : 'error' ,
135
- message : 'This is a field-level alert with an error status.'
170
+ message : < AlertMessage status = ' an error' />
136
171
}
137
172
} ;
0 commit comments