@redsift/table 11.11.0-muiv6 → 11.11.0-muiv8-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/BaseComponents.js +1 -1
- package/_internal/BaseIconButton.js +117 -0
- package/_internal/BaseIconButton.js.map +1 -0
- package/_internal/DataGrid2.js +68 -52
- package/_internal/DataGrid2.js.map +1 -1
- package/_internal/GridToolbarFilterSemanticField2.js +1 -1
- package/_internal/GridToolbarFilterSemanticField2.js.map +1 -1
- package/_internal/Pagination.js +1 -1
- package/_internal/ServerSideControlledPagination.js +18720 -0
- package/_internal/ServerSideControlledPagination.js.map +1 -0
- package/_internal/StatefulDataGrid2.js +731 -465
- package/_internal/StatefulDataGrid2.js.map +1 -1
- package/_internal/Toolbar2.js +22 -5
- package/_internal/Toolbar2.js.map +1 -1
- package/_internal/ToolbarWrapper2.js +1 -1
- package/_internal/useControlledDatagridState.js +905 -35
- package/_internal/useControlledDatagridState.js.map +1 -1
- package/index.d.ts +404 -282
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +7 -7
- package/_internal/BasePopper.js +0 -2448
- package/_internal/BasePopper.js.map +0 -1
- package/_internal/ControlledPagination.js +0 -10507
- package/_internal/ControlledPagination.js.map +0 -1
- package/_internal/Portal.js +0 -4363
- package/_internal/Portal.js.map +0 -1
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { P as PropTypes, z as exactProp, x as useTheme$1, a as _extends, _ as _objectWithoutPropertiesLoose, T as THEME_ID } from './Portal.js';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useState, useEffect } from 'react';
|
|
3
|
+
import { P as PropTypes, J as exactProp, K as useTheme$1, A as useId, L as useEnhancedEffect, M as GlobalStyles, R as RtlProvider, N as DefaultPropsProvider, Q as GlobalStyles$1, T as THEME_ID, j as createTheme, U as createTypography, e as styleFunctionSx } from './ServerSideControlledPagination.js';
|
|
4
4
|
import { j as jsxRuntimeExports } from './jsx-runtime.js';
|
|
5
5
|
import { ThemeContext as ThemeContext$2 } from '@emotion/react';
|
|
6
6
|
import styled, { css } from 'styled-components';
|
|
7
7
|
|
|
8
|
-
/* eslint-disable */
|
|
9
|
-
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
10
|
-
var ponyfillGlobal = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
|
|
11
|
-
|
|
12
8
|
const ThemeContext = /*#__PURE__*/React.createContext(null);
|
|
13
9
|
if (process.env.NODE_ENV !== 'production') {
|
|
14
10
|
ThemeContext.displayName = 'ThemeContext';
|
|
@@ -18,7 +14,8 @@ var ThemeContext$1 = ThemeContext;
|
|
|
18
14
|
function useTheme() {
|
|
19
15
|
const theme = React.useContext(ThemeContext$1);
|
|
20
16
|
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
-
// eslint-disable-next-line react-
|
|
17
|
+
// TODO: uncomment once we enable eslint-plugin-react-compiler eslint-disable-next-line react-compiler/react-compiler
|
|
18
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- It's not required to run React.useDebugValue in production
|
|
22
19
|
React.useDebugValue(theme);
|
|
23
20
|
}
|
|
24
21
|
return theme;
|
|
@@ -60,7 +57,9 @@ function ThemeProvider$2(props) {
|
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
const theme = React.useMemo(() => {
|
|
63
|
-
const output = outerTheme === null ?
|
|
60
|
+
const output = outerTheme === null ? {
|
|
61
|
+
...localTheme
|
|
62
|
+
} : mergeOuterLocalTheme(outerTheme, localTheme);
|
|
64
63
|
if (output != null) {
|
|
65
64
|
output[nested] = outerTheme !== null;
|
|
66
65
|
}
|
|
@@ -85,15 +84,58 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
85
84
|
process.env.NODE_ENV !== "production" ? ThemeProvider$2.propTypes = exactProp(ThemeProvider$2.propTypes) : void 0;
|
|
86
85
|
}
|
|
87
86
|
|
|
87
|
+
function useLayerOrder(theme) {
|
|
88
|
+
const upperTheme = useTheme$1();
|
|
89
|
+
const id = useId() || '';
|
|
90
|
+
const {
|
|
91
|
+
modularCssLayers
|
|
92
|
+
} = theme;
|
|
93
|
+
let layerOrder = 'mui.global, mui.components, mui.theme, mui.custom, mui.sx';
|
|
94
|
+
if (!modularCssLayers || upperTheme !== null) {
|
|
95
|
+
// skip this hook if upper theme exists.
|
|
96
|
+
layerOrder = '';
|
|
97
|
+
} else if (typeof modularCssLayers === 'string') {
|
|
98
|
+
layerOrder = modularCssLayers.replace(/mui(?!\.)/g, layerOrder);
|
|
99
|
+
} else {
|
|
100
|
+
layerOrder = `@layer ${layerOrder};`;
|
|
101
|
+
}
|
|
102
|
+
useEnhancedEffect(() => {
|
|
103
|
+
const head = document.querySelector('head');
|
|
104
|
+
if (!head) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const firstChild = head.firstChild;
|
|
108
|
+
if (layerOrder) {
|
|
109
|
+
// Only insert if first child doesn't have data-mui-layer-order attribute
|
|
110
|
+
if (firstChild && firstChild.hasAttribute?.('data-mui-layer-order') && firstChild.getAttribute('data-mui-layer-order') === id) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const styleElement = document.createElement('style');
|
|
114
|
+
styleElement.setAttribute('data-mui-layer-order', id);
|
|
115
|
+
styleElement.textContent = layerOrder;
|
|
116
|
+
head.prepend(styleElement);
|
|
117
|
+
} else {
|
|
118
|
+
head.querySelector(`style[data-mui-layer-order="${id}"]`)?.remove();
|
|
119
|
+
}
|
|
120
|
+
}, [layerOrder, id]);
|
|
121
|
+
if (!layerOrder) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx(GlobalStyles, {
|
|
125
|
+
styles: layerOrder
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
88
129
|
const EMPTY_THEME = {};
|
|
89
130
|
function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
90
131
|
return React.useMemo(() => {
|
|
91
132
|
const resolvedTheme = themeId ? upperTheme[themeId] || upperTheme : upperTheme;
|
|
92
133
|
if (typeof localTheme === 'function') {
|
|
93
134
|
const mergedTheme = localTheme(resolvedTheme);
|
|
94
|
-
const result = themeId ?
|
|
135
|
+
const result = themeId ? {
|
|
136
|
+
...upperTheme,
|
|
95
137
|
[themeId]: mergedTheme
|
|
96
|
-
}
|
|
138
|
+
} : mergedTheme;
|
|
97
139
|
// must return a function for the private theme to NOT merge with the upper theme.
|
|
98
140
|
// see the test case "use provided theme from a callback" in ThemeProvider.test.js
|
|
99
141
|
if (isPrivate) {
|
|
@@ -101,9 +143,13 @@ function useThemeScoping(themeId, upperTheme, localTheme, isPrivate = false) {
|
|
|
101
143
|
}
|
|
102
144
|
return result;
|
|
103
145
|
}
|
|
104
|
-
return themeId ?
|
|
146
|
+
return themeId ? {
|
|
147
|
+
...upperTheme,
|
|
105
148
|
[themeId]: localTheme
|
|
106
|
-
}
|
|
149
|
+
} : {
|
|
150
|
+
...upperTheme,
|
|
151
|
+
...localTheme
|
|
152
|
+
};
|
|
107
153
|
}, [themeId, upperTheme, localTheme, isPrivate]);
|
|
108
154
|
}
|
|
109
155
|
|
|
@@ -129,19 +175,27 @@ function ThemeProvider$1(props) {
|
|
|
129
175
|
}
|
|
130
176
|
const engineTheme = useThemeScoping(themeId, upperTheme, localTheme);
|
|
131
177
|
const privateTheme = useThemeScoping(themeId, upperPrivateTheme, localTheme, true);
|
|
178
|
+
const rtlValue = (themeId ? engineTheme[themeId] : engineTheme).direction === 'rtl';
|
|
179
|
+
const layerOrder = useLayerOrder(engineTheme);
|
|
132
180
|
return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$2, {
|
|
133
181
|
theme: privateTheme,
|
|
134
182
|
children: /*#__PURE__*/jsxRuntimeExports.jsx(ThemeContext$2.Provider, {
|
|
135
183
|
value: engineTheme,
|
|
136
|
-
children:
|
|
184
|
+
children: /*#__PURE__*/jsxRuntimeExports.jsx(RtlProvider, {
|
|
185
|
+
value: rtlValue,
|
|
186
|
+
children: /*#__PURE__*/jsxRuntimeExports.jsxs(DefaultPropsProvider, {
|
|
187
|
+
value: themeId ? engineTheme[themeId].components : engineTheme.components,
|
|
188
|
+
children: [layerOrder, children]
|
|
189
|
+
})
|
|
190
|
+
})
|
|
137
191
|
})
|
|
138
192
|
});
|
|
139
193
|
}
|
|
140
194
|
process.env.NODE_ENV !== "production" ? ThemeProvider$1.propTypes /* remove-proptypes */ = {
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
195
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
196
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
197
|
+
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
|
|
198
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
145
199
|
/**
|
|
146
200
|
* Your component tree.
|
|
147
201
|
*/
|
|
@@ -159,41 +213,857 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
159
213
|
process.env.NODE_ENV !== "production" ? ThemeProvider$1.propTypes = exactProp(ThemeProvider$1.propTypes) : void 0;
|
|
160
214
|
}
|
|
161
215
|
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
216
|
+
const DEFAULT_MODE_STORAGE_KEY = 'mode';
|
|
217
|
+
const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
218
|
+
const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
219
|
+
function InitColorSchemeScript(options) {
|
|
220
|
+
const {
|
|
221
|
+
defaultMode = 'system',
|
|
222
|
+
defaultLightColorScheme = 'light',
|
|
223
|
+
defaultDarkColorScheme = 'dark',
|
|
224
|
+
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
225
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
226
|
+
attribute: initialAttribute = DEFAULT_ATTRIBUTE,
|
|
227
|
+
colorSchemeNode = 'document.documentElement',
|
|
228
|
+
nonce
|
|
229
|
+
} = options || {};
|
|
230
|
+
let setter = '';
|
|
231
|
+
let attribute = initialAttribute;
|
|
232
|
+
if (initialAttribute === 'class') {
|
|
233
|
+
attribute = '.%s';
|
|
234
|
+
}
|
|
235
|
+
if (initialAttribute === 'data') {
|
|
236
|
+
attribute = '[data-%s]';
|
|
237
|
+
}
|
|
238
|
+
if (attribute.startsWith('.')) {
|
|
239
|
+
const selector = attribute.substring(1);
|
|
240
|
+
setter += `${colorSchemeNode}.classList.remove('${selector}'.replace('%s', light), '${selector}'.replace('%s', dark));
|
|
241
|
+
${colorSchemeNode}.classList.add('${selector}'.replace('%s', colorScheme));`;
|
|
242
|
+
}
|
|
243
|
+
const matches = attribute.match(/\[([^[\]]+)\]/); // case [data-color-scheme='%s'] or [data-color-scheme]
|
|
244
|
+
if (matches) {
|
|
245
|
+
const [attr, value] = matches[1].split('=');
|
|
246
|
+
if (!value) {
|
|
247
|
+
setter += `${colorSchemeNode}.removeAttribute('${attr}'.replace('%s', light));
|
|
248
|
+
${colorSchemeNode}.removeAttribute('${attr}'.replace('%s', dark));`;
|
|
249
|
+
}
|
|
250
|
+
setter += `
|
|
251
|
+
${colorSchemeNode}.setAttribute('${attr}'.replace('%s', colorScheme), ${value ? `${value}.replace('%s', colorScheme)` : '""'});`;
|
|
252
|
+
} else if (attribute !== '.%s') {
|
|
253
|
+
setter += `${colorSchemeNode}.setAttribute('${attribute}', colorScheme);`;
|
|
254
|
+
}
|
|
255
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx("script", {
|
|
256
|
+
suppressHydrationWarning: true,
|
|
257
|
+
nonce: typeof window === 'undefined' ? nonce : ''
|
|
258
|
+
// eslint-disable-next-line react/no-danger
|
|
259
|
+
,
|
|
260
|
+
dangerouslySetInnerHTML: {
|
|
261
|
+
__html: `(function() {
|
|
262
|
+
try {
|
|
263
|
+
let colorScheme = '';
|
|
264
|
+
const mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
|
|
265
|
+
const dark = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
266
|
+
const light = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
267
|
+
if (mode === 'system') {
|
|
268
|
+
// handle system mode
|
|
269
|
+
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
270
|
+
if (mql.matches) {
|
|
271
|
+
colorScheme = dark
|
|
272
|
+
} else {
|
|
273
|
+
colorScheme = light
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (mode === 'light') {
|
|
277
|
+
colorScheme = light;
|
|
278
|
+
}
|
|
279
|
+
if (mode === 'dark') {
|
|
280
|
+
colorScheme = dark;
|
|
281
|
+
}
|
|
282
|
+
if (colorScheme) {
|
|
283
|
+
${setter}
|
|
284
|
+
}
|
|
285
|
+
} catch(e){}})();`
|
|
286
|
+
}
|
|
287
|
+
}, "mui-color-scheme-init");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function noop$1() {}
|
|
291
|
+
const localStorageManager = ({
|
|
292
|
+
key,
|
|
293
|
+
storageWindow
|
|
294
|
+
}) => {
|
|
295
|
+
if (!storageWindow && typeof window !== 'undefined') {
|
|
296
|
+
storageWindow = window;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
get(defaultValue) {
|
|
300
|
+
if (typeof window === 'undefined') {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
if (!storageWindow) {
|
|
304
|
+
return defaultValue;
|
|
305
|
+
}
|
|
306
|
+
let value;
|
|
307
|
+
try {
|
|
308
|
+
value = storageWindow.localStorage.getItem(key);
|
|
309
|
+
} catch {
|
|
310
|
+
// Unsupported
|
|
311
|
+
}
|
|
312
|
+
return value || defaultValue;
|
|
313
|
+
},
|
|
314
|
+
set: value => {
|
|
315
|
+
if (storageWindow) {
|
|
316
|
+
try {
|
|
317
|
+
storageWindow.localStorage.setItem(key, value);
|
|
318
|
+
} catch {
|
|
319
|
+
// Unsupported
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
subscribe: handler => {
|
|
324
|
+
if (!storageWindow) {
|
|
325
|
+
return noop$1;
|
|
326
|
+
}
|
|
327
|
+
const listener = event => {
|
|
328
|
+
const value = event.newValue;
|
|
329
|
+
if (event.key === key) {
|
|
330
|
+
handler(value);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
storageWindow.addEventListener('storage', listener);
|
|
334
|
+
return () => {
|
|
335
|
+
storageWindow.removeEventListener('storage', listener);
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
var localStorageManager$1 = localStorageManager;
|
|
341
|
+
|
|
342
|
+
function noop() {}
|
|
343
|
+
function getSystemMode(mode) {
|
|
344
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function' && mode === 'system') {
|
|
345
|
+
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
346
|
+
if (mql.matches) {
|
|
347
|
+
return 'dark';
|
|
348
|
+
}
|
|
349
|
+
return 'light';
|
|
350
|
+
}
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
function processState(state, callback) {
|
|
354
|
+
if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
|
|
355
|
+
return callback('light');
|
|
356
|
+
}
|
|
357
|
+
if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
|
|
358
|
+
return callback('dark');
|
|
359
|
+
}
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
function getColorScheme(state) {
|
|
363
|
+
return processState(state, mode => {
|
|
364
|
+
if (mode === 'light') {
|
|
365
|
+
return state.lightColorScheme;
|
|
366
|
+
}
|
|
367
|
+
if (mode === 'dark') {
|
|
368
|
+
return state.darkColorScheme;
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function useCurrentColorScheme(options) {
|
|
374
|
+
const {
|
|
375
|
+
defaultMode = 'light',
|
|
376
|
+
defaultLightColorScheme,
|
|
377
|
+
defaultDarkColorScheme,
|
|
378
|
+
supportedColorSchemes = [],
|
|
379
|
+
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
380
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
381
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
382
|
+
storageManager = localStorageManager$1,
|
|
383
|
+
noSsr = false
|
|
384
|
+
} = options;
|
|
385
|
+
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
386
|
+
const isMultiSchemes = supportedColorSchemes.length > 1;
|
|
387
|
+
const modeStorage = React.useMemo(() => storageManager?.({
|
|
388
|
+
key: modeStorageKey,
|
|
389
|
+
storageWindow
|
|
390
|
+
}), [storageManager, modeStorageKey, storageWindow]);
|
|
391
|
+
const lightStorage = React.useMemo(() => storageManager?.({
|
|
392
|
+
key: `${colorSchemeStorageKey}-light`,
|
|
393
|
+
storageWindow
|
|
394
|
+
}), [storageManager, colorSchemeStorageKey, storageWindow]);
|
|
395
|
+
const darkStorage = React.useMemo(() => storageManager?.({
|
|
396
|
+
key: `${colorSchemeStorageKey}-dark`,
|
|
397
|
+
storageWindow
|
|
398
|
+
}), [storageManager, colorSchemeStorageKey, storageWindow]);
|
|
399
|
+
const [state, setState] = React.useState(() => {
|
|
400
|
+
const initialMode = modeStorage?.get(defaultMode) || defaultMode;
|
|
401
|
+
const lightColorScheme = lightStorage?.get(defaultLightColorScheme) || defaultLightColorScheme;
|
|
402
|
+
const darkColorScheme = darkStorage?.get(defaultDarkColorScheme) || defaultDarkColorScheme;
|
|
403
|
+
return {
|
|
404
|
+
mode: initialMode,
|
|
405
|
+
systemMode: getSystemMode(initialMode),
|
|
406
|
+
lightColorScheme,
|
|
407
|
+
darkColorScheme
|
|
408
|
+
};
|
|
409
|
+
});
|
|
410
|
+
const [isClient, setIsClient] = React.useState(noSsr || !isMultiSchemes);
|
|
411
|
+
React.useEffect(() => {
|
|
412
|
+
setIsClient(true); // to rerender the component after hydration
|
|
413
|
+
}, []);
|
|
414
|
+
const colorScheme = getColorScheme(state);
|
|
415
|
+
const setMode = React.useCallback(mode => {
|
|
416
|
+
setState(currentState => {
|
|
417
|
+
if (mode === currentState.mode) {
|
|
418
|
+
// do nothing if mode does not change
|
|
419
|
+
return currentState;
|
|
420
|
+
}
|
|
421
|
+
const newMode = mode ?? defaultMode;
|
|
422
|
+
modeStorage?.set(newMode);
|
|
423
|
+
return {
|
|
424
|
+
...currentState,
|
|
425
|
+
mode: newMode,
|
|
426
|
+
systemMode: getSystemMode(newMode)
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
}, [modeStorage, defaultMode]);
|
|
430
|
+
const setColorScheme = React.useCallback(value => {
|
|
431
|
+
if (!value) {
|
|
432
|
+
setState(currentState => {
|
|
433
|
+
lightStorage?.set(defaultLightColorScheme);
|
|
434
|
+
darkStorage?.set(defaultDarkColorScheme);
|
|
435
|
+
return {
|
|
436
|
+
...currentState,
|
|
437
|
+
lightColorScheme: defaultLightColorScheme,
|
|
438
|
+
darkColorScheme: defaultDarkColorScheme
|
|
439
|
+
};
|
|
440
|
+
});
|
|
441
|
+
} else if (typeof value === 'string') {
|
|
442
|
+
if (value && !joinedColorSchemes.includes(value)) {
|
|
443
|
+
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
444
|
+
} else {
|
|
445
|
+
setState(currentState => {
|
|
446
|
+
const newState = {
|
|
447
|
+
...currentState
|
|
448
|
+
};
|
|
449
|
+
processState(currentState, mode => {
|
|
450
|
+
if (mode === 'light') {
|
|
451
|
+
lightStorage?.set(value);
|
|
452
|
+
newState.lightColorScheme = value;
|
|
453
|
+
}
|
|
454
|
+
if (mode === 'dark') {
|
|
455
|
+
darkStorage?.set(value);
|
|
456
|
+
newState.darkColorScheme = value;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
return newState;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
setState(currentState => {
|
|
464
|
+
const newState = {
|
|
465
|
+
...currentState
|
|
466
|
+
};
|
|
467
|
+
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
468
|
+
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
469
|
+
if (newLightColorScheme) {
|
|
470
|
+
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
471
|
+
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
472
|
+
} else {
|
|
473
|
+
newState.lightColorScheme = newLightColorScheme;
|
|
474
|
+
lightStorage?.set(newLightColorScheme);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (newDarkColorScheme) {
|
|
478
|
+
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
479
|
+
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
480
|
+
} else {
|
|
481
|
+
newState.darkColorScheme = newDarkColorScheme;
|
|
482
|
+
darkStorage?.set(newDarkColorScheme);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return newState;
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}, [joinedColorSchemes, lightStorage, darkStorage, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
489
|
+
const handleMediaQuery = React.useCallback(event => {
|
|
490
|
+
if (state.mode === 'system') {
|
|
491
|
+
setState(currentState => {
|
|
492
|
+
const systemMode = event?.matches ? 'dark' : 'light';
|
|
493
|
+
|
|
494
|
+
// Early exit, nothing changed.
|
|
495
|
+
if (currentState.systemMode === systemMode) {
|
|
496
|
+
return currentState;
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
...currentState,
|
|
500
|
+
systemMode
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}, [state.mode]);
|
|
505
|
+
|
|
506
|
+
// Ref hack to avoid adding handleMediaQuery as a dep
|
|
507
|
+
const mediaListener = React.useRef(handleMediaQuery);
|
|
508
|
+
mediaListener.current = handleMediaQuery;
|
|
509
|
+
React.useEffect(() => {
|
|
510
|
+
if (typeof window.matchMedia !== 'function' || !isMultiSchemes) {
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
const handler = (...args) => mediaListener.current(...args);
|
|
514
|
+
|
|
515
|
+
// Always listen to System preference
|
|
516
|
+
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
|
517
|
+
|
|
518
|
+
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
519
|
+
media.addListener(handler);
|
|
520
|
+
handler(media);
|
|
521
|
+
return () => {
|
|
522
|
+
media.removeListener(handler);
|
|
523
|
+
};
|
|
524
|
+
}, [isMultiSchemes]);
|
|
525
|
+
|
|
526
|
+
// Handle when localStorage has changed
|
|
527
|
+
React.useEffect(() => {
|
|
528
|
+
if (isMultiSchemes) {
|
|
529
|
+
const unsubscribeMode = modeStorage?.subscribe(value => {
|
|
530
|
+
if (!value || ['light', 'dark', 'system'].includes(value)) {
|
|
531
|
+
setMode(value || defaultMode);
|
|
532
|
+
}
|
|
533
|
+
}) || noop;
|
|
534
|
+
const unsubscribeLight = lightStorage?.subscribe(value => {
|
|
535
|
+
if (!value || joinedColorSchemes.match(value)) {
|
|
536
|
+
setColorScheme({
|
|
537
|
+
light: value
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}) || noop;
|
|
541
|
+
const unsubscribeDark = darkStorage?.subscribe(value => {
|
|
542
|
+
if (!value || joinedColorSchemes.match(value)) {
|
|
543
|
+
setColorScheme({
|
|
544
|
+
dark: value
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}) || noop;
|
|
548
|
+
return () => {
|
|
549
|
+
unsubscribeMode();
|
|
550
|
+
unsubscribeLight();
|
|
551
|
+
unsubscribeDark();
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return undefined;
|
|
555
|
+
}, [setColorScheme, setMode, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes, modeStorage, lightStorage, darkStorage]);
|
|
556
|
+
return {
|
|
557
|
+
...state,
|
|
558
|
+
mode: isClient ? state.mode : undefined,
|
|
559
|
+
systemMode: isClient ? state.systemMode : undefined,
|
|
560
|
+
colorScheme: isClient ? colorScheme : undefined,
|
|
561
|
+
setMode,
|
|
562
|
+
setColorScheme
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
567
|
+
function createCssVarsProvider(options) {
|
|
568
|
+
const {
|
|
569
|
+
themeId,
|
|
570
|
+
/**
|
|
571
|
+
* This `theme` object needs to follow a certain structure to
|
|
572
|
+
* be used correctly by the finel `CssVarsProvider`. It should have a
|
|
573
|
+
* `colorSchemes` key with the light and dark (and any other) palette.
|
|
574
|
+
* It should also ideally have a vars object created using `prepareCssVars`.
|
|
575
|
+
*/
|
|
576
|
+
theme: defaultTheme = {},
|
|
577
|
+
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
578
|
+
colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
579
|
+
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
580
|
+
defaultColorScheme,
|
|
581
|
+
resolveTheme
|
|
582
|
+
} = options;
|
|
583
|
+
const defaultContext = {
|
|
584
|
+
allColorSchemes: [],
|
|
585
|
+
colorScheme: undefined,
|
|
586
|
+
darkColorScheme: undefined,
|
|
587
|
+
lightColorScheme: undefined,
|
|
588
|
+
mode: undefined,
|
|
589
|
+
setColorScheme: () => {},
|
|
590
|
+
setMode: () => {},
|
|
591
|
+
systemMode: undefined
|
|
592
|
+
};
|
|
593
|
+
const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
|
|
594
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
595
|
+
ColorSchemeContext.displayName = 'ColorSchemeContext';
|
|
596
|
+
}
|
|
597
|
+
const useColorScheme = () => React.useContext(ColorSchemeContext) || defaultContext;
|
|
598
|
+
const defaultColorSchemes = {};
|
|
599
|
+
const defaultComponents = {};
|
|
600
|
+
function CssVarsProvider(props) {
|
|
601
|
+
const {
|
|
602
|
+
children,
|
|
603
|
+
theme: themeProp,
|
|
604
|
+
modeStorageKey = defaultModeStorageKey,
|
|
605
|
+
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
606
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
607
|
+
storageManager,
|
|
608
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
609
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
610
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
611
|
+
disableNestedContext = false,
|
|
612
|
+
disableStyleSheetGeneration = false,
|
|
613
|
+
defaultMode: initialMode = 'system',
|
|
614
|
+
forceThemeRerender = false,
|
|
615
|
+
noSsr
|
|
616
|
+
} = props;
|
|
617
|
+
const hasMounted = React.useRef(false);
|
|
618
|
+
const upperTheme = useTheme();
|
|
619
|
+
const ctx = React.useContext(ColorSchemeContext);
|
|
620
|
+
const nested = !!ctx && !disableNestedContext;
|
|
621
|
+
const initialTheme = React.useMemo(() => {
|
|
622
|
+
if (themeProp) {
|
|
623
|
+
return themeProp;
|
|
624
|
+
}
|
|
625
|
+
return typeof defaultTheme === 'function' ? defaultTheme() : defaultTheme;
|
|
626
|
+
}, [themeProp]);
|
|
627
|
+
const scopedTheme = initialTheme[themeId];
|
|
628
|
+
const restThemeProp = scopedTheme || initialTheme;
|
|
629
|
+
const {
|
|
630
|
+
colorSchemes = defaultColorSchemes,
|
|
631
|
+
components = defaultComponents,
|
|
632
|
+
cssVarPrefix
|
|
633
|
+
} = restThemeProp;
|
|
634
|
+
const joinedColorSchemes = Object.keys(colorSchemes).filter(k => !!colorSchemes[k]).join(',');
|
|
635
|
+
const allColorSchemes = React.useMemo(() => joinedColorSchemes.split(','), [joinedColorSchemes]);
|
|
636
|
+
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
637
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
638
|
+
const defaultMode = colorSchemes[defaultLightColorScheme] && colorSchemes[defaultDarkColorScheme] ? initialMode : colorSchemes[restThemeProp.defaultColorScheme]?.palette?.mode || restThemeProp.palette?.mode;
|
|
639
|
+
|
|
640
|
+
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
641
|
+
const {
|
|
642
|
+
mode: stateMode,
|
|
643
|
+
setMode,
|
|
644
|
+
systemMode,
|
|
645
|
+
lightColorScheme,
|
|
646
|
+
darkColorScheme,
|
|
647
|
+
colorScheme: stateColorScheme,
|
|
648
|
+
setColorScheme
|
|
649
|
+
} = useCurrentColorScheme({
|
|
650
|
+
supportedColorSchemes: allColorSchemes,
|
|
651
|
+
defaultLightColorScheme,
|
|
652
|
+
defaultDarkColorScheme,
|
|
653
|
+
modeStorageKey,
|
|
654
|
+
colorSchemeStorageKey,
|
|
655
|
+
defaultMode,
|
|
656
|
+
storageManager,
|
|
657
|
+
storageWindow,
|
|
658
|
+
noSsr
|
|
659
|
+
});
|
|
660
|
+
let mode = stateMode;
|
|
661
|
+
let colorScheme = stateColorScheme;
|
|
662
|
+
if (nested) {
|
|
663
|
+
mode = ctx.mode;
|
|
664
|
+
colorScheme = ctx.colorScheme;
|
|
665
|
+
}
|
|
666
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
667
|
+
if (forceThemeRerender && !restThemeProp.vars) {
|
|
668
|
+
console.warn(['MUI: The `forceThemeRerender` prop should only be used with CSS theme variables.', 'Note that it will slow down the app when changing between modes, so only do this when you cannot find a better solution.'].join('\n'));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// `colorScheme` is undefined on the server and hydration phase
|
|
673
|
+
let calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
|
|
674
|
+
if (restThemeProp.vars && !forceThemeRerender) {
|
|
675
|
+
calculatedColorScheme = restThemeProp.defaultColorScheme;
|
|
676
|
+
}
|
|
677
|
+
const memoTheme = React.useMemo(() => {
|
|
678
|
+
// 2. get the `vars` object that refers to the CSS custom properties
|
|
679
|
+
const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
|
|
680
|
+
|
|
681
|
+
// 3. Start composing the theme object
|
|
682
|
+
const theme = {
|
|
683
|
+
...restThemeProp,
|
|
684
|
+
components,
|
|
685
|
+
colorSchemes,
|
|
686
|
+
cssVarPrefix,
|
|
687
|
+
vars: themeVars
|
|
688
|
+
};
|
|
689
|
+
if (typeof theme.generateSpacing === 'function') {
|
|
690
|
+
theme.spacing = theme.generateSpacing();
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// 4. Resolve the color scheme and merge it to the theme
|
|
694
|
+
if (calculatedColorScheme) {
|
|
695
|
+
const scheme = colorSchemes[calculatedColorScheme];
|
|
696
|
+
if (scheme && typeof scheme === 'object') {
|
|
697
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
698
|
+
Object.keys(scheme).forEach(schemeKey => {
|
|
699
|
+
if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
|
|
700
|
+
// shallow merge the 1st level structure of the theme.
|
|
701
|
+
theme[schemeKey] = {
|
|
702
|
+
...theme[schemeKey],
|
|
703
|
+
...scheme[schemeKey]
|
|
704
|
+
};
|
|
705
|
+
} else {
|
|
706
|
+
theme[schemeKey] = scheme[schemeKey];
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return resolveTheme ? resolveTheme(theme) : theme;
|
|
712
|
+
}, [restThemeProp, calculatedColorScheme, components, colorSchemes, cssVarPrefix]);
|
|
713
|
+
|
|
714
|
+
// 5. Declaring effects
|
|
715
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
716
|
+
const colorSchemeSelector = restThemeProp.colorSchemeSelector;
|
|
717
|
+
useEnhancedEffect(() => {
|
|
718
|
+
if (colorScheme && colorSchemeNode && colorSchemeSelector && colorSchemeSelector !== 'media') {
|
|
719
|
+
const selector = colorSchemeSelector;
|
|
720
|
+
let rule = colorSchemeSelector;
|
|
721
|
+
if (selector === 'class') {
|
|
722
|
+
rule = `.%s`;
|
|
723
|
+
}
|
|
724
|
+
if (selector === 'data') {
|
|
725
|
+
rule = `[data-%s]`;
|
|
726
|
+
}
|
|
727
|
+
if (selector?.startsWith('data-') && !selector.includes('%s')) {
|
|
728
|
+
// 'data-mui-color-scheme' -> '[data-mui-color-scheme="%s"]'
|
|
729
|
+
rule = `[${selector}="%s"]`;
|
|
730
|
+
}
|
|
731
|
+
if (rule.startsWith('.')) {
|
|
732
|
+
colorSchemeNode.classList.remove(...allColorSchemes.map(scheme => rule.substring(1).replace('%s', scheme)));
|
|
733
|
+
colorSchemeNode.classList.add(rule.substring(1).replace('%s', colorScheme));
|
|
734
|
+
} else {
|
|
735
|
+
const matches = rule.replace('%s', colorScheme).match(/\[([^\]]+)\]/);
|
|
736
|
+
if (matches) {
|
|
737
|
+
const [attr, value] = matches[1].split('=');
|
|
738
|
+
if (!value) {
|
|
739
|
+
// for attributes like `data-theme-dark`, `data-theme-light`
|
|
740
|
+
// remove all the existing data attributes before setting the new one
|
|
741
|
+
allColorSchemes.forEach(scheme => {
|
|
742
|
+
colorSchemeNode.removeAttribute(attr.replace(colorScheme, scheme));
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
colorSchemeNode.setAttribute(attr, value ? value.replace(/"|'/g, '') : '');
|
|
746
|
+
} else {
|
|
747
|
+
colorSchemeNode.setAttribute(rule, colorScheme);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}, [colorScheme, colorSchemeSelector, colorSchemeNode, allColorSchemes]);
|
|
752
|
+
|
|
753
|
+
// 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
754
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
755
|
+
React.useEffect(() => {
|
|
756
|
+
let timer;
|
|
757
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
758
|
+
const css = documentNode.createElement('style');
|
|
759
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
760
|
+
documentNode.head.appendChild(css);
|
|
761
|
+
|
|
762
|
+
// Force browser repaint
|
|
763
|
+
(() => window.getComputedStyle(documentNode.body))();
|
|
764
|
+
timer = setTimeout(() => {
|
|
765
|
+
documentNode.head.removeChild(css);
|
|
766
|
+
}, 1);
|
|
767
|
+
}
|
|
768
|
+
return () => {
|
|
769
|
+
clearTimeout(timer);
|
|
770
|
+
};
|
|
771
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
772
|
+
React.useEffect(() => {
|
|
773
|
+
hasMounted.current = true;
|
|
774
|
+
return () => {
|
|
775
|
+
hasMounted.current = false;
|
|
776
|
+
};
|
|
777
|
+
}, []);
|
|
778
|
+
const contextValue = React.useMemo(() => ({
|
|
779
|
+
allColorSchemes,
|
|
780
|
+
colorScheme,
|
|
781
|
+
darkColorScheme,
|
|
782
|
+
lightColorScheme,
|
|
783
|
+
mode,
|
|
784
|
+
setColorScheme,
|
|
785
|
+
setMode: process.env.NODE_ENV === 'production' ? setMode : newMode => {
|
|
786
|
+
if (memoTheme.colorSchemeSelector === 'media') {
|
|
787
|
+
console.error(['MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', 'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', 'To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually'].join('\n'));
|
|
788
|
+
}
|
|
789
|
+
setMode(newMode);
|
|
790
|
+
},
|
|
791
|
+
systemMode
|
|
792
|
+
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode, memoTheme.colorSchemeSelector]);
|
|
793
|
+
let shouldGenerateStyleSheet = true;
|
|
794
|
+
if (disableStyleSheetGeneration || restThemeProp.cssVariables === false || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
|
|
795
|
+
shouldGenerateStyleSheet = false;
|
|
796
|
+
}
|
|
797
|
+
const element = /*#__PURE__*/jsxRuntimeExports.jsxs(React.Fragment, {
|
|
798
|
+
children: [/*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$1, {
|
|
799
|
+
themeId: scopedTheme ? themeId : undefined,
|
|
800
|
+
theme: memoTheme,
|
|
801
|
+
children: children
|
|
802
|
+
}), shouldGenerateStyleSheet && /*#__PURE__*/jsxRuntimeExports.jsx(GlobalStyles$1, {
|
|
803
|
+
styles: memoTheme.generateStyleSheets?.() || []
|
|
804
|
+
})]
|
|
805
|
+
});
|
|
806
|
+
if (nested) {
|
|
807
|
+
return element;
|
|
808
|
+
}
|
|
809
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx(ColorSchemeContext.Provider, {
|
|
810
|
+
value: contextValue,
|
|
811
|
+
children: element
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
815
|
+
/**
|
|
816
|
+
* The component tree.
|
|
817
|
+
*/
|
|
818
|
+
children: PropTypes.node,
|
|
819
|
+
/**
|
|
820
|
+
* The node used to attach the color-scheme attribute
|
|
821
|
+
*/
|
|
822
|
+
colorSchemeNode: PropTypes.any,
|
|
823
|
+
/**
|
|
824
|
+
* localStorage key used to store `colorScheme`
|
|
825
|
+
*/
|
|
826
|
+
colorSchemeStorageKey: PropTypes.string,
|
|
827
|
+
/**
|
|
828
|
+
* The default mode when the storage is empty,
|
|
829
|
+
* require the theme to have `colorSchemes` with light and dark.
|
|
830
|
+
*/
|
|
831
|
+
defaultMode: PropTypes.string,
|
|
832
|
+
/**
|
|
833
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
834
|
+
*/
|
|
835
|
+
disableNestedContext: PropTypes.bool,
|
|
836
|
+
/**
|
|
837
|
+
* If `true`, the style sheet won't be generated.
|
|
838
|
+
*
|
|
839
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
840
|
+
*/
|
|
841
|
+
disableStyleSheetGeneration: PropTypes.bool,
|
|
842
|
+
/**
|
|
843
|
+
* Disable CSS transitions when switching between modes or color schemes.
|
|
844
|
+
*/
|
|
845
|
+
disableTransitionOnChange: PropTypes.bool,
|
|
846
|
+
/**
|
|
847
|
+
* The document to attach the attribute to.
|
|
848
|
+
*/
|
|
849
|
+
documentNode: PropTypes.any,
|
|
850
|
+
/**
|
|
851
|
+
* If `true`, theme values are recalculated when the mode changes.
|
|
852
|
+
*/
|
|
853
|
+
forceThemeRerender: PropTypes.bool,
|
|
854
|
+
/**
|
|
855
|
+
* The key in the local storage used to store current color scheme.
|
|
856
|
+
*/
|
|
857
|
+
modeStorageKey: PropTypes.string,
|
|
858
|
+
/**
|
|
859
|
+
* If `true`, the mode will be the same value as the storage without an extra rerendering after the hydration.
|
|
860
|
+
* You should use this option in conjunction with `InitColorSchemeScript` component.
|
|
861
|
+
*/
|
|
862
|
+
noSsr: PropTypes.bool,
|
|
863
|
+
/**
|
|
864
|
+
* The storage manager to be used for storing the mode and color scheme
|
|
865
|
+
* @default using `window.localStorage`
|
|
866
|
+
*/
|
|
867
|
+
storageManager: PropTypes.func,
|
|
868
|
+
/**
|
|
869
|
+
* The window that attaches the 'storage' event listener.
|
|
870
|
+
* @default window
|
|
871
|
+
*/
|
|
872
|
+
storageWindow: PropTypes.any,
|
|
873
|
+
/**
|
|
874
|
+
* The calculated theme object that will be passed through context.
|
|
875
|
+
*/
|
|
876
|
+
theme: PropTypes.object
|
|
877
|
+
} : void 0;
|
|
878
|
+
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
879
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
880
|
+
const getInitColorSchemeScript = params => InitColorSchemeScript({
|
|
881
|
+
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
882
|
+
defaultLightColorScheme,
|
|
883
|
+
defaultDarkColorScheme,
|
|
884
|
+
modeStorageKey: defaultModeStorageKey,
|
|
885
|
+
...params
|
|
886
|
+
});
|
|
887
|
+
return {
|
|
888
|
+
CssVarsProvider,
|
|
889
|
+
useColorScheme,
|
|
890
|
+
getInitColorSchemeScript
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function ThemeProviderNoVars({
|
|
895
|
+
theme: themeInput,
|
|
896
|
+
...props
|
|
897
|
+
}) {
|
|
898
|
+
const scopedTheme = THEME_ID in themeInput ? themeInput[THEME_ID] : undefined;
|
|
899
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProvider$1, {
|
|
900
|
+
...props,
|
|
170
901
|
themeId: scopedTheme ? THEME_ID : undefined,
|
|
171
902
|
theme: scopedTheme || themeInput
|
|
172
|
-
})
|
|
903
|
+
});
|
|
173
904
|
}
|
|
174
|
-
|
|
905
|
+
|
|
906
|
+
const defaultConfig = {
|
|
907
|
+
attribute: 'data-mui-color-scheme',
|
|
908
|
+
colorSchemeStorageKey: 'mui-color-scheme',
|
|
909
|
+
defaultLightColorScheme: 'light',
|
|
910
|
+
defaultDarkColorScheme: 'dark',
|
|
911
|
+
modeStorageKey: 'mui-mode'
|
|
912
|
+
};
|
|
913
|
+
process.env.NODE_ENV !== "production" ? {
|
|
914
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
915
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
916
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
917
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
175
918
|
/**
|
|
176
|
-
*
|
|
919
|
+
* DOM attribute for applying a color scheme.
|
|
920
|
+
* @default 'data-mui-color-scheme'
|
|
921
|
+
* @example '.mode-%s' // for class based color scheme
|
|
922
|
+
* @example '[data-mode-%s]' // for data-attribute without '='
|
|
177
923
|
*/
|
|
178
|
-
|
|
924
|
+
attribute: PropTypes.string,
|
|
179
925
|
/**
|
|
180
|
-
*
|
|
926
|
+
* The node (provided as string) used to attach the color-scheme attribute.
|
|
927
|
+
* @default 'document.documentElement'
|
|
181
928
|
*/
|
|
182
|
-
|
|
929
|
+
colorSchemeNode: PropTypes.string,
|
|
930
|
+
/**
|
|
931
|
+
* localStorage key used to store `colorScheme`.
|
|
932
|
+
* @default 'mui-color-scheme'
|
|
933
|
+
*/
|
|
934
|
+
colorSchemeStorageKey: PropTypes.string,
|
|
935
|
+
/**
|
|
936
|
+
* The default color scheme to be used in dark mode.
|
|
937
|
+
* @default 'dark'
|
|
938
|
+
*/
|
|
939
|
+
defaultDarkColorScheme: PropTypes.string,
|
|
940
|
+
/**
|
|
941
|
+
* The default color scheme to be used in light mode.
|
|
942
|
+
* @default 'light'
|
|
943
|
+
*/
|
|
944
|
+
defaultLightColorScheme: PropTypes.string,
|
|
945
|
+
/**
|
|
946
|
+
* The default mode when the storage is empty (user's first visit).
|
|
947
|
+
* @default 'system'
|
|
948
|
+
*/
|
|
949
|
+
defaultMode: PropTypes.oneOf(['dark', 'light', 'system']),
|
|
950
|
+
/**
|
|
951
|
+
* localStorage key used to store `mode`.
|
|
952
|
+
* @default 'mui-mode'
|
|
953
|
+
*/
|
|
954
|
+
modeStorageKey: PropTypes.string,
|
|
955
|
+
/**
|
|
956
|
+
* Nonce string to pass to the inline script for CSP headers.
|
|
957
|
+
*/
|
|
958
|
+
nonce: PropTypes.string
|
|
183
959
|
} : void 0;
|
|
184
960
|
|
|
961
|
+
const {
|
|
962
|
+
CssVarsProvider: InternalCssVarsProvider,
|
|
963
|
+
useColorScheme,
|
|
964
|
+
getInitColorSchemeScript: deprecatedGetInitColorSchemeScript
|
|
965
|
+
} = createCssVarsProvider({
|
|
966
|
+
themeId: THEME_ID,
|
|
967
|
+
// @ts-ignore ignore module augmentation tests
|
|
968
|
+
theme: () => createTheme({
|
|
969
|
+
cssVariables: true
|
|
970
|
+
}),
|
|
971
|
+
colorSchemeStorageKey: defaultConfig.colorSchemeStorageKey,
|
|
972
|
+
modeStorageKey: defaultConfig.modeStorageKey,
|
|
973
|
+
defaultColorScheme: {
|
|
974
|
+
light: defaultConfig.defaultLightColorScheme,
|
|
975
|
+
dark: defaultConfig.defaultDarkColorScheme
|
|
976
|
+
},
|
|
977
|
+
resolveTheme: theme => {
|
|
978
|
+
const newTheme = {
|
|
979
|
+
...theme,
|
|
980
|
+
typography: createTypography(theme.palette, theme.typography)
|
|
981
|
+
};
|
|
982
|
+
newTheme.unstable_sx = function sx(props) {
|
|
983
|
+
return styleFunctionSx({
|
|
984
|
+
sx: props,
|
|
985
|
+
theme: this
|
|
986
|
+
});
|
|
987
|
+
};
|
|
988
|
+
return newTheme;
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* TODO: remove this export in v7
|
|
994
|
+
* @deprecated
|
|
995
|
+
* The `CssVarsProvider` component has been deprecated and ported into `ThemeProvider`.
|
|
996
|
+
*
|
|
997
|
+
* You should use `ThemeProvider` and `createTheme()` instead:
|
|
998
|
+
*
|
|
999
|
+
* ```diff
|
|
1000
|
+
* - import { CssVarsProvider, extendTheme } from '@mui/material/styles';
|
|
1001
|
+
* + import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
1002
|
+
*
|
|
1003
|
+
* - const theme = extendTheme();
|
|
1004
|
+
* + const theme = createTheme({
|
|
1005
|
+
* + cssVariables: true,
|
|
1006
|
+
* + colorSchemes: { light: true, dark: true },
|
|
1007
|
+
* + });
|
|
1008
|
+
*
|
|
1009
|
+
* - <CssVarsProvider theme={theme}>
|
|
1010
|
+
* + <ThemeProvider theme={theme}>
|
|
1011
|
+
* ```
|
|
1012
|
+
*
|
|
1013
|
+
* To see the full documentation, check out https://mui.com/material-ui/customization/css-theme-variables/usage/.
|
|
1014
|
+
*/
|
|
1015
|
+
const CssVarsProvider = InternalCssVarsProvider;
|
|
1016
|
+
|
|
1017
|
+
function ThemeProvider({
|
|
1018
|
+
theme,
|
|
1019
|
+
...props
|
|
1020
|
+
}) {
|
|
1021
|
+
const noVarsTheme = React.useMemo(() => {
|
|
1022
|
+
if (typeof theme === 'function') {
|
|
1023
|
+
return theme;
|
|
1024
|
+
}
|
|
1025
|
+
const muiTheme = THEME_ID in theme ? theme[THEME_ID] : theme;
|
|
1026
|
+
if (!('colorSchemes' in muiTheme)) {
|
|
1027
|
+
if (!('vars' in muiTheme)) {
|
|
1028
|
+
// For non-CSS variables themes, set `vars` to null to prevent theme inheritance from the upper theme.
|
|
1029
|
+
// The example use case is the docs demo that uses ThemeProvider to customize the theme while the upper theme is using CSS variables.
|
|
1030
|
+
return {
|
|
1031
|
+
...theme,
|
|
1032
|
+
vars: null
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
return theme;
|
|
1036
|
+
}
|
|
1037
|
+
return null;
|
|
1038
|
+
}, [theme]);
|
|
1039
|
+
if (noVarsTheme) {
|
|
1040
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx(ThemeProviderNoVars, {
|
|
1041
|
+
theme: noVarsTheme,
|
|
1042
|
+
...props
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
return /*#__PURE__*/jsxRuntimeExports.jsx(CssVarsProvider, {
|
|
1046
|
+
theme: theme,
|
|
1047
|
+
...props
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* @ignore - do not document.
|
|
1053
|
+
*/
|
|
1054
|
+
|
|
185
1055
|
// Store the license information in a global, so it can be shared
|
|
186
1056
|
// when module duplication occurs. The duplication of the modules can happen
|
|
187
1057
|
// if using multiple version of MUI X at the same time of the bundler
|
|
188
1058
|
// decide to duplicate to improve the size of the chunks.
|
|
189
1059
|
// eslint-disable-next-line no-underscore-dangle
|
|
190
|
-
|
|
1060
|
+
globalThis.__MUI_LICENSE_INFO__ = globalThis.__MUI_LICENSE_INFO__ || {
|
|
191
1061
|
key: undefined
|
|
192
1062
|
};
|
|
193
1063
|
class LicenseInfo {
|
|
194
1064
|
static getLicenseInfo() {
|
|
195
1065
|
// eslint-disable-next-line no-underscore-dangle
|
|
196
|
-
return
|
|
1066
|
+
return globalThis.__MUI_LICENSE_INFO__;
|
|
197
1067
|
}
|
|
198
1068
|
static getLicenseKey() {
|
|
199
1069
|
return LicenseInfo.getLicenseInfo().key;
|
|
@@ -316,11 +1186,11 @@ const useControlledDatagridState = _ref => {
|
|
|
316
1186
|
useEffect(() => {
|
|
317
1187
|
setPinnedColumns(propsPinnedColumns);
|
|
318
1188
|
}, [propsPinnedColumns]);
|
|
319
|
-
const onPinnedColumnsChange = (
|
|
1189
|
+
const onPinnedColumnsChange = (pinnedColumns, details) => {
|
|
320
1190
|
if (propsOnPinnedColumnsChange) {
|
|
321
|
-
propsOnPinnedColumnsChange(
|
|
1191
|
+
propsOnPinnedColumnsChange(pinnedColumns, details);
|
|
322
1192
|
} else {
|
|
323
|
-
setPinnedColumns(
|
|
1193
|
+
setPinnedColumns(pinnedColumns);
|
|
324
1194
|
}
|
|
325
1195
|
};
|
|
326
1196
|
const [sortModel, setSortModel] = useState(propsSortModel);
|