0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,2 @@
export { default } from './withWidth';
export * from './withWidth';

27
web/node_modules/@material-ui/core/withWidth/index.js generated vendored Normal file
View file

@ -0,0 +1,27 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
Object.defineProperty(exports, "default", {
enumerable: true,
get: function get() {
return _withWidth.default;
}
});
var _withWidth = _interopRequireWildcard(require("./withWidth"));
Object.keys(_withWidth).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _withWidth[key];
}
});
});

View file

@ -0,0 +1,5 @@
{
"sideEffects": false,
"module": "../esm/withWidth/index.js",
"typings": "./index.d.ts"
}

View file

@ -0,0 +1,33 @@
import { Breakpoint } from '../styles/createBreakpoints';
import { PropInjector } from '@material-ui/types';
export interface WithWidthOptions {
withTheme?: boolean;
noSSR?: boolean;
initialWidth?: Breakpoint;
resizeInterval?: number;
}
export interface WithWidth {
width: Breakpoint;
}
export interface WithWidthProps extends Partial<WithWidth> {
innerRef?: React.Ref<any>;
}
export function isWidthDown(
breakpoint: Breakpoint,
screenWidth: Breakpoint,
inclusive?: boolean
): boolean;
export function isWidthUp(
breakpoint: Breakpoint,
screenWidth: Breakpoint,
inclusive?: boolean
): boolean;
export default function withWidth(
options?: WithWidthOptions
): PropInjector<WithWidth, WithWidthProps>;

View file

@ -0,0 +1,151 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.isWidthDown = exports.isWidthUp = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _utils = require("@material-ui/utils");
var _styles = require("@material-ui/styles");
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
var _createBreakpoints = require("../styles/createBreakpoints");
var _useMediaQuery = _interopRequireDefault(require("../useMediaQuery"));
// By default, returns true if screen width is the same or greater than the given breakpoint.
var isWidthUp = function isWidthUp(breakpoint, width) {
var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (inclusive) {
return _createBreakpoints.keys.indexOf(breakpoint) <= _createBreakpoints.keys.indexOf(width);
}
return _createBreakpoints.keys.indexOf(breakpoint) < _createBreakpoints.keys.indexOf(width);
}; // By default, returns true if screen width is the same or less than the given breakpoint.
exports.isWidthUp = isWidthUp;
var isWidthDown = function isWidthDown(breakpoint, width) {
var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (inclusive) {
return _createBreakpoints.keys.indexOf(width) <= _createBreakpoints.keys.indexOf(breakpoint);
}
return _createBreakpoints.keys.indexOf(width) < _createBreakpoints.keys.indexOf(breakpoint);
};
exports.isWidthDown = isWidthDown;
var useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
var withWidth = function withWidth() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return function (Component) {
var _options$withTheme = options.withTheme,
withThemeOption = _options$withTheme === void 0 ? false : _options$withTheme,
_options$noSSR = options.noSSR,
noSSR = _options$noSSR === void 0 ? false : _options$noSSR,
initialWidthOption = options.initialWidth;
function WithWidth(props) {
var contextTheme = (0, _useTheme.default)();
var theme = props.theme || contextTheme;
var _getThemeProps = (0, _styles.getThemeProps)({
theme: theme,
name: 'MuiWithWidth',
props: (0, _extends2.default)({}, props)
}),
initialWidth = _getThemeProps.initialWidth,
width = _getThemeProps.width,
other = (0, _objectWithoutProperties2.default)(_getThemeProps, ["initialWidth", "width"]);
var _React$useState = React.useState(false),
mountedState = _React$useState[0],
setMountedState = _React$useState[1];
useEnhancedEffect(function () {
setMountedState(true);
}, []);
/**
* innerWidth |xs sm md lg xl
* |-------|-------|-------|-------|------>
* width | xs | sm | md | lg | xl
*/
var keys = theme.breakpoints.keys.slice().reverse();
var widthComputed = keys.reduce(function (output, key) {
// eslint-disable-next-line react-hooks/rules-of-hooks
var matches = (0, _useMediaQuery.default)(theme.breakpoints.up(key));
return !output && matches ? key : output;
}, null);
var more = (0, _extends2.default)({
width: width || (mountedState || noSSR ? widthComputed : undefined) || initialWidth || initialWidthOption
}, withThemeOption ? {
theme: theme
} : {}, other); // When rendering the component on the server,
// we have no idea about the client browser screen width.
// In order to prevent blinks and help the reconciliation of the React tree
// we are not rendering the child component.
//
// An alternative is to use the `initialWidth` property.
if (more.width === undefined) {
return null;
}
return /*#__PURE__*/React.createElement(Component, more);
}
process.env.NODE_ENV !== "production" ? WithWidth.propTypes = {
/**
* As `window.innerWidth` is unavailable on the server,
* we default to rendering an empty component during the first mount.
* You might want to use an heuristic to approximate
* the screen width of the client browser screen width.
*
* For instance, you could be using the user-agent or the client-hints.
* https://caniuse.com/#search=client%20hint
*/
initialWidth: _propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
/**
* @ignore
*/
theme: _propTypes.default.object,
/**
* Bypass the width calculation logic.
*/
width: _propTypes.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl'])
} : void 0;
if (process.env.NODE_ENV !== 'production') {
WithWidth.displayName = "WithWidth(".concat((0, _utils.getDisplayName)(Component), ")");
}
(0, _hoistNonReactStatics.default)(WithWidth, Component);
return WithWidth;
};
};
var _default = withWidth;
exports.default = _default;