UNPKG

6.41 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 { styled } from "../zero-styled/index.js";
8import { useDefaultProps } from "../DefaultPropsProvider/index.js";
9import useSlot from "../utils/useSlot.js";
10import Fade from "../Fade/index.js";
11import { getBackdropUtilityClass } from "./backdropClasses.js";
12import { jsx as _jsx } from "react/jsx-runtime";
13const removeOwnerState = props => {
14 const {
15 ownerState,
16 ...rest
17 } = props;
18 return rest;
19};
20const useUtilityClasses = ownerState => {
21 const {
22 classes,
23 invisible
24 } = ownerState;
25 const slots = {
26 root: ['root', invisible && 'invisible']
27 };
28 return composeClasses(slots, getBackdropUtilityClass, classes);
29};
30const BackdropRoot = styled('div', {
31 name: 'MuiBackdrop',
32 slot: 'Root',
33 overridesResolver: (props, styles) => {
34 const {
35 ownerState
36 } = props;
37 return [styles.root, ownerState.invisible && styles.invisible];
38 }
39})({
40 position: 'fixed',
41 display: 'flex',
42 alignItems: 'center',
43 justifyContent: 'center',
44 right: 0,
45 bottom: 0,
46 top: 0,
47 left: 0,
48 backgroundColor: 'rgba(0, 0, 0, 0.5)',
49 WebkitTapHighlightColor: 'transparent',
50 variants: [{
51 props: {
52 invisible: true
53 },
54 style: {
55 backgroundColor: 'transparent'
56 }
57 }]
58});
59const Backdrop = /*#__PURE__*/React.forwardRef(function Backdrop(inProps, ref) {
60 const props = useDefaultProps({
61 props: inProps,
62 name: 'MuiBackdrop'
63 });
64 const {
65 children,
66 className,
67 component = 'div',
68 invisible = false,
69 open,
70 components = {},
71 componentsProps = {},
72 slotProps = {},
73 slots = {},
74 TransitionComponent: TransitionComponentProp,
75 transitionDuration,
76 ...other
77 } = props;
78 const ownerState = {
79 ...props,
80 component,
81 invisible
82 };
83 const classes = useUtilityClasses(ownerState);
84 const backwardCompatibleSlots = {
85 transition: TransitionComponentProp,
86 root: components.Root,
87 ...slots
88 };
89 const backwardCompatibleSlotProps = {
90 ...componentsProps,
91 ...slotProps
92 };
93 const externalForwardedProps = {
94 slots: backwardCompatibleSlots,
95 slotProps: backwardCompatibleSlotProps
96 };
97 const [RootSlot, rootProps] = useSlot('root', {
98 elementType: BackdropRoot,
99 externalForwardedProps,
100 className: clsx(classes.root, className),
101 ownerState
102 });
103 const [TransitionSlot, transitionProps] = useSlot('transition', {
104 elementType: Fade,
105 externalForwardedProps,
106 ownerState
107 });
108 const transitionPropsRemoved = removeOwnerState(transitionProps);
109 return /*#__PURE__*/_jsx(TransitionSlot, {
110 in: open,
111 timeout: transitionDuration,
112 ...other,
113 ...transitionPropsRemoved,
114 children: /*#__PURE__*/_jsx(RootSlot, {
115 "aria-hidden": true,
116 ...rootProps,
117 classes: classes,
118 ref: ref,
119 children: children
120 })
121 });
122});
123process.env.NODE_ENV !== "production" ? Backdrop.propTypes /* remove-proptypes */ = {
124 // ┌────────────────────────────── Warning ──────────────────────────────┐
125 // │ These PropTypes are generated from the TypeScript type definitions. │
126 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
127 // └─────────────────────────────────────────────────────────────────────┘
128 /**
129 * The content of the component.
130 */
131 children: PropTypes.node,
132 /**
133 * Override or extend the styles applied to the component.
134 */
135 classes: PropTypes.object,
136 /**
137 * @ignore
138 */
139 className: PropTypes.string,
140 /**
141 * The component used for the root node.
142 * Either a string to use a HTML element or a component.
143 */
144 component: PropTypes.elementType,
145 /**
146 * The components used for each slot inside.
147 *
148 * @deprecated Use the `slots` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
149 *
150 * @default {}
151 */
152 components: PropTypes.shape({
153 Root: PropTypes.elementType
154 }),
155 /**
156 * The extra props for the slot components.
157 * You can override the existing props or add new ones.
158 *
159 * @deprecated Use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
160 *
161 * @default {}
162 */
163 componentsProps: PropTypes.shape({
164 root: PropTypes.object
165 }),
166 /**
167 * If `true`, the backdrop is invisible.
168 * It can be used when rendering a popover or a custom select component.
169 * @default false
170 */
171 invisible: PropTypes.bool,
172 /**
173 * If `true`, the component is shown.
174 */
175 open: PropTypes.bool.isRequired,
176 /**
177 * The props used for each slot inside.
178 * @default {}
179 */
180 slotProps: PropTypes.shape({
181 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
182 transition: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
183 }),
184 /**
185 * The components used for each slot inside.
186 * @default {}
187 */
188 slots: PropTypes.shape({
189 root: PropTypes.elementType,
190 transition: PropTypes.elementType
191 }),
192 /**
193 * The system prop that allows defining system overrides as well as additional CSS styles.
194 */
195 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
196 /**
197 * The component used for the transition.
198 * [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
199 * @default Fade
200 */
201 TransitionComponent: PropTypes.elementType,
202 /**
203 * The duration for the transition, in milliseconds.
204 * You may specify a single timeout for all transitions, or individually with an object.
205 */
206 transitionDuration: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
207 appear: PropTypes.number,
208 enter: PropTypes.number,
209 exit: PropTypes.number
210 })])
211} : void 0;
212export default Backdrop;
\No newline at end of file