Repository navigation
Expand file tree
/
Copy paththeme.tsx
More file actions
414 lines (399 loc) · 15.8 KB
/
Copy paththeme.tsx
File metadata and controls
414 lines (399 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/********************************************************************************
* Copyright (c) 2020 TypeFox and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { CSSProperties } from 'react';
import { alpha, backdropClasses, createTheme, Theme } from '@mui/material';
import type {} from '@mui/x-data-grid/themeAugmentation';
export const MONO_FONT = "'Geist Mono', monospace";
export const NAVBAR_HEIGHT = '3.875rem';
// Pixel twin for scroll math (rem values assume the 16px root font size).
export const NAVBAR_HEIGHT_PX = parseFloat(NAVBAR_HEIGHT) * 16;
// Shared look of alerts (see also components/banner.tsx): soft tinted surface
// with accent icon and links.
const alertTone = (theme: Theme, accent: string, background?: string) => ({
padding: theme.spacing(1, 2),
backgroundColor: background ?? alpha(accent, 0.1),
color: theme.palette.text.primary,
border: `1px solid ${alpha(accent, 0.25)}`,
borderRadius: theme.shape.borderRadiusCard,
'& .MuiAlert-icon': { color: accent },
'& a': {
color: accent,
fontWeight: 700,
textDecoration: 'none',
display: 'inline-flex',
alignItems: 'center',
gap: theme.spacing(0.75),
'&:hover': { textDecoration: 'underline' }
}
});
// Shared look of floating surfaces (menus, popovers, dialogs). The nested selector
// outranks MuiPaper's own rounded style, so no !important is needed.
const floatingPaper = (theme: Theme) => ({
border: `1px solid ${theme.palette.divider}`,
boxShadow: 'var(--shadow-lg)',
backgroundColor: theme.palette.background.paper,
backgroundImage: 'none',
'&.MuiPaper-rounded': { borderRadius: theme.shape.borderRadiusCard }
});
type Color = CSSProperties['color'];
interface StatusColors {
dark: Color;
light: Color;
}
interface NeutralColors {
light: Color;
dark: Color;
}
interface SelectedColors {
border: Color;
background: Color;
backgroundHover: Color;
hover: Color;
}
interface ScanBackgroundColors {
default: Color;
light: Color;
dark: Color;
}
interface GrayColors {
start: Color;
middle: Color;
end: Color;
gradient: string;
}
interface UnenforcedColors {
stripe: string;
}
interface CustomPaletteColors {
neutral: NeutralColors;
textHint: Color;
checkboxUnchecked: Color;
passed: StatusColors;
quarantined: StatusColors;
rejected: StatusColors;
errorStatus: StatusColors;
allowed: Color;
blocked: Color;
review: Color;
selected: SelectedColors;
scanBackground: ScanBackgroundColors;
gray: GrayColors;
unenforced: UnenforcedColors;
// Surface tiers not covered by MUI's background.paper
surface2: string;
surface3: string;
border2: string;
accentSoft: string;
warningSoft: string;
warningAccent: string;
bg2: string;
}
declare module '@mui/material/styles/createPalette' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Palette extends CustomPaletteColors {}
interface PaletteOptions extends Partial<CustomPaletteColors> {
neutral: NeutralColors;
textHint: Color;
}
}
declare module '@mui/system/createTheme/shape' {
interface Shape {
borderRadiusCard: number;
borderRadiusPill: number;
}
}
export default function createDefaultTheme(themeType: 'light' | 'dark'): Theme {
const dark = themeType === 'dark';
return createTheme({
typography: {
fontFamily: "'Geist', 'Roboto', system-ui, -apple-system, sans-serif",
button: {
textTransform: 'none',
fontWeight: 400,
letterSpacing: 0
}
},
// Tuned to VS Code's newer "islands" look: softly rounded controls, rounder panels.
shape: {
borderRadius: 4,
borderRadiusCard: 6,
borderRadiusPill: 6
},
mixins: {
toolbar: { minHeight: NAVBAR_HEIGHT }
},
palette: {
mode: themeType,
// Standard MUI palette — these replace the matching CSS vars
background: {
default: dark ? '#0c0c11' : '#ffffff',
paper: dark ? '#15151d' : '#ffffff'
},
text: {
primary: dark ? '#ededf2' : '#16161c',
secondary: dark ? '#b2b2bf' : '#54545f',
disabled: dark ? '#7a7a87' : '#8c8c98'
},
divider: dark ? '#262630' : '#e9e9ee',
primary: {
main: dark ? '#ededf2' : '#16161c',
dark: dark ? '#f4f4f4' : '#0d0d11'
},
secondary: {
main: dark ? '#a855f7' : '#8b1fd6',
dark: dark ? '#9333ea' : '#7916bd',
light: dark ? '#c084fc' : '#8b1fd6', // accent-fg
contrastText: '#ffffff'
},
// Custom surface tiers
bg2: dark ? '#101016' : '#f7f7f9',
surface2: dark ? '#1a1a23' : '#fafafa',
surface3: dark ? '#20202b' : '#f2f2f5',
border2: dark ? '#1d1d26' : '#f0f0f3',
accentSoft: dark ? '#291a3d' : '#f4e9fd',
warningSoft: dark ? '#3a2c14' : '#fdf3e2',
warningAccent: dark ? '#fbbf24' : '#d97706',
// Legacy admin palette
neutral: {
light: dark ? '#000' : '#e6e6e6',
dark: dark ? '#151515' : '#fff'
},
textHint: 'rgba(0, 0, 0, 0.38)',
checkboxUnchecked: dark ? 'rgba(255, 255, 255, 0.23)' : 'rgba(0, 0, 0, 0.23)',
passed: {
dark: dark ? '#2e5c32' : '#4db052',
light: dark ? '#a5d6a7' : '#c8e6c9'
},
quarantined: {
dark: dark ? '#8e5518' : '#e09030',
light: dark ? '#ffcc80' : '#ffe0b2'
},
rejected: {
dark: dark ? '#7d2e2e' : '#d63c3c',
light: dark ? '#ef9a9a' : '#ffcdd2'
},
errorStatus: {
dark: dark ? '#5a5a5a' : '#8a8a8a',
light: dark ? '#b0b0b0' : '#e0e0e0'
},
allowed: '#4caf50',
blocked: '#f44336',
review: '#e6a800',
selected: {
border: '#c160ef',
background: dark ? '#3d1b4d' : '#f3e5f9',
backgroundHover: dark ? '#4d2360' : '#e9d5f5',
hover: dark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.04)'
},
scanBackground: {
default: dark ? '#1e1e1e' : '#f5f5f5',
light: dark ? '#2d2d2d' : '#f0f0f0',
dark: dark ? '#0a0a0a' : '#fafafa'
},
gray: {
start: '#888888',
middle: '#cccccc',
end: '#888888',
gradient: 'linear-gradient(90deg, #888888 0%, #cccccc 50%, #888888 100%)'
},
unenforced: {
stripe: dark
? 'repeating-linear-gradient(-45deg, transparent, transparent 4px, rgba(255, 255, 255, 0.12) 4px, rgba(255, 255, 255, 0.12) 8px)'
: 'repeating-linear-gradient(-45deg, transparent, transparent 4px, rgba(0, 0, 0, 0.12) 4px, rgba(0, 0, 0, 0.12) 8px)'
}
},
breakpoints: {
values: { xs: 0, sm: 550, md: 800, lg: 1040, xl: 1320 }
},
components: {
MuiAccordion: {
styleOverrides: {
root: {
border: 0,
boxShadow: 'none',
background: 'transparent',
'&:before': { display: 'none' }
}
}
},
MuiAlert: {
styleOverrides: {
standardInfo: ({ theme }) =>
alertTone(theme, theme.palette.secondary.light, theme.palette.accentSoft),
standardWarning: ({ theme }) =>
alertTone(theme, theme.palette.warningAccent, theme.palette.warningSoft),
standardError: ({ theme }) => alertTone(theme, theme.palette.error.main),
standardSuccess: ({ theme }) => alertTone(theme, theme.palette.success.main)
}
},
// VS Code buttons are flat and compact (~24px page actions), with corners
// a touch softer than inputs; outlined trims 1px per side so the border
// doesn't add height.
MuiButton: {
defaultProps: { disableElevation: true },
styleOverrides: {
// Neutral outlined buttons use the hairline divider instead of MUI's
// half-opacity primary border, darkening on hover like the card borders.
outlined: ({ theme }) => ({
borderColor: theme.palette.divider,
color: theme.palette.text.secondary,
'&:hover': {
backgroundColor: 'transparent',
borderColor: theme.palette.text.secondary,
color: theme.palette.text.primary
}
}),
outlinedSecondary: ({ theme }) => ({
color: theme.palette.secondary.main,
borderColor: alpha(theme.palette.secondary.main, 0.5),
'&:hover': {
borderColor: theme.palette.secondary.main,
color: theme.palette.secondary.main
}
}),
outlinedWarning: ({ theme }) => ({
color: theme.palette.warningAccent,
borderColor: alpha(theme.palette.warningAccent, 0.5),
'&:hover': {
borderColor: theme.palette.warningAccent,
color: theme.palette.warningAccent
}
}),
outlinedError: ({ theme }) => ({
backgroundColor: theme.palette.surface2,
borderColor: theme.palette.divider,
color: theme.palette.error.main,
// Background only: transitioning color/border makes the disabled→enabled swap look like a fade.
transition: 'background-color 0.15s',
'&:hover': {
backgroundColor: theme.palette.error.main,
borderColor: theme.palette.error.main,
color: theme.palette.common.white
}
})
}
},
// MUI X derives the grid's borders from `divider` via lighten/darken, which
// almost erases our already-light opaque divider. Feed the grid's design
// tokens directly; `&.MuiDataGrid-root` outranks the injected
// `.MuiDataGridVariables-*` class that carries the derived defaults.
MuiDataGrid: {
styleOverrides: {
root: ({ theme }) => ({
'&.MuiDataGrid-root': {
'--DataGrid-t-color-border-base': theme.palette.divider,
'--DataGrid-t-header-background-base': theme.palette.bg2,
'--DataGrid-t-radius-base': `${theme.shape.borderRadiusCard}px`,
'--DataGrid-t-color-interactive-focus': theme.palette.secondary.main,
'--DataGrid-t-color-interactive-selected': theme.palette.secondary.main,
'--DataGrid-t-color-foreground-accent': theme.palette.secondary.light
}
}),
columnHeaderTitle: ({ theme }) => ({
fontSize: '0.8125rem',
fontWeight: 600,
color: theme.palette.text.secondary
})
}
},
MuiTableCell: {
styleOverrides: {
root: ({ theme }) => ({ borderBottomColor: theme.palette.divider })
}
},
MuiTabs: {
styleOverrides: {
indicator: ({ theme }) => ({
backgroundColor: theme.palette.secondary.main,
height: '1px'
})
}
},
// VS Code tabs: 13px, regular weight, selection shown by color alone.
MuiTab: {
styleOverrides: {
root: ({ theme }) => ({
fontSize: '0.8125rem',
fontWeight: 400,
textTransform: 'none',
color: theme.palette.text.disabled,
minHeight: '2.5rem',
padding: '0.625rem 0.875rem',
'&.Mui-selected': { color: theme.palette.text.primary }
})
}
},
// Menu and Select popups inherit the floating look from MuiPopover.
MuiMenu: {
styleOverrides: {
paper: { marginTop: '0.375rem' },
list: { padding: '0.25rem' }
}
},
MuiMenuItem: {
styleOverrides: {
root: ({ theme }) => ({
borderRadius: theme.shape.borderRadius,
fontSize: '0.8125rem',
fontWeight: 400,
minHeight: '2rem'
})
}
},
MuiTypography: {
styleOverrides: {
overline: {
textTransform: 'none',
letterSpacing: 0,
lineHeight: 1.4
}
}
},
MuiPopover: {
// no body scroll lock: toggling it jumps the scroll position on mobile and
// shifts the pinned chrome; dialogs (MuiModal directly) keep theirs
defaultProps: { disableScrollLock: true },
styleOverrides: {
paper: ({ theme }) => floatingPaper(theme)
}
},
// Autocomplete popups (e.g. the publisher filter) render their own paper, not a popover.
MuiAutocomplete: {
styleOverrides: {
paper: ({ theme }) => floatingPaper(theme)
}
},
MuiDialog: {
styleOverrides: {
// Only dialogs: menus and popovers mount an invisible backdrop that must not blur the page.
root: {
[`& .${backdropClasses.root}`]: {
backdropFilter: 'blur(1.5px)',
WebkitBackdropFilter: 'blur(1.5px)'
}
},
paper: ({ theme }) => floatingPaper(theme)
}
},
MuiDivider: {
styleOverrides: {
root: ({ theme }) => ({ borderColor: theme.palette.divider })
}
},
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: ({ theme }) => ({
borderColor: theme.palette.divider
})
}
}
}
});
}