UNPKG

11.1 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
14var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _styles = require("@material-ui/core/styles");
23
24var _Paper = _interopRequireDefault(require("@material-ui/core/Paper"));
25
26var _SuccessOutlined = _interopRequireDefault(require("../internal/svg-icons/SuccessOutlined"));
27
28var _ReportProblemOutlined = _interopRequireDefault(require("../internal/svg-icons/ReportProblemOutlined"));
29
30var _ErrorOutline = _interopRequireDefault(require("../internal/svg-icons/ErrorOutline"));
31
32var _InfoOutlined = _interopRequireDefault(require("../internal/svg-icons/InfoOutlined"));
33
34var _Close = _interopRequireDefault(require("../internal/svg-icons/Close"));
35
36var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
37
38var _utils = require("@material-ui/core/utils");
39
40var styles = function styles(theme) {
41 var getColor = theme.palette.type === 'light' ? _styles.darken : _styles.lighten;
42 var getBackgroundColor = theme.palette.type === 'light' ? _styles.lighten : _styles.darken;
43 return {
44 /* Styles applied to the root element. */
45 root: (0, _extends2.default)({}, theme.typography.body2, {
46 borderRadius: theme.shape.borderRadius,
47 backgroundColor: 'transparent',
48 display: 'flex',
49 padding: '6px 16px'
50 }),
51
52 /* Styles applied to the root element if `variant="standard"` and `color="success"`. */
53 standardSuccess: {
54 color: getColor(theme.palette.success.main, 0.6),
55 backgroundColor: getBackgroundColor(theme.palette.success.main, 0.9),
56 '& $icon': {
57 color: theme.palette.success.main
58 }
59 },
60
61 /* Styles applied to the root element if `variant="standard"` and `color="info"`. */
62 standardInfo: {
63 color: getColor(theme.palette.info.main, 0.6),
64 backgroundColor: getBackgroundColor(theme.palette.info.main, 0.9),
65 '& $icon': {
66 color: theme.palette.info.main
67 }
68 },
69
70 /* Styles applied to the root element if `variant="standard"` and `color="warning"`. */
71 standardWarning: {
72 color: getColor(theme.palette.warning.main, 0.6),
73 backgroundColor: getBackgroundColor(theme.palette.warning.main, 0.9),
74 '& $icon': {
75 color: theme.palette.warning.main
76 }
77 },
78
79 /* Styles applied to the root element if `variant="standard"` and `color="error"`. */
80 standardError: {
81 color: getColor(theme.palette.error.main, 0.6),
82 backgroundColor: getBackgroundColor(theme.palette.error.main, 0.9),
83 '& $icon': {
84 color: theme.palette.error.main
85 }
86 },
87
88 /* Styles applied to the root element if `variant="outlined"` and `color="success"`. */
89 outlinedSuccess: {
90 color: getColor(theme.palette.success.main, 0.6),
91 border: "1px solid ".concat(theme.palette.success.main),
92 '& $icon': {
93 color: theme.palette.success.main
94 }
95 },
96
97 /* Styles applied to the root element if `variant="outlined"` and `color="info"`. */
98 outlinedInfo: {
99 color: getColor(theme.palette.info.main, 0.6),
100 border: "1px solid ".concat(theme.palette.info.main),
101 '& $icon': {
102 color: theme.palette.info.main
103 }
104 },
105
106 /* Styles applied to the root element if `variant="outlined"` and `color="warning"`. */
107 outlinedWarning: {
108 color: getColor(theme.palette.warning.main, 0.6),
109 border: "1px solid ".concat(theme.palette.warning.main),
110 '& $icon': {
111 color: theme.palette.warning.main
112 }
113 },
114
115 /* Styles applied to the root element if `variant="outlined"` and `color="error"`. */
116 outlinedError: {
117 color: getColor(theme.palette.error.main, 0.6),
118 border: "1px solid ".concat(theme.palette.error.main),
119 '& $icon': {
120 color: theme.palette.error.main
121 }
122 },
123
124 /* Styles applied to the root element if `variant="filled"` and `color="success"`. */
125 filledSuccess: {
126 color: '#fff',
127 fontWeight: theme.typography.fontWeightMedium,
128 backgroundColor: theme.palette.success.main
129 },
130
131 /* Styles applied to the root element if `variant="filled"` and `color="info"`. */
132 filledInfo: {
133 color: '#fff',
134 fontWeight: theme.typography.fontWeightMedium,
135 backgroundColor: theme.palette.info.main
136 },
137
138 /* Styles applied to the root element if `variant="filled"` and `color="warning"`. */
139 filledWarning: {
140 color: '#fff',
141 fontWeight: theme.typography.fontWeightMedium,
142 backgroundColor: theme.palette.warning.main
143 },
144
145 /* Styles applied to the root element if `variant="filled"` and `color="error"`. */
146 filledError: {
147 color: '#fff',
148 fontWeight: theme.typography.fontWeightMedium,
149 backgroundColor: theme.palette.error.main
150 },
151
152 /* Styles applied to the icon wrapper element. */
153 icon: {
154 marginRight: 12,
155 padding: '7px 0',
156 display: 'flex',
157 fontSize: 22,
158 opacity: 0.9
159 },
160
161 /* Styles applied to the message wrapper element. */
162 message: {
163 padding: '8px 0'
164 },
165
166 /* Styles applied to the action wrapper element if `action` is provided. */
167 action: {
168 display: 'flex',
169 alignItems: 'center',
170 marginLeft: 'auto',
171 paddingLeft: 16,
172 marginRight: -8
173 }
174 };
175};
176
177exports.styles = styles;
178var defaultIconMapping = {
179 success: /*#__PURE__*/React.createElement(_SuccessOutlined.default, {
180 fontSize: "inherit"
181 }),
182 warning: /*#__PURE__*/React.createElement(_ReportProblemOutlined.default, {
183 fontSize: "inherit"
184 }),
185 error: /*#__PURE__*/React.createElement(_ErrorOutline.default, {
186 fontSize: "inherit"
187 }),
188 info: /*#__PURE__*/React.createElement(_InfoOutlined.default, {
189 fontSize: "inherit"
190 })
191};
192
193var _ref = /*#__PURE__*/React.createElement(_Close.default, {
194 fontSize: "small"
195});
196
197var Alert = /*#__PURE__*/React.forwardRef(function Alert(props, ref) {
198 var action = props.action,
199 children = props.children,
200 classes = props.classes,
201 className = props.className,
202 _props$closeText = props.closeText,
203 closeText = _props$closeText === void 0 ? 'Close' : _props$closeText,
204 color = props.color,
205 icon = props.icon,
206 _props$iconMapping = props.iconMapping,
207 iconMapping = _props$iconMapping === void 0 ? defaultIconMapping : _props$iconMapping,
208 onClose = props.onClose,
209 _props$role = props.role,
210 role = _props$role === void 0 ? 'alert' : _props$role,
211 _props$severity = props.severity,
212 severity = _props$severity === void 0 ? 'success' : _props$severity,
213 _props$variant = props.variant,
214 variant = _props$variant === void 0 ? 'standard' : _props$variant,
215 other = (0, _objectWithoutProperties2.default)(props, ["action", "children", "classes", "className", "closeText", "color", "icon", "iconMapping", "onClose", "role", "severity", "variant"]);
216 return /*#__PURE__*/React.createElement(_Paper.default, (0, _extends2.default)({
217 role: role,
218 square: true,
219 elevation: 0,
220 className: (0, _clsx.default)(classes.root, classes["".concat(variant).concat((0, _utils.capitalize)(color || severity))], className),
221 ref: ref
222 }, other), icon !== false ? /*#__PURE__*/React.createElement("div", {
223 className: classes.icon
224 }, icon || iconMapping[severity] || defaultIconMapping[severity]) : null, /*#__PURE__*/React.createElement("div", {
225 className: classes.message
226 }, children), action != null ? /*#__PURE__*/React.createElement("div", {
227 className: classes.action
228 }, action) : null, action == null && onClose ? /*#__PURE__*/React.createElement("div", {
229 className: classes.action
230 }, /*#__PURE__*/React.createElement(_IconButton.default, {
231 size: "small",
232 "aria-label": closeText,
233 title: closeText,
234 color: "inherit",
235 onClick: onClose
236 }, _ref)) : null);
237});
238process.env.NODE_ENV !== "production" ? Alert.propTypes = {
239 // ----------------------------- Warning --------------------------------
240 // | These PropTypes are generated from the TypeScript type definitions |
241 // | To update them edit the d.ts file and run "yarn proptypes" |
242 // ----------------------------------------------------------------------
243
244 /**
245 * The action to display. It renders after the message, at the end of the alert.
246 */
247 action: _propTypes.default.node,
248
249 /**
250 * The content of the component.
251 */
252 children: _propTypes.default.node,
253
254 /**
255 * Override or extend the styles applied to the component.
256 * See [CSS API](#css) below for more details.
257 */
258 classes: _propTypes.default.object,
259
260 /**
261 * @ignore
262 */
263 className: _propTypes.default.string,
264
265 /**
266 * Override the default label for the *close popup* icon button.
267 *
268 * For localization purposes, you can use the provided [translations](/guides/localization/).
269 */
270 closeText: _propTypes.default.string,
271
272 /**
273 * The main color for the alert. Unless provided, the value is taken from the `severity` prop.
274 */
275 color: _propTypes.default.oneOf(['error', 'info', 'success', 'warning']),
276
277 /**
278 * Override the icon displayed before the children.
279 * Unless provided, the icon is mapped to the value of the `severity` prop.
280 */
281 icon: _propTypes.default.node,
282
283 /**
284 * The component maps the `severity` prop to a range of different icons,
285 * for instance success to `<SuccessOutlined>`.
286 * If you wish to change this mapping, you can provide your own.
287 * Alternatively, you can use the `icon` prop to override the icon displayed.
288 */
289 iconMapping: _propTypes.default.shape({
290 error: _propTypes.default.node,
291 info: _propTypes.default.node,
292 success: _propTypes.default.node,
293 warning: _propTypes.default.node
294 }),
295
296 /**
297 * Callback fired when the component requests to be closed.
298 * When provided and no `action` prop is set, a close icon button is displayed that triggers the callback when clicked.
299 *
300 * @param {object} event The event source of the callback.
301 */
302 onClose: _propTypes.default.func,
303
304 /**
305 * The ARIA role attribute of the element.
306 */
307 role: _propTypes.default.string,
308
309 /**
310 * The severity of the alert. This defines the color and icon used.
311 */
312 severity: _propTypes.default.oneOf(['error', 'info', 'success', 'warning']),
313
314 /**
315 * The variant to use.
316 */
317 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
318} : void 0;
319
320var _default = (0, _styles.withStyles)(styles, {
321 name: 'MuiAlert'
322})(Alert);
323
324exports.default = _default;
\No newline at end of file