@mui/system 5.10.16 → 5.10.17
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/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +74 -0
- package/Container/Container.d.ts +13 -13
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/createContainer.d.ts +18 -18
- package/Stack/Stack.d.ts +13 -13
- package/Stack/StackProps.d.ts +42 -42
- package/Stack/createStack.d.ts +21 -21
- package/Stack/index.d.ts +5 -5
- package/Stack/stackClasses.d.ts +8 -8
- package/Unstable_Grid/Grid.d.ts +12 -12
- package/Unstable_Grid/GridProps.d.ts +162 -162
- package/Unstable_Grid/createGrid.d.ts +11 -11
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridGenerator.d.ts +29 -29
- package/Unstable_Grid/index.d.ts +5 -5
- package/colorManipulator.d.ts +10 -0
- package/colorManipulator.js +57 -1
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +54 -1
- package/cssVars/createCssVarsProvider.js +47 -13
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +63 -63
- package/cssVars/getInitColorSchemeScript.d.ts +42 -42
- package/cssVars/index.d.ts +3 -3
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/colorManipulator.js +50 -0
- package/esm/cssVars/createCssVarsProvider.js +47 -13
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/colorManipulator.js +50 -0
- package/legacy/cssVars/createCssVarsProvider.js +47 -11
- package/legacy/index.js +1 -1
- package/modern/colorManipulator.js +50 -0
- package/modern/cssVars/createCssVarsProvider.js +47 -13
- package/modern/index.js +1 -1
- package/package.json +1 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -66,7 +66,7 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
|
|
|
66
66
|
* The node used to attach the color-scheme attribute
|
|
67
67
|
* @default document
|
|
68
68
|
*/
|
|
69
|
-
colorSchemeNode?:
|
|
69
|
+
colorSchemeNode?: Element | null;
|
|
70
70
|
/**
|
|
71
71
|
* The CSS selector for attaching the generated custom properties
|
|
72
72
|
* @default ':root'
|
|
@@ -77,10 +77,63 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
|
|
|
77
77
|
* @default window
|
|
78
78
|
*/
|
|
79
79
|
storageWindow?: Window | null;
|
|
80
|
+
/**
|
|
81
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
82
|
+
*/
|
|
83
|
+
disableNestedContext?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* If `true`, the style sheet won't be generated.
|
|
86
|
+
*
|
|
87
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
disableStyleSheetGeneration?: boolean;
|
|
80
91
|
}
|
|
81
92
|
>,
|
|
82
93
|
) => React.ReactElement;
|
|
83
94
|
useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
|
|
95
|
+
generateCssThemeVars: (options?: {
|
|
96
|
+
/**
|
|
97
|
+
* Design system default color scheme.
|
|
98
|
+
* - provides string if the design system has one default color scheme (either light or dark)
|
|
99
|
+
* - provides object if the design system has default light & dark color schemes
|
|
100
|
+
*/
|
|
101
|
+
defaultColorScheme?: ColorScheme | { light: ColorScheme; dark: ColorScheme };
|
|
102
|
+
/**
|
|
103
|
+
* @default 'light'
|
|
104
|
+
*/
|
|
105
|
+
defaultMode?: 'light' | 'dark';
|
|
106
|
+
/**
|
|
107
|
+
* The selector for attaching CSS variables that are **outside** of `theme.colorSchemes.*`.
|
|
108
|
+
* @default ':root'
|
|
109
|
+
*/
|
|
110
|
+
rootSelector: string;
|
|
111
|
+
/**
|
|
112
|
+
* The selector for attaching CSS variables that are **outside** of `theme.colorSchemes.*`.
|
|
113
|
+
* @default (key) => `[data-color-scheme="${key}"]`
|
|
114
|
+
*/
|
|
115
|
+
colorSchemeSelector: (key: ColorScheme) => string;
|
|
116
|
+
/**
|
|
117
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
118
|
+
* `keys` is an array that represents the object path keys.
|
|
119
|
+
* Ex, if the theme is { foo: { bar: 'var(--test)' } }
|
|
120
|
+
* then, keys = ['foo', 'bar']
|
|
121
|
+
* value = 'var(--test)'
|
|
122
|
+
*/
|
|
123
|
+
shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Controlled mode. If not provided, it will try to read the value from the upper CssVarsProvider.
|
|
126
|
+
*/
|
|
127
|
+
mode?: Mode;
|
|
128
|
+
/**
|
|
129
|
+
* Controlled color scheme. If not provided, it will try to read the value from the upper CssVarsProvider.
|
|
130
|
+
*/
|
|
131
|
+
colorScheme?: ColorScheme;
|
|
132
|
+
theme?: {
|
|
133
|
+
cssVarPrefix?: string;
|
|
134
|
+
colorSchemes: Record<ColorScheme, Record<string, any>>;
|
|
135
|
+
};
|
|
136
|
+
}) => Record<string, any>;
|
|
84
137
|
getInitColorSchemeScript: typeof getInitColorSchemeScript;
|
|
85
138
|
}
|
|
86
139
|
|
|
@@ -12,6 +12,7 @@ var _utils = require("@mui/utils");
|
|
|
12
12
|
var React = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
14
|
var _styledEngine = require("@mui/styled-engine");
|
|
15
|
+
var _privateTheming = require("@mui/private-theming");
|
|
15
16
|
var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
|
|
16
17
|
var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
|
|
17
18
|
var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
|
|
@@ -59,9 +60,14 @@ function createCssVarsProvider(options) {
|
|
|
59
60
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
60
61
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
61
62
|
colorSchemeSelector = ':root',
|
|
62
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
63
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
64
|
+
disableNestedContext = false,
|
|
65
|
+
disableStyleSheetGeneration = false
|
|
63
66
|
}) {
|
|
64
67
|
const hasMounted = React.useRef(false);
|
|
68
|
+
const upperTheme = (0, _privateTheming.useTheme)();
|
|
69
|
+
const ctx = React.useContext(ColorSchemeContext);
|
|
70
|
+
const nested = !!ctx && !disableNestedContext;
|
|
65
71
|
const {
|
|
66
72
|
colorSchemes = {},
|
|
67
73
|
components = {},
|
|
@@ -74,12 +80,12 @@ function createCssVarsProvider(options) {
|
|
|
74
80
|
|
|
75
81
|
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
76
82
|
const {
|
|
77
|
-
mode,
|
|
83
|
+
mode: stateMode,
|
|
78
84
|
setMode,
|
|
79
85
|
systemMode,
|
|
80
86
|
lightColorScheme,
|
|
81
87
|
darkColorScheme,
|
|
82
|
-
colorScheme,
|
|
88
|
+
colorScheme: stateColorScheme,
|
|
83
89
|
setColorScheme
|
|
84
90
|
} = (0, _useCurrentColorScheme.default)({
|
|
85
91
|
supportedColorSchemes: allColorSchemes,
|
|
@@ -90,6 +96,12 @@ function createCssVarsProvider(options) {
|
|
|
90
96
|
defaultMode,
|
|
91
97
|
storageWindow
|
|
92
98
|
});
|
|
99
|
+
let mode = stateMode;
|
|
100
|
+
let colorScheme = stateColorScheme;
|
|
101
|
+
if (nested) {
|
|
102
|
+
mode = ctx.mode;
|
|
103
|
+
colorScheme = ctx.colorScheme;
|
|
104
|
+
}
|
|
93
105
|
const calculatedMode = (() => {
|
|
94
106
|
if (!mode) {
|
|
95
107
|
// This scope occurs on the server
|
|
@@ -226,21 +238,33 @@ function createCssVarsProvider(options) {
|
|
|
226
238
|
setColorScheme,
|
|
227
239
|
allColorSchemes
|
|
228
240
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
241
|
+
let shouldGenerateStyleSheet = true;
|
|
242
|
+
if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
|
|
243
|
+
shouldGenerateStyleSheet = false;
|
|
244
|
+
}
|
|
245
|
+
const element = /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
|
|
246
|
+
children: [shouldGenerateStyleSheet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
|
|
247
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
248
|
+
styles: {
|
|
249
|
+
[colorSchemeSelector]: rootCss
|
|
250
|
+
}
|
|
251
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
252
|
+
styles: defaultColorSchemeStyleSheet
|
|
253
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
254
|
+
styles: otherColorSchemesStyleSheet
|
|
255
|
+
})]
|
|
239
256
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
240
257
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
241
258
|
children: children
|
|
242
259
|
})]
|
|
243
260
|
});
|
|
261
|
+
if (nested) {
|
|
262
|
+
return element;
|
|
263
|
+
}
|
|
264
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ColorSchemeContext.Provider, {
|
|
265
|
+
value: contextValue,
|
|
266
|
+
children: element
|
|
267
|
+
});
|
|
244
268
|
}
|
|
245
269
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
246
270
|
/**
|
|
@@ -271,6 +295,16 @@ function createCssVarsProvider(options) {
|
|
|
271
295
|
* The initial mode used.
|
|
272
296
|
*/
|
|
273
297
|
defaultMode: _propTypes.default.string,
|
|
298
|
+
/**
|
|
299
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
300
|
+
*/
|
|
301
|
+
disableNestedContext: _propTypes.default.bool,
|
|
302
|
+
/**
|
|
303
|
+
* If `true`, the style sheet won't be generated.
|
|
304
|
+
*
|
|
305
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
306
|
+
*/
|
|
307
|
+
disableStyleSheetGeneration: _propTypes.default.bool,
|
|
274
308
|
/**
|
|
275
309
|
* Disable CSS transitions when switching between modes or color schemes
|
|
276
310
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
-
* and they does not need to remember the prefix (defined once).
|
|
4
|
-
*/
|
|
5
|
-
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
|
|
1
|
+
/**
|
|
2
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
+
* and they does not need to remember the prefix (defined once).
|
|
4
|
+
*/
|
|
5
|
+
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
-
/**
|
|
35
|
-
* a function that parse theme and return { css, vars }
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} theme
|
|
38
|
-
* @param {{
|
|
39
|
-
* prefix?: string,
|
|
40
|
-
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
41
|
-
* }} options.
|
|
42
|
-
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
43
|
-
*
|
|
44
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* const { css, vars } = parser({
|
|
48
|
-
* fontSize: 12,
|
|
49
|
-
* lineHeight: 1.2,
|
|
50
|
-
* palette: { primary: { 500: 'var(--color)' } }
|
|
51
|
-
* }, { prefix: 'foo' })
|
|
52
|
-
*
|
|
53
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
54
|
-
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
55
|
-
*/
|
|
56
|
-
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
57
|
-
prefix?: string;
|
|
58
|
-
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
59
|
-
}): {
|
|
60
|
-
css: Record<string, string | number>;
|
|
61
|
-
vars: NestedRecord<string>;
|
|
62
|
-
};
|
|
63
|
-
export {};
|
|
1
|
+
type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{
|
|
39
|
+
* prefix?: string,
|
|
40
|
+
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
41
|
+
* }} options.
|
|
42
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
43
|
+
*
|
|
44
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const { css, vars } = parser({
|
|
48
|
+
* fontSize: 12,
|
|
49
|
+
* lineHeight: 1.2,
|
|
50
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
51
|
+
* }, { prefix: 'foo' })
|
|
52
|
+
*
|
|
53
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
54
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
55
|
+
*/
|
|
56
|
+
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
57
|
+
prefix?: string;
|
|
58
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
59
|
+
}): {
|
|
60
|
+
css: Record<string, string | number>;
|
|
61
|
+
vars: NestedRecord<string>;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
-
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
-
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
-
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The mode to be used for the first visit
|
|
8
|
-
* @default 'light'
|
|
9
|
-
*/
|
|
10
|
-
defaultMode?: 'light' | 'dark' | 'system';
|
|
11
|
-
/**
|
|
12
|
-
* The default color scheme to be used on the light mode
|
|
13
|
-
* @default 'light'
|
|
14
|
-
*/
|
|
15
|
-
defaultLightColorScheme?: string;
|
|
16
|
-
/**
|
|
17
|
-
* The default color scheme to be used on the dark mode
|
|
18
|
-
* * @default 'dark'
|
|
19
|
-
*/
|
|
20
|
-
defaultDarkColorScheme?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The node (provided as string) used to attach the color-scheme attribute
|
|
23
|
-
* @default 'document.documentElement'
|
|
24
|
-
*/
|
|
25
|
-
colorSchemeNode?: string;
|
|
26
|
-
/**
|
|
27
|
-
* localStorage key used to store `mode`
|
|
28
|
-
* @default 'mode'
|
|
29
|
-
*/
|
|
30
|
-
modeStorageKey?: string;
|
|
31
|
-
/**
|
|
32
|
-
* localStorage key used to store `colorScheme`
|
|
33
|
-
* @default 'color-scheme'
|
|
34
|
-
*/
|
|
35
|
-
colorSchemeStorageKey?: string;
|
|
36
|
-
/**
|
|
37
|
-
* DOM attribute for applying color scheme
|
|
38
|
-
* @default 'data-color-scheme'
|
|
39
|
-
*/
|
|
40
|
-
attribute?: string;
|
|
41
|
-
}
|
|
42
|
-
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
+
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
+
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
+
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The mode to be used for the first visit
|
|
8
|
+
* @default 'light'
|
|
9
|
+
*/
|
|
10
|
+
defaultMode?: 'light' | 'dark' | 'system';
|
|
11
|
+
/**
|
|
12
|
+
* The default color scheme to be used on the light mode
|
|
13
|
+
* @default 'light'
|
|
14
|
+
*/
|
|
15
|
+
defaultLightColorScheme?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The default color scheme to be used on the dark mode
|
|
18
|
+
* * @default 'dark'
|
|
19
|
+
*/
|
|
20
|
+
defaultDarkColorScheme?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The node (provided as string) used to attach the color-scheme attribute
|
|
23
|
+
* @default 'document.documentElement'
|
|
24
|
+
*/
|
|
25
|
+
colorSchemeNode?: string;
|
|
26
|
+
/**
|
|
27
|
+
* localStorage key used to store `mode`
|
|
28
|
+
* @default 'mode'
|
|
29
|
+
*/
|
|
30
|
+
modeStorageKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* localStorage key used to store `colorScheme`
|
|
33
|
+
* @default 'color-scheme'
|
|
34
|
+
*/
|
|
35
|
+
colorSchemeStorageKey?: string;
|
|
36
|
+
/**
|
|
37
|
+
* DOM attribute for applying color scheme
|
|
38
|
+
* @default 'data-color-scheme'
|
|
39
|
+
*/
|
|
40
|
+
attribute?: string;
|
|
41
|
+
}
|
|
42
|
+
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
|
|
3
|
-
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
|
|
3
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
export type Mode = 'light' | 'dark' | 'system';
|
|
2
|
-
export type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
-
export interface State<SupportedColorScheme extends string> {
|
|
4
|
-
/**
|
|
5
|
-
* User selected mode.
|
|
6
|
-
* Note: on the server, mode is always undefined
|
|
7
|
-
*/
|
|
8
|
-
mode: Mode | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
-
*/
|
|
12
|
-
systemMode: SystemMode | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* The color scheme for the light mode.
|
|
15
|
-
*/
|
|
16
|
-
lightColorScheme: SupportedColorScheme;
|
|
17
|
-
/**
|
|
18
|
-
* The color scheme for the dark mode.
|
|
19
|
-
*/
|
|
20
|
-
darkColorScheme: SupportedColorScheme;
|
|
21
|
-
}
|
|
22
|
-
export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
-
/**
|
|
24
|
-
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
-
*/
|
|
26
|
-
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* `mode` is saved to internal state and localStorage
|
|
29
|
-
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
-
*/
|
|
31
|
-
setMode: (mode: Mode | null) => void;
|
|
32
|
-
/**
|
|
33
|
-
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
-
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
-
*/
|
|
36
|
-
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
-
light: SupportedColorScheme | null;
|
|
38
|
-
dark: SupportedColorScheme | null;
|
|
39
|
-
}> | null) => void;
|
|
40
|
-
};
|
|
41
|
-
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
-
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
-
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
-
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
-
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
-
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
-
defaultMode?: Mode;
|
|
48
|
-
modeStorageKey?: string;
|
|
49
|
-
colorSchemeStorageKey?: string;
|
|
50
|
-
storageWindow?: Window | null;
|
|
51
|
-
}
|
|
52
|
-
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
-
export {};
|
|
1
|
+
export type Mode = 'light' | 'dark' | 'system';
|
|
2
|
+
export type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
+
export interface State<SupportedColorScheme extends string> {
|
|
4
|
+
/**
|
|
5
|
+
* User selected mode.
|
|
6
|
+
* Note: on the server, mode is always undefined
|
|
7
|
+
*/
|
|
8
|
+
mode: Mode | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
+
*/
|
|
12
|
+
systemMode: SystemMode | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The color scheme for the light mode.
|
|
15
|
+
*/
|
|
16
|
+
lightColorScheme: SupportedColorScheme;
|
|
17
|
+
/**
|
|
18
|
+
* The color scheme for the dark mode.
|
|
19
|
+
*/
|
|
20
|
+
darkColorScheme: SupportedColorScheme;
|
|
21
|
+
}
|
|
22
|
+
export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
+
/**
|
|
24
|
+
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
+
*/
|
|
26
|
+
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `mode` is saved to internal state and localStorage
|
|
29
|
+
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
+
*/
|
|
31
|
+
setMode: (mode: Mode | null) => void;
|
|
32
|
+
/**
|
|
33
|
+
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
+
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
+
*/
|
|
36
|
+
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
+
light: SupportedColorScheme | null;
|
|
38
|
+
dark: SupportedColorScheme | null;
|
|
39
|
+
}> | null) => void;
|
|
40
|
+
};
|
|
41
|
+
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
+
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
+
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
storageWindow?: Window | null;
|
|
51
|
+
}
|
|
52
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
+
export {};
|
package/esm/colorManipulator.js
CHANGED
|
@@ -90,6 +90,16 @@ export const colorChannel = color => {
|
|
|
90
90
|
const decomposedColor = decomposeColor(color);
|
|
91
91
|
return decomposedColor.values.slice(0, 3).map((val, idx) => decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? `${val}%` : val).join(' ');
|
|
92
92
|
};
|
|
93
|
+
export const private_safeColorChannel = (color, warning) => {
|
|
94
|
+
try {
|
|
95
|
+
return colorChannel(color);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
98
|
+
console.warn(warning);
|
|
99
|
+
}
|
|
100
|
+
return color;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
93
103
|
|
|
94
104
|
/**
|
|
95
105
|
* Converts a color object with type and values to a string.
|
|
@@ -220,6 +230,16 @@ export function alpha(color, value) {
|
|
|
220
230
|
}
|
|
221
231
|
return recomposeColor(color);
|
|
222
232
|
}
|
|
233
|
+
export function private_safeAlpha(color, value, warning) {
|
|
234
|
+
try {
|
|
235
|
+
return alpha(color, value);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
238
|
+
console.warn(warning);
|
|
239
|
+
}
|
|
240
|
+
return color;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
223
243
|
|
|
224
244
|
/**
|
|
225
245
|
* Darkens a color.
|
|
@@ -239,6 +259,16 @@ export function darken(color, coefficient) {
|
|
|
239
259
|
}
|
|
240
260
|
return recomposeColor(color);
|
|
241
261
|
}
|
|
262
|
+
export function private_safeDarken(color, coefficient, warning) {
|
|
263
|
+
try {
|
|
264
|
+
return darken(color, coefficient);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
267
|
+
console.warn(warning);
|
|
268
|
+
}
|
|
269
|
+
return color;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
242
272
|
|
|
243
273
|
/**
|
|
244
274
|
* Lightens a color.
|
|
@@ -262,6 +292,16 @@ export function lighten(color, coefficient) {
|
|
|
262
292
|
}
|
|
263
293
|
return recomposeColor(color);
|
|
264
294
|
}
|
|
295
|
+
export function private_safeLighten(color, coefficient, warning) {
|
|
296
|
+
try {
|
|
297
|
+
return lighten(color, coefficient);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
300
|
+
console.warn(warning);
|
|
301
|
+
}
|
|
302
|
+
return color;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
265
305
|
|
|
266
306
|
/**
|
|
267
307
|
* Darken or lighten a color, depending on its luminance.
|
|
@@ -272,4 +312,14 @@ export function lighten(color, coefficient) {
|
|
|
272
312
|
*/
|
|
273
313
|
export function emphasize(color, coefficient = 0.15) {
|
|
274
314
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
315
|
+
}
|
|
316
|
+
export function private_safeEmphasize(color, coefficient, warning) {
|
|
317
|
+
try {
|
|
318
|
+
return private_safeEmphasize(color, coefficient);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
321
|
+
console.warn(warning);
|
|
322
|
+
}
|
|
323
|
+
return color;
|
|
324
|
+
}
|
|
275
325
|
}
|