UNPKG

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