@material-ui/unstyled
Version:
Unstyled React components with which to implement custom design systems.
108 lines (96 loc) • 3.09 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["classes", "className", "invisible", "component", "components", "componentsProps", "theme"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '../composeClasses';
import isHostComponent from '../utils/isHostComponent';
import { getBackdropUtilityClass } from './backdropUnstyledClasses';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes,
invisible
} = ownerState;
const slots = {
root: ['root', invisible && 'invisible']
};
return composeClasses(slots, getBackdropUtilityClass, classes);
};
const BackdropUnstyled = /*#__PURE__*/React.forwardRef(function BackdropUnstyled(props, ref) {
const {
classes: classesProp,
className,
invisible = false,
component = 'div',
components = {},
componentsProps = {},
/* eslint-disable react/prop-types */
theme
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const ownerState = _extends({}, props, {
classes: classesProp,
invisible
});
const classes = useUtilityClasses(ownerState);
const Root = components.Root || component;
const rootProps = componentsProps.root || {};
return /*#__PURE__*/_jsx(Root, _extends({
"aria-hidden": true
}, rootProps, !isHostComponent(Root) && {
as: component,
ownerState: _extends({}, ownerState, rootProps.ownerState),
theme
}, {
ref: ref
}, other, {
className: clsx(classes.root, rootProps.className, className)
}));
});
process.env.NODE_ENV !== "production" ? BackdropUnstyled.propTypes
/* remove-proptypes */
= {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The components used for each slot inside the Backdrop.
* Either a string to use a HTML element or a component.
* @default {}
*/
components: PropTypes.shape({
Root: PropTypes.elementType
}),
/**
* The props used for each slot inside the Backdrop.
* @default {}
*/
componentsProps: PropTypes.object,
/**
* If `true`, the backdrop is invisible.
* It can be used when rendering a popover or a custom select component.
* @default false
*/
invisible: PropTypes.bool
} : void 0;
export default BackdropUnstyled;