1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import clsx from 'clsx';
|
5 | import PropTypes from 'prop-types';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import capitalize from "../utils/capitalize.js";
|
8 | import styled from "../styles/styled.js";
|
9 | import useTheme from "../styles/useTheme.js";
|
10 | import { getHiddenCssUtilityClass } from "./hiddenCssClasses.js";
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | const useUtilityClasses = ownerState => {
|
13 | const {
|
14 | classes,
|
15 | breakpoints
|
16 | } = ownerState;
|
17 | const slots = {
|
18 | root: ['root', ...breakpoints.map(({
|
19 | breakpoint,
|
20 | dir
|
21 | }) => {
|
22 | return dir === 'only' ? `${dir}${capitalize(breakpoint)}` : `${breakpoint}${capitalize(dir)}`;
|
23 | })]
|
24 | };
|
25 | return composeClasses(slots, getHiddenCssUtilityClass, classes);
|
26 | };
|
27 |
|
28 |
|
29 | const HiddenCssRoot = styled('div', {
|
30 | name: 'PrivateHiddenCss',
|
31 | slot: 'Root'
|
32 | })(({
|
33 | theme,
|
34 | ownerState
|
35 | }) => {
|
36 | const hidden = {
|
37 | display: 'none'
|
38 | };
|
39 | return {
|
40 | ...ownerState.breakpoints.map(({
|
41 | breakpoint,
|
42 | dir
|
43 | }) => {
|
44 | if (dir === 'only') {
|
45 | return {
|
46 | [theme.breakpoints.only(breakpoint)]: hidden
|
47 | };
|
48 | }
|
49 | return dir === 'up' ? {
|
50 | [theme.breakpoints.up(breakpoint)]: hidden
|
51 | } : {
|
52 | [theme.breakpoints.down(breakpoint)]: hidden
|
53 | };
|
54 | }).reduce((r, o) => {
|
55 | Object.keys(o).forEach(k => {
|
56 | r[k] = o[k];
|
57 | });
|
58 | return r;
|
59 | }, {})
|
60 | };
|
61 | });
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | function HiddenCss(props) {
|
67 | const {
|
68 | children,
|
69 | className,
|
70 | only,
|
71 | ...other
|
72 | } = props;
|
73 | const theme = useTheme();
|
74 | if (process.env.NODE_ENV !== 'production') {
|
75 | const unknownProps = Object.keys(other).filter(propName => {
|
76 | const isUndeclaredBreakpoint = !theme.breakpoints.keys.some(breakpoint => {
|
77 | return `${breakpoint}Up` === propName || `${breakpoint}Down` === propName;
|
78 | });
|
79 | return !['classes', 'theme', 'isRtl', 'sx'].includes(propName) && isUndeclaredBreakpoint;
|
80 | });
|
81 | if (unknownProps.length > 0) {
|
82 | console.error(`MUI: Unsupported props received by \`<Hidden implementation="css" />\`: ${unknownProps.join(', ')}. Did you forget to wrap this component in a ThemeProvider declaring these breakpoints?`);
|
83 | }
|
84 | }
|
85 | const breakpoints = [];
|
86 | for (let i = 0; i < theme.breakpoints.keys.length; i += 1) {
|
87 | const breakpoint = theme.breakpoints.keys[i];
|
88 | const breakpointUp = other[`${breakpoint}Up`];
|
89 | const breakpointDown = other[`${breakpoint}Down`];
|
90 | if (breakpointUp) {
|
91 | breakpoints.push({
|
92 | breakpoint,
|
93 | dir: 'up'
|
94 | });
|
95 | }
|
96 | if (breakpointDown) {
|
97 | breakpoints.push({
|
98 | breakpoint,
|
99 | dir: 'down'
|
100 | });
|
101 | }
|
102 | }
|
103 | if (only) {
|
104 | const onlyBreakpoints = Array.isArray(only) ? only : [only];
|
105 | onlyBreakpoints.forEach(breakpoint => {
|
106 | breakpoints.push({
|
107 | breakpoint,
|
108 | dir: 'only'
|
109 | });
|
110 | });
|
111 | }
|
112 | const ownerState = {
|
113 | ...props,
|
114 | breakpoints
|
115 | };
|
116 | const classes = useUtilityClasses(ownerState);
|
117 | return _jsx(HiddenCssRoot, {
|
118 | className: clsx(classes.root, className),
|
119 | ownerState: ownerState,
|
120 | children: children
|
121 | });
|
122 | }
|
123 | process.env.NODE_ENV !== "production" ? HiddenCss.propTypes = {
|
124 | |
125 |
|
126 |
|
127 | children: PropTypes.node,
|
128 | |
129 |
|
130 |
|
131 | className: PropTypes.string,
|
132 | |
133 |
|
134 |
|
135 |
|
136 | implementation: PropTypes.oneOf(['js', 'css']),
|
137 | |
138 |
|
139 |
|
140 | lgDown: PropTypes.bool,
|
141 | |
142 |
|
143 |
|
144 | lgUp: PropTypes.bool,
|
145 | |
146 |
|
147 |
|
148 | mdDown: PropTypes.bool,
|
149 | |
150 |
|
151 |
|
152 | mdUp: PropTypes.bool,
|
153 | |
154 |
|
155 |
|
156 | only: PropTypes.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]),
|
157 | |
158 |
|
159 |
|
160 | smDown: PropTypes.bool,
|
161 | |
162 |
|
163 |
|
164 | smUp: PropTypes.bool,
|
165 | |
166 |
|
167 |
|
168 | xlDown: PropTypes.bool,
|
169 | |
170 |
|
171 |
|
172 | xlUp: PropTypes.bool,
|
173 | |
174 |
|
175 |
|
176 | xsDown: PropTypes.bool,
|
177 | |
178 |
|
179 |
|
180 | xsUp: PropTypes.bool
|
181 | } : void 0;
|
182 | export default HiddenCss; |
\ | No newline at end of file |