UNPKG

4.28 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _exactProp = _interopRequireDefault(require("@mui/utils/exactProp"));
13var _withWidth = _interopRequireWildcard(require("./withWidth"));
14var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
15var _jsxRuntime = require("react/jsx-runtime");
16/**
17 * @ignore - internal component.
18 */function HiddenJs(props) {
19 const {
20 children,
21 only,
22 width
23 } = props;
24 const theme = (0, _useTheme.default)();
25 let visible = true;
26
27 // `only` check is faster to get out sooner if used.
28 if (only) {
29 if (Array.isArray(only)) {
30 for (let i = 0; i < only.length; i += 1) {
31 const breakpoint = only[i];
32 if (width === breakpoint) {
33 visible = false;
34 break;
35 }
36 }
37 } else if (only && width === only) {
38 visible = false;
39 }
40 }
41
42 // Allow `only` to be combined with other props. If already hidden, no need to check others.
43 if (visible) {
44 // determine visibility based on the smallest size up
45 for (let i = 0; i < theme.breakpoints.keys.length; i += 1) {
46 const breakpoint = theme.breakpoints.keys[i];
47 const breakpointUp = props[`${breakpoint}Up`];
48 const breakpointDown = props[`${breakpoint}Down`];
49 if (breakpointUp && (0, _withWidth.isWidthUp)(breakpoint, width) || breakpointDown && (0, _withWidth.isWidthDown)(breakpoint, width)) {
50 visible = false;
51 break;
52 }
53 }
54 }
55 if (!visible) {
56 return null;
57 }
58 return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
59 children: children
60 });
61}
62process.env.NODE_ENV !== "production" ? HiddenJs.propTypes = {
63 /**
64 * The content of the component.
65 */
66 children: _propTypes.default.node,
67 /**
68 * If `true`, screens this size and down are hidden.
69 */
70 // eslint-disable-next-line react/no-unused-prop-types
71 lgDown: _propTypes.default.bool,
72 /**
73 * If `true`, screens this size and up are hidden.
74 */
75 // eslint-disable-next-line react/no-unused-prop-types
76 lgUp: _propTypes.default.bool,
77 /**
78 * If `true`, screens this size and down are hidden.
79 */
80 // eslint-disable-next-line react/no-unused-prop-types
81 mdDown: _propTypes.default.bool,
82 /**
83 * If `true`, screens this size and up are hidden.
84 */
85 // eslint-disable-next-line react/no-unused-prop-types
86 mdUp: _propTypes.default.bool,
87 /**
88 * Hide the given breakpoint(s).
89 */
90 only: _propTypes.default.oneOfType([_propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), _propTypes.default.arrayOf(_propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]),
91 /**
92 * If `true`, screens this size and down are hidden.
93 */
94 // eslint-disable-next-line react/no-unused-prop-types
95 smDown: _propTypes.default.bool,
96 /**
97 * If `true`, screens this size and up are hidden.
98 */
99 // eslint-disable-next-line react/no-unused-prop-types
100 smUp: _propTypes.default.bool,
101 /**
102 * @ignore
103 * width prop provided by withWidth decorator.
104 */
105 width: _propTypes.default.string.isRequired,
106 /**
107 * If `true`, screens this size and down are hidden.
108 */
109 // eslint-disable-next-line react/no-unused-prop-types
110 xlDown: _propTypes.default.bool,
111 /**
112 * If `true`, screens this size and up are hidden.
113 */
114 // eslint-disable-next-line react/no-unused-prop-types
115 xlUp: _propTypes.default.bool,
116 /**
117 * If `true`, screens this size and down are hidden.
118 */
119 // eslint-disable-next-line react/no-unused-prop-types
120 xsDown: _propTypes.default.bool,
121 /**
122 * If `true`, screens this size and up are hidden.
123 */
124 // eslint-disable-next-line react/no-unused-prop-types
125 xsUp: _propTypes.default.bool
126} : void 0;
127if (process.env.NODE_ENV !== 'production') {
128 process.env.NODE_ENV !== "production" ? HiddenJs.propTypes = (0, _exactProp.default)(HiddenJs.propTypes) : void 0;
129}
130var _default = exports.default = (0, _withWidth.default)()(HiddenJs);
\No newline at end of file