UNPKG

@mui/material

Version:

Material UI is an open-source React component library that implements Google's Material Design. It's comprehensive and can be used in production out of the box.

127 lines (124 loc) 4 kB
"use strict"; 'use client'; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); var _exactProp = _interopRequireDefault(require("@mui/utils/exactProp")); var _withWidth = _interopRequireWildcard(require("./withWidth")); var _useTheme = _interopRequireDefault(require("../styles/useTheme")); /** * @ignore - internal component. */ function HiddenJs(props) { const { children, only, width } = props; const theme = (0, _useTheme.default)(); let visible = true; // `only` check is faster to get out sooner if used. if (only) { if (Array.isArray(only)) { for (let i = 0; i < only.length; i += 1) { const breakpoint = only[i]; if (width === breakpoint) { visible = false; break; } } } else if (only && width === only) { visible = false; } } // Allow `only` to be combined with other props. If already hidden, no need to check others. if (visible) { // determine visibility based on the smallest size up for (let i = 0; i < theme.breakpoints.keys.length; i += 1) { const breakpoint = theme.breakpoints.keys[i]; const breakpointUp = props[`${breakpoint}Up`]; const breakpointDown = props[`${breakpoint}Down`]; if (breakpointUp && (0, _withWidth.isWidthUp)(breakpoint, width) || breakpointDown && (0, _withWidth.isWidthDown)(breakpoint, width)) { visible = false; break; } } } if (!visible) { return null; } return children; } HiddenJs.propTypes = { /** * The content of the component. */ children: _propTypes.default.node, /** * If `true`, screens this size and down are hidden. */ // eslint-disable-next-line react/no-unused-prop-types lgDown: _propTypes.default.bool, /** * If `true`, screens this size and up are hidden. */ // eslint-disable-next-line react/no-unused-prop-types lgUp: _propTypes.default.bool, /** * If `true`, screens this size and down are hidden. */ // eslint-disable-next-line react/no-unused-prop-types mdDown: _propTypes.default.bool, /** * If `true`, screens this size and up are hidden. */ // eslint-disable-next-line react/no-unused-prop-types mdUp: _propTypes.default.bool, /** * Hide the given breakpoint(s). */ only: _propTypes.default.oneOfType([_propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), _propTypes.default.arrayOf(_propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]), /** * If `true`, screens this size and down are hidden. */ // eslint-disable-next-line react/no-unused-prop-types smDown: _propTypes.default.bool, /** * If `true`, screens this size and up are hidden. */ // eslint-disable-next-line react/no-unused-prop-types smUp: _propTypes.default.bool, /** * @ignore * width prop provided by withWidth decorator. */ width: _propTypes.default.string.isRequired, /** * If `true`, screens this size and down are hidden. */ // eslint-disable-next-line react/no-unused-prop-types xlDown: _propTypes.default.bool, /** * If `true`, screens this size and up are hidden. */ // eslint-disable-next-line react/no-unused-prop-types xlUp: _propTypes.default.bool, /** * If `true`, screens this size and down are hidden. */ // eslint-disable-next-line react/no-unused-prop-types xsDown: _propTypes.default.bool, /** * If `true`, screens this size and up are hidden. */ // eslint-disable-next-line react/no-unused-prop-types xsUp: _propTypes.default.bool }; if (process.env.NODE_ENV !== 'production') { HiddenJs.propTypes = (0, _exactProp.default)(HiddenJs.propTypes); } var _default = exports.default = (0, _withWidth.default)()(HiddenJs);