1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { withStyles, lighten, darken } from '@material-ui/core/styles';
|
7 | import Paper from '@material-ui/core/Paper';
|
8 | import SuccessOutlinedIcon from '../internal/svg-icons/SuccessOutlined';
|
9 | import ReportProblemOutlinedIcon from '../internal/svg-icons/ReportProblemOutlined';
|
10 | import ErrorOutlineIcon from '../internal/svg-icons/ErrorOutline';
|
11 | import InfoOutlinedIcon from '../internal/svg-icons/InfoOutlined';
|
12 | import CloseIcon from '../internal/svg-icons/Close';
|
13 | import IconButton from '@material-ui/core/IconButton';
|
14 | import { capitalize } from '@material-ui/core/utils';
|
15 | export const styles = theme => {
|
16 | const getColor = theme.palette.type === 'light' ? darken : lighten;
|
17 | const getBackgroundColor = theme.palette.type === 'light' ? lighten : darken;
|
18 | return {
|
19 |
|
20 | root: _extends({}, theme.typography.body2, {
|
21 | borderRadius: theme.shape.borderRadius,
|
22 | backgroundColor: 'transparent',
|
23 | display: 'flex',
|
24 | padding: '6px 16px'
|
25 | }),
|
26 |
|
27 |
|
28 | standardSuccess: {
|
29 | color: getColor(theme.palette.success.main, 0.6),
|
30 | backgroundColor: getBackgroundColor(theme.palette.success.main, 0.9),
|
31 | '& $icon': {
|
32 | color: theme.palette.success.main
|
33 | }
|
34 | },
|
35 |
|
36 |
|
37 | standardInfo: {
|
38 | color: getColor(theme.palette.info.main, 0.6),
|
39 | backgroundColor: getBackgroundColor(theme.palette.info.main, 0.9),
|
40 | '& $icon': {
|
41 | color: theme.palette.info.main
|
42 | }
|
43 | },
|
44 |
|
45 |
|
46 | standardWarning: {
|
47 | color: getColor(theme.palette.warning.main, 0.6),
|
48 | backgroundColor: getBackgroundColor(theme.palette.warning.main, 0.9),
|
49 | '& $icon': {
|
50 | color: theme.palette.warning.main
|
51 | }
|
52 | },
|
53 |
|
54 |
|
55 | standardError: {
|
56 | color: getColor(theme.palette.error.main, 0.6),
|
57 | backgroundColor: getBackgroundColor(theme.palette.error.main, 0.9),
|
58 | '& $icon': {
|
59 | color: theme.palette.error.main
|
60 | }
|
61 | },
|
62 |
|
63 |
|
64 | outlinedSuccess: {
|
65 | color: getColor(theme.palette.success.main, 0.6),
|
66 | border: `1px solid ${theme.palette.success.main}`,
|
67 | '& $icon': {
|
68 | color: theme.palette.success.main
|
69 | }
|
70 | },
|
71 |
|
72 |
|
73 | outlinedInfo: {
|
74 | color: getColor(theme.palette.info.main, 0.6),
|
75 | border: `1px solid ${theme.palette.info.main}`,
|
76 | '& $icon': {
|
77 | color: theme.palette.info.main
|
78 | }
|
79 | },
|
80 |
|
81 |
|
82 | outlinedWarning: {
|
83 | color: getColor(theme.palette.warning.main, 0.6),
|
84 | border: `1px solid ${theme.palette.warning.main}`,
|
85 | '& $icon': {
|
86 | color: theme.palette.warning.main
|
87 | }
|
88 | },
|
89 |
|
90 |
|
91 | outlinedError: {
|
92 | color: getColor(theme.palette.error.main, 0.6),
|
93 | border: `1px solid ${theme.palette.error.main}`,
|
94 | '& $icon': {
|
95 | color: theme.palette.error.main
|
96 | }
|
97 | },
|
98 |
|
99 |
|
100 | filledSuccess: {
|
101 | color: '#fff',
|
102 | fontWeight: theme.typography.fontWeightMedium,
|
103 | backgroundColor: theme.palette.success.main
|
104 | },
|
105 |
|
106 |
|
107 | filledInfo: {
|
108 | color: '#fff',
|
109 | fontWeight: theme.typography.fontWeightMedium,
|
110 | backgroundColor: theme.palette.info.main
|
111 | },
|
112 |
|
113 |
|
114 | filledWarning: {
|
115 | color: '#fff',
|
116 | fontWeight: theme.typography.fontWeightMedium,
|
117 | backgroundColor: theme.palette.warning.main
|
118 | },
|
119 |
|
120 |
|
121 | filledError: {
|
122 | color: '#fff',
|
123 | fontWeight: theme.typography.fontWeightMedium,
|
124 | backgroundColor: theme.palette.error.main
|
125 | },
|
126 |
|
127 |
|
128 | icon: {
|
129 | marginRight: 12,
|
130 | padding: '7px 0',
|
131 | display: 'flex',
|
132 | fontSize: 22,
|
133 | opacity: 0.9
|
134 | },
|
135 |
|
136 |
|
137 | message: {
|
138 | padding: '8px 0'
|
139 | },
|
140 |
|
141 |
|
142 | action: {
|
143 | display: 'flex',
|
144 | alignItems: 'center',
|
145 | marginLeft: 'auto',
|
146 | paddingLeft: 16,
|
147 | marginRight: -8
|
148 | }
|
149 | };
|
150 | };
|
151 | const defaultIconMapping = {
|
152 | success: React.createElement(SuccessOutlinedIcon, {
|
153 | fontSize: "inherit"
|
154 | }),
|
155 | warning: React.createElement(ReportProblemOutlinedIcon, {
|
156 | fontSize: "inherit"
|
157 | }),
|
158 | error: React.createElement(ErrorOutlineIcon, {
|
159 | fontSize: "inherit"
|
160 | }),
|
161 | info: React.createElement(InfoOutlinedIcon, {
|
162 | fontSize: "inherit"
|
163 | })
|
164 | };
|
165 |
|
166 | var _ref = React.createElement(CloseIcon, {
|
167 | fontSize: "small"
|
168 | });
|
169 |
|
170 | const Alert = React.forwardRef(function Alert(props, ref) {
|
171 | const {
|
172 | action,
|
173 | children,
|
174 | classes,
|
175 | className,
|
176 | closeText = 'Close',
|
177 | color,
|
178 | icon,
|
179 | iconMapping = defaultIconMapping,
|
180 | onClose,
|
181 | role = 'alert',
|
182 | severity = 'success',
|
183 | variant = 'standard'
|
184 | } = props,
|
185 | other = _objectWithoutPropertiesLoose(props, ["action", "children", "classes", "className", "closeText", "color", "icon", "iconMapping", "onClose", "role", "severity", "variant"]);
|
186 |
|
187 | return React.createElement(Paper, _extends({
|
188 | role: role,
|
189 | square: true,
|
190 | elevation: 0,
|
191 | className: clsx(classes.root, classes[`${variant}${capitalize(color || severity)}`], className),
|
192 | ref: ref
|
193 | }, other), icon !== false ? React.createElement("div", {
|
194 | className: classes.icon
|
195 | }, icon || iconMapping[severity] || defaultIconMapping[severity]) : null, React.createElement("div", {
|
196 | className: classes.message
|
197 | }, children), action != null ? React.createElement("div", {
|
198 | className: classes.action
|
199 | }, action) : null, action == null && onClose ? React.createElement("div", {
|
200 | className: classes.action
|
201 | }, React.createElement(IconButton, {
|
202 | size: "small",
|
203 | "aria-label": closeText,
|
204 | title: closeText,
|
205 | color: "inherit",
|
206 | onClick: onClose
|
207 | }, _ref)) : null);
|
208 | });
|
209 | process.env.NODE_ENV !== "production" ? Alert.propTypes = {
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | |
216 |
|
217 |
|
218 | action: PropTypes.node,
|
219 |
|
220 | |
221 |
|
222 |
|
223 | children: PropTypes.node,
|
224 |
|
225 | |
226 |
|
227 |
|
228 |
|
229 | classes: PropTypes.object,
|
230 |
|
231 | |
232 |
|
233 |
|
234 | className: PropTypes.string,
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 | closeText: PropTypes.string,
|
242 |
|
243 | |
244 |
|
245 |
|
246 | color: PropTypes.oneOf(['error', 'info', 'success', 'warning']),
|
247 |
|
248 | |
249 |
|
250 |
|
251 |
|
252 | icon: PropTypes.node,
|
253 |
|
254 | |
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | iconMapping: PropTypes.shape({
|
261 | error: PropTypes.node,
|
262 | info: PropTypes.node,
|
263 | success: PropTypes.node,
|
264 | warning: PropTypes.node
|
265 | }),
|
266 |
|
267 | |
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | onClose: PropTypes.func,
|
274 |
|
275 | |
276 |
|
277 |
|
278 | role: PropTypes.string,
|
279 |
|
280 | |
281 |
|
282 |
|
283 | severity: PropTypes.oneOf(['error', 'info', 'success', 'warning']),
|
284 |
|
285 | |
286 |
|
287 |
|
288 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
289 | } : void 0;
|
290 | export default withStyles(styles, {
|
291 | name: 'MuiAlert'
|
292 | })(Alert); |
\ | No newline at end of file |