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.

36 lines (35 loc) 1.36 kB
import PropTypes from 'prop-types'; export const refType = PropTypes.oneOfType([PropTypes.func, PropTypes.object]); export 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. export 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; } }; }