@carbon/react
Version:
React components for the Carbon Design System
40 lines (38 loc) • 1.44 kB
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.
*/
import { warning } from "../internal/warning.js";
//#region src/prop-types/deprecate.ts
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const warningCache = /* @__PURE__ */ 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, /* @__PURE__ */ new Set());
const warnedProps = warningCache.get(componentName);
if (warnedProps && !warnedProps.has(propName)) {
warnedProps.add(propName);
warning(false, message || `The prop \`${propName}\` has been deprecated for the ${componentName} component. It will be removed in the next major release`);
}
return propType(props, propName, componentName, ...rest);
};
return checker;
};
//#endregion
export { deprecate };