Skip to content

Commit 75b7fe2

Browse files
authored
[devtools] add dialog behavior to panel ui (#80355)
### Testing Plan Open Storybook and goto `dev-overlay > With Panel` OR `devtools-panel > Default` https://github.com/user-attachments/assets/d1b08482-9382-4a1c-906d-a8e9d7c68f66 Closes NEXT-4516
1 parent eade7d2 commit 75b7fe2

File tree

5 files changed

+139
-16
lines changed

5 files changed

+139
-16
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import type { OverlayState } from '../../shared'
3+
4+
import { DevToolsPanel } from './devtools-panel'
5+
import { INITIAL_OVERLAY_STATE } from '../../shared'
6+
import { withShadowPortal } from '../../storybook/with-shadow-portal'
7+
8+
const meta: Meta<typeof DevToolsPanel> = {
9+
component: DevToolsPanel,
10+
parameters: {
11+
layout: 'centered',
12+
},
13+
argTypes: {},
14+
decorators: [withShadowPortal],
15+
}
16+
17+
export default meta
18+
type Story = StoryObj<typeof DevToolsPanel>
19+
20+
const state: OverlayState = {
21+
...INITIAL_OVERLAY_STATE,
22+
routerType: 'app',
23+
isErrorOverlayOpen: false,
24+
isDevToolsPanelOpen: true,
25+
}
26+
27+
export const Default: Story = {
28+
args: {
29+
state,
30+
dispatch: () => {},
31+
},
32+
}
Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,62 @@
1+
import type { OverlayDispatch, OverlayState } from '../../shared'
2+
3+
import { Dialog, DialogContent, DialogHeader, DialogBody } from '../dialog'
4+
import { Overlay } from '../overlay/overlay'
5+
import { ACTION_DEVTOOLS_PANEL_TOGGLE } from '../../shared'
16
import { css } from '../../utils/css'
27

3-
export function DevToolsPanel() {
4-
// TODO: Remove style; It is to indicate faster in the browser.
5-
return <div data-nextjs-devtools-panel>DevToolsPanel</div>
8+
export function DevToolsPanel({
9+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10+
state,
11+
dispatch,
12+
}: {
13+
state: OverlayState
14+
dispatch: OverlayDispatch
15+
}) {
16+
const onClose = () => {
17+
dispatch({ type: ACTION_DEVTOOLS_PANEL_TOGGLE })
18+
}
19+
20+
return (
21+
<Overlay data-nextjs-devtools-panel-overlay>
22+
<Dialog
23+
data-nextjs-devtools-panel-dialog
24+
aria-labelledby="nextjs__container_dev_tools_panel_label"
25+
aria-describedby="nextjs__container_dev_tools_panel_desc"
26+
onClose={onClose}
27+
>
28+
<DialogContent>
29+
<DialogHeader></DialogHeader>
30+
<DialogBody></DialogBody>
31+
</DialogContent>
32+
</Dialog>
33+
</Overlay>
34+
)
635
}
736

837
export const DEVTOOLS_PANEL_STYLES = css`
9-
[data-nextjs-devtools-panel] {
10-
color: black;
38+
[data-nextjs-devtools-panel-overlay] {
39+
padding: initial;
40+
top: 10vh;
41+
}
42+
43+
[data-nextjs-devtools-panel-dialog] {
44+
-webkit-font-smoothing: antialiased;
45+
display: flex;
46+
flex-direction: column;
47+
background: var(--color-background-100);
48+
background-clip: padding-box;
49+
border: 1px solid var(--color-gray-400);
50+
border-radius: var(--rounded-xl);
51+
box-shadow: var(--shadow-lg);
52+
position: relative;
53+
overflow-y: auto;
54+
55+
/* TODO: Remove once the content is filled. */
56+
min-width: 800px;
57+
min-height: 500px;
58+
59+
/* This is handled from dialog/styles.ts */
60+
max-width: var(--next-dialog-max-width);
1161
}
1262
`

packages/next/src/next-devtools/dev-overlay/components/dialog/styles.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const styles = `
1+
import { css } from '../../utils/css'
2+
3+
export const styles = css`
24
[data-nextjs-dialog-root] {
35
--next-dialog-radius: var(--rounded-xl);
46
--next-dialog-max-width: 960px;
@@ -25,9 +27,11 @@ const styles = `
2527
scale: 1;
2628
}
2729
28-
[data-nextjs-scroll-fader][data-side="top"] {
30+
[data-nextjs-scroll-fader][data-side='top'] {
2931
left: 1px;
30-
top: calc(var(--next-dialog-notch-height) + var(--next-dialog-border-width));
32+
top: calc(
33+
var(--next-dialog-notch-height) + var(--next-dialog-border-width)
34+
);
3135
width: calc(100% - var(--next-dialog-padding));
3236
opacity: 0;
3337
}
@@ -37,7 +41,8 @@ const styles = `
3741
outline: 0;
3842
}
3943
40-
[data-nextjs-dialog], [data-nextjs-dialog] * {
44+
[data-nextjs-dialog],
45+
[data-nextjs-dialog] * {
4146
&::-webkit-scrollbar {
4247
width: 6px;
4348
height: 6px;
@@ -53,7 +58,7 @@ const styles = `
5358
border-radius: 0 0 1rem 1rem;
5459
background-color: var(--color-background-100);
5560
}
56-
61+
5762
&::-webkit-scrollbar-thumb {
5863
border-radius: 1rem;
5964
background-color: var(--color-gray-500);
@@ -123,5 +128,3 @@ const styles = `
123128
}
124129
}
125130
`
126-
127-
export { styles }

packages/next/src/next-devtools/dev-overlay/dev-overlay.stories.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import imgApp from './app.png'
77
import { useReducer } from 'react'
88
import { DevOverlay } from './dev-overlay'
99
import {
10+
ACTION_DEVTOOLS_PANEL_TOGGLE,
1011
ACTION_ERROR_OVERLAY_CLOSE,
1112
ACTION_ERROR_OVERLAY_OPEN,
1213
ACTION_ERROR_OVERLAY_TOGGLE,
@@ -93,8 +94,7 @@ const initialState: OverlayState = {
9394
installed: '15.2.0',
9495
staleness: 'fresh',
9596
},
96-
isErrorOverlayOpen: true,
97-
// TODO: This will be handled on the next stack——with proper story.
97+
isErrorOverlayOpen: false,
9898
isDevToolsPanelOpen: false,
9999
}
100100

@@ -111,11 +111,13 @@ function useOverlayReducer() {
111111
case ACTION_ERROR_OVERLAY_TOGGLE: {
112112
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
113113
}
114+
case ACTION_DEVTOOLS_PANEL_TOGGLE: {
115+
return { ...state, isDevToolsPanelOpen: !state.isDevToolsPanelOpen }
116+
}
114117
default: {
115118
return state
116119
}
117120
}
118-
return state
119121
},
120122
initialState
121123
)
@@ -150,3 +152,37 @@ export const Default: Story = {
150152
)
151153
},
152154
}
155+
156+
export const WithPanel: Story = {
157+
beforeEach: () => {
158+
process.env.__NEXT_DEVTOOL_NEW_PANEL_UI = 'true'
159+
160+
// clean up callback function
161+
return () => {
162+
delete process.env.__NEXT_DEVTOOL_NEW_PANEL_UI
163+
}
164+
},
165+
render: function DevOverlayStory() {
166+
const [state, dispatch] = useOverlayReducer()
167+
return (
168+
<>
169+
<img
170+
src={imgApp}
171+
style={{
172+
width: '100%',
173+
height: '100vh',
174+
objectFit: 'contain',
175+
}}
176+
/>
177+
<DevOverlay
178+
state={state}
179+
dispatch={dispatch}
180+
getSquashedHydrationErrorDetails={
181+
// Testing like App Router where we no longer quash hydration errors
182+
getNoSquashedHydrationErrorDetails
183+
}
184+
/>
185+
</>
186+
)
187+
},
188+
}

packages/next/src/next-devtools/dev-overlay/dev-overlay.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export function DevOverlay({
4848
isBuildError={isBuildError}
4949
/>
5050

51-
{state.isDevToolsPanelOpen && <DevToolsPanel />}
51+
{state.isDevToolsPanelOpen && (
52+
<DevToolsPanel state={state} dispatch={dispatch} />
53+
)}
5254
</>
5355
) : (
5456
<DevToolsIndicator

0 commit comments

Comments
 (0)