UNPKG

@carbon/react

Version:

React components for the Carbon Design System

29 lines (24 loc) 1.05 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * @param {string} name The name of the prop that must exist to validate * the current prop. * @param {React.Validator} propType The original prop type checker. * @returns {React.Validator} The new prop type checker for the current prop that * becomes required if the prop corresponding to the provided prop name exists. */ function requiredIfGivenPropIsTruthy(name, propType) { return function check(props, propName, componentName, ...rest) { if (process.env.NODE_ENV !== 'production' && props[name] == true && props[propName] == null) { return new Error(`You must provide a value for \`${propName}\` in \`${componentName}\` if \`${name}\` exists.`); } return propType(props, propName, componentName, ...rest); }; } exports.default = requiredIfGivenPropIsTruthy;