Skip to content

Commit ad96392

Browse files
committed
[devtools] port devtools scale to dispatcher
1 parent 582375f commit ad96392

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CSSProperties } from 'react'
22
import type { OverlayState, OverlayDispatch } from '../../shared'
3-
import type { DevToolsScale } from '../errors/dev-tools-indicator/dev-tools-info/preferences'
43

54
import { useState } from 'react'
65
import { NextLogo } from './next-logo'
@@ -26,13 +25,11 @@ export function DevToolsIndicator({
2625
dispatch,
2726
errorCount,
2827
isBuildError,
29-
scale,
3028
}: {
3129
state: OverlayState
3230
dispatch: OverlayDispatch
3331
errorCount: number
3432
isBuildError: boolean
35-
scale: DevToolsScale
3633
}) {
3734
const [open, setOpen] = useState(false)
3835

@@ -88,7 +85,7 @@ export function DevToolsIndicator({
8885
isDevBuilding={state.buildingIndicator}
8986
isDevRendering={state.renderingIndicator}
9087
isBuildError={isBuildError}
91-
scale={scale}
88+
scale={state.scale}
9289
/>
9390
</Draggable>
9491
</Toast>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export function DevOverlay({
4141
(process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ? (
4242
<>
4343
<DevToolsIndicatorNew
44-
scale={scale}
4544
state={state}
4645
dispatch={dispatch}
4746
errorCount={totalErrorCount}

packages/next/src/next-devtools/dev-overlay/shared.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export type DevToolsIndicatorPosition =
1414
| 'top-left'
1515
| 'top-right'
1616

17+
const BASE_SIZE = 16
18+
19+
export const NEXT_DEV_TOOLS_SCALE = {
20+
Small: BASE_SIZE / 14,
21+
Medium: BASE_SIZE / 16,
22+
Large: BASE_SIZE / 18,
23+
}
24+
1725
type FastRefreshState =
1826
/** No refresh in progress. */
1927
| { type: 'idle' }
@@ -37,6 +45,7 @@ export interface OverlayState {
3745
isErrorOverlayOpen: boolean
3846
isDevToolsPanelOpen: boolean
3947
indicatorPosition: DevToolsIndicatorPosition
48+
scale: number
4049
}
4150
export type OverlayDispatch = React.Dispatch<DispatcherEvent>
4251

@@ -65,6 +74,7 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
6574
export const ACTION_DEVTOOLS_PANEL_TOGGLE = 'devtools-panel-toggle'
6675

6776
export const ACTION_DEVTOOLS_INDICATOR_POSITION = 'devtools-indicator-position'
77+
export const ACTION_DEVTOOLS_SCALE = 'devtools-scale'
6878

6979
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
7080
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
@@ -152,6 +162,11 @@ export interface DevToolsIndicatorPositionAction {
152162
indicatorPosition: DevToolsIndicatorPosition
153163
}
154164

165+
export interface DevToolsScaleAction {
166+
type: typeof ACTION_DEVTOOLS_SCALE
167+
scale: number
168+
}
169+
155170
export type DispatcherEvent =
156171
| BuildOkAction
157172
| BuildErrorAction
@@ -174,6 +189,7 @@ export type DispatcherEvent =
174189
| DevToolsPanelCloseAction
175190
| DevToolsPanelToggleAction
176191
| DevToolsIndicatorPositionAction
192+
| DevToolsScaleAction
177193

178194
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
179195
// 1st group: v8
@@ -216,6 +232,10 @@ export const INITIAL_OVERLAY_STATE: Omit<
216232
indicatorPosition:
217233
(localStorage.getItem(STORAGE_KEY_POSITION) as DevToolsIndicatorPosition) ??
218234
'bottom-left',
235+
scale:
236+
localStorage.getItem(STORAGE_KEY_SCALE)
237+
? Number(localStorage.getItem(STORAGE_KEY_SCALE))
238+
: NEXT_DEV_TOOLS_SCALE.Medium,
219239
}
220240

221241
function getInitialState(
@@ -390,6 +410,9 @@ export function useErrorOverlayReducer(
390410
case ACTION_DEVTOOLS_INDICATOR_POSITION: {
391411
return { ...state, indicatorPosition: action.indicatorPosition }
392412
}
413+
case ACTION_DEVTOOLS_SCALE: {
414+
return { ...state, scale: action.scale }
415+
}
393416
default: {
394417
return state
395418
}

0 commit comments

Comments
 (0)