Unverified Commit 2dbdbdac authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[dev-overlay]: make open in editor button a separate click region (#76243)

Currently the code frame/terminal headers are treated as a clickable
region to open in your editor. However, the editor integration might not
always work or be desired, and folks might instead want to copy the file
path for other reasons.

This moves the "open in editor" functionality to be a specific click
area around the icon, removing interactivity from the header & call
stack frames.



https://github.com/user-attachments/assets/e7e1c282-233f-4ca1-9668-f520f0b7bbe8



Closes NDX-794
Closes NDX-802

---------
Co-authored-by: 's avatardevjiwonchoi <devjiwonchoi@gmail.com>
parent b77f8cdd
...@@ -38,34 +38,27 @@ export const CallStackFrame: React.FC<{ ...@@ -38,34 +38,27 @@ export const CallStackFrame: React.FC<{
return null return null
} }
const props = {
...(hasSource && {
role: 'button',
tabIndex: 0,
'aria-label': 'Click to open in your editor',
title: 'Click to open in your editor',
onClick: open,
}),
}
return ( return (
<div <div
data-nextjs-call-stack-frame data-nextjs-call-stack-frame
data-nextjs-call-stack-frame-ignored={!hasSource} data-nextjs-call-stack-frame-ignored={!hasSource}
{...props}
style={ style={
{ {
'--index': index, '--index': index,
} as React.CSSProperties } as React.CSSProperties
} }
> >
<span <div
data-nextjs-frame-expanded={!frame.ignored} data-nextjs-frame-expanded={!frame.ignored}
className="call-stack-frame-method-name" className="call-stack-frame-method-name"
> >
<HotlinkedText text={formattedMethod} /> <HotlinkedText text={formattedMethod} />
{hasSource && <ExternalIcon width={16} height={16} />} {hasSource && (
</span> <button onClick={open} className="open-in-editor-button">
<ExternalIcon width={16} height={16} />
</button>
)}
</div>
<span <span
className="call-stack-frame-file-source" className="call-stack-frame-file-source"
data-has-source={hasSource} data-has-source={hasSource}
...@@ -101,20 +94,6 @@ export const CALL_STACK_FRAME_STYLES = css` ...@@ -101,20 +94,6 @@ export const CALL_STACK_FRAME_STYLES = css`
padding: 6px 8px; padding: 6px 8px;
border-radius: var(--rounded-lg); border-radius: var(--rounded-lg);
transition: background 100ms ease-out;
&:not(:disabled)[role='button']:hover {
background: var(--color-gray-alpha-100);
cursor: pointer;
}
&:not(:disabled)[role='button']:active {
background: var(--color-gray-alpha-200);
}
&:focus-visible {
outline: var(--focus-ring);
}
} }
.call-stack-frame-method-name { .call-stack-frame-method-name {
...@@ -131,6 +110,24 @@ export const CALL_STACK_FRAME_STYLES = css` ...@@ -131,6 +110,24 @@ export const CALL_STACK_FRAME_STYLES = css`
line-height: var(--size-5); line-height: var(--size-5);
} }
.open-in-editor-button {
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--rounded-full);
padding: 4px;
color: var(--color-font);
&:focus-visible {
outline: var(--focus-ring);
outline-offset: -2px;
}
&:hover {
background: var(--color-gray-100);
}
}
.call-stack-frame-file-source { .call-stack-frame-file-source {
color: var(--color-gray-900); color: var(--color-gray-900);
font-size: var(--size-font-small); font-size: var(--size-font-small);
......
...@@ -63,24 +63,31 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) { ...@@ -63,24 +63,31 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) {
// TODO: make the caret absolute // TODO: make the caret absolute
return ( return (
<div data-nextjs-codeframe> <div data-nextjs-codeframe>
<button <div className="code-frame-header">
aria-label="Open error location in editor" {/* TODO: This is <div> in `Terminal` component.
className="code-frame-header" Changing now will require multiple test snapshots updates.
onClick={open} Leaving as <div> as is trivial and does not affect the UI.
> Change when the new redbox matcher `toDisplayRedbox` is used.
*/}
<p className="code-frame-link"> <p className="code-frame-link">
<span className="code-frame-icon" data-icon="left"> <span className="code-frame-icon">
<FileIcon lang={fileExtension} /> <FileIcon lang={fileExtension} />
</span> </span>
<span data-text> <span data-text>
{getFrameSource(stackFrame)} @{' '} {getFrameSource(stackFrame)} @{' '}
<HotlinkedText text={stackFrame.methodName} /> <HotlinkedText text={stackFrame.methodName} />
</span> </span>
<span className="code-frame-icon" data-icon="right"> <button
<ExternalIcon width={16} height={16} /> aria-label="Open in editor"
</span> data-with-open-in-editor-link-source-file
onClick={open}
>
<span className="code-frame-icon" data-icon="right">
<ExternalIcon width={16} height={16} />
</span>
</button>
</p> </p>
</button> </div>
<pre className="code-frame-pre"> <pre className="code-frame-pre">
{decoded.map((entry, index) => ( {decoded.map((entry, index) => (
<span <span
...@@ -140,11 +147,16 @@ export const CODE_FRAME_STYLES = css` ...@@ -140,11 +147,16 @@ export const CODE_FRAME_STYLES = css`
.code-frame-header { .code-frame-header {
width: 100%; width: 100%;
cursor: pointer;
transition: background 100ms ease-out; transition: background 100ms ease-out;
border-radius: 8px 8px 0 0; border-radius: 8px 8px 0 0;
border-bottom: 1px solid var(--color-gray-400); border-bottom: 1px solid var(--color-gray-400);
}
[data-with-open-in-editor-link-source-file] {
padding: 4px;
margin: -4px 0 -4px auto;
border-radius: var(--rounded-full);
margin-left: auto;
&:focus-visible { &:focus-visible {
outline: var(--focus-ring); outline: var(--focus-ring);
outline-offset: -2px; outline-offset: -2px;
......
...@@ -93,12 +93,7 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({ ...@@ -93,12 +93,7 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
return ( return (
<div data-nextjs-codeframe> <div data-nextjs-codeframe>
<button <div className="code-frame-header">
aria-label="Open in editor"
className="code-frame-header"
data-with-open-in-editor-link-source-file
onClick={open}
>
<div className="code-frame-link"> <div className="code-frame-link">
<span className="code-frame-icon"> <span className="code-frame-icon">
<FileIcon lang={fileExtension} /> <FileIcon lang={fileExtension} />
...@@ -107,11 +102,17 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({ ...@@ -107,11 +102,17 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
{/* TODO: Unlike the CodeFrame component, the `methodName` is unavailable. */} {/* TODO: Unlike the CodeFrame component, the `methodName` is unavailable. */}
{getFrameSource(stackFrame)} {getFrameSource(stackFrame)}
</span> </span>
<span className="code-frame-icon" data-icon="right"> <button
<ExternalIcon width={16} height={16} /> aria-label="Open in editor"
</span> data-with-open-in-editor-link-source-file
onClick={open}
>
<span className="code-frame-icon" data-icon="right">
<ExternalIcon width={16} height={16} />
</span>
</button>
</div> </div>
</button> </div>
<pre className="code-frame-pre"> <pre className="code-frame-pre">
{decoded.map((entry, index) => ( {decoded.map((entry, index) => (
<span <span
......
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