@instructure/ui-alerts 8.15.1-snapshot.0 → 8.16.0
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 +4 -0
- package/es/Alert/index.js +14 -6
- package/es/Alert/props.js +0 -54
- package/lib/Alert/index.js +16 -6
- package/lib/Alert/props.js +0 -54
- package/package.json +17 -18
- package/src/Alert/index.tsx +27 -40
- package/src/Alert/props.ts +46 -42
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Alert/index.d.ts +22 -19
- package/types/Alert/index.d.ts.map +1 -1
- package/types/Alert/props.d.ts +49 -4
- package/types/Alert/props.d.ts.map +1 -1
- package/LICENSE.md +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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.16.0](https://github.com/instructure/instructure-ui/compare/v8.15.0...v8.16.0) (2022-02-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-alerts
|
|
9
|
+
|
|
6
10
|
# [8.15.0](https://github.com/instructure/instructure-ui/compare/v8.14.0...v8.15.0) (2022-01-26)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-alerts
|
package/es/Alert/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var _dec, _class, _class2, _temp;
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/** @jsx jsx */
|
|
28
|
-
import { Component } from 'react';
|
|
28
|
+
import React, { Component } from 'react';
|
|
29
29
|
import ReactDOM from 'react-dom';
|
|
30
30
|
import keycode from 'keycode';
|
|
31
31
|
import { callRenderProp } from '@instructure/ui-react-utils';
|
|
@@ -46,11 +46,13 @@ import { propTypes, allowedProps } from './props';
|
|
|
46
46
|
---
|
|
47
47
|
category: components
|
|
48
48
|
---
|
|
49
|
+
@tsProps
|
|
49
50
|
**/
|
|
50
51
|
let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class Alert extends Component {
|
|
51
52
|
constructor(props) {
|
|
52
53
|
super(props);
|
|
53
54
|
this._timeouts = [];
|
|
55
|
+
this.srid = void 0;
|
|
54
56
|
this.variantUI = {
|
|
55
57
|
error: IconNoSolid,
|
|
56
58
|
info: IconInfoBorderlessSolid,
|
|
@@ -127,7 +129,7 @@ let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
127
129
|
if (liveRegion) {
|
|
128
130
|
liveRegion.setAttribute('aria-live', this.props.liveRegionPoliteness);
|
|
129
131
|
liveRegion.setAttribute('aria-relevant', 'additions text');
|
|
130
|
-
liveRegion.setAttribute('aria-atomic', this.props.isLiveRegionAtomic);
|
|
132
|
+
liveRegion.setAttribute('aria-atomic', `${this.props.isLiveRegionAtomic}`);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
|
|
@@ -176,6 +178,8 @@ let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
176
178
|
const div = document.getElementById(this.srid);
|
|
177
179
|
|
|
178
180
|
if (div) {
|
|
181
|
+
var _div$parentNode;
|
|
182
|
+
|
|
179
183
|
// Accessibility attributes must be removed for the deletion of the node
|
|
180
184
|
// and then reapplied because JAWS/IE will not respect the
|
|
181
185
|
// "aria-relevant" attribute and read when the node is deleted if
|
|
@@ -184,14 +188,16 @@ let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
184
188
|
liveRegion.removeAttribute('aria-relevant');
|
|
185
189
|
liveRegion.removeAttribute('aria-atomic');
|
|
186
190
|
ReactDOM.unmountComponentAtNode(div);
|
|
187
|
-
div.parentNode.removeChild(div);
|
|
191
|
+
div === null || div === void 0 ? void 0 : (_div$parentNode = div.parentNode) === null || _div$parentNode === void 0 ? void 0 : _div$parentNode.removeChild(div);
|
|
188
192
|
this.initLiveRegion(liveRegion);
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
componentDidMount() {
|
|
194
|
-
|
|
198
|
+
var _this$props$makeStyle, _this$props;
|
|
199
|
+
|
|
200
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
195
201
|
const liveRegion = this.getLiveRegion();
|
|
196
202
|
|
|
197
203
|
if (liveRegion) {
|
|
@@ -203,7 +209,9 @@ let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
componentDidUpdate(prevProps) {
|
|
206
|
-
|
|
212
|
+
var _this$props$makeStyle2, _this$props2;
|
|
213
|
+
|
|
214
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
207
215
|
|
|
208
216
|
if (!!this.props.open === false && !!this.props.open !== !!prevProps.open) {
|
|
209
217
|
// this outside world is asking us to close the alert, which needs to
|
|
@@ -261,7 +269,7 @@ let Alert = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_clas
|
|
|
261
269
|
render() {
|
|
262
270
|
// Don't render anything if screen reader only
|
|
263
271
|
if (this.props.screenReaderOnly) {
|
|
264
|
-
error(this.getLiveRegion(), `[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`);
|
|
272
|
+
error(!!this.getLiveRegion(), `[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`);
|
|
265
273
|
return null;
|
|
266
274
|
}
|
|
267
275
|
|
package/es/Alert/props.js
CHANGED
|
@@ -24,72 +24,18 @@
|
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
import { ThemeablePropTypes } from '@instructure/emotion';
|
|
26
26
|
const propTypes = {
|
|
27
|
-
/**
|
|
28
|
-
* content to be rendered within Alert
|
|
29
|
-
*/
|
|
30
27
|
children: PropTypes.node,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Determines color and icon
|
|
34
|
-
*/
|
|
35
28
|
variant: PropTypes.oneOf(['info', 'success', 'warning', 'error']),
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
39
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
40
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
41
|
-
*/
|
|
42
29
|
margin: ThemeablePropTypes.spacing,
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Function that returns the DIV where screenreader alerts will be placed.
|
|
46
|
-
*/
|
|
47
30
|
liveRegion: PropTypes.func,
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Choose the politeness level of screenreader alerts.
|
|
51
|
-
*/
|
|
52
31
|
liveRegionPoliteness: PropTypes.oneOf(['polite', 'assertive']),
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* If the screenreader alert should be atomic
|
|
56
|
-
*/
|
|
57
32
|
isLiveRegionAtomic: PropTypes.bool,
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* If the alert should only be visible to screen readers
|
|
61
|
-
*/
|
|
62
33
|
screenReaderOnly: PropTypes.bool,
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Milliseconds until the Alert is dismissed automatically
|
|
66
|
-
*/
|
|
67
34
|
timeout: PropTypes.number,
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Close button label. Can be a React component
|
|
71
|
-
*/
|
|
72
35
|
renderCloseButtonLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Callback after the alert is closed
|
|
76
|
-
*/
|
|
77
36
|
onDismiss: PropTypes.func,
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Transition used to make the alert appear and disappear
|
|
81
|
-
*/
|
|
82
37
|
transition: PropTypes.oneOf(['none', 'fade']),
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* if open transitions from truthy to falsey, it's a signal to close and unmount the alert.
|
|
86
|
-
* This is necessary to close the alert from the outside and still run the transition.
|
|
87
|
-
*/
|
|
88
38
|
open: PropTypes.bool,
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* If the alert should have a shadow.
|
|
92
|
-
*/
|
|
93
39
|
hasShadow: PropTypes.bool
|
|
94
40
|
};
|
|
95
41
|
const allowedProps = ['children', 'variant', 'margin', 'liveRegion', 'liveRegionPoliteness', 'isLiveRegionAtomic', 'screenReaderOnly', 'timeout', 'renderCloseButtonLabel', 'onDismiss', 'transition', 'open', 'hasShadow'];
|
package/lib/Alert/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
|
|
3
5
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7,7 +9,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
9
|
});
|
|
8
10
|
exports.default = exports.Alert = void 0;
|
|
9
11
|
|
|
10
|
-
var _react = require("react");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
13
|
|
|
12
14
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
15
|
|
|
@@ -51,11 +53,13 @@ var _dec, _class, _class2, _temp;
|
|
|
51
53
|
---
|
|
52
54
|
category: components
|
|
53
55
|
---
|
|
56
|
+
@tsProps
|
|
54
57
|
**/
|
|
55
58
|
let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_temp = _class2 = class Alert extends _react.Component {
|
|
56
59
|
constructor(props) {
|
|
57
60
|
super(props);
|
|
58
61
|
this._timeouts = [];
|
|
62
|
+
this.srid = void 0;
|
|
59
63
|
this.variantUI = {
|
|
60
64
|
error: _IconNoSolid.IconNoSolid,
|
|
61
65
|
info: _IconInfoBorderlessSolid.IconInfoBorderlessSolid,
|
|
@@ -132,7 +136,7 @@ let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
132
136
|
if (liveRegion) {
|
|
133
137
|
liveRegion.setAttribute('aria-live', this.props.liveRegionPoliteness);
|
|
134
138
|
liveRegion.setAttribute('aria-relevant', 'additions text');
|
|
135
|
-
liveRegion.setAttribute('aria-atomic', this.props.isLiveRegionAtomic);
|
|
139
|
+
liveRegion.setAttribute('aria-atomic', `${this.props.isLiveRegionAtomic}`);
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
|
|
@@ -182,6 +186,8 @@ let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
182
186
|
const div = document.getElementById(this.srid);
|
|
183
187
|
|
|
184
188
|
if (div) {
|
|
189
|
+
var _div$parentNode;
|
|
190
|
+
|
|
185
191
|
// Accessibility attributes must be removed for the deletion of the node
|
|
186
192
|
// and then reapplied because JAWS/IE will not respect the
|
|
187
193
|
// "aria-relevant" attribute and read when the node is deleted if
|
|
@@ -192,14 +198,16 @@ let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
192
198
|
|
|
193
199
|
_reactDom.default.unmountComponentAtNode(div);
|
|
194
200
|
|
|
195
|
-
div.parentNode.removeChild(div);
|
|
201
|
+
div === null || div === void 0 ? void 0 : (_div$parentNode = div.parentNode) === null || _div$parentNode === void 0 ? void 0 : _div$parentNode.removeChild(div);
|
|
196
202
|
this.initLiveRegion(liveRegion);
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
componentDidMount() {
|
|
202
|
-
|
|
208
|
+
var _this$props$makeStyle, _this$props;
|
|
209
|
+
|
|
210
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
203
211
|
const liveRegion = this.getLiveRegion();
|
|
204
212
|
|
|
205
213
|
if (liveRegion) {
|
|
@@ -211,7 +219,9 @@ let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
211
219
|
}
|
|
212
220
|
|
|
213
221
|
componentDidUpdate(prevProps) {
|
|
214
|
-
|
|
222
|
+
var _this$props$makeStyle2, _this$props2;
|
|
223
|
+
|
|
224
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
215
225
|
|
|
216
226
|
if (!!this.props.open === false && !!this.props.open !== !!prevProps.open) {
|
|
217
227
|
// this outside world is asking us to close the alert, which needs to
|
|
@@ -269,7 +279,7 @@ let Alert = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _d
|
|
|
269
279
|
render() {
|
|
270
280
|
// Don't render anything if screen reader only
|
|
271
281
|
if (this.props.screenReaderOnly) {
|
|
272
|
-
(0, _console.logError)(this.getLiveRegion(), `[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`);
|
|
282
|
+
(0, _console.logError)(!!this.getLiveRegion(), `[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`);
|
|
273
283
|
return null;
|
|
274
284
|
}
|
|
275
285
|
|
package/lib/Alert/props.js
CHANGED
|
@@ -35,72 +35,18 @@ var _emotion = require("@instructure/emotion");
|
|
|
35
35
|
* SOFTWARE.
|
|
36
36
|
*/
|
|
37
37
|
const propTypes = {
|
|
38
|
-
/**
|
|
39
|
-
* content to be rendered within Alert
|
|
40
|
-
*/
|
|
41
38
|
children: _propTypes.default.node,
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Determines color and icon
|
|
45
|
-
*/
|
|
46
39
|
variant: _propTypes.default.oneOf(['info', 'success', 'warning', 'error']),
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
50
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
51
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
52
|
-
*/
|
|
53
40
|
margin: _emotion.ThemeablePropTypes.spacing,
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Function that returns the DIV where screenreader alerts will be placed.
|
|
57
|
-
*/
|
|
58
41
|
liveRegion: _propTypes.default.func,
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Choose the politeness level of screenreader alerts.
|
|
62
|
-
*/
|
|
63
42
|
liveRegionPoliteness: _propTypes.default.oneOf(['polite', 'assertive']),
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* If the screenreader alert should be atomic
|
|
67
|
-
*/
|
|
68
43
|
isLiveRegionAtomic: _propTypes.default.bool,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* If the alert should only be visible to screen readers
|
|
72
|
-
*/
|
|
73
44
|
screenReaderOnly: _propTypes.default.bool,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Milliseconds until the Alert is dismissed automatically
|
|
77
|
-
*/
|
|
78
45
|
timeout: _propTypes.default.number,
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Close button label. Can be a React component
|
|
82
|
-
*/
|
|
83
46
|
renderCloseButtonLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Callback after the alert is closed
|
|
87
|
-
*/
|
|
88
47
|
onDismiss: _propTypes.default.func,
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Transition used to make the alert appear and disappear
|
|
92
|
-
*/
|
|
93
48
|
transition: _propTypes.default.oneOf(['none', 'fade']),
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* if open transitions from truthy to falsey, it's a signal to close and unmount the alert.
|
|
97
|
-
* This is necessary to close the alert from the outside and still run the transition.
|
|
98
|
-
*/
|
|
99
49
|
open: _propTypes.default.bool,
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* If the alert should have a shadow.
|
|
103
|
-
*/
|
|
104
50
|
hasShadow: _propTypes.default.bool
|
|
105
51
|
};
|
|
106
52
|
exports.propTypes = propTypes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-alerts",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.0",
|
|
4
4
|
"description": "An alert component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,24 +24,24 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/ui-babel-preset": "8.
|
|
28
|
-
"@instructure/ui-color-utils": "8.
|
|
29
|
-
"@instructure/ui-test-utils": "8.
|
|
27
|
+
"@instructure/ui-babel-preset": "8.16.0",
|
|
28
|
+
"@instructure/ui-color-utils": "8.16.0",
|
|
29
|
+
"@instructure/ui-test-utils": "8.16.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.13.10",
|
|
33
|
-
"@instructure/console": "8.
|
|
34
|
-
"@instructure/emotion": "8.
|
|
35
|
-
"@instructure/shared-types": "8.
|
|
36
|
-
"@instructure/ui-a11y-content": "8.
|
|
37
|
-
"@instructure/ui-buttons": "8.
|
|
38
|
-
"@instructure/ui-icons": "8.
|
|
39
|
-
"@instructure/ui-motion": "8.
|
|
40
|
-
"@instructure/ui-react-utils": "8.
|
|
41
|
-
"@instructure/ui-themes": "8.
|
|
42
|
-
"@instructure/ui-utils": "8.
|
|
43
|
-
"@instructure/ui-view": "8.
|
|
44
|
-
"@instructure/uid": "8.
|
|
33
|
+
"@instructure/console": "8.16.0",
|
|
34
|
+
"@instructure/emotion": "8.16.0",
|
|
35
|
+
"@instructure/shared-types": "8.16.0",
|
|
36
|
+
"@instructure/ui-a11y-content": "8.16.0",
|
|
37
|
+
"@instructure/ui-buttons": "8.16.0",
|
|
38
|
+
"@instructure/ui-icons": "8.16.0",
|
|
39
|
+
"@instructure/ui-motion": "8.16.0",
|
|
40
|
+
"@instructure/ui-react-utils": "8.16.0",
|
|
41
|
+
"@instructure/ui-themes": "8.16.0",
|
|
42
|
+
"@instructure/ui-utils": "8.16.0",
|
|
43
|
+
"@instructure/ui-view": "8.16.0",
|
|
44
|
+
"@instructure/uid": "8.16.0",
|
|
45
45
|
"keycode": "^2",
|
|
46
46
|
"prop-types": "^15"
|
|
47
47
|
},
|
|
@@ -52,6 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"sideEffects": false
|
|
56
|
-
"gitHead": "d331a2330d5b1d0e2353093d05c28b12b329b6b3"
|
|
55
|
+
"sideEffects": false
|
|
57
56
|
}
|
package/src/Alert/index.tsx
CHANGED
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
|
-
import { Component } from 'react'
|
|
25
|
+
import React, { Component } from 'react'
|
|
26
26
|
import ReactDOM from 'react-dom'
|
|
27
27
|
import keycode from 'keycode'
|
|
28
28
|
|
|
29
29
|
import { callRenderProp } from '@instructure/ui-react-utils'
|
|
30
30
|
import { CloseButton } from '@instructure/ui-buttons'
|
|
31
31
|
import { View } from '@instructure/ui-view'
|
|
32
|
+
import type { ViewOwnProps } from '@instructure/ui-view'
|
|
32
33
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
33
34
|
import {
|
|
34
35
|
IconCheckMarkSolid,
|
|
@@ -46,15 +47,16 @@ import generateStyle from './styles'
|
|
|
46
47
|
import generateComponentTheme from './theme'
|
|
47
48
|
|
|
48
49
|
import { propTypes, allowedProps } from './props'
|
|
49
|
-
import type { AlertProps } from './props'
|
|
50
|
+
import type { AlertProps, AlertState } from './props'
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
---
|
|
53
54
|
category: components
|
|
54
55
|
---
|
|
56
|
+
@tsProps
|
|
55
57
|
**/
|
|
56
58
|
@withStyle(generateStyle, generateComponentTheme)
|
|
57
|
-
class Alert extends Component<AlertProps> {
|
|
59
|
+
class Alert extends Component<AlertProps, AlertState> {
|
|
58
60
|
static readonly componentId = 'Alert'
|
|
59
61
|
|
|
60
62
|
static propTypes = propTypes
|
|
@@ -72,8 +74,7 @@ class Alert extends Component<AlertProps> {
|
|
|
72
74
|
hasShadow: true
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
constructor(props) {
|
|
77
|
+
constructor(props: AlertProps) {
|
|
77
78
|
super(props)
|
|
78
79
|
|
|
79
80
|
this.state = {
|
|
@@ -81,7 +82,8 @@ class Alert extends Component<AlertProps> {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
_timeouts = []
|
|
85
|
+
_timeouts: ReturnType<typeof setTimeout>[] = []
|
|
86
|
+
srid?: string
|
|
85
87
|
|
|
86
88
|
variantUI = {
|
|
87
89
|
error: IconNoSolid,
|
|
@@ -97,10 +99,8 @@ class Alert extends Component<AlertProps> {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
handleTimeout = () => {
|
|
100
|
-
|
|
101
|
-
if (this.props.timeout > 0) {
|
|
102
|
+
if (this.props.timeout! > 0) {
|
|
102
103
|
this._timeouts.push(
|
|
103
|
-
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Timeout' is not assignable to pa... Remove this comment to see the full error message
|
|
104
104
|
setTimeout(() => {
|
|
105
105
|
this.close()
|
|
106
106
|
}, this.props.timeout)
|
|
@@ -130,8 +130,7 @@ class Alert extends Component<AlertProps> {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// duck type for a dom node
|
|
133
|
-
|
|
134
|
-
isDOMNode(n) {
|
|
133
|
+
isDOMNode(n: Element | null) {
|
|
135
134
|
return n && typeof n === 'object' && n.nodeType === 1
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -144,17 +143,19 @@ class Alert extends Component<AlertProps> {
|
|
|
144
143
|
return this.isDOMNode(lr) ? lr : null
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
initLiveRegion(liveRegion) {
|
|
146
|
+
initLiveRegion(liveRegion: Element) {
|
|
149
147
|
error(
|
|
150
148
|
liveRegion.getAttribute('role') === 'alert',
|
|
151
149
|
`[Alert] live region must have role='alert' set on page load in order to announce content`
|
|
152
150
|
)
|
|
153
151
|
|
|
154
152
|
if (liveRegion) {
|
|
155
|
-
liveRegion.setAttribute('aria-live', this.props.liveRegionPoliteness)
|
|
153
|
+
liveRegion.setAttribute('aria-live', this.props.liveRegionPoliteness!)
|
|
156
154
|
liveRegion.setAttribute('aria-relevant', 'additions text')
|
|
157
|
-
liveRegion.setAttribute(
|
|
155
|
+
liveRegion.setAttribute(
|
|
156
|
+
'aria-atomic',
|
|
157
|
+
`${this.props.isLiveRegionAtomic!}`
|
|
158
|
+
)
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
|
|
@@ -165,11 +166,9 @@ class Alert extends Component<AlertProps> {
|
|
|
165
166
|
createScreenreaderAlert() {
|
|
166
167
|
const liveRegion = this.getLiveRegion()
|
|
167
168
|
if (liveRegion) {
|
|
168
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'srid' does not exist on type 'Alert'.
|
|
169
169
|
this.srid = uid('Alert')
|
|
170
170
|
|
|
171
171
|
const div = document.createElement('div')
|
|
172
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'srid' does not exist on type 'Alert'.
|
|
173
172
|
div.setAttribute('id', this.srid)
|
|
174
173
|
|
|
175
174
|
this.renderScreenreeaderAlert(div)
|
|
@@ -179,19 +178,16 @@ class Alert extends Component<AlertProps> {
|
|
|
179
178
|
|
|
180
179
|
updateScreenreaderAlert() {
|
|
181
180
|
if (this.getLiveRegion()) {
|
|
182
|
-
|
|
183
|
-
const div = document.getElementById(this.srid)
|
|
181
|
+
const div = document.getElementById(this.srid!) as HTMLDivElement
|
|
184
182
|
if (div) {
|
|
185
|
-
|
|
186
|
-
ReactDOM.render(null, div, () => {
|
|
183
|
+
ReactDOM.render(null as any, div, () => {
|
|
187
184
|
this.renderScreenreeaderAlert(div)
|
|
188
185
|
})
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
189
|
|
|
193
|
-
|
|
194
|
-
renderScreenreeaderAlert(div) {
|
|
190
|
+
renderScreenreeaderAlert(div: HTMLDivElement) {
|
|
195
191
|
const content = this.createScreenreaderContentNode()
|
|
196
192
|
ReactDOM.render(
|
|
197
193
|
// since ScreenReaderContent gets rendered outside the app,
|
|
@@ -205,8 +201,7 @@ class Alert extends Component<AlertProps> {
|
|
|
205
201
|
removeScreenreaderAlert() {
|
|
206
202
|
const liveRegion = this.getLiveRegion()
|
|
207
203
|
if (liveRegion) {
|
|
208
|
-
|
|
209
|
-
const div = document.getElementById(this.srid)
|
|
204
|
+
const div = document.getElementById(this.srid!)
|
|
210
205
|
if (div) {
|
|
211
206
|
// Accessibility attributes must be removed for the deletion of the node
|
|
212
207
|
// and then reapplied because JAWS/IE will not respect the
|
|
@@ -217,16 +212,14 @@ class Alert extends Component<AlertProps> {
|
|
|
217
212
|
liveRegion.removeAttribute('aria-atomic')
|
|
218
213
|
|
|
219
214
|
ReactDOM.unmountComponentAtNode(div)
|
|
220
|
-
|
|
221
|
-
div.parentNode.removeChild(div)
|
|
215
|
+
div?.parentNode?.removeChild(div)
|
|
222
216
|
|
|
223
217
|
this.initLiveRegion(liveRegion)
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
}
|
|
227
221
|
|
|
228
|
-
|
|
229
|
-
handleKeyUp = (event) => {
|
|
222
|
+
handleKeyUp = (event: React.KeyboardEvent<ViewOwnProps>) => {
|
|
230
223
|
if (
|
|
231
224
|
this.props.renderCloseButtonLabel &&
|
|
232
225
|
event.keyCode === keycode.codes.esc
|
|
@@ -236,8 +229,7 @@ class Alert extends Component<AlertProps> {
|
|
|
236
229
|
}
|
|
237
230
|
|
|
238
231
|
componentDidMount() {
|
|
239
|
-
|
|
240
|
-
this.props.makeStyles()
|
|
232
|
+
this.props.makeStyles?.()
|
|
241
233
|
const liveRegion = this.getLiveRegion()
|
|
242
234
|
if (liveRegion) {
|
|
243
235
|
this.initLiveRegion(liveRegion)
|
|
@@ -247,10 +239,8 @@ class Alert extends Component<AlertProps> {
|
|
|
247
239
|
this.createScreenreaderAlert()
|
|
248
240
|
}
|
|
249
241
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
|
253
|
-
this.props.makeStyles()
|
|
242
|
+
componentDidUpdate(prevProps: AlertProps) {
|
|
243
|
+
this.props.makeStyles?.()
|
|
254
244
|
if (!!this.props.open === false && !!this.props.open !== !!prevProps.open) {
|
|
255
245
|
// this outside world is asking us to close the alert, which needs to
|
|
256
246
|
// take place internally so the transition runs
|
|
@@ -268,8 +258,7 @@ class Alert extends Component<AlertProps> {
|
|
|
268
258
|
}
|
|
269
259
|
|
|
270
260
|
renderIcon() {
|
|
271
|
-
|
|
272
|
-
const Icon = this.variantUI[this.props.variant]
|
|
261
|
+
const Icon = this.variantUI[this.props.variant!]
|
|
273
262
|
return (
|
|
274
263
|
<div css={this.props.styles?.icon}>
|
|
275
264
|
<Icon />
|
|
@@ -313,7 +302,7 @@ class Alert extends Component<AlertProps> {
|
|
|
313
302
|
// Don't render anything if screen reader only
|
|
314
303
|
if (this.props.screenReaderOnly) {
|
|
315
304
|
error(
|
|
316
|
-
this.getLiveRegion(),
|
|
305
|
+
!!this.getLiveRegion(),
|
|
317
306
|
`[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`
|
|
318
307
|
)
|
|
319
308
|
|
|
@@ -321,14 +310,12 @@ class Alert extends Component<AlertProps> {
|
|
|
321
310
|
}
|
|
322
311
|
|
|
323
312
|
if (this.props.transition === 'none') {
|
|
324
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'open' does not exist on type 'Readonly<{... Remove this comment to see the full error message
|
|
325
313
|
return this.state.open ? this.renderAlert() : null
|
|
326
314
|
}
|
|
327
315
|
return (
|
|
328
316
|
<Transition
|
|
329
317
|
type={this.props.transition}
|
|
330
318
|
transitionOnMount
|
|
331
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'open' does not exist on type 'Readonly<{... Remove this comment to see the full error message
|
|
332
319
|
in={this.state.open}
|
|
333
320
|
unmountOnExit
|
|
334
321
|
onExited={this.onExitTransition}
|