-
Notifications
You must be signed in to change notification settings - Fork 69
[LG-4952] feat(codemods): add modal-v20 codemod for automatic Modal v20 upgrade #3049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: steph/modal-dialog-top-layer
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e7c4141 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: 0 B Total Size: 1.99 MB ℹ️ View Unchanged
|
8f62307
to
e7c4141
Compare
Key changes include: | ||
|
||
- `className` → `backdropClassName` | ||
- **Note:** `backdropClassName` is also deprecated in v20 and only provided for migration ease. For custom backdrop styles, use the CSS `::backdrop` pseudo-element to target and style the dialog backdrop instead of relying on this prop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you provide an example of where you would use ::backdrop
?
|
||
1. In the root of your project, install [@lg-tools/cli](https://github.com/mongodb/leafygreen-ui/blob/main/tools/cli/README.md#installation) and [@lg-tools/codemods](https://github.com/mongodb/leafygreen-ui/blob/main/tools/codemods/README.md#installation). | ||
2. Bump to the version of the Modal packages you'd like to upgrade and install the bumped packages. | ||
3. Run [modal-v20 codemod](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#modal-v20). By default, this will apply for all relevant packages in the specified directory. The `--packages` flag can be used to only modify specified packages. However, it is recommended to upgrade all packages simultaneously. If necessary, re-lint your project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could you provide the snippet to run?
* This must happen after step 1 to avoid className being renamed to backdropClassName | ||
*/ | ||
packagesToCheck.forEach(packageName => { | ||
const componentsToTransform = getImportSpecifiersForDeclaration({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can getImportSpecifiersForDeclaration
be called before steps 1, 2, and 3, so you don't have to call it for each step?
✍️ Proposed changes
This PR adds the
modal-v20
codemod to automatically upgrade Modal components to v20 breaking changes. The codemod provides seamless migration from the old prop structure to the new top-layer rendering architecture, handling all the breaking changes automatically while preserving developer intent.Key features:
className
→backdropClassName
,contentClassName
→className
initialFocus
prop with helpful guidanceModal as LGModal
)--packages
flagModal v20 changes made in PR #3048
🎟️ Jira ticket: LG-4952
✅ Checklist
pnpm changeset
and documented my changes🧪 How to test changes
Testing the Modal v20 Codemod
Build the codemods package:
Run the test suite:
pnpm run test tools/codemods/src/codemods/modal-v20
Verify all test scenarios pass:
rename-className-props
: Sequential prop renamingremove-initialFocus
: Prop removal with guidance commentshandle-aliases
: Alias handling (e.g.,MyModal
,LGConfirmationModal
)filter-packages
: Selective package transformation