-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(popover): Deprecate PopoverAlignment type values (#16346)
* fix(popover wip): custom fn to warn,deprecate old values,and unite both * fix(popover): align prop values updated with new ones in repro * chore(popover): type fixes * chore(popover): message string updated * refactor(16467): deprecateValuesWithin signature changed
- Loading branch information
1 parent
9788258
commit b62c6b6
Showing
6 changed files
with
134 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import { warning } from '../internal/warning'; | ||
|
||
const didWarnAboutDeprecation = {}; | ||
|
||
export default function deprecateValuesWithin( | ||
propType, | ||
allowedValues, | ||
propMappingFunction | ||
) { | ||
return function checker(props, propName, componentName, ...rest) { | ||
if (props[propName] === undefined) { | ||
return; | ||
} | ||
|
||
if ( | ||
!didWarnAboutDeprecation[componentName] || | ||
!didWarnAboutDeprecation[componentName][propName] | ||
) { | ||
didWarnAboutDeprecation[componentName] = { | ||
...didWarnAboutDeprecation[componentName], | ||
[propName]: true, | ||
}; | ||
|
||
const deprecatedValue = props[propName]; | ||
const newValue = propMappingFunction | ||
? propMappingFunction(deprecatedValue) | ||
: null; | ||
|
||
if (allowedValues && !allowedValues.includes(deprecatedValue)) { | ||
const message = propMappingFunction | ||
? `"${deprecatedValue}" is a deprecated value for the "${propName}" prop on the "${componentName}" component. Use "${newValue}" instead. "${deprecatedValue}" will be removed in the next major release.` | ||
: `"${deprecatedValue}" is a deprecated value for the "${propName}" prop on the "${componentName}" component. Allowed values is/are: ${allowedValues.join( | ||
', ' | ||
)}. "${deprecatedValue}" will be removed in the next major release. `; | ||
|
||
warning(false, message); | ||
} | ||
} | ||
return propType(props, propName, componentName, ...rest); | ||
}; | ||
} |