Unverified Commit d89afa76 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[devtools] port devtools scale to dispatcher (#80537)

### Why?

Since the DevTools Panel and the DevTools Indicator are decoupled, use the dispatcher to communicate the DevTools scale from the DevTools Panel (Settings tab).
parent 3e8c13ac
import type { CSSProperties } from 'react' import type { CSSProperties } from 'react'
import type { OverlayState, OverlayDispatch } from '../../shared' import type { OverlayState, OverlayDispatch } from '../../shared'
import type { DevToolsScale } from '../errors/dev-tools-indicator/dev-tools-info/preferences'
import { useState } from 'react' import { useState } from 'react'
import { NextLogo } from './next-logo' import { NextLogo } from './next-logo'
...@@ -26,13 +25,11 @@ export function DevToolsIndicator({ ...@@ -26,13 +25,11 @@ export function DevToolsIndicator({
dispatch, dispatch,
errorCount, errorCount,
isBuildError, isBuildError,
scale,
}: { }: {
state: OverlayState state: OverlayState
dispatch: OverlayDispatch dispatch: OverlayDispatch
errorCount: number errorCount: number
isBuildError: boolean isBuildError: boolean
scale: DevToolsScale
}) { }) {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
...@@ -89,7 +86,7 @@ export function DevToolsIndicator({ ...@@ -89,7 +86,7 @@ export function DevToolsIndicator({
isDevBuilding={state.buildingIndicator} isDevBuilding={state.buildingIndicator}
isDevRendering={state.renderingIndicator} isDevRendering={state.renderingIndicator}
isBuildError={isBuildError} isBuildError={isBuildError}
scale={scale} scale={state.scale}
/> />
</Draggable> </Draggable>
</Toast> </Toast>
......
...@@ -62,6 +62,7 @@ const state: OverlayState = { ...@@ -62,6 +62,7 @@ const state: OverlayState = {
// TODO: This will be handled on the next stack——with proper story. // TODO: This will be handled on the next stack——with proper story.
isDevToolsPanelOpen: false, isDevToolsPanelOpen: false,
devToolsPosition: 'bottom-left', devToolsPosition: 'bottom-left',
scale: 1,
} }
export const StaticRoute: Story = { export const StaticRoute: Story = {
......
import { useState } from 'react' import { useState } from 'react'
import { import {
NEXT_DEV_TOOLS_SCALE,
STORAGE_KEY_POSITION, STORAGE_KEY_POSITION,
STORAGE_KEY_SCALE, STORAGE_KEY_SCALE,
STORAGE_KEY_THEME, STORAGE_KEY_THEME,
...@@ -26,14 +27,6 @@ export function getInitialPosition() { ...@@ -26,14 +27,6 @@ export function getInitialPosition() {
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
const BASE_SIZE = 16
export const NEXT_DEV_TOOLS_SCALE = {
Small: BASE_SIZE / 14,
Medium: BASE_SIZE / 16,
Large: BASE_SIZE / 18,
} as const
export type DevToolsScale = export type DevToolsScale =
(typeof NEXT_DEV_TOOLS_SCALE)[keyof typeof NEXT_DEV_TOOLS_SCALE] (typeof NEXT_DEV_TOOLS_SCALE)[keyof typeof NEXT_DEV_TOOLS_SCALE]
......
import { useState, type HTMLProps } from 'react' import { useState, type HTMLProps } from 'react'
import { css } from '../../../../utils/css' import { css } from '../../../../utils/css'
import EyeIcon from '../../../../icons/eye-icon' import EyeIcon from '../../../../icons/eye-icon'
import { STORAGE_KEY_POSITION, STORAGE_KEY_THEME } from '../../../../shared' import {
NEXT_DEV_TOOLS_SCALE,
STORAGE_KEY_POSITION,
STORAGE_KEY_THEME,
} from '../../../../shared'
import LightIcon from '../../../../icons/light-icon' import LightIcon from '../../../../icons/light-icon'
import DarkIcon from '../../../../icons/dark-icon' import DarkIcon from '../../../../icons/dark-icon'
import SystemIcon from '../../../../icons/system-icon' import SystemIcon from '../../../../icons/system-icon'
...@@ -9,7 +13,6 @@ import type { DevToolsInfoPropsCore } from './dev-tools-info' ...@@ -9,7 +13,6 @@ import type { DevToolsInfoPropsCore } from './dev-tools-info'
import { DevToolsInfo } from './dev-tools-info' import { DevToolsInfo } from './dev-tools-info'
import { import {
getInitialTheme, getInitialTheme,
NEXT_DEV_TOOLS_SCALE,
type DevToolsIndicatorPosition, type DevToolsIndicatorPosition,
type DevToolsScale, type DevToolsScale,
} from './preferences' } from './preferences'
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ 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,
NEXT_DEV_TOOLS_SCALE,
} from './shared' } from './shared'
const meta: Meta<typeof DevOverlay> = { const meta: Meta<typeof DevOverlay> = {
...@@ -99,6 +100,7 @@ const initialState: OverlayState = { ...@@ -99,6 +100,7 @@ const initialState: OverlayState = {
isErrorOverlayOpen: false, isErrorOverlayOpen: false,
isDevToolsPanelOpen: false, isDevToolsPanelOpen: false,
devToolsPosition: 'bottom-left', devToolsPosition: 'bottom-left',
scale: NEXT_DEV_TOOLS_SCALE.Medium,
} }
function useOverlayReducer() { function useOverlayReducer() {
......
...@@ -41,7 +41,6 @@ export function DevOverlay({ ...@@ -41,7 +41,6 @@ export function DevOverlay({
(process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ? ( (process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ? (
<> <>
<DevToolsIndicatorNew <DevToolsIndicatorNew
scale={scale}
state={state} state={state}
dispatch={dispatch} dispatch={dispatch}
errorCount={totalErrorCount} errorCount={totalErrorCount}
......
...@@ -10,6 +10,14 @@ import { isConsoleError } from '../shared/console-error' ...@@ -10,6 +10,14 @@ import { isConsoleError } from '../shared/console-error'
export type Corners = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' export type Corners = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
const BASE_SIZE = 16
export const NEXT_DEV_TOOLS_SCALE = {
Small: BASE_SIZE / 14,
Medium: BASE_SIZE / 16,
Large: BASE_SIZE / 18,
}
type FastRefreshState = type FastRefreshState =
/** No refresh in progress. */ /** No refresh in progress. */
| { type: 'idle' } | { type: 'idle' }
...@@ -33,6 +41,7 @@ export interface OverlayState { ...@@ -33,6 +41,7 @@ export interface OverlayState {
isErrorOverlayOpen: boolean isErrorOverlayOpen: boolean
isDevToolsPanelOpen: boolean isDevToolsPanelOpen: boolean
devToolsPosition: Corners devToolsPosition: Corners
scale: number
} }
export type OverlayDispatch = React.Dispatch<DispatcherEvent> export type OverlayDispatch = React.Dispatch<DispatcherEvent>
...@@ -61,6 +70,7 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close' ...@@ -61,6 +70,7 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
export const ACTION_DEVTOOLS_PANEL_TOGGLE = 'devtools-panel-toggle' export const ACTION_DEVTOOLS_PANEL_TOGGLE = 'devtools-panel-toggle'
export const ACTION_DEVTOOLS_POSITION = 'devtools-position' export const ACTION_DEVTOOLS_POSITION = 'devtools-position'
export const ACTION_DEVTOOLS_SCALE = 'devtools-scale'
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme' export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position' export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
...@@ -148,6 +158,11 @@ export interface DevToolsIndicatorPositionAction { ...@@ -148,6 +158,11 @@ export interface DevToolsIndicatorPositionAction {
devToolsPosition: Corners devToolsPosition: Corners
} }
export interface DevToolsScaleAction {
type: typeof ACTION_DEVTOOLS_SCALE
scale: number
}
export type DispatcherEvent = export type DispatcherEvent =
| BuildOkAction | BuildOkAction
| BuildErrorAction | BuildErrorAction
...@@ -170,6 +185,7 @@ export type DispatcherEvent = ...@@ -170,6 +185,7 @@ export type DispatcherEvent =
| DevToolsPanelCloseAction | DevToolsPanelCloseAction
| DevToolsPanelToggleAction | DevToolsPanelToggleAction
| DevToolsIndicatorPositionAction | DevToolsIndicatorPositionAction
| DevToolsScaleAction
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
// 1st group: v8 // 1st group: v8
...@@ -210,6 +226,7 @@ export const INITIAL_OVERLAY_STATE: Omit< ...@@ -210,6 +226,7 @@ export const INITIAL_OVERLAY_STATE: Omit<
debugInfo: { devtoolsFrontendUrl: undefined }, debugInfo: { devtoolsFrontendUrl: undefined },
isDevToolsPanelOpen: false, isDevToolsPanelOpen: false,
devToolsPosition: 'bottom-left', devToolsPosition: 'bottom-left',
scale: NEXT_DEV_TOOLS_SCALE.Medium,
} }
function getInitialState( function getInitialState(
...@@ -384,6 +401,9 @@ export function useErrorOverlayReducer( ...@@ -384,6 +401,9 @@ export function useErrorOverlayReducer(
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
} }
......
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