-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(popup): Remove containerElement prop from Popper (#1524)
* fix(popup): Remove containerElement prop from Popper * chore!: Combine Icon Buttons with Primary, Secondary and Tertiary (#1477) Fixes: #1379 [category:Components] - Combined Icon Buttons with Primary, Secondary, and Tertiary buttons - Remove IconButton component - Add a new XS, L sizes - Removed the `toggled` prop when migrating over Icon Buttons - Converted `SegmentedControl` into a compound component and it no longer renders `IconButton` as children - Changed the values of `IconPosition`: `left` | `right` - > `start` | `end` - Refactored `AccentIcon`, `AppletIcon`, `Graphic`, `Icon`, `Svg`, `SystemIcon`, and `SystemIconCircle` to use create component and remove `iconRef` prop and now just pass the ref forward - Remove `dataLabel` prop from `PrimaryButton` and `SecondaryButton` * feat(popup): Add codemod to remove containerElement prop from Popper Co-authored-by: Manuel Carrera <[email protected]> Co-authored-by: Alan B Smith <[email protected]>
- Loading branch information
1 parent
3b8329e
commit 5f4eca7
Showing
4 changed files
with
89 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {API, FileInfo, Options, JSXElement} from 'jscodeshift'; | ||
import {getImportRenameMap} from './utils/getImportRenameMap'; | ||
import {hasImportSpecifiers} from '../v6/utils'; | ||
|
||
const popupBarPackage = '@workday/canvas-kit-react/popup'; | ||
|
||
export default function transformer(file: FileInfo, api: API, options: Options) { | ||
const j = api.jscodeshift; | ||
|
||
const root = j(file.source); | ||
|
||
if (!hasImportSpecifiers(api, root, popupBarPackage, ['Popper'])) { | ||
return file.source; | ||
} | ||
|
||
const {importMap, styledMap} = getImportRenameMap(j, root, popupBarPackage); | ||
|
||
root | ||
.find( | ||
j.JSXElement, | ||
(value: JSXElement) => | ||
value.openingElement.name.type === 'JSXIdentifier' && | ||
(value.openingElement.name.name === importMap.Popper || | ||
value.openingElement.name.name === styledMap.Popper) | ||
) | ||
.forEach(nodePath => { | ||
const attributes = nodePath.value.openingElement.attributes; | ||
// Remove containerElement prop from Popper component | ||
if (attributes) { | ||
nodePath.value.openingElement.attributes = attributes.filter(item => | ||
item.type === 'JSXAttribute' && | ||
item.name.type === 'JSXIdentifier' && | ||
['containerElement'].includes(item.name.name) | ||
? false | ||
: true | ||
); | ||
} | ||
}); | ||
|
||
return root.toSource(); | ||
} |
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,39 @@ | ||
import {expectTransformFactory} from './expectTransformFactory'; | ||
import transform from '../removePropFromPopper'; | ||
import {stripIndent} from 'common-tags'; | ||
|
||
const expectTransform = expectTransformFactory(transform); | ||
|
||
describe('removePropFromPopper', () => { | ||
it('should remove containerElement prop from Popper component', () => { | ||
const input = stripIndent` | ||
import {Popper} from '@workday/canvas-kit-react/popup'; | ||
<Popper containerElement="any element here" /> | ||
`; | ||
|
||
const expected = stripIndent` | ||
import {Popper} from '@workday/canvas-kit-react/popup'; | ||
<Popper /> | ||
`; | ||
|
||
expectTransform(input, expected); | ||
}); | ||
|
||
it('should remove containerElement prop from Popper component imported from main package', () => { | ||
const input = stripIndent` | ||
import {Popper} from '@workday/canvas-kit-react'; | ||
<Popper containerElement="any element here" /> | ||
`; | ||
|
||
const expected = stripIndent` | ||
import {Popper} from '@workday/canvas-kit-react'; | ||
<Popper /> | ||
`; | ||
|
||
expectTransform(input, expected); | ||
}); | ||
}); |
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