-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[devtools] add dialog behavior to panel ui #80355
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import type { OverlayState } from '../../shared' | ||
|
||
import { DevToolsPanel } from './devtools-panel' | ||
import { INITIAL_OVERLAY_STATE } from '../../shared' | ||
import { withShadowPortal } from '../../storybook/with-shadow-portal' | ||
|
||
const meta: Meta<typeof DevToolsPanel> = { | ||
component: DevToolsPanel, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
argTypes: {}, | ||
decorators: [withShadowPortal], | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof DevToolsPanel> | ||
|
||
const state: OverlayState = { | ||
...INITIAL_OVERLAY_STATE, | ||
routerType: 'app', | ||
isErrorOverlayOpen: false, | ||
isDevToolsPanelOpen: true, | ||
} | ||
|
||
export const Default: Story = { | ||
args: { | ||
state, | ||
dispatch: () => {}, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
import type { OverlayDispatch, OverlayState } from '../../shared' | ||
|
||
import { Dialog, DialogContent, DialogHeader, DialogBody } from '../dialog' | ||
import { Overlay } from '../overlay/overlay' | ||
import { ACTION_DEVTOOLS_PANEL_TOGGLE } from '../../shared' | ||
import { css } from '../../utils/css' | ||
|
||
export function DevToolsPanel() { | ||
// TODO: Remove style; It is to indicate faster in the browser. | ||
return <div data-nextjs-devtools-panel>DevToolsPanel</div> | ||
export function DevToolsPanel({ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
state, | ||
dispatch, | ||
}: { | ||
state: OverlayState | ||
dispatch: OverlayDispatch | ||
}) { | ||
const onClose = () => { | ||
dispatch({ type: ACTION_DEVTOOLS_PANEL_TOGGLE }) | ||
} | ||
|
||
return ( | ||
<Overlay data-nextjs-devtools-panel-overlay> | ||
<Dialog | ||
data-nextjs-devtools-panel-dialog | ||
aria-labelledby="nextjs__container_dev_tools_panel_label" | ||
aria-describedby="nextjs__container_dev_tools_panel_desc" | ||
onClose={onClose} | ||
> | ||
<DialogContent> | ||
<DialogHeader></DialogHeader> | ||
<DialogBody></DialogBody> | ||
</DialogContent> | ||
</Dialog> | ||
</Overlay> | ||
) | ||
} | ||
|
||
export const DEVTOOLS_PANEL_STYLES = css` | ||
[data-nextjs-devtools-panel] { | ||
color: black; | ||
[data-nextjs-devtools-panel-overlay] { | ||
padding: initial; | ||
top: 10vh; | ||
} | ||
|
||
[data-nextjs-devtools-panel-dialog] { | ||
-webkit-font-smoothing: antialiased; | ||
display: flex; | ||
flex-direction: column; | ||
background: var(--color-background-100); | ||
background-clip: padding-box; | ||
border: 1px solid var(--color-gray-400); | ||
border-radius: var(--rounded-xl); | ||
box-shadow: var(--shadow-lg); | ||
position: relative; | ||
overflow-y: auto; | ||
|
||
/* TODO: Remove once the content is filled. */ | ||
min-width: 800px; | ||
min-height: 500px; | ||
|
||
/* This is handled from dialog/styles.ts */ | ||
max-width: var(--next-dialog-max-width); | ||
} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import imgApp from './app.png' | |
import { useReducer } from 'react' | ||
import { DevOverlay } from './dev-overlay' | ||
import { | ||
ACTION_DEVTOOLS_PANEL_TOGGLE, | ||
ACTION_ERROR_OVERLAY_CLOSE, | ||
ACTION_ERROR_OVERLAY_OPEN, | ||
ACTION_ERROR_OVERLAY_TOGGLE, | ||
|
@@ -93,8 +94,7 @@ const initialState: OverlayState = { | |
installed: '15.2.0', | ||
staleness: 'fresh', | ||
}, | ||
isErrorOverlayOpen: true, | ||
// TODO: This will be handled on the next stack——with proper story. | ||
isErrorOverlayOpen: false, | ||
isDevToolsPanelOpen: false, | ||
} | ||
|
||
|
@@ -111,11 +111,13 @@ function useOverlayReducer() { | |
case ACTION_ERROR_OVERLAY_TOGGLE: { | ||
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen } | ||
} | ||
case ACTION_DEVTOOLS_PANEL_TOGGLE: { | ||
return { ...state, isDevToolsPanelOpen: !state.isDevToolsPanelOpen } | ||
} | ||
default: { | ||
return state | ||
} | ||
} | ||
return state | ||
}, | ||
initialState | ||
) | ||
|
@@ -150,3 +152,37 @@ export const Default: Story = { | |
) | ||
}, | ||
} | ||
|
||
export const WithPanel: Story = { | ||
beforeEach: () => { | ||
process.env.__NEXT_DEVTOOL_NEW_PANEL_UI = 'true' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that work? I thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah it does seem to work, what is it replaced with at build time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably somewhere else we declare a global |
||
|
||
// clean up callback function | ||
return () => { | ||
delete process.env.__NEXT_DEVTOOL_NEW_PANEL_UI | ||
} | ||
}, | ||
render: function DevOverlayStory() { | ||
const [state, dispatch] = useOverlayReducer() | ||
return ( | ||
<> | ||
<img | ||
src={imgApp} | ||
style={{ | ||
width: '100%', | ||
height: '100vh', | ||
objectFit: 'contain', | ||
}} | ||
/> | ||
<DevOverlay | ||
state={state} | ||
dispatch={dispatch} | ||
getSquashedHydrationErrorDetails={ | ||
// Testing like App Router where we no longer quash hydration errors | ||
getNoSquashedHydrationErrorDetails | ||
} | ||
/> | ||
</> | ||
) | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we only pass the onClose prop to DevtoolPanel? This can be more headless instead of bound with dispatch. We can group the dispatch actions on the top and pass them down as separate props instead of passing the dispatch itself which might lead to abuse in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think passing the dispatcher to DevToolsPanel is reasonable because it is feature-flagged above.
But for layers under (e.g. Settings), agreed to pass the scoped action, not the whole dispatch.