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