-
Notifications
You must be signed in to change notification settings - Fork 1.3k
adding some composition options for modals #15084
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
Changes from all commits
8dd290c
9d01bcd
44d3d87
692cc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useEffect } from "react"; | ||
import { ReactNode, useEffect } from "react"; | ||
import cn from "classnames"; | ||
import { getGitpodService } from "../service/service"; | ||
|
||
type CloseModalManner = "esc" | "enter" | "x"; | ||
|
@@ -14,8 +15,8 @@ export default function Modal(props: { | |
specify?: string; | ||
title?: string; | ||
hideDivider?: boolean; | ||
buttons?: React.ReactChild[] | React.ReactChild; | ||
children: React.ReactChild[] | React.ReactChild; | ||
buttons?: ReactNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
children: ReactNode; | ||
visible: boolean; | ||
closeable?: boolean; | ||
className?: string; | ||
|
@@ -75,10 +76,10 @@ export default function Modal(props: { | |
<div className="fixed top-0 left-0 bg-black bg-opacity-70 z-50 w-screen h-screen"> | ||
<div className="w-screen h-screen align-middle" style={{ display: "table-cell" }}> | ||
<div | ||
className={ | ||
"relative bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 rounded-xl p-6 max-w-lg mx-auto text-left " + | ||
(props.className || "") | ||
} | ||
className={cn( | ||
"flex flex-col max-h-screen relative bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 rounded-xl p-6 max-w-lg mx-auto text-left ", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this allows the modal container to adjust height, while being height constrained to the screen viewport There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: This will also resolve #10747. I've updated the PR description to also include that issue. |
||
props.className, | ||
)} | ||
> | ||
{props.closeable !== false && ( | ||
<div | ||
|
@@ -93,16 +94,9 @@ export default function Modal(props: { | |
)} | ||
{props.title ? ( | ||
<> | ||
<h3 className="pb-2">{props.title}</h3> | ||
<div | ||
className={ | ||
"border-gray-200 dark:border-gray-800 -mx-6 px-6 " + | ||
(props.hideDivider ? "" : "border-t border-b mt-2 py-4") | ||
} | ||
> | ||
{props.children} | ||
</div> | ||
<div className="flex justify-end mt-6 space-x-2">{props.buttons}</div> | ||
<ModalHeader>{props.title}</ModalHeader> | ||
<ModalBody hideDivider={props.hideDivider}>{props.children}</ModalBody> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi: Not sure where to add this comment, but one modal I'd love to improve after thes changes is the feedback modal. Cross-posting follow up issue (#10307) for visibility. |
||
<ModalFooter>{props.buttons}</ModalFooter> | ||
Comment on lines
+97
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Not sure if this introduces unnecessary complexity, but more structure like this is definitely needed! ✨ |
||
</> | ||
) : ( | ||
props.children | ||
|
@@ -112,3 +106,35 @@ export default function Modal(props: { | |
</div> | ||
); | ||
} | ||
|
||
type ModalHeaderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const ModalHeader = ({ children }: ModalHeaderProps) => { | ||
return <h3 className="pb-2">{children}</h3>; | ||
}; | ||
|
||
type ModalBodyProps = { | ||
children: ReactNode; | ||
hideDivider?: boolean; | ||
}; | ||
|
||
export const ModalBody = ({ children, hideDivider = false }: ModalBodyProps) => { | ||
return ( | ||
<div | ||
className={cn("overflow-y-auto border-gray-200 dark:border-gray-800 -mx-6 px-6 ", { | ||
"border-t border-b mt-2 py-4": !hideDivider, | ||
})} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
type ModalFooterProps = { | ||
children: ReactNode; | ||
}; | ||
export const ModalFooter = ({ children }: ModalFooterProps) => { | ||
return <div className="flex justify-end mt-6 space-x-2">{children}</div>; | ||
}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -13,7 +13,7 @@ import ConfirmationModal from "../components/ConfirmationModal"; | |||
import { ContextMenuEntry } from "../components/ContextMenu"; | ||||
import InfoBox from "../components/InfoBox"; | ||||
import { Item, ItemField, ItemFieldContextMenu, ItemFieldIcon, ItemsList } from "../components/ItemsList"; | ||||
import Modal from "../components/Modal"; | ||||
import Modal, { ModalBody, ModalHeader, ModalFooter } from "../components/Modal"; | ||||
import copy from "../images/copy.svg"; | ||||
import exclamation from "../images/exclamation.svg"; | ||||
import { openAuthorizeWindow } from "../provider-utils"; | ||||
|
@@ -291,8 +291,8 @@ function GitProviders() { | |||
{editModal && ( | ||||
// TODO: Use title and buttons props | ||||
<Modal visible={true} onClose={() => setEditModal(undefined)}> | ||||
<h3 className="pb-2">Edit Permissions</h3> | ||||
<div className="border-t border-b border-gray-200 dark:border-gray-800 mt-2 -mx-6 px-6 py-4"> | ||||
<ModalHeader>Edit Permissions</ModalHeader> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Since you've replaced the modal contents here could we also replace the contents for the New Git integration modal which is also much needed, see
|
||||
<ModalBody> | ||||
<div className="text-gray-500">Configure provider permissions.</div> | ||||
{(editModal.provider.scopes || []).map((scope) => ( | ||||
<div key={`scope-${scope}`}> | ||||
|
@@ -307,15 +307,15 @@ function GitProviders() { | |||
></CheckBox> | ||||
</div> | ||||
))} | ||||
</div> | ||||
<div className="flex justify-end mt-6"> | ||||
</ModalBody> | ||||
<ModalFooter> | ||||
<button | ||||
onClick={() => updatePermissions()} | ||||
disabled={equals(editModal.nextScopes, editModal.prevScopes)} | ||||
> | ||||
Update Permissions | ||||
</button> | ||||
</div> | ||||
</ModalFooter> | ||||
</Modal> | ||||
)} | ||||
|
||||
|
Uh oh!
There was an error while loading. Please reload this page.