Unverified Commit 9823f470 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[devtools] panel ui settings tab (#80538)

https://github.com/user-attachments/assets/04c936c2-770f-4032-b962-2aad3259404a

Closes NEXT-4530
parent d89afa76
import type { DevToolsPanelTabType } from '../devtools-panel' import type { DevToolsPanelTabType } from '../devtools-panel'
import type { Corners } from '../../../shared'
import { SettingsTab } from './settings-tab'
export function DevToolsPanelTab({ export function DevToolsPanelTab({
activeTab, activeTab,
devToolsPosition,
scale,
handlePositionChange,
handleScaleChange,
}: { }: {
activeTab: DevToolsPanelTabType activeTab: DevToolsPanelTabType
devToolsPosition: Corners
scale: number
handlePositionChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
handleScaleChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
}) { }) {
switch (activeTab) { switch (activeTab) {
case 'settings': case 'settings':
return <div>Settings</div> return (
<SettingsTab
devToolsPosition={devToolsPosition}
scale={scale}
handlePositionChange={handlePositionChange}
handleScaleChange={handleScaleChange}
/>
)
case 'route': case 'route':
return <div>Route</div> return <div>Route</div>
case 'issues': case 'issues':
......
import type { Corners } from '../../../shared'
import { useTheme } from '../hooks/use-theme'
import { Select } from '../../select/select'
import { STORAGE_KEY_THEME, NEXT_DEV_TOOLS_SCALE } from '../../../shared'
import { css } from '../../../utils/css'
import LightIcon from '../../../icons/light-icon'
import DarkIcon from '../../../icons/dark-icon'
import SystemIcon from '../../../icons/system-icon'
import EyeIcon from '../../../icons/eye-icon'
function ThemeIcon({ theme }: { theme: 'dark' | 'light' | 'system' }) {
switch (theme) {
case 'system':
return <SystemIcon />
case 'dark':
return <DarkIcon />
case 'light':
return <LightIcon />
default:
return null
}
}
export function SettingsTab({
devToolsPosition,
scale,
handlePositionChange,
handleScaleChange,
}: {
devToolsPosition: Corners
scale: number
handlePositionChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
handleScaleChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
}) {
const [theme, setTheme] = useTheme()
const handleThemeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const portal = document.querySelector('nextjs-portal')
if (!portal) return
setTheme(e.target.value)
if (e.target.value === 'system') {
portal.classList.remove('dark')
portal.classList.remove('light')
localStorage.removeItem(STORAGE_KEY_THEME)
return
}
if (e.target.value === 'dark') {
portal.classList.add('dark')
portal.classList.remove('light')
localStorage.setItem(STORAGE_KEY_THEME, 'dark')
} else {
portal.classList.remove('dark')
portal.classList.add('light')
localStorage.setItem(STORAGE_KEY_THEME, 'light')
}
}
function handleRestartDevServer(invalidatePersistentCache: boolean) {
let endpoint = '/__nextjs_restart_dev'
if (invalidatePersistentCache) {
endpoint = '/__nextjs_restart_dev?invalidatePersistentCache'
}
fetch(endpoint, {
method: 'POST',
}).then(() => {
// TODO: poll server status and reload when the server is back up.
// https://github.com/vercel/next.js/pull/80005
})
}
function hide() {
fetch('/__nextjs_disable_dev_indicator', {
method: 'POST',
})
}
return (
<div data-nextjs-devtools-panel-settings>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label htmlFor="theme">Theme</label>
<p data-nextjs-devtools-panel-settings-section-description>
Select your theme preference.
</p>
</div>
<Select
id="theme"
name="theme"
prefix={<ThemeIcon theme={theme as 'dark' | 'light' | 'system'} />}
value={theme}
onChange={handleThemeChange}
>
<option value="system">System</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</Select>
</div>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label htmlFor="position">Position</label>
<p data-nextjs-devtools-panel-settings-section-description>
Adjust the placement of your dev tools.
</p>
</div>
<Select
id="position"
name="position"
value={devToolsPosition}
onChange={handlePositionChange}
>
<option value="bottom-left">Bottom Left</option>
<option value="bottom-right">Bottom Right</option>
<option value="top-left">Top Left</option>
<option value="top-right">Top Right</option>
</Select>
</div>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label htmlFor="size">Size</label>
<p data-nextjs-devtools-panel-settings-section-description>
Adjust the size of your dev tools.
</p>
</div>
<Select
id="size"
name="size"
value={scale}
onChange={handleScaleChange}
>
{Object.entries(NEXT_DEV_TOOLS_SCALE).map(([key, value]) => {
return (
<option value={value} key={key}>
{key}
</option>
)
})}
</Select>
</div>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label id="hide-dev-tools">Hide Dev Tools for this session</label>
<p data-nextjs-devtools-panel-settings-section-description>
Hide Dev Tools until you restart your dev server, or 1 day.
</p>
</div>
<div>
<button
aria-describedby="hide-dev-tools"
name="hide-dev-tools"
data-hide-dev-tools
data-nextjs-devtools-panel-settings-section-action-button
onClick={hide}
>
<EyeIcon />
<span>Hide</span>
</button>
</div>
</div>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label>Disable Dev Tools for this project</label>
<p data-nextjs-devtools-panel-settings-section-description>
To disable this UI completely, set{' '}
<code className="dev-tools-info-code">devIndicators: false</code> in
your <code className="dev-tools-info-code">next.config</code> file.
</p>
</div>
</div>
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label id="restart-dev-server">Restart Dev Server</label>
<p data-nextjs-devtools-panel-settings-section-description>
Restarts the development server without needing to leave the
browser.
</p>
</div>
<div>
<button
aria-describedby="restart-dev-server"
title="Restarts the development server without needing to leave the browser."
name="restart-dev-server"
data-restart-dev-server
data-nextjs-devtools-panel-settings-section-action-button
onClick={() =>
handleRestartDevServer(/*invalidatePersistentCache*/ false)
}
>
<span>Restart</span>
</button>
</div>
</div>
{process.env.__NEXT_TURBOPACK_PERSISTENT_CACHE ? (
<div data-nextjs-devtools-panel-settings-section>
<div data-nextjs-devtools-panel-settings-section-header>
<label id="reset-bundler-cache">Reset Bundler Cache</label>
<p data-nextjs-devtools-panel-settings-section-description>
Clears the bundler cache and restarts the dev server. Helpful if
you are seeing stale errors or changes are not appearing.
</p>
</div>
<div>
<button
aria-describedby="reset-bundler-cache"
title="Clears the bundler cache and restarts the dev server. Helpful if you are seeing stale errors or changes are not appearing."
name="reset-bundler-cache"
data-reset-bundler-cache
data-nextjs-devtools-panel-settings-section-action-button
onClick={() =>
handleRestartDevServer(/*invalidatePersistentCache*/ true)
}
>
<span>Reset Cache</span>
</button>
</div>
</div>
) : null}
</div>
)
}
export const DEVTOOLS_PANEL_TAB_SETTINGS_STYLES = css`
[data-nextjs-devtools-panel-settings] {
padding: 16px;
}
[data-nextjs-devtools-panel-settings-section]:first-child {
padding-top: 0;
}
[data-nextjs-devtools-panel-settings-section] {
padding: 12px 0;
border-bottom: 1px solid var(--color-gray-400);
display: flex;
justify-content: space-between;
align-items: center;
gap: 24px;
}
[data-nextjs-devtools-panel-settings-section]:last-child {
padding-bottom: 0;
border-bottom: none;
}
[data-nextjs-devtools-panel-settings-section-header] {
margin-bottom: 0;
flex: 1;
}
[data-nextjs-devtools-panel-settings-section-header] label {
font-size: var(--size-14);
font-weight: 500;
color: var(--color-gray-1000);
margin: 0;
}
[data-nextjs-devtools-panel-settings-section-description] {
color: var(--color-gray-900);
font-size: var(--size-14);
margin: 0;
}
[data-nextjs-select],
[data-nextjs-devtools-panel-settings-section-action-button] {
display: flex;
align-items: center;
gap: 8px;
background: var(--color-background-100);
border: 1px solid var(--color-gray-400);
border-radius: var(--rounded-lg);
font-weight: 400;
font-size: var(--size-14);
color: var(--color-gray-1000);
padding: 6px 8px;
&:hover {
background: var(--color-gray-100);
}
}
[data-nextjs-select] {
&:focus-within {
outline: var(--focus-ring);
}
select {
all: unset;
}
option {
color: var(--color-gray-1000);
background: var(--color-background-100);
}
}
:global(.icon) {
width: 18px;
height: 18px;
color: #666;
}
`
import type { OverlayDispatch, OverlayState } from '../../shared' import type { OverlayDispatch, OverlayState, Corners } from '../../shared'
import { useState } from 'react' import { useState } from 'react'
...@@ -9,6 +9,8 @@ import { Overlay } from '../overlay/overlay' ...@@ -9,6 +9,8 @@ import { Overlay } from '../overlay/overlay'
import { import {
ACTION_DEVTOOLS_PANEL_CLOSE, ACTION_DEVTOOLS_PANEL_CLOSE,
ACTION_DEVTOOLS_POSITION, ACTION_DEVTOOLS_POSITION,
ACTION_DEVTOOLS_SCALE,
STORAGE_KEY_SCALE,
STORAGE_KEY_POSITION, STORAGE_KEY_POSITION,
} from '../../shared' } from '../../shared'
import { css } from '../../utils/css' import { css } from '../../utils/css'
...@@ -34,10 +36,26 @@ export function DevToolsPanel({ ...@@ -34,10 +36,26 @@ export function DevToolsPanel({
) )
const [vertical, horizontal] = state.devToolsPosition.split('-', 2) const [vertical, horizontal] = state.devToolsPosition.split('-', 2)
const onClose = () => { const onCloseDevToolsPanel = () => {
dispatch({ type: ACTION_DEVTOOLS_PANEL_CLOSE }) dispatch({ type: ACTION_DEVTOOLS_PANEL_CLOSE })
} }
const handlePositionChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
dispatch({
type: ACTION_DEVTOOLS_POSITION,
devToolsPosition: e.target.value as Corners,
})
localStorage.setItem(STORAGE_KEY_POSITION, e.target.value)
}
const handleScaleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
dispatch({
type: ACTION_DEVTOOLS_SCALE,
scale: Number(e.target.value),
})
localStorage.setItem(STORAGE_KEY_SCALE, e.target.value)
}
return ( return (
<Overlay <Overlay
data-nextjs-devtools-panel-overlay data-nextjs-devtools-panel-overlay
...@@ -48,10 +66,10 @@ export function DevToolsPanel({ ...@@ -48,10 +66,10 @@ export function DevToolsPanel({
[horizontal === 'left' ? 'right' : 'left']: 'auto', [horizontal === 'left' ? 'right' : 'left']: 'auto',
}} }}
> >
{/* TODO: Investigate why onClose on Dialog doesn't close when clicked outside. */} {/* TODO: Investigate why onCloseDevToolsPanel on Dialog doesn't close when clicked outside. */}
<OverlayBackdrop <OverlayBackdrop
data-nextjs-devtools-panel-overlay-backdrop data-nextjs-devtools-panel-overlay-backdrop
onClick={onClose} onClick={onCloseDevToolsPanel}
/> />
<Draggable <Draggable
padding={INDICATOR_PADDING} padding={INDICATOR_PADDING}
...@@ -70,10 +88,10 @@ export function DevToolsPanel({ ...@@ -70,10 +88,10 @@ export function DevToolsPanel({
data-nextjs-devtools-panel-dialog data-nextjs-devtools-panel-dialog
aria-labelledby="nextjs__container_dev_tools_panel_label" aria-labelledby="nextjs__container_dev_tools_panel_label"
aria-describedby="nextjs__container_dev_tools_panel_desc" aria-describedby="nextjs__container_dev_tools_panel_desc"
onClose={onClose} onClose={onCloseDevToolsPanel}
> >
<DialogContent> <DialogContent>
<DialogHeader> <DialogHeader data-nextjs-devtools-panel-dialog-header>
<div data-nextjs-devtools-panel-header> <div data-nextjs-devtools-panel-header>
<div data-nextjs-devtools-panel-header-tab-group> <div data-nextjs-devtools-panel-header-tab-group>
<button <button
...@@ -111,7 +129,7 @@ export function DevToolsPanel({ ...@@ -111,7 +129,7 @@ export function DevToolsPanel({
</button> </button>
<button <button
data-nextjs-devtools-panel-header-action-button data-nextjs-devtools-panel-header-action-button
onClick={onClose} onClick={onCloseDevToolsPanel}
> >
<Cross width={16} height={16} /> <Cross width={16} height={16} />
</button> </button>
...@@ -119,7 +137,13 @@ export function DevToolsPanel({ ...@@ -119,7 +137,13 @@ export function DevToolsPanel({
</div> </div>
</DialogHeader> </DialogHeader>
<DialogBody> <DialogBody>
<DevToolsPanelTab activeTab={activeTab} /> <DevToolsPanelTab
activeTab={activeTab}
devToolsPosition={state.devToolsPosition}
scale={state.scale}
handlePositionChange={handlePositionChange}
handleScaleChange={handleScaleChange}
/>
</DialogBody> </DialogBody>
</DialogContent> </DialogContent>
<DevToolsPanelFooter versionInfo={state.versionInfo} /> <DevToolsPanelFooter versionInfo={state.versionInfo} />
...@@ -158,7 +182,6 @@ export const DEVTOOLS_PANEL_STYLES = css` ...@@ -158,7 +182,6 @@ export const DEVTOOLS_PANEL_STYLES = css`
/* TODO: Remove once the content is filled. */ /* TODO: Remove once the content is filled. */
min-width: 800px; min-width: 800px;
min-height: 500px; min-height: 500px;
/* This is handled from dialog/styles.ts */ /* This is handled from dialog/styles.ts */
max-width: var(--next-dialog-max-width); max-width: var(--next-dialog-max-width);
} }
......
import { useState } from 'react'
import { STORAGE_KEY_THEME } from '../../../shared'
function getInitialTheme() {
if (typeof localStorage === 'undefined') {
return 'system'
}
const theme = localStorage.getItem(STORAGE_KEY_THEME)
return theme === 'dark' || theme === 'light' ? theme : 'system'
}
export function useTheme() {
return useState(getInitialTheme())
}
import { ChevronDownIcon } from '../../icons/chevron-down'
export function Select({
children,
prefix,
...props
}: {
prefix?: React.ReactNode
} & Omit<React.HTMLProps<HTMLSelectElement>, 'prefix'>) {
return (
<div data-nextjs-select>
{prefix}
<select {...props}>{children}</select>
<ChevronDownIcon width={16} height={16} />
</div>
)
}
...@@ -13,7 +13,9 @@ import { ...@@ -13,7 +13,9 @@ import {
ACTION_ERROR_OVERLAY_CLOSE, ACTION_ERROR_OVERLAY_CLOSE,
ACTION_ERROR_OVERLAY_OPEN, ACTION_ERROR_OVERLAY_OPEN,
ACTION_ERROR_OVERLAY_TOGGLE, ACTION_ERROR_OVERLAY_TOGGLE,
ACTION_DEVTOOLS_SCALE,
NEXT_DEV_TOOLS_SCALE, NEXT_DEV_TOOLS_SCALE,
INITIAL_OVERLAY_STATE,
} from './shared' } from './shared'
const meta: Meta<typeof DevOverlay> = { const meta: Meta<typeof DevOverlay> = {
...@@ -39,10 +41,8 @@ export default meta ...@@ -39,10 +41,8 @@ export default meta
type Story = StoryObj<typeof DevOverlay> type Story = StoryObj<typeof DevOverlay>
const initialState: OverlayState = { const initialState: OverlayState = {
nextId: 0, ...INITIAL_OVERLAY_STATE,
routerType: 'app', routerType: 'app',
buildError: null,
disableDevIndicator: false,
showIndicator: true, showIndicator: true,
errors: [ errors: [
{ {
...@@ -87,12 +87,6 @@ const initialState: OverlayState = { ...@@ -87,12 +87,6 @@ const initialState: OverlayState = {
type: 'runtime', type: 'runtime',
}, },
], ],
refreshState: { type: 'idle' },
notFound: false,
buildingIndicator: false,
renderingIndicator: false,
staticIndicator: false,
debugInfo: { devtoolsFrontendUrl: undefined },
versionInfo: { versionInfo: {
installed: '15.2.0', installed: '15.2.0',
staleness: 'fresh', staleness: 'fresh',
...@@ -125,6 +119,9 @@ function useOverlayReducer() { ...@@ -125,6 +119,9 @@ function useOverlayReducer() {
case ACTION_DEVTOOLS_POSITION: { case ACTION_DEVTOOLS_POSITION: {
return { ...state, devToolsPosition: action.devToolsPosition } return { ...state, devToolsPosition: action.devToolsPosition }
} }
case ACTION_DEVTOOLS_SCALE: {
return { ...state, scale: action.scale }
}
default: { default: {
return state return state
} }
......
...@@ -27,7 +27,9 @@ export function DevOverlay({ ...@@ -27,7 +27,9 @@ export function DevOverlay({
return ( return (
<ShadowPortal> <ShadowPortal>
<CssReset /> <CssReset />
<Base scale={scale} /> <Base
scale={process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ? state.scale : scale}
/>
<Colors /> <Colors />
<ComponentStyles /> <ComponentStyles />
<DarkTheme /> <DarkTheme />
......
export function ChevronDownIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden {...props}>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M14.0607 5.49999L13.5303 6.03032L8.7071 10.8535C8.31658 11.2441 7.68341 11.2441 7.29289 10.8535L2.46966 6.03032L1.93933 5.49999L2.99999 4.43933L3.53032 4.96966L7.99999 9.43933L12.4697 4.96966L13 4.43933L14.0607 5.49999Z"
fill="currentColor"
/>
</svg>
)
}
...@@ -27,6 +27,7 @@ import { RESTART_SERVER_BUTTON_STYLES } from '../components/errors/error-overlay ...@@ -27,6 +27,7 @@ import { RESTART_SERVER_BUTTON_STYLES } from '../components/errors/error-overlay
import { DEVTOOLS_PANEL_STYLES } from '../components/devtools-panel/devtools-panel' import { DEVTOOLS_PANEL_STYLES } from '../components/devtools-panel/devtools-panel'
import { DEVTOOLS_PANEL_FOOTER_STYLES } from '../components/devtools-panel/devtools-panel-footer' import { DEVTOOLS_PANEL_FOOTER_STYLES } from '../components/devtools-panel/devtools-panel-footer'
import { DEVTOOLS_PANEL_VERSION_INFO_STYLES } from '../components/devtools-panel/devtools-panel-version-info' import { DEVTOOLS_PANEL_VERSION_INFO_STYLES } from '../components/devtools-panel/devtools-panel-version-info'
import { DEVTOOLS_PANEL_TAB_SETTINGS_STYLES } from '../components/devtools-panel/devtools-panel-tab/settings-tab'
export function ComponentStyles() { export function ComponentStyles() {
return ( return (
...@@ -60,6 +61,7 @@ export function ComponentStyles() { ...@@ -60,6 +61,7 @@ export function ComponentStyles() {
${DEVTOOLS_PANEL_STYLES} ${DEVTOOLS_PANEL_STYLES}
${DEVTOOLS_PANEL_FOOTER_STYLES} ${DEVTOOLS_PANEL_FOOTER_STYLES}
${DEVTOOLS_PANEL_VERSION_INFO_STYLES} ${DEVTOOLS_PANEL_VERSION_INFO_STYLES}
${DEVTOOLS_PANEL_TAB_SETTINGS_STYLES}
`} `}
</style> </style>
) )
......
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