@instructure/ui-alerts 11.6.0 → 11.6.1-snapshot-129
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 +36 -295
- package/es/Alert/{index.js → v1/index.js} +3 -3
- package/es/Alert/v2/index.js +263 -0
- package/es/Alert/v2/props.js +26 -0
- package/es/Alert/v2/styles.js +134 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Alert/{index.js → v1/index.js} +9 -9
- package/lib/Alert/v2/index.js +270 -0
- package/lib/Alert/v2/props.js +31 -0
- package/lib/Alert/v2/styles.js +140 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +44 -22
- package/src/Alert/{index.tsx → v1/index.tsx} +4 -4
- package/src/Alert/v2/README.md +249 -0
- package/src/Alert/v2/index.tsx +349 -0
- package/src/Alert/v2/props.ts +148 -0
- package/src/Alert/v2/styles.ts +137 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Alert/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Alert/v1/index.d.ts.map +1 -0
- package/types/Alert/v1/props.d.ts.map +1 -0
- package/types/Alert/v1/styles.d.ts.map +1 -0
- package/types/Alert/v1/theme.d.ts.map +1 -0
- package/types/Alert/v2/index.d.ts +73 -0
- package/types/Alert/v2/index.d.ts.map +1 -0
- package/types/Alert/v2/props.d.ts +92 -0
- package/types/Alert/v2/props.d.ts.map +1 -0
- package/types/Alert/v2/styles.d.ts +15 -0
- package/types/Alert/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Alert/index.d.ts.map +0 -1
- package/types/Alert/props.d.ts.map +0 -1
- package/types/Alert/styles.d.ts.map +0 -1
- package/types/Alert/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Alert/{props.js → v1/props.js} +0 -0
- /package/es/Alert/{styles.js → v1/styles.js} +0 -0
- /package/es/Alert/{theme.js → v1/theme.js} +0 -0
- /package/lib/Alert/{props.js → v1/props.js} +0 -0
- /package/lib/Alert/{styles.js → v1/styles.js} +0 -0
- /package/lib/Alert/{theme.js → v1/theme.js} +0 -0
- /package/src/Alert/{README.md → v1/README.md} +0 -0
- /package/src/Alert/{props.ts → v1/props.ts} +0 -0
- /package/src/Alert/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Alert/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Alert/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Alert/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Alert/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
const _excluded = ["margin", "styles", "children", "onDismiss", "variantScreenReaderLabel"];
|
|
3
|
+
var _dec, _dec2, _class, _Alert;
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { Fragment, Component } from 'react';
|
|
29
|
+
import ReactDOM from 'react-dom';
|
|
30
|
+
import keycode from 'keycode';
|
|
31
|
+
import { callRenderProp, withDeterministicId, passthroughProps } from '@instructure/ui-react-utils';
|
|
32
|
+
import { CloseButton } from '@instructure/ui-buttons/latest';
|
|
33
|
+
import { View } from '@instructure/ui-view/latest';
|
|
34
|
+
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
|
|
35
|
+
import { InfoInstUIIcon, XCircleInstUIIcon, CircleCheckInstUIIcon, TriangleAlertInstUIIcon } from '@instructure/ui-icons';
|
|
36
|
+
import { Transition } from '@instructure/ui-motion';
|
|
37
|
+
import { logError as error } from '@instructure/console';
|
|
38
|
+
import { withStyle } from '@instructure/emotion';
|
|
39
|
+
import generateStyle from "./styles.js";
|
|
40
|
+
import { allowedProps } from "./props.js";
|
|
41
|
+
import { jsxs as _jsxs, jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
42
|
+
/**
|
|
43
|
+
---
|
|
44
|
+
category: components
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
let Alert = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Alert = class Alert extends Component {
|
|
48
|
+
constructor(props) {
|
|
49
|
+
super(props);
|
|
50
|
+
this._timeouts = [];
|
|
51
|
+
this.srid = void 0;
|
|
52
|
+
this.variantUI = {
|
|
53
|
+
error: XCircleInstUIIcon,
|
|
54
|
+
info: InfoInstUIIcon,
|
|
55
|
+
success: CircleCheckInstUIIcon,
|
|
56
|
+
warning: TriangleAlertInstUIIcon
|
|
57
|
+
};
|
|
58
|
+
this.ref = null;
|
|
59
|
+
this.handleRef = el => {
|
|
60
|
+
this.ref = el;
|
|
61
|
+
};
|
|
62
|
+
this.handleTimeout = () => {
|
|
63
|
+
if (this.props.timeout > 0) {
|
|
64
|
+
this._timeouts.push(setTimeout(() => {
|
|
65
|
+
this.close();
|
|
66
|
+
}, this.props.timeout));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.onExitTransition = () => {
|
|
70
|
+
if (this.props.onDismiss) {
|
|
71
|
+
this.props.onDismiss();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
this.close = () => {
|
|
75
|
+
this.clearTimeouts();
|
|
76
|
+
this.removeScreenreaderAlert();
|
|
77
|
+
this.setState({
|
|
78
|
+
open: false
|
|
79
|
+
}, () => {
|
|
80
|
+
if (this.props.onDismiss && (this.props.transition === 'none' || this.props.screenReaderOnly)) {
|
|
81
|
+
this.props.onDismiss();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
this.handleKeyUp = event => {
|
|
86
|
+
if (this.props.renderCloseButtonLabel && event.keyCode === keycode.codes.esc) {
|
|
87
|
+
this.close();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.srid = this.props.deterministicId();
|
|
91
|
+
this.state = {
|
|
92
|
+
open: true
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
clearTimeouts() {
|
|
96
|
+
this._timeouts.forEach(timeout => clearTimeout(timeout));
|
|
97
|
+
this._timeouts = [];
|
|
98
|
+
}
|
|
99
|
+
// duck type for a dom node
|
|
100
|
+
isDOMNode(n) {
|
|
101
|
+
return n && typeof n === 'object' && n.nodeType === 1;
|
|
102
|
+
}
|
|
103
|
+
getLiveRegion() {
|
|
104
|
+
const lr = typeof this.props.liveRegion === 'function' ? this.props.liveRegion() : this.props.liveRegion;
|
|
105
|
+
return this.isDOMNode(lr) ? lr : null;
|
|
106
|
+
}
|
|
107
|
+
initLiveRegion(liveRegion) {
|
|
108
|
+
error(liveRegion.getAttribute('role') === 'alert', `[Alert] live region must have role='alert' set on page load in order to announce content`);
|
|
109
|
+
if (liveRegion) {
|
|
110
|
+
liveRegion.setAttribute('aria-live', this.props.liveRegionPoliteness);
|
|
111
|
+
// indicates what notifications the user agent will trigger when the
|
|
112
|
+
// accessibility tree within a live region is modified.
|
|
113
|
+
// additions: elements are added, text: Text content is added
|
|
114
|
+
liveRegion.setAttribute('aria-relevant', 'additions text');
|
|
115
|
+
liveRegion.setAttribute('aria-atomic', `${this.props.isLiveRegionAtomic}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
createScreenreaderContentNode() {
|
|
119
|
+
return _jsxs(ScreenReaderContent, {
|
|
120
|
+
children: [this.props.variantScreenReaderLabel || '', " ", this.props.children]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
createScreenreaderAlert() {
|
|
124
|
+
const liveRegion = this.getLiveRegion();
|
|
125
|
+
if (liveRegion) {
|
|
126
|
+
const div = document.createElement('div');
|
|
127
|
+
div.setAttribute('id', this.srid);
|
|
128
|
+
liveRegion.appendChild(div);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
removeScreenreaderAlert() {
|
|
132
|
+
const liveRegion = this.getLiveRegion();
|
|
133
|
+
if (liveRegion) {
|
|
134
|
+
const div = document.getElementById(this.srid);
|
|
135
|
+
if (div) {
|
|
136
|
+
// Accessibility attributes must be removed for the deletion of the node
|
|
137
|
+
// and then reapplied because JAWS/IE will not respect the
|
|
138
|
+
// "aria-relevant" attribute and read when the node is deleted if
|
|
139
|
+
// the attributes are in place
|
|
140
|
+
liveRegion.removeAttribute('aria-live');
|
|
141
|
+
liveRegion.removeAttribute('aria-relevant');
|
|
142
|
+
liveRegion.removeAttribute('aria-atomic');
|
|
143
|
+
this.initLiveRegion(liveRegion);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
componentDidMount() {
|
|
148
|
+
var _this$props$makeStyle, _this$props;
|
|
149
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
150
|
+
const liveRegion = this.getLiveRegion();
|
|
151
|
+
if (liveRegion) {
|
|
152
|
+
this.initLiveRegion(liveRegion);
|
|
153
|
+
}
|
|
154
|
+
this.handleTimeout();
|
|
155
|
+
}
|
|
156
|
+
componentWillUnmount() {
|
|
157
|
+
this.clearTimeouts();
|
|
158
|
+
}
|
|
159
|
+
componentDidUpdate(prevProps) {
|
|
160
|
+
var _this$props$makeStyle2, _this$props2;
|
|
161
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
162
|
+
if (!!this.props.open === false && !!this.props.open !== !!prevProps.open) {
|
|
163
|
+
// this outside world is asking us to close the alert, which needs to
|
|
164
|
+
// take place internally so the transition runs
|
|
165
|
+
this.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
renderIcon() {
|
|
169
|
+
const _this$props3 = this.props,
|
|
170
|
+
renderCustomIcon = _this$props3.renderCustomIcon,
|
|
171
|
+
variant = _this$props3.variant,
|
|
172
|
+
styles = _this$props3.styles;
|
|
173
|
+
const Icon = this.variantUI[variant];
|
|
174
|
+
return _jsx("div", {
|
|
175
|
+
css: styles === null || styles === void 0 ? void 0 : styles.icon,
|
|
176
|
+
children: renderCustomIcon ? callRenderProp(renderCustomIcon) : _jsx(Icon, {})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
renderCloseButton() {
|
|
180
|
+
var _this$props$styles;
|
|
181
|
+
const closeButtonLabel = this.props.renderCloseButtonLabel && callRenderProp(this.props.renderCloseButtonLabel);
|
|
182
|
+
return closeButtonLabel ? _jsx("div", {
|
|
183
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.closeButton,
|
|
184
|
+
children: _jsx(CloseButton, {
|
|
185
|
+
onClick: this.close,
|
|
186
|
+
size: "small",
|
|
187
|
+
screenReaderLabel: closeButtonLabel
|
|
188
|
+
})
|
|
189
|
+
}, "closeButton") : null;
|
|
190
|
+
}
|
|
191
|
+
renderAlert() {
|
|
192
|
+
// prevent onDismiss from being passed to the View component
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
194
|
+
const _this$props4 = this.props,
|
|
195
|
+
margin = _this$props4.margin,
|
|
196
|
+
styles = _this$props4.styles,
|
|
197
|
+
children = _this$props4.children,
|
|
198
|
+
onDismiss = _this$props4.onDismiss,
|
|
199
|
+
variantScreenReaderLabel = _this$props4.variantScreenReaderLabel,
|
|
200
|
+
props = _objectWithoutProperties(_this$props4, _excluded);
|
|
201
|
+
return _jsxs(View, {
|
|
202
|
+
...passthroughProps({
|
|
203
|
+
...props
|
|
204
|
+
}),
|
|
205
|
+
as: "div",
|
|
206
|
+
margin: margin,
|
|
207
|
+
css: styles === null || styles === void 0 ? void 0 : styles.alert,
|
|
208
|
+
onKeyUp: this.handleKeyUp,
|
|
209
|
+
elementRef: this.handleRef,
|
|
210
|
+
children: [this.renderIcon(), _jsxs("div", {
|
|
211
|
+
css: styles === null || styles === void 0 ? void 0 : styles.content,
|
|
212
|
+
children: [variantScreenReaderLabel && _jsx("span", {
|
|
213
|
+
css: styles === null || styles === void 0 ? void 0 : styles.variantScreenReaderLabel,
|
|
214
|
+
children: variantScreenReaderLabel
|
|
215
|
+
}), children]
|
|
216
|
+
}), this.renderCloseButton()]
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
createScreenReaderPortal(liveRegion) {
|
|
220
|
+
const open = this.state.open;
|
|
221
|
+
return open ? /*#__PURE__*/ReactDOM.createPortal(_jsx("div", {
|
|
222
|
+
id: this.srid,
|
|
223
|
+
children: this.createScreenreaderContentNode()
|
|
224
|
+
}), liveRegion) : null;
|
|
225
|
+
}
|
|
226
|
+
render() {
|
|
227
|
+
const liveRegion = this.getLiveRegion();
|
|
228
|
+
const screenReaderContent = liveRegion ? this.createScreenReaderPortal(liveRegion) : null;
|
|
229
|
+
// Don't render anything if screen reader only
|
|
230
|
+
if (this.props.screenReaderOnly) {
|
|
231
|
+
error(!!this.getLiveRegion(), `[Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.`);
|
|
232
|
+
return screenReaderContent;
|
|
233
|
+
}
|
|
234
|
+
if (this.props.transition === 'none') {
|
|
235
|
+
return this.state.open ? _jsxs(Fragment, {
|
|
236
|
+
children: [screenReaderContent, this.renderAlert()]
|
|
237
|
+
}) : null;
|
|
238
|
+
}
|
|
239
|
+
return _jsxs(Fragment, {
|
|
240
|
+
children: [screenReaderContent, _jsx(Transition, {
|
|
241
|
+
type: this.props.transition,
|
|
242
|
+
transitionOnMount: true,
|
|
243
|
+
in: this.state.open,
|
|
244
|
+
unmountOnExit: true,
|
|
245
|
+
onExited: this.onExitTransition,
|
|
246
|
+
children: this.renderAlert()
|
|
247
|
+
})]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}, _Alert.displayName = "Alert", _Alert.componentId = 'Alert', _Alert.allowedProps = allowedProps, _Alert.defaultProps = {
|
|
251
|
+
variant: 'info',
|
|
252
|
+
margin: 'x-small 0',
|
|
253
|
+
timeout: 0,
|
|
254
|
+
transition: 'fade',
|
|
255
|
+
open: true,
|
|
256
|
+
screenReaderOnly: false,
|
|
257
|
+
liveRegionPoliteness: 'assertive',
|
|
258
|
+
isLiveRegionAtomic: false,
|
|
259
|
+
children: null,
|
|
260
|
+
hasShadow: true
|
|
261
|
+
}, _Alert)) || _class) || _class);
|
|
262
|
+
export default Alert;
|
|
263
|
+
export { Alert };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['children', 'variant', 'margin', 'liveRegion', 'liveRegionPoliteness', 'isLiveRegionAtomic', 'screenReaderOnly', 'timeout', 'renderCloseButtonLabel', 'onDismiss', 'transition', 'open', 'hasShadow', 'renderCustomIcon'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { boxShadowObjectsToCSSString } from '@instructure/ui-themes';
|
|
26
|
+
/**
|
|
27
|
+
* ---
|
|
28
|
+
* private: true
|
|
29
|
+
* ---
|
|
30
|
+
* Generates the style object from the theme and provided additional information
|
|
31
|
+
* @param {Object} componentTheme The theme variable object.
|
|
32
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
33
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
34
|
+
* @return {Object} The final style object, which will be used in the component
|
|
35
|
+
*/
|
|
36
|
+
const generateStyle = (componentTheme, props, sharedTokens) => {
|
|
37
|
+
const variant = props.variant,
|
|
38
|
+
hasShadow = props.hasShadow;
|
|
39
|
+
const variantStyles = {
|
|
40
|
+
error: {
|
|
41
|
+
alert: {
|
|
42
|
+
borderColor: componentTheme.dangerBorderColor
|
|
43
|
+
},
|
|
44
|
+
icon: {
|
|
45
|
+
background: componentTheme.dangerIconBackground,
|
|
46
|
+
borderRightColor: componentTheme.dangerIconBackground
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
info: {
|
|
50
|
+
alert: {
|
|
51
|
+
borderColor: componentTheme.infoBorderColor
|
|
52
|
+
},
|
|
53
|
+
icon: {
|
|
54
|
+
background: componentTheme.infoIconBackground,
|
|
55
|
+
borderRightColor: componentTheme.infoIconBackground
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
success: {
|
|
59
|
+
alert: {
|
|
60
|
+
borderColor: componentTheme.successBorderColor
|
|
61
|
+
},
|
|
62
|
+
icon: {
|
|
63
|
+
backgroundColor: componentTheme.successIconBackground,
|
|
64
|
+
borderRightColor: componentTheme.successIconBackground
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
warning: {
|
|
68
|
+
alert: {
|
|
69
|
+
borderColor: componentTheme.warningBorderColor
|
|
70
|
+
},
|
|
71
|
+
icon: {
|
|
72
|
+
background: componentTheme.warningIconBackground,
|
|
73
|
+
borderRightColor: componentTheme.warningIconBackground
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
alert: {
|
|
79
|
+
label: 'alert',
|
|
80
|
+
color: componentTheme.color,
|
|
81
|
+
background: componentTheme.background,
|
|
82
|
+
boxSizing: 'border-box',
|
|
83
|
+
display: 'flex',
|
|
84
|
+
minWidth: '12rem',
|
|
85
|
+
borderWidth: componentTheme.borderWidth,
|
|
86
|
+
borderStyle: componentTheme.borderStyle,
|
|
87
|
+
borderRadius: componentTheme.borderRadius,
|
|
88
|
+
...variantStyles[variant].alert,
|
|
89
|
+
...(hasShadow && {
|
|
90
|
+
boxShadow: boxShadowObjectsToCSSString(sharedTokens.boxShadow.elevation4)
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
icon: {
|
|
94
|
+
color: componentTheme.iconColor,
|
|
95
|
+
boxSizing: 'border-box',
|
|
96
|
+
flex: '0 0 2.5rem',
|
|
97
|
+
display: 'flex',
|
|
98
|
+
alignItems: 'center',
|
|
99
|
+
justifyContent: 'center',
|
|
100
|
+
fontSize: '1.125rem',
|
|
101
|
+
borderRight: `${componentTheme.borderWidth} ${componentTheme.borderStyle}`,
|
|
102
|
+
margin: -1,
|
|
103
|
+
borderStartStartRadius: componentTheme.borderRadius,
|
|
104
|
+
borderEndStartRadius: componentTheme.borderRadius,
|
|
105
|
+
...variantStyles[variant].icon
|
|
106
|
+
},
|
|
107
|
+
closeButton: {
|
|
108
|
+
boxSizing: 'border-box',
|
|
109
|
+
display: 'flex',
|
|
110
|
+
alignItems: 'flex-start',
|
|
111
|
+
order: 1,
|
|
112
|
+
marginTop: componentTheme.closeButtonMarginTop,
|
|
113
|
+
marginRight: componentTheme.closeButtonMarginRight
|
|
114
|
+
},
|
|
115
|
+
content: {
|
|
116
|
+
boxSizing: 'border-box',
|
|
117
|
+
flex: 1,
|
|
118
|
+
minWidth: '0.0625rem',
|
|
119
|
+
fontSize: componentTheme.contentFontSize,
|
|
120
|
+
fontFamily: componentTheme.contentFontFamily,
|
|
121
|
+
fontWeight: componentTheme.contentFontWeight,
|
|
122
|
+
lineHeight: componentTheme.contentLineHeight,
|
|
123
|
+
padding: `${componentTheme.contentPaddingVertical} ${componentTheme.contentPaddingHorizontal}`
|
|
124
|
+
},
|
|
125
|
+
variantScreenReaderLabel: {
|
|
126
|
+
position: 'absolute',
|
|
127
|
+
height: '1px',
|
|
128
|
+
width: '1px',
|
|
129
|
+
overflow: 'hidden',
|
|
130
|
+
margin: '-1px'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export default generateStyle;
|
|
@@ -12,13 +12,13 @@ var _keycode = _interopRequireDefault(require("keycode"));
|
|
|
12
12
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
13
13
|
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
14
14
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
15
|
-
var
|
|
16
|
-
var
|
|
15
|
+
var _v11_ = require("@instructure/ui-buttons/v11_6");
|
|
16
|
+
var _v11_2 = require("@instructure/ui-view/v11_6");
|
|
17
17
|
var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
|
|
18
|
-
var _IconCheckMarkSolid = require("@instructure/ui-icons/lib/IconCheckMarkSolid.js");
|
|
19
|
-
var _IconInfoBorderlessSolid = require("@instructure/ui-icons/lib/IconInfoBorderlessSolid.js");
|
|
20
|
-
var _IconWarningBorderlessSolid = require("@instructure/ui-icons/lib/IconWarningBorderlessSolid.js");
|
|
21
|
-
var _IconNoSolid = require("@instructure/ui-icons/lib/IconNoSolid.js");
|
|
18
|
+
var _IconCheckMarkSolid = require("@instructure/ui-icons/lib/generated/IconCheckMarkSolid.js");
|
|
19
|
+
var _IconInfoBorderlessSolid = require("@instructure/ui-icons/lib/generated/IconInfoBorderlessSolid.js");
|
|
20
|
+
var _IconWarningBorderlessSolid = require("@instructure/ui-icons/lib/generated/IconWarningBorderlessSolid.js");
|
|
21
|
+
var _IconNoSolid = require("@instructure/ui-icons/lib/generated/IconNoSolid.js");
|
|
22
22
|
var _Transition = require("@instructure/ui-motion/lib/Transition");
|
|
23
23
|
var _console = require("@instructure/console");
|
|
24
24
|
var _emotion = require("@instructure/emotion");
|
|
@@ -56,7 +56,7 @@ var _dec, _dec2, _class, _Alert;
|
|
|
56
56
|
category: components
|
|
57
57
|
---
|
|
58
58
|
**/
|
|
59
|
-
let Alert = exports.Alert = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.
|
|
59
|
+
let Alert = exports.Alert = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_Alert = class Alert extends _react.Component {
|
|
60
60
|
constructor(props) {
|
|
61
61
|
super(props);
|
|
62
62
|
this._timeouts = [];
|
|
@@ -193,7 +193,7 @@ let Alert = exports.Alert = (_dec = (0, _withDeterministicId.withDeterministicId
|
|
|
193
193
|
const closeButtonLabel = this.props.renderCloseButtonLabel && (0, _callRenderProp.callRenderProp)(this.props.renderCloseButtonLabel);
|
|
194
194
|
return closeButtonLabel ? (0, _jsxRuntime.jsx)("div", {
|
|
195
195
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.closeButton,
|
|
196
|
-
children: (0, _jsxRuntime.jsx)(
|
|
196
|
+
children: (0, _jsxRuntime.jsx)(_v11_.CloseButton, {
|
|
197
197
|
onClick: this.close,
|
|
198
198
|
size: "small",
|
|
199
199
|
screenReaderLabel: closeButtonLabel
|
|
@@ -210,7 +210,7 @@ let Alert = exports.Alert = (_dec = (0, _withDeterministicId.withDeterministicId
|
|
|
210
210
|
onDismiss = _this$props4.onDismiss,
|
|
211
211
|
variantScreenReaderLabel = _this$props4.variantScreenReaderLabel,
|
|
212
212
|
props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
|
|
213
|
-
return (0, _jsxRuntime.jsxs)(
|
|
213
|
+
return (0, _jsxRuntime.jsxs)(_v11_2.View, {
|
|
214
214
|
...(0, _passthroughProps.passthroughProps)({
|
|
215
215
|
...props
|
|
216
216
|
}),
|