UNPKG

4.45 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { emphasize } from '@mui/system/colorManipulator';
8import { styled } from "../zero-styled/index.js";
9import memoTheme from "../utils/memoTheme.js";
10import { useDefaultProps } from "../DefaultPropsProvider/index.js";
11import Paper from "../Paper/index.js";
12import { getSnackbarContentUtilityClass } from "./snackbarContentClasses.js";
13import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14const useUtilityClasses = ownerState => {
15 const {
16 classes
17 } = ownerState;
18 const slots = {
19 root: ['root'],
20 action: ['action'],
21 message: ['message']
22 };
23 return composeClasses(slots, getSnackbarContentUtilityClass, classes);
24};
25const SnackbarContentRoot = styled(Paper, {
26 name: 'MuiSnackbarContent',
27 slot: 'Root',
28 overridesResolver: (props, styles) => styles.root
29})(memoTheme(({
30 theme
31}) => {
32 const emphasis = theme.palette.mode === 'light' ? 0.8 : 0.98;
33 const backgroundColor = emphasize(theme.palette.background.default, emphasis);
34 return {
35 ...theme.typography.body2,
36 color: theme.vars ? theme.vars.palette.SnackbarContent.color : theme.palette.getContrastText(backgroundColor),
37 backgroundColor: theme.vars ? theme.vars.palette.SnackbarContent.bg : backgroundColor,
38 display: 'flex',
39 alignItems: 'center',
40 flexWrap: 'wrap',
41 padding: '6px 16px',
42 borderRadius: (theme.vars || theme).shape.borderRadius,
43 flexGrow: 1,
44 [theme.breakpoints.up('sm')]: {
45 flexGrow: 'initial',
46 minWidth: 288
47 }
48 };
49}));
50const SnackbarContentMessage = styled('div', {
51 name: 'MuiSnackbarContent',
52 slot: 'Message',
53 overridesResolver: (props, styles) => styles.message
54})({
55 padding: '8px 0'
56});
57const SnackbarContentAction = styled('div', {
58 name: 'MuiSnackbarContent',
59 slot: 'Action',
60 overridesResolver: (props, styles) => styles.action
61})({
62 display: 'flex',
63 alignItems: 'center',
64 marginLeft: 'auto',
65 paddingLeft: 16,
66 marginRight: -8
67});
68const SnackbarContent = /*#__PURE__*/React.forwardRef(function SnackbarContent(inProps, ref) {
69 const props = useDefaultProps({
70 props: inProps,
71 name: 'MuiSnackbarContent'
72 });
73 const {
74 action,
75 className,
76 message,
77 role = 'alert',
78 ...other
79 } = props;
80 const ownerState = props;
81 const classes = useUtilityClasses(ownerState);
82 return /*#__PURE__*/_jsxs(SnackbarContentRoot, {
83 role: role,
84 square: true,
85 elevation: 6,
86 className: clsx(classes.root, className),
87 ownerState: ownerState,
88 ref: ref,
89 ...other,
90 children: [/*#__PURE__*/_jsx(SnackbarContentMessage, {
91 className: classes.message,
92 ownerState: ownerState,
93 children: message
94 }), action ? /*#__PURE__*/_jsx(SnackbarContentAction, {
95 className: classes.action,
96 ownerState: ownerState,
97 children: action
98 }) : null]
99 });
100});
101process.env.NODE_ENV !== "production" ? SnackbarContent.propTypes /* remove-proptypes */ = {
102 // ┌────────────────────────────── Warning ──────────────────────────────┐
103 // │ These PropTypes are generated from the TypeScript type definitions. │
104 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
105 // └─────────────────────────────────────────────────────────────────────┘
106 /**
107 * The action to display. It renders after the message, at the end of the snackbar.
108 */
109 action: PropTypes.node,
110 /**
111 * Override or extend the styles applied to the component.
112 */
113 classes: PropTypes.object,
114 /**
115 * @ignore
116 */
117 className: PropTypes.string,
118 /**
119 * The message to display.
120 */
121 message: PropTypes.node,
122 /**
123 * The ARIA role attribute of the element.
124 * @default 'alert'
125 */
126 role: PropTypes /* @typescript-to-proptypes-ignore */.string,
127 /**
128 * The system prop that allows defining system overrides as well as additional CSS styles.
129 */
130 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
131} : void 0;
132export default SnackbarContent;
\No newline at end of file