@carbon/react
Version:
React components for the Carbon Design System
24 lines (22 loc) • 935 B
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
//#region src/prop-types/requiredIfGivenPropIsTruthy.ts
/**
* @param name The name of the prop that must exist to validate the current
* prop.
* @param propType The original prop type checker.
* @returns The new prop type checker for the current prop that becomes required
* if the prop corresponding to the provided prop name exists.
*/
const requiredIfGivenPropIsTruthy = (name, propType) => {
return (props, propName, componentName, ...rest) => {
if (props[name] === true && props[propName] === null) return /* @__PURE__ */ new Error(`You must provide a value for \`${propName}\` in \`${componentName}\` if \`${name}\` exists.`);
return propType(props, propName, componentName, ...rest);
};
};
//#endregion
export { requiredIfGivenPropIsTruthy };