Skip to content
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

[DevOverlay] Decouple Dialog component from Error Overlay #74638

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export type DialogProps = {
type: 'error' | 'warning'
'aria-labelledby': string
'aria-describedby': string
className?: string
onClose?: () => void
}

const Dialog: React.FC<DialogProps> = function Dialog({
children,
type,
className,
onClose,
...props
}) {
Expand Down Expand Up @@ -81,6 +83,7 @@ const Dialog: React.FC<DialogProps> = function Dialog({
aria-labelledby={props['aria-labelledby']}
aria-describedby={props['aria-describedby']}
aria-modal="true"
className={className}
>
{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ const styles = css`
margin-right: auto;
margin-left: auto;
background: var(--color-background-100);
border: 1px solid var(--color-gray-400);
border-radius: var(--rounded-xl);
box-shadow: var(--shadow-md);
max-height: calc(100% - 56px);
position: relative;
z-index: 50;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z-index is always a good example for extraction into variables. But no need to follow-up. Just good to keep in mind when we add more layering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea probably good to have some constants z-indexes, so we can order them easily. I've seen z-index: 2, 48 and 50 in error overlay which vary a lot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will follow up!

outline: none;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { noop as css } from '../../../helpers/noop-template'
import { DialogBody } from '../../Dialog'

type ErrorOverlayDialogBodyProps = {
children?: React.ReactNode
onClose?: () => void
}

export function ErrorOverlayDialogBody({
children,
}: ErrorOverlayDialogBodyProps) {
return (
<DialogBody className="nextjs-container-errors-body">{children}</DialogBody>
)
}

export const DIALOG_BODY_STYLES = css``
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Dialog } from '../../Dialog/Dialog'
import { noop as css } from '../../../helpers/noop-template'

type ErrorOverlayDialogProps = {
children?: React.ReactNode
onClose?: () => void
}

export function ErrorOverlayDialog({
children,
onClose,
}: ErrorOverlayDialogProps) {
return (
<Dialog
type="error"
aria-labelledby="nextjs__container_errors_label"
aria-describedby="nextjs__container_errors_desc"
onClose={onClose}
className="error-overlay-dialog"
>
{children}
</Dialog>
)
}

export const DIALOG_STYLES = css`
.error-overlay-dialog {
background: var(--color-background-100);
border: 1px solid var(--color-gray-400);
border-radius: var(--rounded-xl);
box-shadow: var(--shadow-md);
position: relative;
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { DialogHeader } from '../../Dialog/DialogHeader'
import { noop as css } from '../../../helpers/noop-template'

type ErrorOverlayDialogHeaderProps = {
children?: React.ReactNode
}

export function ErrorOverlayDialogHeader({
children,
}: ErrorOverlayDialogHeaderProps) {
return (
<DialogHeader className="nextjs-container-errors-header">
{children}
</DialogHeader>
)
}

export const DIALOG_HEADER_STYLES = css`
.nextjs-container-errors-header {
position: relative;
}
.nextjs-container-errors-header > h1 {
font-size: var(--size-font-big);
line-height: var(--size-font-bigger);
font-weight: bold;
margin: calc(var(--size-gap-double) * 1.5) 0;
color: var(--color-title-h1);
}
.nextjs-container-errors-header small {
font-size: var(--size-font-small);
color: var(--color-accents-1);
margin-left: var(--size-gap-double);
}
.nextjs-container-errors-header small > span {
font-family: var(--font-stack-monospace);
}
.nextjs-container-errors-header > div > small {
margin: 0;
margin-top: var(--size-gap-half);
}
.nextjs-container-errors-header > p > a {
color: inherit;
font-weight: bold;
}
.nextjs-container-errors-header
> .nextjs-container-build-error-version-status {
position: absolute;
top: var(--size-4);
right: var(--size-4);
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import type { VersionInfo } from '../../../../../../../../server/dev/parse-versi
import type { ErrorMessageType } from '../error-message/error-message'
import type { ErrorType } from '../error-type-label/error-type-label'

import {
Dialog,
DialogHeader,
DialogBody,
DialogContent,
DialogFooter,
} from '../../Dialog'
import { DialogContent, DialogFooter } from '../../Dialog'
import { Overlay } from '../../Overlay'
import {
ErrorOverlayToolbar,
Expand All @@ -32,6 +26,13 @@ import {
styles as floatingHeaderStyles,
} from '../error-overlay-floating-header/error-overlay-floating-header'

import { ErrorOverlayDialog, DIALOG_STYLES } from '../dialog/dialog'
import {
ErrorOverlayDialogHeader,
DIALOG_HEADER_STYLES,
} from '../dialog/header'
import { ErrorOverlayDialogBody, DIALOG_BODY_STYLES } from '../dialog/body'

type ErrorOverlayLayoutProps = {
errorMessage: ErrorMessageType
errorType: ErrorType
Expand Down Expand Up @@ -66,20 +67,16 @@ export function ErrorOverlayLayout({
}: ErrorOverlayLayoutProps) {
return (
<Overlay fixed={isBuildError}>
<Dialog
type="error"
aria-labelledby="nextjs__container_errors_label"
aria-describedby="nextjs__container_errors_desc"
onClose={onClose}
>

<ErrorOverlayDialog onClose={onClose}>
<ErrorOverlayFloatingHeader
readyErrors={readyErrors}
activeIdx={activeIdx}
setActiveIndex={setActiveIndex}
versionInfo={versionInfo}
/>
<DialogContent>
<DialogHeader className="nextjs-container-errors-header">
<ErrorOverlayDialogHeader>
<div
className="nextjs__container_errors__error_title"
// allow assertion in tests before error rating is implemented
Expand All @@ -89,10 +86,10 @@ export function ErrorOverlayLayout({
<ErrorOverlayToolbar error={error} debugInfo={debugInfo} />
</div>
<ErrorMessage errorMessage={errorMessage} />
</DialogHeader>
<DialogBody className="nextjs-container-errors-body">
{children}
</DialogBody>
</ErrorOverlayDialogHeader>

<ErrorOverlayDialogBody>{children}</ErrorOverlayDialogBody>

<DialogFooter>
{/* TODO: errorCode should not be undefined whatsoever */}
<ErrorOverlayFooter
Expand All @@ -105,12 +102,16 @@ export function ErrorOverlayLayout({
errorsCount={readyErrors?.length ?? 0}
activeIdx={activeIdx ?? 0}
/>
</Dialog>
</ErrorOverlayDialog>
</Overlay>
)
}

export const styles = css`
${DIALOG_STYLES}
${DIALOG_HEADER_STYLES}
${DIALOG_BODY_STYLES}

${floatingHeaderStyles}
${errorTypeLabelStyles}
${errorMessageStyles}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,4 @@ export const BuildError: React.FC<BuildErrorProps> = function BuildError({
)
}

export const styles = css`
.nextjs-container-errors-body footer {
margin-top: var(--size-gap);
}
.nextjs-container-errors-body footer p {
margin: 0;
}
.nextjs-container-errors-body small {
color: var(--color-font);
}
`
export const styles = css``
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,6 @@ export const styles = css`
.nextjs-error-with-static {
bottom: calc(var(--size-gap-double) * 4.5);
}
.nextjs-container-errors-header {
position: relative;
}
.nextjs-container-errors-header > h1 {
font-size: var(--size-font-big);
line-height: var(--size-font-bigger);
font-weight: bold;
margin: calc(var(--size-gap-double) * 1.5) 0;
color: var(--color-title-h1);
}
.nextjs-container-errors-header small {
font-size: var(--size-font-small);
color: var(--color-accents-1);
margin-left: var(--size-gap-double);
}
.nextjs-container-errors-header small > span {
font-family: var(--font-stack-monospace);
}
p.nextjs__container_errors__link {
color: var(--color-text-color-red-1);
font-weight: 600;
Expand All @@ -343,14 +325,6 @@ export const styles = css`
font-weight: 600;
font-size: 15px;
}
.nextjs-container-errors-header > div > small {
margin: 0;
margin-top: var(--size-gap-half);
}
.nextjs-container-errors-header > p > a {
color: inherit;
font-weight: bold;
}
.nextjs-container-errors-body > h2:not(:first-child) {
margin-top: calc(var(--size-gap-double) + var(--size-gap));
}
Expand Down Expand Up @@ -392,12 +366,6 @@ export const styles = css`
.nextjs-toast-hide-button:hover {
opacity: 1;
}
.nextjs-container-errors-header
> .nextjs-container-build-error-version-status {
position: absolute;
top: var(--size-4);
right: var(--size-4);
}
.nextjs__container_errors_inspect_copy_button {
cursor: pointer;
background: none;
Expand Down
Loading