Skip to content

Commit 7cd98ce

Browse files
committed
[devtools] add dialog behavior to panel ui
1 parent acf0ad0 commit 7cd98ce

File tree

3 files changed

+90
-4
lines changed

3 files changed

+90
-4
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 './dev-tools-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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
1-
export function DevToolsPanel() {
2-
// TODO: Remove style; It is to indicate faster in the browser.
3-
return <div className="text-black">DevToolsPanel</div>
1+
import type { OverlayDispatch, OverlayState } from '../../shared'
2+
3+
import { Suspense, useRef } from 'react'
4+
import { Dialog, DialogContent, DialogHeader, DialogBody } from '../dialog'
5+
import { Overlay } from '../overlay/overlay'
6+
import { useFocusTrap } from '../errors/dev-tools-indicator/utils'
7+
import { useDelayedRender } from '../../hooks/use-delayed-render'
8+
import { ACTION_DEV_TOOLS_PANEL_TOGGLE } from '../../shared'
9+
10+
export function DevToolsPanel({
11+
state,
12+
dispatch,
13+
}: {
14+
state: OverlayState
15+
dispatch: OverlayDispatch
16+
}) {
17+
const dialogRef = useRef<HTMLDivElement>(null)
18+
19+
// This hook lets us do an exit animation before unmounting the component
20+
const { mounted, rendered } = useDelayedRender(state.isDevToolsPanelOpen)
21+
22+
useFocusTrap(dialogRef, null, rendered)
23+
24+
if (!mounted) {
25+
// Workaround React quirk that triggers "Switch to client-side rendering" if
26+
// we return no Suspense boundary here.
27+
return <Suspense />
28+
}
29+
30+
const onClose = () => {
31+
dispatch({ type: ACTION_DEV_TOOLS_PANEL_TOGGLE })
32+
}
33+
34+
return (
35+
<Overlay className="p-0 top-[10vh]">
36+
<div
37+
className="dev-tools-panel-dialog-container antialiased flex flex-col bg-[var(--color-background-100)] bg-clip-padding border-solid border-[var(--color-gray-400)] rounded-b-[var(--next-dialog-radius)] shadow-[var(--shadow-menu)] relative overflow-hidden min-w-[800px] min-h-[500px]"
38+
ref={dialogRef}
39+
>
40+
<Dialog
41+
aria-labelledby="nextjs__container_dev_tools_panel_label"
42+
aria-describedby="nextjs__container_dev_tools_panel_desc"
43+
className="dev-tools-panel-dialog-scroll overflow-y-auto h-full"
44+
onClose={onClose}
45+
>
46+
<DialogContent>
47+
<DialogHeader></DialogHeader>
48+
<DialogBody>
49+
<div>DevToolsPanel</div>
50+
</DialogBody>
51+
</DialogContent>
52+
</Dialog>
53+
</div>
54+
</Overlay>
55+
)
456
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export function DevOverlay({
5858
))}
5959

6060
{process.env.__NEXT_DEVTOOL_NEW_PANEL_UI &&
61-
state.isDevToolsPanelOpen && <DevToolsPanel />}
61+
state.isDevToolsPanelOpen && (
62+
<DevToolsPanel state={state} dispatch={dispatch} />
63+
)}
6264

6365
<ErrorOverlay
6466
state={state}

0 commit comments

Comments
 (0)