1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import getDisplayName from '@mui/utils/getDisplayName';
|
6 | import { getThemeProps } from '@mui/system/useThemeProps';
|
7 | import useTheme from '../styles/useTheme';
|
8 | import useEnhancedEffect from '../utils/useEnhancedEffect';
|
9 | import useMediaQuery from '../useMediaQuery';
|
10 | import { jsx as _jsx } from "react/jsx-runtime";
|
11 | var breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
12 |
|
13 |
|
14 | export var isWidthUp = function isWidthUp(breakpoint, width) {
|
15 | var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
16 | if (inclusive) {
|
17 | return breakpointKeys.indexOf(breakpoint) <= breakpointKeys.indexOf(width);
|
18 | }
|
19 | return breakpointKeys.indexOf(breakpoint) < breakpointKeys.indexOf(width);
|
20 | };
|
21 |
|
22 |
|
23 | export var isWidthDown = function isWidthDown(breakpoint, width) {
|
24 | var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
25 | if (inclusive) {
|
26 | return breakpointKeys.indexOf(width) <= breakpointKeys.indexOf(breakpoint);
|
27 | }
|
28 | return breakpointKeys.indexOf(width) < breakpointKeys.indexOf(breakpoint);
|
29 | };
|
30 | var withWidth = function withWidth() {
|
31 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
32 | return function (Component) {
|
33 | var _options$withTheme = options.withTheme,
|
34 | withThemeOption = _options$withTheme === void 0 ? false : _options$withTheme,
|
35 | _options$noSSR = options.noSSR,
|
36 | noSSR = _options$noSSR === void 0 ? false : _options$noSSR,
|
37 | initialWidthOption = options.initialWidth;
|
38 | function WithWidth(props) {
|
39 | var contextTheme = useTheme();
|
40 | var theme = props.theme || contextTheme;
|
41 | var _getThemeProps = getThemeProps({
|
42 | theme: theme,
|
43 | name: 'MuiWithWidth',
|
44 | props: props
|
45 | }),
|
46 | initialWidth = _getThemeProps.initialWidth,
|
47 | width = _getThemeProps.width,
|
48 | other = _objectWithoutProperties(_getThemeProps, ["initialWidth", "width"]);
|
49 | var _React$useState = React.useState(false),
|
50 | mountedState = _React$useState[0],
|
51 | setMountedState = _React$useState[1];
|
52 | useEnhancedEffect(function () {
|
53 | setMountedState(true);
|
54 | }, []);
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | var keys = theme.breakpoints.keys.slice().reverse();
|
62 | var widthComputed = keys.reduce(function (output, key) {
|
63 |
|
64 | var matches = useMediaQuery(theme.breakpoints.up(key));
|
65 | return !output && matches ? key : output;
|
66 | }, null);
|
67 | var more = _extends({
|
68 | width: width || (mountedState || noSSR ? widthComputed : undefined) || initialWidth || initialWidthOption
|
69 | }, withThemeOption ? {
|
70 | theme: theme
|
71 | } : {}, other);
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | if (more.width === undefined) {
|
80 | return null;
|
81 | }
|
82 | return _jsx(Component, _extends({}, more));
|
83 | }
|
84 | process.env.NODE_ENV !== "production" ? WithWidth.propTypes = {
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | initialWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
|
95 | |
96 |
|
97 |
|
98 | theme: PropTypes.object,
|
99 | |
100 |
|
101 |
|
102 | width: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl'])
|
103 | } : void 0;
|
104 | if (process.env.NODE_ENV !== 'production') {
|
105 | WithWidth.displayName = "WithWidth(".concat(getDisplayName(Component), ")");
|
106 | }
|
107 | return WithWidth;
|
108 | };
|
109 | };
|
110 | export default withWidth; |
\ | No newline at end of file |