1 | 'use client';
|
2 |
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
5 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
6 | import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
7 | import _extends from "@babel/runtime/helpers/esm/extends";
|
8 | import * as React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import clsx from 'clsx';
|
11 | import composeClasses from '@mui/utils/composeClasses';
|
12 | import { darken, lighten } from '@mui/system/colorManipulator';
|
13 | import { styled } from '../zero-styled';
|
14 | import { useDefaultProps } from '../DefaultPropsProvider';
|
15 | import useSlot from '../utils/useSlot';
|
16 | import capitalize from '../utils/capitalize';
|
17 | import Paper from '../Paper';
|
18 | import alertClasses, { getAlertUtilityClass } from './alertClasses';
|
19 | import IconButton from '../IconButton';
|
20 | import SuccessOutlinedIcon from '../internal/svg-icons/SuccessOutlined';
|
21 | import ReportProblemOutlinedIcon from '../internal/svg-icons/ReportProblemOutlined';
|
22 | import ErrorOutlineIcon from '../internal/svg-icons/ErrorOutline';
|
23 | import InfoOutlinedIcon from '../internal/svg-icons/InfoOutlined';
|
24 | import CloseIcon from '../internal/svg-icons/Close';
|
25 | import { jsx as _jsx } from "react/jsx-runtime";
|
26 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
27 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
28 | var variant = ownerState.variant,
|
29 | color = ownerState.color,
|
30 | severity = ownerState.severity,
|
31 | classes = ownerState.classes;
|
32 | var slots = {
|
33 | root: ['root', "color".concat(capitalize(color || severity)), "".concat(variant).concat(capitalize(color || severity)), "".concat(variant)],
|
34 | icon: ['icon'],
|
35 | message: ['message'],
|
36 | action: ['action']
|
37 | };
|
38 | return composeClasses(slots, getAlertUtilityClass, classes);
|
39 | };
|
40 | var AlertRoot = styled(Paper, {
|
41 | name: 'MuiAlert',
|
42 | slot: 'Root',
|
43 | overridesResolver: function overridesResolver(props, styles) {
|
44 | var ownerState = props.ownerState;
|
45 | return [styles.root, styles[ownerState.variant], styles["".concat(ownerState.variant).concat(capitalize(ownerState.color || ownerState.severity))]];
|
46 | }
|
47 | })(function (_ref) {
|
48 | var theme = _ref.theme;
|
49 | var getColor = theme.palette.mode === 'light' ? darken : lighten;
|
50 | var getBackgroundColor = theme.palette.mode === 'light' ? lighten : darken;
|
51 | return _extends({}, theme.typography.body2, {
|
52 | backgroundColor: 'transparent',
|
53 | display: 'flex',
|
54 | padding: '6px 16px',
|
55 | variants: [].concat(_toConsumableArray(Object.entries(theme.palette).filter(function (_ref2) {
|
56 | var _ref3 = _slicedToArray(_ref2, 2),
|
57 | value = _ref3[1];
|
58 | return value.main && value.light;
|
59 | }).map(function (_ref4) {
|
60 | var _ref5 = _slicedToArray(_ref4, 1),
|
61 | color = _ref5[0];
|
62 | return {
|
63 | props: {
|
64 | colorSeverity: color,
|
65 | variant: 'standard'
|
66 | },
|
67 | style: _defineProperty({
|
68 | color: theme.vars ? theme.vars.palette.Alert["".concat(color, "Color")] : getColor(theme.palette[color].light, 0.6),
|
69 | backgroundColor: theme.vars ? theme.vars.palette.Alert["".concat(color, "StandardBg")] : getBackgroundColor(theme.palette[color].light, 0.9)
|
70 | }, "& .".concat(alertClasses.icon), theme.vars ? {
|
71 | color: theme.vars.palette.Alert["".concat(color, "IconColor")]
|
72 | } : {
|
73 | color: theme.palette[color].main
|
74 | })
|
75 | };
|
76 | })), _toConsumableArray(Object.entries(theme.palette).filter(function (_ref6) {
|
77 | var _ref7 = _slicedToArray(_ref6, 2),
|
78 | value = _ref7[1];
|
79 | return value.main && value.light;
|
80 | }).map(function (_ref8) {
|
81 | var _ref9 = _slicedToArray(_ref8, 1),
|
82 | color = _ref9[0];
|
83 | return {
|
84 | props: {
|
85 | colorSeverity: color,
|
86 | variant: 'outlined'
|
87 | },
|
88 | style: _defineProperty({
|
89 | color: theme.vars ? theme.vars.palette.Alert["".concat(color, "Color")] : getColor(theme.palette[color].light, 0.6),
|
90 | border: "1px solid ".concat((theme.vars || theme).palette[color].light)
|
91 | }, "& .".concat(alertClasses.icon), theme.vars ? {
|
92 | color: theme.vars.palette.Alert["".concat(color, "IconColor")]
|
93 | } : {
|
94 | color: theme.palette[color].main
|
95 | })
|
96 | };
|
97 | })), _toConsumableArray(Object.entries(theme.palette).filter(function (_ref10) {
|
98 | var _ref11 = _slicedToArray(_ref10, 2),
|
99 | value = _ref11[1];
|
100 | return value.main && value.dark;
|
101 | }).map(function (_ref12) {
|
102 | var _ref13 = _slicedToArray(_ref12, 1),
|
103 | color = _ref13[0];
|
104 | return {
|
105 | props: {
|
106 | colorSeverity: color,
|
107 | variant: 'filled'
|
108 | },
|
109 | style: _extends({
|
110 | fontWeight: theme.typography.fontWeightMedium
|
111 | }, theme.vars ? {
|
112 | color: theme.vars.palette.Alert["".concat(color, "FilledColor")],
|
113 | backgroundColor: theme.vars.palette.Alert["".concat(color, "FilledBg")]
|
114 | } : {
|
115 | backgroundColor: theme.palette.mode === 'dark' ? theme.palette[color].dark : theme.palette[color].main,
|
116 | color: theme.palette.getContrastText(theme.palette[color].main)
|
117 | })
|
118 | };
|
119 | })))
|
120 | });
|
121 | });
|
122 | var AlertIcon = styled('div', {
|
123 | name: 'MuiAlert',
|
124 | slot: 'Icon',
|
125 | overridesResolver: function overridesResolver(props, styles) {
|
126 | return styles.icon;
|
127 | }
|
128 | })({
|
129 | marginRight: 12,
|
130 | padding: '7px 0',
|
131 | display: 'flex',
|
132 | fontSize: 22,
|
133 | opacity: 0.9
|
134 | });
|
135 | var AlertMessage = styled('div', {
|
136 | name: 'MuiAlert',
|
137 | slot: 'Message',
|
138 | overridesResolver: function overridesResolver(props, styles) {
|
139 | return styles.message;
|
140 | }
|
141 | })({
|
142 | padding: '8px 0',
|
143 | minWidth: 0,
|
144 | overflow: 'auto'
|
145 | });
|
146 | var AlertAction = styled('div', {
|
147 | name: 'MuiAlert',
|
148 | slot: 'Action',
|
149 | overridesResolver: function overridesResolver(props, styles) {
|
150 | return styles.action;
|
151 | }
|
152 | })({
|
153 | display: 'flex',
|
154 | alignItems: 'flex-start',
|
155 | padding: '4px 0 0 16px',
|
156 | marginLeft: 'auto',
|
157 | marginRight: -8
|
158 | });
|
159 | var defaultIconMapping = {
|
160 | success: _jsx(SuccessOutlinedIcon, {
|
161 | fontSize: "inherit"
|
162 | }),
|
163 | warning: _jsx(ReportProblemOutlinedIcon, {
|
164 | fontSize: "inherit"
|
165 | }),
|
166 | error: _jsx(ErrorOutlineIcon, {
|
167 | fontSize: "inherit"
|
168 | }),
|
169 | info: _jsx(InfoOutlinedIcon, {
|
170 | fontSize: "inherit"
|
171 | })
|
172 | };
|
173 | var Alert = React.forwardRef(function Alert(inProps, ref) {
|
174 | var props = useDefaultProps({
|
175 | props: inProps,
|
176 | name: 'MuiAlert'
|
177 | });
|
178 | var action = props.action,
|
179 | children = props.children,
|
180 | className = props.className,
|
181 | _props$closeText = props.closeText,
|
182 | closeText = _props$closeText === void 0 ? 'Close' : _props$closeText,
|
183 | color = props.color,
|
184 | _props$components = props.components,
|
185 | components = _props$components === void 0 ? {} : _props$components,
|
186 | _props$componentsProp = props.componentsProps,
|
187 | componentsProps = _props$componentsProp === void 0 ? {} : _props$componentsProp,
|
188 | icon = props.icon,
|
189 | _props$iconMapping = props.iconMapping,
|
190 | iconMapping = _props$iconMapping === void 0 ? defaultIconMapping : _props$iconMapping,
|
191 | onClose = props.onClose,
|
192 | _props$role = props.role,
|
193 | role = _props$role === void 0 ? 'alert' : _props$role,
|
194 | _props$severity = props.severity,
|
195 | severity = _props$severity === void 0 ? 'success' : _props$severity,
|
196 | _props$slotProps = props.slotProps,
|
197 | slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
|
198 | _props$slots = props.slots,
|
199 | slots = _props$slots === void 0 ? {} : _props$slots,
|
200 | _props$variant = props.variant,
|
201 | variant = _props$variant === void 0 ? 'standard' : _props$variant,
|
202 | other = _objectWithoutProperties(props, ["action", "children", "className", "closeText", "color", "components", "componentsProps", "icon", "iconMapping", "onClose", "role", "severity", "slotProps", "slots", "variant"]);
|
203 | var ownerState = _extends({}, props, {
|
204 | color: color,
|
205 | severity: severity,
|
206 | variant: variant,
|
207 | colorSeverity: color || severity
|
208 | });
|
209 | var classes = useUtilityClasses(ownerState);
|
210 | var externalForwardedProps = {
|
211 | slots: _extends({
|
212 | closeButton: components.CloseButton,
|
213 | closeIcon: components.CloseIcon
|
214 | }, slots),
|
215 | slotProps: _extends({}, componentsProps, slotProps)
|
216 | };
|
217 | var _useSlot = useSlot('closeButton', {
|
218 | elementType: IconButton,
|
219 | externalForwardedProps: externalForwardedProps,
|
220 | ownerState: ownerState
|
221 | }),
|
222 | _useSlot2 = _slicedToArray(_useSlot, 2),
|
223 | CloseButtonSlot = _useSlot2[0],
|
224 | closeButtonProps = _useSlot2[1];
|
225 | var _useSlot3 = useSlot('closeIcon', {
|
226 | elementType: CloseIcon,
|
227 | externalForwardedProps: externalForwardedProps,
|
228 | ownerState: ownerState
|
229 | }),
|
230 | _useSlot4 = _slicedToArray(_useSlot3, 2),
|
231 | CloseIconSlot = _useSlot4[0],
|
232 | closeIconProps = _useSlot4[1];
|
233 | return _jsxs(AlertRoot, _extends({
|
234 | role: role,
|
235 | elevation: 0,
|
236 | ownerState: ownerState,
|
237 | className: clsx(classes.root, className),
|
238 | ref: ref
|
239 | }, other, {
|
240 | children: [icon !== false ? _jsx(AlertIcon, {
|
241 | ownerState: ownerState,
|
242 | className: classes.icon,
|
243 | children: icon || iconMapping[severity] || defaultIconMapping[severity]
|
244 | }) : null, _jsx(AlertMessage, {
|
245 | ownerState: ownerState,
|
246 | className: classes.message,
|
247 | children: children
|
248 | }), action != null ? _jsx(AlertAction, {
|
249 | ownerState: ownerState,
|
250 | className: classes.action,
|
251 | children: action
|
252 | }) : null, action == null && onClose ? _jsx(AlertAction, {
|
253 | ownerState: ownerState,
|
254 | className: classes.action,
|
255 | children: _jsx(CloseButtonSlot, _extends({
|
256 | size: "small",
|
257 | "aria-label": closeText,
|
258 | title: closeText,
|
259 | color: "inherit",
|
260 | onClick: onClose
|
261 | }, closeButtonProps, {
|
262 | children: _jsx(CloseIconSlot, _extends({
|
263 | fontSize: "small"
|
264 | }, closeIconProps))
|
265 | }))
|
266 | }) : null]
|
267 | }));
|
268 | });
|
269 | process.env.NODE_ENV !== "production" ? Alert.propTypes = {
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | |
275 |
|
276 |
|
277 | action: PropTypes.node,
|
278 | |
279 |
|
280 |
|
281 | children: PropTypes.node,
|
282 | |
283 |
|
284 |
|
285 | classes: PropTypes.object,
|
286 | |
287 |
|
288 |
|
289 | className: PropTypes.string,
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | closeText: PropTypes.string,
|
297 | |
298 |
|
299 |
|
300 |
|
301 |
|
302 | color: PropTypes .oneOfType([PropTypes.oneOf(['error', 'info', 'success', 'warning']), PropTypes.string]),
|
303 | |
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 | components: PropTypes.shape({
|
311 | CloseButton: PropTypes.elementType,
|
312 | CloseIcon: PropTypes.elementType
|
313 | }),
|
314 | |
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 | componentsProps: PropTypes.shape({
|
323 | closeButton: PropTypes.object,
|
324 | closeIcon: PropTypes.object
|
325 | }),
|
326 | |
327 |
|
328 |
|
329 |
|
330 |
|
331 | icon: PropTypes.node,
|
332 | |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | iconMapping: PropTypes.shape({
|
339 | error: PropTypes.node,
|
340 | info: PropTypes.node,
|
341 | success: PropTypes.node,
|
342 | warning: PropTypes.node
|
343 | }),
|
344 | |
345 |
|
346 |
|
347 |
|
348 |
|
349 | onClose: PropTypes.func,
|
350 | |
351 |
|
352 |
|
353 |
|
354 | role: PropTypes.string,
|
355 | |
356 |
|
357 |
|
358 |
|
359 | severity: PropTypes .oneOfType([PropTypes.oneOf(['error', 'info', 'success', 'warning']), PropTypes.string]),
|
360 | |
361 |
|
362 |
|
363 |
|
364 | slotProps: PropTypes.shape({
|
365 | closeButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
366 | closeIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
367 | }),
|
368 | |
369 |
|
370 |
|
371 |
|
372 | slots: PropTypes.shape({
|
373 | closeButton: PropTypes.elementType,
|
374 | closeIcon: PropTypes.elementType
|
375 | }),
|
376 | |
377 |
|
378 |
|
379 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
380 | |
381 |
|
382 |
|
383 |
|
384 | variant: PropTypes .oneOfType([PropTypes.oneOf(['filled', 'outlined', 'standard']), PropTypes.string])
|
385 | } : void 0;
|
386 | export default Alert; |
\ | No newline at end of file |