forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(menu): carbon-design-system#16882 Menu's target prop fix
- Loading branch information
1 parent
51d2a21
commit a105f85
Showing
14 changed files
with
229 additions
and
8 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
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
7 changes: 7 additions & 0 deletions
7
packages/upgrade/transforms/__testfixtures__/update-menu-target-prop.input.js
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,7 @@ | ||
function Menu() { | ||
return ( | ||
<div> | ||
<Menu className="test" target={document.body} /> | ||
</div> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/upgrade/transforms/__testfixtures__/update-menu-target-prop.output.js
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,7 @@ | ||
function Menu() { | ||
return ( | ||
<div> | ||
<Menu className="test" menuTarget={document.body} /> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/upgrade/transforms/__tests__/update-menu-target-prop-test.js
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,12 @@ | ||
/** | ||
* 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'; | ||
|
||
const { defineTest } = require('jscodeshift/dist/testUtils'); | ||
|
||
defineTest(__dirname, 'update-menu-target-prop'); |
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,59 @@ | ||
/** | ||
* Copyright Your Company Name. 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* Update `target` prop to `menuTarget` within <Menu> components | ||
* and adds a deprecation warning. | ||
* | ||
* Transforms: | ||
* | ||
* <Menu target={props.target} /> | ||
* | ||
* Into: | ||
* | ||
* <Menu menuTarget={props.target} /> | ||
* | ||
* And adds the following warning at the top of the file: | ||
* | ||
* console.warn('The "target" prop is deprecated and will be removed in a future release. Please use "menuTarget" instead.'); | ||
*/ | ||
|
||
function transformer(file, api) { | ||
const j = api.jscodeshift; | ||
|
||
return ( | ||
j(file.source) | ||
// Added deprecation warning at the top of the file | ||
.find(j.Program) | ||
.forEach((path) => { | ||
path.node.body.unshift( | ||
j.expressionStatement( | ||
j.callExpression( | ||
j.memberExpression(j.identifier('console'), j.identifier('warn')), | ||
[ | ||
j.literal( | ||
'The "target" prop is deprecated and will be removed in a future release. Please use "menuTarget" instead.' | ||
), | ||
] | ||
) | ||
) | ||
); | ||
}) | ||
// Finding <Menu> components and replace `target` with `menuTarget` | ||
.find(j.JSXElement, { | ||
openingElement: { name: { name: 'Menu' } }, | ||
}) | ||
.forEach((path) => { | ||
path | ||
.find(j.JSXAttribute, { name: { name: 'target' } }) | ||
.forEach((attrPath) => { | ||
attrPath.get('name').replace(j.jsxIdentifier('menuTarget')); | ||
}); | ||
}) | ||
.toSource({ quote: 'single' }) | ||
); | ||
} | ||
|
||
module.exports = transformer; |