GoScrobble/web/node_modules/@material-ui/styles/es/withTheme/withTheme.js

66 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React from 'react';
import PropTypes from 'prop-types';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { chainPropTypes, getDisplayName } from '@material-ui/utils';
import useTheme from '../useTheme';
export function withThemeCreator(options = {}) {
const {
defaultTheme
} = options;
const withTheme = Component => {
if (process.env.NODE_ENV !== 'production') {
if (Component === undefined) {
throw new Error(['You are calling withTheme(Component) with an undefined component.', 'You may have forgotten to import it.'].join('\n'));
}
}
const WithTheme = /*#__PURE__*/React.forwardRef(function WithTheme(props, ref) {
const {
innerRef
} = props,
other = _objectWithoutPropertiesLoose(props, ["innerRef"]);
const theme = useTheme() || defaultTheme;
return /*#__PURE__*/React.createElement(Component, _extends({
theme: theme,
ref: innerRef || ref
}, other));
});
process.env.NODE_ENV !== "production" ? WithTheme.propTypes = {
/**
* Use that prop to pass a ref to the decorated component.
* @deprecated
*/
innerRef: chainPropTypes(PropTypes.oneOfType([PropTypes.func, PropTypes.object]), props => {
if (props.innerRef == null) {
return null;
}
return new Error('Material-UI: The `innerRef` prop is deprecated and will be removed in v5. ' + 'Refs are now automatically forwarded to the inner component.');
})
} : void 0;
if (process.env.NODE_ENV !== 'production') {
WithTheme.displayName = `WithTheme(${getDisplayName(Component)})`;
}
hoistNonReactStatics(WithTheme, Component);
if (process.env.NODE_ENV !== 'production') {
// Exposed for test purposes.
WithTheme.Naked = Component;
}
return WithTheme;
};
return withTheme;
} // Provide the theme object as a prop to the input component.
// It's an alternative API to useTheme().
// We encourage the usage of useTheme() where possible.
const withTheme = withThemeCreator();
export default withTheme;