UNPKG

@carbon/react

Version:

React components for the Carbon Design System

41 lines (35 loc) 1.33 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'; var warning = require('../internal/warning.js'); const warningCache = new Map(); /** * Wraps a prop-type validator with a deprecation warning. * * @param propType - The original prop validator function. * @param message - Deprecation message. * @returns A new validator function that emits a warning the first time a * deprecated prop is used. */ const deprecate = (propType, message) => { const checker = (props, propName, componentName, ...rest) => { if (typeof props[propName] === 'undefined') { return; } if (!warningCache.has(componentName)) { warningCache.set(componentName, new Set()); } const warnedProps = warningCache.get(componentName); if (warnedProps && !warnedProps.has(propName)) { warnedProps.add(propName); process.env.NODE_ENV !== "production" ? warning.warning(false, message || `The prop \`${propName}\` has been deprecated for the ` + `${componentName} component. It will be removed in the next major ` + `release`) : void 0; } return propType(props, propName, componentName, ...rest); }; return checker; }; exports.deprecate = deprecate;