UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

45 lines (43 loc) 1.67 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.HTMLElementType = HTMLElementType; exports.exactProp = exactProp; exports.refType = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); const refType = exports.refType = _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]); function HTMLElementType(props, propName, componentName, location, propFullName) { if (process.env.NODE_ENV === 'production') { return null; } const propValue = props[propName]; const safePropName = propFullName || propName; if (propValue == null) { return null; } if (propValue && propValue.nodeType !== 1) { return new Error(`Invalid ${location} \`${safePropName}\` supplied to \`${componentName}\`. ` + `Expected an HTMLElement.`); } return null; } const specialProperty = 'exact-prop: \u200b'; // This module is based on https://github.com/airbnb/prop-types-exact repository. // However, in order to reduce the number of dependencies and to remove some extra safe checks // the module was forked. function exactProp(propTypes) { if (process.env.NODE_ENV === 'production') { return propTypes; } return { ...propTypes, [specialProperty]: props => { const unsupportedProps = Object.keys(props).filter(prop => !propTypes.hasOwnProperty(prop)); if (unsupportedProps.length > 0) { return new Error(`The following props are not supported: ${unsupportedProps.map(prop => `\`${prop}\``).join(', ')}. Please remove them.`); } return null; } }; }