-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Added renderTo prop instead of appendToBody #45
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
Merged
andrewrubin
merged 9 commits into
release/v3.0.0
from
feature/renderto-instead-appendbody
Jul 30, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd10788
WIP - Removed appendToBody, added renderTo prop to accept string | HT…
pravton 308d061
WIP - Removed render to same parent, can use ref/selecter to pass any…
pravton 210f29c
WIP - Updated documentaion to reflect the changes
pravton d618772
WIP - added client side check to prevent ssr issues on next js
pravton 0337d29
WIP - moved getModalRoot inside component, added error handling and u…
pravton 2cd8e40
update(react-modal): WIP - removed string prop, made prop mandatory a…
pravton a71a040
udpate(react-modal): WIP - updated documentation to reflect the updat…
pravton 3744520
update(react-modal): added an example of appending to body and update…
pravton 6610bbf
update(react-modal): bumping the version using changeset
pravton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
| --- | ||
| "@wethegit/react-modal": major | ||
| --- | ||
|
|
||
| ## Breaking changes | ||
|
|
||
| - **Removed** `appendToBody` prop. | ||
| - The `appendToBody` prop has been removed. This prop was previously used to determine whether the modal should be appended to the body element. | ||
|
|
||
| ## New Features | ||
|
|
||
| - **Added** `renderTo` prop. | ||
| - Introduced the `renderTo` prop, which accepts an HTMLElement where the modal will be appended. This provides greater flexibilty, allowing users to specify any element to render the modal, including the body. This change enhances the customization options for the modal rendering. | ||
|
|
||
| ## Migration | ||
|
|
||
| - **Before** | ||
|
|
||
| ```javascript | ||
| <Modal appendToBody={true} /> | ||
| ``` | ||
|
|
||
| - **After** | ||
|
|
||
| ```javascript | ||
| <Modal renderTo={modalRef} /> | ||
| ``` |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,34 +1,27 @@ | ||
| import ReactDOM from "react-dom" | ||
| import { usePreventScroll } from "@wethegit/react-hooks" | ||
| "use client" | ||
|
|
||
| import ReactDOM from "react-dom" | ||
| import { ModalInner } from "../modal-inner" | ||
| import type { ModalInnerProps } from "../modal-inner" | ||
| import { classnames } from "../../../utils/classnames" | ||
|
|
||
| import styles from "./modal.module.scss" | ||
|
|
||
| export interface ModalProps extends ModalInnerProps { | ||
| /** | ||
| * If true, the modal will be appended to the body instead of being rendered in place. | ||
| * @defaultValue true | ||
| */ | ||
| appendToBody?: boolean | ||
| * The modal will be appended to the passed element instead of being rendered in place | ||
| * @defaultValue defaults inPlace | ||
| **/ | ||
| renderTo: HTMLElement | ||
| } | ||
|
|
||
| export function Modal({ appendToBody, className, ...props }: ModalProps) { | ||
| usePreventScroll(appendToBody) | ||
| export function Modal({ renderTo, className, ...props }: ModalProps) { | ||
| const classes = classnames([styles.ModalFixed, className]) | ||
|
|
||
| const classes = classnames([ | ||
| appendToBody ? styles.ModalFixed : styles.ModalAbsolute, | ||
| className, | ||
| ]) | ||
| const modalContent = <ModalInner className={classes} {...props} /> | ||
|
|
||
| if (appendToBody) { | ||
| return ReactDOM.createPortal( | ||
| <ModalInner className={classes} {...props} />, | ||
| document.body | ||
| ) | ||
| } else { | ||
| return <ModalInner className={classes} {...props} /> | ||
| if (renderTo) { | ||
| return ReactDOM.createPortal(modalContent, renderTo) | ||
| } | ||
|
|
||
| return modalContent | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -31,3 +31,7 @@ | |
| --ease: cubic-bezier(0.77, 0, 0.1, 1.39); | ||
| --scale: 1; | ||
| } | ||
|
|
||
| .CustomModalAbsolute { | ||
| position: absolute; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.