-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LG-4525: popover-v12 code mod (#2484)
* Add addJSXAttributes code mod util * Update consolidateJSXAttributes util to handle edge case * Add removeJSXAttributes code mod util * Fix comment utils * Export utils from utils/transformations * Add popover-v12 codemod * Changeset * Fix build type * Clean up comments * Update docs * Add commentOverride * Update transform.config.js
- Loading branch information
Showing
38 changed files
with
1,215 additions
and
86 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,22 @@ | ||
--- | ||
'@lg-tools/codemods': minor | ||
--- | ||
|
||
[LG-4525](https://jira.mongodb.org/browse/LG-4525) Add `popover-v12` codemod which can be used to refactor popover component instances. It does the following: | ||
1. Adds an explicit `usePortal={true}` declaration if left undefined and consolidates the `usePortal` and `renderMode` props into a single `renderMode` prop for the following components: | ||
- `Combobox` | ||
- `Menu` | ||
- `Popover` | ||
- `Select` | ||
- `SplitButton` | ||
- `Tooltip` | ||
2. Removes `popoverZIndex`, `portalClassName`, `portalContainer`, `portalRef`, `scrollContainer`, and `usePortal` props from the following components: | ||
- `InfoSprinkle` | ||
- `InlineDefinition` | ||
- `NumberInput` | ||
3. Removes `popoverZIndex`, `portalClassName`, `portalContainer`, `portalRef`, and `scrollContainer` props from the following components: | ||
- `DatePicker` | ||
- `GuideCue` | ||
4. Removes `popoverZIndex`, `portalClassName`, `portalContainer`, `scrollContainer`, and `usePortal` props from `Code` component | ||
5. Removes `portalClassName`, `portalContainer`, `portalRef`, `scrollContainer`, and `usePortal` props from `SearchInput` component | ||
6. Removes `shouldTooltipUsePortal` prop from `Copyable` component |
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
65 changes: 65 additions & 0 deletions
65
tools/codemods/src/codemods/popover-v12/tests/add-usePortal-consolidate-renderMode.input.tsx
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,65 @@ | ||
import React from 'react'; | ||
|
||
const Combobox = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Menu = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Popover = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Select = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const SplitButton = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Tooltip = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Child = (props: any) => { | ||
return <div>{props.children}</div>; | ||
}; | ||
|
||
export const App = () => { | ||
const spreadProps = { | ||
prop: true, | ||
} as const; | ||
|
||
const WrappedPopover = () => { | ||
return <Popover usePortal={false} {...spreadProps} />; | ||
}; | ||
|
||
const DefaultWrappedPopover = () => { | ||
return <Popover {...spreadProps} />; | ||
}; | ||
|
||
return ( | ||
<> | ||
<Combobox /> | ||
<Menu usePortal /> | ||
<Popover usePortal={false} /> | ||
<Select usePortal={true} /> | ||
<SplitButton /> | ||
<Tooltip usePortal={false} /> | ||
<Popover /> | ||
<Popover renderMode="inline" usePortal={false} /> | ||
<Popover renderMode="portal" usePortal={true} /> | ||
<Popover usePortal> | ||
<Child usePortal={false} /> | ||
</Popover> | ||
<Popover usePortal={false} /> | ||
<Popover usePortal={true} {...spreadProps} /> | ||
<Popover {...spreadProps} /> | ||
<WrappedPopover /> | ||
<DefaultWrappedPopover /> | ||
</> | ||
); | ||
}; |
73 changes: 73 additions & 0 deletions
73
...s/codemods/src/codemods/popover-v12/tests/add-usePortal-consolidate-renderMode.output.tsx
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,73 @@ | ||
import React from 'react'; | ||
|
||
const Combobox = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Menu = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Popover = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Select = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const SplitButton = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Tooltip = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Child = (props: any) => { | ||
return <div>{props.children}</div>; | ||
}; | ||
|
||
export const App = () => { | ||
const spreadProps = { | ||
prop: true, | ||
} as const; | ||
|
||
const WrappedPopover = () => { | ||
return ( | ||
/* Please manually update from prop: usePortal to prop: renderMode */ | ||
<Popover usePortal={false} {...spreadProps} /> | ||
); | ||
}; | ||
|
||
const DefaultWrappedPopover = () => { | ||
return ( | ||
/* Please manually add prop: renderMode */ | ||
<Popover {...spreadProps} /> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Combobox renderMode="portal" /> | ||
<Menu renderMode="portal" /> | ||
<Popover renderMode="inline" /> | ||
<Select renderMode="portal" /> | ||
<SplitButton renderMode="portal" /> | ||
<Tooltip renderMode="inline" /> | ||
<Popover renderMode="portal" /> | ||
<Popover renderMode="inline" /> | ||
<Popover renderMode="portal" /> | ||
<Popover renderMode="portal"> | ||
<Child usePortal={false} /> | ||
</Popover> | ||
<Popover renderMode="inline" /> | ||
{/* Please manually update from prop: usePortal to prop: renderMode */} | ||
<Popover usePortal={true} {...spreadProps} /> | ||
{/* Please manually add prop: renderMode */} | ||
<Popover {...spreadProps} /> | ||
<WrappedPopover /> | ||
<DefaultWrappedPopover /> | ||
</> | ||
); | ||
}; |
69 changes: 69 additions & 0 deletions
69
tools/codemods/src/codemods/popover-v12/tests/remove-legacy-props.input.tsx
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,69 @@ | ||
import React from 'react'; | ||
|
||
const Code = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const DatePicker = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const GuideCue = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const InfoSprinkle = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const InlineDefinition = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const NumberInput = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const SearchInput = ({ children, ...props }: any) => { | ||
return <div {...props}>{children}</div>; | ||
}; | ||
|
||
const Child = (props: any) => { | ||
return <div>{props.children}</div>; | ||
}; | ||
|
||
export const App = () => { | ||
const spreadProps = { | ||
prop: true, | ||
} as const; | ||
|
||
const WrappedInfoSprinkle = (props: any) => { | ||
return <InfoSprinkle usePortal={false} {...props} />; | ||
}; | ||
|
||
return ( | ||
<> | ||
<Code usePortal /> | ||
<DatePicker /> | ||
<GuideCue /> | ||
<InfoSprinkle usePortal /> | ||
<InlineDefinition usePortal={false} /> | ||
<NumberInput usePortal={true} /> | ||
<SearchInput usePortal /> | ||
<InfoSprinkle /> | ||
<InfoSprinkle | ||
portalClassName="portal-class" | ||
portalRef={{ current: null }} | ||
/> | ||
<InfoSprinkle | ||
portalContainer={{ current: null }} | ||
scrollContainer={{ current: null }} | ||
/> | ||
<InfoSprinkle popoverZIndex={9999} usePortal> | ||
<Child usePortal={false} /> | ||
</InfoSprinkle> | ||
<InfoSprinkle usePortal={true} {...spreadProps} /> | ||
<WrappedInfoSprinkle /> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.