@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
29 lines (24 loc) • 1.04 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* @param {string} name The name of the prop that must exist to validate
* the current prop.
* @param {Function} propType The original prop type checker.
* @returns {Function} 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) {
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.`);
}
for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
rest[_key - 3] = arguments[_key];
}
return propType(props, propName, componentName, ...rest);
};
}
exports["default"] = requiredIfGivenPropIsTruthy;