Unverified Commit 19caa18e authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[DevOverlay] Add Toolbar (#74555)

This PR added style for Toolbar buttons, and moved files to `Errors/error-overlay-toolbar`.

Will follow up with TBD:

- Replace the Node.js button with the "Debugging" Icon
- Add Docs Button?

### Light

![CleanShot 2025-01-07 at 01 12 52](https://github.com/user-attachments/assets/a26ad870-d938-4b24-a8e7-2409e65026d1)

### Dark

![CleanShot 2025-01-07 at 01 12 25](https://github.com/user-attachments/assets/0abe5d67-677b-4002-bf43-6d7a26dee602)

Closes NDX-601
Closes NDX-602
parent b0a0c926
......@@ -13,7 +13,10 @@ import {
} from '../../Dialog'
import { Overlay } from '../../Overlay'
import { ErrorPagination } from '../ErrorPagination/ErrorPagination'
import { ToolButtonsGroup } from '../../ToolButtonsGroup/ToolButtonsGroup'
import {
ErrorOverlayToolbar,
styles as toolbarStyles,
} from '../error-overlay-toolbar/error-overlay-toolbar'
import { VersionStalenessInfo } from '../../VersionStalenessInfo'
import { ErrorOverlayBottomStacks } from '../error-overlay-bottom-stacks/error-overlay-bottom-stacks'
import { ErrorOverlayFooter } from '../error-overlay-footer/error-overlay-footer'
......@@ -81,7 +84,7 @@ export function ErrorOverlayLayout({
data-nextjs-error-code={errorCode}
>
<ErrorTypeLabel errorType={errorType} />
<ToolButtonsGroup error={error} debugInfo={debugInfo} />
<ErrorOverlayToolbar error={error} debugInfo={debugInfo} />
</div>
<VersionStalenessInfo versionInfo={versionInfo} />
<ErrorMessage errorMessage={errorMessage} />
......@@ -109,4 +112,5 @@ export function ErrorOverlayLayout({
export const styles = css`
${errorTypeLabelStyles}
${errorMessageStyles}
${toolbarStyles}
`
import type { Meta, StoryObj } from '@storybook/react'
import { CopyStackTraceButton } from './copy-stack-trace-button'
import { withShadowPortal } from '../../../storybook/with-shadow-portal'
const meta: Meta<typeof CopyStackTraceButton> = {
title: 'ErrorOverlayToolbar/CopyStackTraceButton',
component: CopyStackTraceButton,
parameters: {
layout: 'centered',
},
decorators: [withShadowPortal],
}
export default meta
type Story = StoryObj<typeof CopyStackTraceButton>
const errorWithStack = new Error('Test error')
errorWithStack.stack = `Error: Test error
at Context.<anonymous> (test.ts:1:1)
at processImmediate (node:internal/timers:466:21)`
export const WithStackTrace: Story = {
args: {
error: errorWithStack,
},
}
export const WithoutStackTrace: Story = {
args: {
error: new Error('Error without stack'),
},
}
export const Disabled: Story = {
args: {
error: undefined,
},
}
import { CopyButton } from '../../copy-button'
export function CopyStackTraceButton({ error }: { error: Error | undefined }) {
return (
<CopyButton
data-nextjs-data-runtime-error-copy-stack
className="copy-stack-trace-button"
actionLabel="Copy Stack Trace"
successLabel="Stack Trace Copied"
content={error?.stack || ''}
disabled={!error?.stack}
/>
)
}
import type { Meta, StoryObj } from '@storybook/react'
import { ErrorOverlayToolbar } from './error-overlay-toolbar'
import { withShadowPortal } from '../../../storybook/with-shadow-portal'
const meta: Meta<typeof ErrorOverlayToolbar> = {
title: 'ErrorOverlayToolbar',
component: ErrorOverlayToolbar,
parameters: {
layout: 'centered',
},
decorators: [withShadowPortal],
}
export default meta
type Story = StoryObj<typeof ErrorOverlayToolbar>
export const WithErrorAndDebugInfo: Story = {
args: {
error: new Error('Test error with stack trace'),
debugInfo: {
devtoolsFrontendUrl: 'chrome-devtools://devtools/bundled/inspector.html',
},
},
}
export const WithErrorOnly: Story = {
args: {
error: new Error('Test error without debug info'),
debugInfo: undefined,
},
}
export const WithoutError: Story = {
args: {
error: undefined,
debugInfo: undefined,
},
}
import type { DebugInfo } from '../../../../../types'
import { NodejsInspectorButton } from './nodejs-inspector-button'
import { noop as css } from '../../../helpers/noop-template'
import { CopyStackTraceButton } from './copy-stack-trace-button'
type ErrorOverlayToolbarProps = {
error: Error | undefined
debugInfo: DebugInfo | undefined
}
export function ErrorOverlayToolbar({
error,
debugInfo,
}: ErrorOverlayToolbarProps) {
return (
<span className="error-overlay-toolbar">
<CopyStackTraceButton error={error} />
<NodejsInspectorButton
devtoolsFrontendUrl={debugInfo?.devtoolsFrontendUrl}
/>
</span>
)
}
export const styles = css`
.error-overlay-toolbar {
display: flex;
gap: var(--size-1_5);
}
.nodejs-inspector-button,
.copy-stack-trace-button {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
width: var(--size-8);
padding: var(--size-1_5);
background: var(--color-background-100);
box-shadow: var(--shadow-sm);
border-radius: var(--rounded-full);
border: 1px solid var(--color-gray-400);
&:focus {
outline: none;
}
&:not(:disabled):hover {
background: var(--color-gray-alpha-100);
}
&:active {
background: var(--color-gray-alpha-200);
}
&:disabled {
opacity: 0.7;
cursor: not-allowed;
}
}
.error-overlay-toolbar-button-icon {
color: var(--color-gray-900);
}
`
import type { Meta, StoryObj } from '@storybook/react'
import { NodejsInspectorButton } from './nodejs-inspector-button'
import { withShadowPortal } from '../../../storybook/with-shadow-portal'
const meta: Meta<typeof NodejsInspectorButton> = {
title: 'ErrorOverlayToolbar/NodejsInspectorButton',
component: NodejsInspectorButton,
parameters: {
layout: 'centered',
},
decorators: [withShadowPortal],
}
export default meta
type Story = StoryObj<typeof NodejsInspectorButton>
export const WithDevtoolsUrl: Story = {
args: {
devtoolsFrontendUrl: 'chrome-devtools://devtools/bundled/inspector.html',
},
}
export const WithoutDevtoolsUrl: Story = {
args: {
devtoolsFrontendUrl: undefined,
},
}
import { CopyButton } from './copy-button'
import { CopyButton } from '../../copy-button'
// Inline this helper to avoid widely used across the codebase,
// as for this feature the Chrome detector doesn't need to be super accurate.
......@@ -75,7 +75,7 @@ function NodeJsDisabledIcon(props: any) {
const label =
'Learn more about enabling Node.js inspector for server code with Chrome DevTools'
export function NodejsInspectorCopyButton({
export function NodejsInspectorButton({
devtoolsFrontendUrl,
}: {
devtoolsFrontendUrl: string | undefined
......@@ -87,22 +87,33 @@ export function NodejsInspectorCopyButton({
<a
title={label}
aria-label={label}
className="nextjs-data-runtime-error-inspect-link"
className="nodejs-inspector-button"
href={`https://nextjs.org/docs/app/building-your-application/configuring/debugging#server-side-code`}
target="_blank"
rel="noopener noreferrer"
>
<NodeJsDisabledIcon width={16} height={16} />
<NodeJsDisabledIcon
className="error-overlay-toolbar-button-icon"
width={16}
height={16}
/>
</a>
)
}
return (
<CopyButton
data-nextjs-data-runtime-error-copy-devtools-url
className="nodejs-inspector-button"
actionLabel={'Copy Chrome DevTools URL'}
successLabel="Copied"
content={content}
icon={<NodeJsIcon width={16} height={16} />}
icon={
<NodeJsIcon
className="error-overlay-toolbar-button-icon"
width={16}
height={16}
/>
}
/>
)
}
import type { DebugInfo } from '../../../../types'
import { CopyButton } from '../copy-button'
import { NodejsInspectorCopyButton } from '../nodejs-inspector'
type ToolButtonsGroupProps = {
error: Error | undefined
debugInfo: DebugInfo | undefined
}
export function ToolButtonsGroup({ error, debugInfo }: ToolButtonsGroupProps) {
return (
<span>
<CopyButton
data-nextjs-data-runtime-error-copy-stack
actionLabel="Copy error stack"
successLabel="Copied"
content={error?.stack || ''}
disabled={!error?.stack}
/>
<NodejsInspectorCopyButton
devtoolsFrontendUrl={debugInfo?.devtoolsFrontendUrl}
/>
</span>
)
}
......@@ -181,8 +181,9 @@ export function CopyButton({
title={label}
aria-label={label}
aria-disabled={isDisabled}
disabled={isDisabled}
data-nextjs-data-runtime-error-copy-button
className={`nextjs-data-runtime-error-copy-button nextjs-data-runtime-error-copy-button--${copyState.state}`}
className={`${props.className || ''} nextjs-data-runtime-error-copy-button nextjs-data-runtime-error-copy-button--${copyState.state}`}
onClick={() => {
if (!isDisabled) {
copy()
......@@ -200,15 +201,17 @@ function CopyIcon() {
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="transparent"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="error-overlay-toolbar-button-icon"
>
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
<path
fillRule="evenodd"
clipRule="evenodd"
d="M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z"
fill="currentColor"
/>
</svg>
)
}
......
......@@ -410,12 +410,6 @@ export const styles = css`
align-items: center;
justify-content: space-between;
}
.nextjs-data-runtime-error-inspect-link,
.nextjs-data-runtime-error-inspect-link:hover {
margin: 0 8px;
color: inherit;
}
.error-overlay-notes-container {
padding: var(--size-4);
padding-top: 0;
......
......@@ -101,28 +101,6 @@ export const styles = css`
outline: none;
}
[data-nextjs-data-runtime-error-copy-button],
[data-nextjs-data-runtime-error-copy-button]:focus:not(:focus-visible) {
position: relative;
margin-left: var(--size-gap);
padding: 0;
border: none;
background: none;
outline: none;
}
[data-nextjs-data-runtime-error-copy-button] > svg {
vertical-align: middle;
}
.nextjs-data-runtime-error-copy-button {
color: inherit;
}
.nextjs-data-runtime-error-copy-button--initial:hover {
cursor: pointer;
}
.nextjs-data-runtime-error-copy-button[aria-disabled='true'] {
opacity: 0.3;
cursor: not-allowed;
}
.nextjs-data-runtime-error-copy-button--error,
.nextjs-data-runtime-error-copy-button--error:hover {
color: var(--color-ansi-red);
......
......@@ -86,6 +86,7 @@ export function Base() {
--rounded-xl: 0.75rem; /* 12px */
--rounded-2xl: 1rem; /* 16px */
--rounded-3xl: 1.5rem; /* 24px */
--rounded-full: 9999px;
--size-0: 0px;
--size-px: 1px;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment