@instructure/ui-alerts 8.50.1-snapshot-2 → 8.50.1-snapshot-14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.50.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v8.50.0...v8.50.1-snapshot-2) (2023-12-06)
6
+ ## [8.50.1-snapshot-14](https://github.com/instructure/instructure-ui/compare/v8.50.0...v8.50.1-snapshot-14) (2023-12-08)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-alerts
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-alerts",
3
- "version": "8.50.1-snapshot-2",
3
+ "version": "8.50.1-snapshot-14",
4
4
  "description": "An alert component",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,24 +23,24 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.50.1-snapshot-2",
27
- "@instructure/ui-color-utils": "8.50.1-snapshot-2",
28
- "@instructure/ui-test-utils": "8.50.1-snapshot-2"
26
+ "@instructure/ui-babel-preset": "8.50.1-snapshot-14",
27
+ "@instructure/ui-color-utils": "8.50.1-snapshot-14",
28
+ "@instructure/ui-test-utils": "8.50.1-snapshot-14"
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.23.2",
32
- "@instructure/console": "8.50.1-snapshot-2",
33
- "@instructure/emotion": "8.50.1-snapshot-2",
34
- "@instructure/shared-types": "8.50.1-snapshot-2",
35
- "@instructure/ui-a11y-content": "8.50.1-snapshot-2",
36
- "@instructure/ui-buttons": "8.50.1-snapshot-2",
37
- "@instructure/ui-icons": "8.50.1-snapshot-2",
38
- "@instructure/ui-motion": "8.50.1-snapshot-2",
39
- "@instructure/ui-react-utils": "8.50.1-snapshot-2",
40
- "@instructure/ui-themes": "8.50.1-snapshot-2",
41
- "@instructure/ui-utils": "8.50.1-snapshot-2",
42
- "@instructure/ui-view": "8.50.1-snapshot-2",
43
- "@instructure/uid": "8.50.1-snapshot-2",
32
+ "@instructure/console": "8.50.1-snapshot-14",
33
+ "@instructure/emotion": "8.50.1-snapshot-14",
34
+ "@instructure/shared-types": "8.50.1-snapshot-14",
35
+ "@instructure/ui-a11y-content": "8.50.1-snapshot-14",
36
+ "@instructure/ui-buttons": "8.50.1-snapshot-14",
37
+ "@instructure/ui-icons": "8.50.1-snapshot-14",
38
+ "@instructure/ui-motion": "8.50.1-snapshot-14",
39
+ "@instructure/ui-react-utils": "8.50.1-snapshot-14",
40
+ "@instructure/ui-themes": "8.50.1-snapshot-14",
41
+ "@instructure/ui-utils": "8.50.1-snapshot-14",
42
+ "@instructure/ui-view": "8.50.1-snapshot-14",
43
+ "@instructure/uid": "8.50.1-snapshot-14",
44
44
  "keycode": "^2.2.1",
45
45
  "prop-types": "^15.8.1"
46
46
  },
@@ -12,7 +12,7 @@ space above or below the alert.
12
12
 
13
13
  ```js
14
14
  ---
15
- example: true
15
+ type: example
16
16
  ---
17
17
  <div>
18
18
  <Alert
@@ -53,7 +53,7 @@ The `timeout` prop can be used to automatically dismiss an alert after a time.
53
53
 
54
54
  ```js
55
55
  ---
56
- example: true
56
+ type: example
57
57
  ---
58
58
  <Alert
59
59
  variant="info"
@@ -76,132 +76,210 @@ ensure that element has the correct ARIA attributes.
76
76
  For more information about live regions, see
77
77
  [this MDN article](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions).
78
78
 
79
- ```js
80
- ---
81
- example: true
82
- render: false
83
- ---
84
- class Example extends React.Component {
85
- constructor (props) {
86
- super(props)
79
+ - ```js
80
+ class Example extends React.Component {
81
+ constructor(props) {
82
+ super(props)
87
83
 
88
- this.state = {
89
- alerts: []
84
+ this.state = {
85
+ alerts: []
86
+ }
87
+
88
+ this.i = 0
89
+ this.variants = ['info', 'success', 'warning', 'error']
90
+ this.politeness = ['polite', 'assertive']
90
91
  }
91
92
 
92
- this.i = 0
93
- this.variants = ['info', 'success', 'warning', 'error']
94
- this.politeness = ['polite', 'assertive']
95
- }
93
+ addAlert() {
94
+ const variant = this.variants[this.i++ % this.variants.length]
95
+ const politeness = Math.random() < 0.5 ? 'polite' : 'assertive'
96
+ const alerts = [...this.state.alerts]
97
+ const key = new Number(this.i)
98
+ alerts.push({
99
+ key,
100
+ variant,
101
+ politeness,
102
+ onDismiss: () => this.closeAlert(key)
103
+ })
104
+ this.setState({ alerts })
105
+ }
96
106
 
97
- addAlert () {
98
- const variant = this.variants[this.i++ % this.variants.length]
99
- const politeness = Math.random() < 0.5 ? 'polite' : 'assertive'
100
- const alerts = [...this.state.alerts]
101
- const key = new Number(this.i)
102
- alerts.push({
103
- key,
104
- variant,
105
- politeness,
106
- onDismiss: () => this.closeAlert(key)
107
- })
108
- this.setState({ alerts })
109
- }
107
+ closeAlert(key) {
108
+ const alerts = this.state.alerts.filter((alert) => {
109
+ return alert.key !== key
110
+ })
111
+ this.setState({ alerts })
112
+ }
110
113
 
111
- closeAlert (key) {
112
- const alerts = this.state.alerts.filter((alert) => {
113
- return alert.key !== key
114
- })
115
- this.setState({ alerts })
114
+ render() {
115
+ return (
116
+ <div>
117
+ <Button onClick={this.addAlert.bind(this)}>Add Alert</Button>
118
+ {this.state.alerts.map((alert) => {
119
+ return (
120
+ <View key={alert.key} display="block" margin="small 0">
121
+ <Alert
122
+ variant={alert.variant}
123
+ renderCloseButtonLabel="Close"
124
+ onDismiss={alert.onDismiss}
125
+ liveRegion={() => document.getElementById('flash-messages')}
126
+ liveRegionPoliteness={alert.politeness}
127
+ margin="small 0"
128
+ >
129
+ This is {alert.politeness === 'polite' ? 'a' : 'an'}{' '}
130
+ {alert.politeness} {alert.variant} alert
131
+ </Alert>
132
+ </View>
133
+ )
134
+ })}
135
+ </div>
136
+ )
137
+ }
116
138
  }
117
139
 
118
- render () {
140
+ render(<Example />)
141
+ ```
142
+
143
+ - ```js
144
+ const Example = () => {
145
+ const [alerts, setAlerts] = useState([])
146
+ const [count, setcount] = useState(0)
147
+
148
+ const variants = ['info', 'success', 'warning', 'error']
149
+
150
+ const addAlert = () => {
151
+ const variant = variants[count % variants.length]
152
+ const politeness = Math.random() < 0.5 ? 'polite' : 'assertive'
153
+ setAlerts([
154
+ ...alerts,
155
+ {
156
+ key: count,
157
+ variant,
158
+ politeness
159
+ }
160
+ ])
161
+ setcount(count + 1)
162
+ }
163
+
164
+ const closeAlert = (key) =>
165
+ setAlerts(alerts.filter((alert) => alert.key !== key))
166
+
119
167
  return (
120
168
  <div>
121
- <Button onClick={this.addAlert.bind(this)}>Add Alert</Button>
122
- {this.state.alerts.map((alert) => {
169
+ <Button onClick={addAlert}>Add Alert</Button>
170
+ {alerts.map((alert) => {
123
171
  return (
124
- <View
125
- key={alert.key}
126
- display="block"
127
- margin="small 0"
128
- >
172
+ <View key={alert.key} display="block" margin="small 0">
129
173
  <Alert
130
174
  variant={alert.variant}
131
175
  renderCloseButtonLabel="Close"
132
- onDismiss={alert.onDismiss}
176
+ onDismiss={() => closeAlert(alert.key)}
133
177
  liveRegion={() => document.getElementById('flash-messages')}
134
178
  liveRegionPoliteness={alert.politeness}
135
179
  margin="small 0"
136
180
  >
137
- This is {alert.politeness === 'polite' ? 'a' : 'an'} {alert.politeness} {alert.variant} alert
181
+ This is {alert.politeness === 'polite' ? 'a' : 'an'}{' '}
182
+ {alert.politeness} {alert.variant} alert
138
183
  </Alert>
139
184
  </View>
140
185
  )
141
186
  })}
142
187
  </div>
143
- );
188
+ )
144
189
  }
145
- }
146
190
 
147
- render(<Example />)
148
- ```
191
+ render(<Example />)
192
+ ```
149
193
 
150
194
  Alerts can be used to emit screenreader only messages too
151
195
 
152
- ```js
153
- ---
154
- example: true
155
- render: false
156
- ---
157
- class Example extends React.Component {
158
- constructor (props) {
159
- super(props)
196
+ - ```js
197
+ class Example extends React.Component {
198
+ constructor(props) {
199
+ super(props)
160
200
 
161
- this.state = {
162
- message: null,
163
- count: 1
201
+ this.state = {
202
+ message: null,
203
+ count: 1
204
+ }
164
205
  }
165
- }
166
206
 
167
- changeMessage = () => {
168
- this.setState({
169
- message: `this is message ${this.state.count}`,
170
- count: this.state.count + 1
207
+ changeMessage = () => {
208
+ this.setState({
209
+ message: `this is message ${this.state.count}`,
210
+ count: this.state.count + 1
171
211
  })
172
- }
212
+ }
173
213
 
174
- clearMessage =() => {
175
- this.setState({
176
- message: null,
177
- count: this.state.count + 1})
214
+ clearMessage = () => {
215
+ this.setState({
216
+ message: null,
217
+ count: this.state.count + 1
218
+ })
219
+ }
220
+
221
+ render() {
222
+ return (
223
+ <div>
224
+ <Button onClick={this.changeMessage}>Change Message</Button>
225
+ <Button onClick={this.clearMessage} margin="0 0 0 small">
226
+ Clear Message
227
+ </Button>
228
+ <Alert
229
+ liveRegion={() => document.getElementById('flash-messages')}
230
+ isLiveRegionAtomic
231
+ screenReaderOnly
232
+ >
233
+ {this.state.message}
234
+ </Alert>
235
+ </div>
236
+ )
237
+ }
178
238
  }
179
239
 
180
- render () {
240
+ render(<Example />)
241
+ ```
242
+
243
+ - ```js
244
+ const Example = () => {
245
+ const [message, setMessage] = useState(null)
246
+ const [count, setCount] = useState(1)
247
+
248
+ const changeMessage = () => {
249
+ setMessage(`this is message ${count}`)
250
+ setCount(count + 1)
251
+ }
252
+
253
+ const clearMessage = () => {
254
+ setMessage(null)
255
+ setCount(count + 1)
256
+ }
257
+
181
258
  return (
182
259
  <div>
183
- <Button onClick={this.changeMessage}>Change Message</Button>
184
- <Button onClick={this.clearMessage} margin="0 0 0 small">Clear Message</Button>
260
+ <Button onClick={changeMessage}>Change Message</Button>
261
+ <Button onClick={clearMessage} margin="0 0 0 small">
262
+ Clear Message
263
+ </Button>
185
264
  <Alert
186
265
  liveRegion={() => document.getElementById('flash-messages')}
187
266
  isLiveRegionAtomic
188
267
  screenReaderOnly
189
- >
190
- {this.state.message}
268
+ >
269
+ {message}
191
270
  </Alert>
192
271
  </div>
193
- );
272
+ )
194
273
  }
195
- }
196
274
 
197
- render(<Example />)
198
- ```
275
+ render(<Example />)
276
+ ```
199
277
 
200
278
  When Alerts are used inline, the shadow can be removed with the `hasShadow` property.
201
279
 
202
280
  ```js
203
281
  ---
204
- example: true
282
+ type: example
205
283
  ---
206
284
  <View as="div" background="primary" padding="large">
207
285
  <View
@@ -239,7 +317,7 @@ example: true
239
317
 
240
318
  ```js
241
319
  ---
242
- guidelines: true
320
+ type: embed
243
321
  ---
244
322
  <Guidelines>
245
323
  <Figure recommendation="yes" title="Do">
@@ -257,7 +335,7 @@ guidelines: true
257
335
 
258
336
  ```js
259
337
  ---
260
- guidelines: true
338
+ type: embed
261
339
  ---
262
340
  <Guidelines>
263
341
  <Figure recommendation="a11y" title="Accessibility">