@instructure/emotion 11.7.4-snapshot-97 → 11.7.4-snapshot-100
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/CHANGELOG.md +7 -1
- package/es/styleUtils/applyColorModifiers.js +6 -8
- package/es/useComputedTheme.js +5 -4
- package/es/useStyleNew.js +3 -3
- package/es/withStyleNew.js +10 -6
- package/lib/styleUtils/applyColorModifiers.js +5 -7
- package/lib/useComputedTheme.js +5 -4
- package/lib/useStyleNew.js +3 -3
- package/lib/withStyleNew.js +10 -6
- package/package.json +10 -10
- package/src/styleUtils/applyColorModifiers.ts +12 -10
- package/src/useComputedTheme.ts +20 -17
- package/src/useStyleNew.ts +10 -7
- package/src/withStyleNew.tsx +26 -14
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/styleUtils/applyColorModifiers.d.ts.map +1 -1
- package/types/useComputedTheme.d.ts +3 -3
- package/types/useComputedTheme.d.ts.map +1 -1
- package/types/useStyleNew.d.ts.map +1 -1
- package/types/withStyleNew.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [11.7.4-snapshot-
|
|
6
|
+
## [11.7.4-snapshot-100](https://github.com/instructure/instructure-ui/compare/v11.7.3...v11.7.4-snapshot-100) (2026-07-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **emotion:** propagate resolved component theme override to wrapped component ([446e820](https://github.com/instructure/instructure-ui/commit/446e8205cb7eb8282af565530d5f82a9f2355dfa))
|
|
7
12
|
|
|
8
13
|
|
|
9
14
|
### Features
|
|
10
15
|
|
|
16
|
+
* **emotion,ui-scripts:** resolve tokens studio color modifiers and emit hex ([99141c0](https://github.com/instructure/instructure-ui/commit/99141c036c6a353c25200c57e2cd68a1bc1b8205))
|
|
11
17
|
* **emotion:** support alpha color modifier in applyColorModifiers ([c1643b3](https://github.com/instructure/instructure-ui/commit/c1643b3de2f0be084a042d8fd9478b963907da77))
|
|
12
18
|
* **ui-scripts:** refactor theme type generation and fix token fetching script ([ab0536f](https://github.com/instructure/instructure-ui/commit/ab0536f81ffe9ae60f8b8cdc5038f4f323314416))
|
|
13
19
|
|
|
@@ -21,16 +21,14 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { colorToHsla } from '@instructure/ui-color-utils';
|
|
24
|
+
import { colorToHsla, color2hex, colorToHex8 } from '@instructure/ui-color-utils';
|
|
25
25
|
// Matches Tokens Studio's HSL modifier math: move L by `amount` (0–1) of the
|
|
26
26
|
// remaining distance toward the endpoint, so the step shrinks as it approaches
|
|
27
27
|
// black/white and never overshoots.
|
|
28
28
|
const modifyLightness = (l, amount, type) => type === 'darken' ? Math.max(0, l - l * amount) : Math.min(1, l + (1 - l) * amount);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const ll = +(l * 100).toFixed(2);
|
|
33
|
-
return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
|
|
29
|
+
const formatColor = (h, s, l, a) => {
|
|
30
|
+
const hsla = `hsla(${Math.round(h)}, ${+(s * 100).toFixed(2)}%, ${+(l * 100).toFixed(2)}%, ${a})`;
|
|
31
|
+
return a < 1 ? colorToHex8(hsla) : color2hex(hsla);
|
|
34
32
|
};
|
|
35
33
|
const isModifyColor = val => typeof val === 'object' && val !== null && typeof val.value === 'string' && typeof val.modify === 'object' && val.modify !== null;
|
|
36
34
|
const resolveModifyColor = ({
|
|
@@ -45,7 +43,7 @@ const resolveModifyColor = ({
|
|
|
45
43
|
a
|
|
46
44
|
} = colorToHsla(value);
|
|
47
45
|
const newL = modifyLightness(l, modify.value, modify.type);
|
|
48
|
-
return
|
|
46
|
+
return formatColor(h, s, newL, a);
|
|
49
47
|
}
|
|
50
48
|
if (modify.type === 'alpha') {
|
|
51
49
|
const {
|
|
@@ -54,7 +52,7 @@ const resolveModifyColor = ({
|
|
|
54
52
|
l
|
|
55
53
|
} = colorToHsla(value);
|
|
56
54
|
const newA = Math.min(1, Math.max(0, Number(modify.value)));
|
|
57
|
-
return
|
|
55
|
+
return formatColor(h, s, l, newA);
|
|
58
56
|
}
|
|
59
57
|
return value;
|
|
60
58
|
};
|
package/es/useComputedTheme.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { useTheme } from '@emotion/react';
|
|
26
|
+
import { applyColorModifiers } from './styleUtils/applyColorModifiers.js';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* ---
|
|
@@ -42,12 +43,12 @@ import { useTheme } from '@emotion/react';
|
|
|
42
43
|
export const useComputedTheme = () => {
|
|
43
44
|
const rawTheme = useTheme().newTheme;
|
|
44
45
|
const primitives = rawTheme?.primitives;
|
|
45
|
-
const semantics = rawTheme?.semantics?.(primitives);
|
|
46
|
-
const components = Object.keys(rawTheme?.components).reduce((acc, component) => ({
|
|
46
|
+
const semantics = applyColorModifiers(rawTheme?.semantics?.(primitives));
|
|
47
|
+
const components = applyColorModifiers(Object.keys(rawTheme?.components).reduce((acc, component) => ({
|
|
47
48
|
...acc,
|
|
48
49
|
[component]: rawTheme.components[component]?.(semantics)
|
|
49
|
-
}), {});
|
|
50
|
-
const sharedTokens = rawTheme?.sharedTokens?.(semantics);
|
|
50
|
+
}), {}));
|
|
51
|
+
const sharedTokens = applyColorModifiers(rawTheme?.sharedTokens?.(semantics));
|
|
51
52
|
return {
|
|
52
53
|
primitives,
|
|
53
54
|
semantics,
|
package/es/useStyleNew.js
CHANGED
|
@@ -62,10 +62,10 @@ const useStyleNew = useStyleParams => {
|
|
|
62
62
|
const primitiveOverrides = themeOverrideFromProvider?.primitives;
|
|
63
63
|
const semanticsOverrides = themeOverrideFromProvider?.semantics;
|
|
64
64
|
const sharedTokensOverrides = themeOverrideFromProvider?.sharedTokens;
|
|
65
|
-
const componentOverridesFromSettingsProvider = themeOverrideFromProvider?.components?.[
|
|
65
|
+
const componentOverridesFromSettingsProvider = themeOverrideFromProvider?.components?.[componentId];
|
|
66
66
|
const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides);
|
|
67
|
-
const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
68
|
-
const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
67
|
+
const semantics = applyColorModifiers(mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides));
|
|
68
|
+
const sharedTokens = applyColorModifiers(mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides));
|
|
69
69
|
const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
|
|
70
70
|
primitives,
|
|
71
71
|
semantics,
|
package/es/withStyleNew.js
CHANGED
|
@@ -71,7 +71,8 @@ const defaultValues = {
|
|
|
71
71
|
*/
|
|
72
72
|
const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom, frozenTheme, generateComponentTheme) => {
|
|
73
73
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
74
|
-
const
|
|
74
|
+
const rawComponentId = ComposedComponent.componentId?.replace('.', '');
|
|
75
|
+
const componentId = useTokensFrom ?? rawComponentId;
|
|
75
76
|
const WithStyle = /*#__PURE__*/forwardRef((props, ref) => {
|
|
76
77
|
const themeInContext = useTheme();
|
|
77
78
|
const themeKey = themeInContext.key;
|
|
@@ -103,11 +104,11 @@ const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom,
|
|
|
103
104
|
const primitiveOverrides = themeOverride?.primitives;
|
|
104
105
|
const semanticsOverrides = themeOverride?.semantics;
|
|
105
106
|
const sharedTokensOverrides = themeOverride?.sharedTokens;
|
|
106
|
-
const componentOverridesFromSettingsProvider = themeOverride?.components?.[
|
|
107
|
+
const componentOverridesFromSettingsProvider = themeOverride?.components?.[rawComponentId] ?? {};
|
|
107
108
|
const componentOverridesFromThemeOverrideProp = componentProps.themeOverride;
|
|
108
109
|
const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides);
|
|
109
|
-
const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
110
|
-
const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
110
|
+
const semantics = applyColorModifiers(mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides));
|
|
111
|
+
const sharedTokens = applyColorModifiers(mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides));
|
|
111
112
|
// Note: Some components do not have a theme, e.g., FormFieldMessages
|
|
112
113
|
const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
|
|
113
114
|
primitives,
|
|
@@ -115,9 +116,11 @@ const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom,
|
|
|
115
116
|
sharedTokens
|
|
116
117
|
}) : theme.newTheme.components[componentId]?.(semantics));
|
|
117
118
|
const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
|
|
119
|
+
const resolvedComponentOverrideFromThemeOverrideProp = (typeof componentOverridesFromThemeOverrideProp === 'function' ? componentOverridesFromThemeOverrideProp(componentThemeFromSettingsProvider, themeInContext) : componentOverridesFromThemeOverrideProp) ?? {};
|
|
118
120
|
const componentTheme = mergeDeep(componentThemeFromSettingsProvider,
|
|
119
121
|
// @ts-ignore TODO-theme-types: fix typing
|
|
120
|
-
|
|
122
|
+
resolvedComponentOverrideFromThemeOverrideProp);
|
|
123
|
+
const derivedComponentOverride = mergeDeep(componentOverridesFromSettingsProvider, resolvedComponentOverrideFromThemeOverrideProp);
|
|
121
124
|
|
|
122
125
|
// TODO do not call here generateStyle, it does not receive the extraArgs
|
|
123
126
|
const [styles, setStyles] = useState(generateStyle ?
|
|
@@ -135,7 +138,8 @@ const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom,
|
|
|
135
138
|
ref: ref,
|
|
136
139
|
...props,
|
|
137
140
|
makeStyles: makeStyleHandler,
|
|
138
|
-
styles: styles
|
|
141
|
+
styles: styles,
|
|
142
|
+
themeOverride: derivedComponentOverride
|
|
139
143
|
});
|
|
140
144
|
});
|
|
141
145
|
hoistNonReactStatics(WithStyle, ComposedComponent);
|
|
@@ -33,11 +33,9 @@ var _uiColorUtils = require("@instructure/ui-color-utils");
|
|
|
33
33
|
// remaining distance toward the endpoint, so the step shrinks as it approaches
|
|
34
34
|
// black/white and never overshoots.
|
|
35
35
|
const modifyLightness = (l, amount, type) => type === 'darken' ? Math.max(0, l - l * amount) : Math.min(1, l + (1 - l) * amount);
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const ll = +(l * 100).toFixed(2);
|
|
40
|
-
return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
|
|
36
|
+
const formatColor = (h, s, l, a) => {
|
|
37
|
+
const hsla = `hsla(${Math.round(h)}, ${+(s * 100).toFixed(2)}%, ${+(l * 100).toFixed(2)}%, ${a})`;
|
|
38
|
+
return a < 1 ? (0, _uiColorUtils.colorToHex8)(hsla) : (0, _uiColorUtils.color2hex)(hsla);
|
|
41
39
|
};
|
|
42
40
|
const isModifyColor = val => typeof val === 'object' && val !== null && typeof val.value === 'string' && typeof val.modify === 'object' && val.modify !== null;
|
|
43
41
|
const resolveModifyColor = ({
|
|
@@ -52,7 +50,7 @@ const resolveModifyColor = ({
|
|
|
52
50
|
a
|
|
53
51
|
} = (0, _uiColorUtils.colorToHsla)(value);
|
|
54
52
|
const newL = modifyLightness(l, modify.value, modify.type);
|
|
55
|
-
return
|
|
53
|
+
return formatColor(h, s, newL, a);
|
|
56
54
|
}
|
|
57
55
|
if (modify.type === 'alpha') {
|
|
58
56
|
const {
|
|
@@ -61,7 +59,7 @@ const resolveModifyColor = ({
|
|
|
61
59
|
l
|
|
62
60
|
} = (0, _uiColorUtils.colorToHsla)(value);
|
|
63
61
|
const newA = Math.min(1, Math.max(0, Number(modify.value)));
|
|
64
|
-
return
|
|
62
|
+
return formatColor(h, s, l, newA);
|
|
65
63
|
}
|
|
66
64
|
return value;
|
|
67
65
|
};
|
package/lib/useComputedTheme.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useComputedTheme = void 0;
|
|
7
7
|
var _react = require("@emotion/react");
|
|
8
|
+
var _applyColorModifiers = require("./styleUtils/applyColorModifiers.js");
|
|
8
9
|
/*
|
|
9
10
|
* The MIT License (MIT)
|
|
10
11
|
*
|
|
@@ -47,12 +48,12 @@ var _react = require("@emotion/react");
|
|
|
47
48
|
const useComputedTheme = () => {
|
|
48
49
|
const rawTheme = (0, _react.useTheme)().newTheme;
|
|
49
50
|
const primitives = rawTheme?.primitives;
|
|
50
|
-
const semantics = rawTheme?.semantics?.(primitives);
|
|
51
|
-
const components = Object.keys(rawTheme?.components).reduce((acc, component) => ({
|
|
51
|
+
const semantics = (0, _applyColorModifiers.applyColorModifiers)(rawTheme?.semantics?.(primitives));
|
|
52
|
+
const components = (0, _applyColorModifiers.applyColorModifiers)(Object.keys(rawTheme?.components).reduce((acc, component) => ({
|
|
52
53
|
...acc,
|
|
53
54
|
[component]: rawTheme.components[component]?.(semantics)
|
|
54
|
-
}), {});
|
|
55
|
-
const sharedTokens = rawTheme?.sharedTokens?.(semantics);
|
|
55
|
+
}), {}));
|
|
56
|
+
const sharedTokens = (0, _applyColorModifiers.applyColorModifiers)(rawTheme?.sharedTokens?.(semantics));
|
|
56
57
|
return {
|
|
57
58
|
primitives,
|
|
58
59
|
semantics,
|
package/lib/useStyleNew.js
CHANGED
|
@@ -67,10 +67,10 @@ const useStyleNew = useStyleParams => {
|
|
|
67
67
|
const primitiveOverrides = themeOverrideFromProvider?.primitives;
|
|
68
68
|
const semanticsOverrides = themeOverrideFromProvider?.semantics;
|
|
69
69
|
const sharedTokensOverrides = themeOverrideFromProvider?.sharedTokens;
|
|
70
|
-
const componentOverridesFromSettingsProvider = themeOverrideFromProvider?.components?.[
|
|
70
|
+
const componentOverridesFromSettingsProvider = themeOverrideFromProvider?.components?.[componentId];
|
|
71
71
|
const primitives = (0, _mergeDeep.mergeDeep)(theme.newTheme.primitives, primitiveOverrides);
|
|
72
|
-
const semantics = (0, _mergeDeep.mergeDeep)(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
73
|
-
const sharedTokens = (0, _mergeDeep.mergeDeep)(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
72
|
+
const semantics = (0, _applyColorModifiers.applyColorModifiers)((0, _mergeDeep.mergeDeep)(theme.newTheme.semantics?.(primitives), semanticsOverrides));
|
|
73
|
+
const sharedTokens = (0, _applyColorModifiers.applyColorModifiers)((0, _mergeDeep.mergeDeep)(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides));
|
|
74
74
|
const baseComponentTheme = (0, _applyColorModifiers.applyColorModifiers)(generateComponentTheme ? generateComponentTheme({
|
|
75
75
|
primitives,
|
|
76
76
|
semantics,
|
package/lib/withStyleNew.js
CHANGED
|
@@ -79,7 +79,8 @@ const defaultValues = {
|
|
|
79
79
|
*/
|
|
80
80
|
const withStyleNew = exports.withStyleNew = (0, _decorator.decorator)((ComposedComponent, generateStyle, useTokensFrom, frozenTheme, generateComponentTheme) => {
|
|
81
81
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
82
|
-
const
|
|
82
|
+
const rawComponentId = ComposedComponent.componentId?.replace('.', '');
|
|
83
|
+
const componentId = useTokensFrom ?? rawComponentId;
|
|
83
84
|
const WithStyle = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
84
85
|
const themeInContext = (0, _useTheme.useTheme)();
|
|
85
86
|
const themeKey = themeInContext.key;
|
|
@@ -111,11 +112,11 @@ const withStyleNew = exports.withStyleNew = (0, _decorator.decorator)((ComposedC
|
|
|
111
112
|
const primitiveOverrides = themeOverride?.primitives;
|
|
112
113
|
const semanticsOverrides = themeOverride?.semantics;
|
|
113
114
|
const sharedTokensOverrides = themeOverride?.sharedTokens;
|
|
114
|
-
const componentOverridesFromSettingsProvider = themeOverride?.components?.[
|
|
115
|
+
const componentOverridesFromSettingsProvider = themeOverride?.components?.[rawComponentId] ?? {};
|
|
115
116
|
const componentOverridesFromThemeOverrideProp = componentProps.themeOverride;
|
|
116
117
|
const primitives = (0, _mergeDeep.mergeDeep)(theme.newTheme.primitives, primitiveOverrides);
|
|
117
|
-
const semantics = (0, _mergeDeep.mergeDeep)(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
118
|
-
const sharedTokens = (0, _mergeDeep.mergeDeep)(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
118
|
+
const semantics = (0, _applyColorModifiers.applyColorModifiers)((0, _mergeDeep.mergeDeep)(theme.newTheme.semantics?.(primitives), semanticsOverrides));
|
|
119
|
+
const sharedTokens = (0, _applyColorModifiers.applyColorModifiers)((0, _mergeDeep.mergeDeep)(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides));
|
|
119
120
|
// Note: Some components do not have a theme, e.g., FormFieldMessages
|
|
120
121
|
const baseComponentTheme = (0, _applyColorModifiers.applyColorModifiers)(generateComponentTheme ? generateComponentTheme({
|
|
121
122
|
primitives,
|
|
@@ -123,9 +124,11 @@ const withStyleNew = exports.withStyleNew = (0, _decorator.decorator)((ComposedC
|
|
|
123
124
|
sharedTokens
|
|
124
125
|
}) : theme.newTheme.components[componentId]?.(semantics));
|
|
125
126
|
const componentThemeFromSettingsProvider = (0, _mergeDeep.mergeDeep)(baseComponentTheme, componentOverridesFromSettingsProvider);
|
|
127
|
+
const resolvedComponentOverrideFromThemeOverrideProp = (typeof componentOverridesFromThemeOverrideProp === 'function' ? componentOverridesFromThemeOverrideProp(componentThemeFromSettingsProvider, themeInContext) : componentOverridesFromThemeOverrideProp) ?? {};
|
|
126
128
|
const componentTheme = (0, _mergeDeep.mergeDeep)(componentThemeFromSettingsProvider,
|
|
127
129
|
// @ts-ignore TODO-theme-types: fix typing
|
|
128
|
-
|
|
130
|
+
resolvedComponentOverrideFromThemeOverrideProp);
|
|
131
|
+
const derivedComponentOverride = (0, _mergeDeep.mergeDeep)(componentOverridesFromSettingsProvider, resolvedComponentOverrideFromThemeOverrideProp);
|
|
129
132
|
|
|
130
133
|
// TODO do not call here generateStyle, it does not receive the extraArgs
|
|
131
134
|
const [styles, setStyles] = (0, _react.useState)(generateStyle ?
|
|
@@ -143,7 +146,8 @@ const withStyleNew = exports.withStyleNew = (0, _decorator.decorator)((ComposedC
|
|
|
143
146
|
ref: ref,
|
|
144
147
|
...props,
|
|
145
148
|
makeStyles: makeStyleHandler,
|
|
146
|
-
styles: styles
|
|
149
|
+
styles: styles,
|
|
150
|
+
themeOverride: derivedComponentOverride
|
|
147
151
|
});
|
|
148
152
|
});
|
|
149
153
|
(0, _hoistNonReactStatics.default)(WithStyle, ComposedComponent);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/emotion",
|
|
3
|
-
"version": "11.7.4-snapshot-
|
|
3
|
+
"version": "11.7.4-snapshot-100",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"@babel/runtime": "^7.29.7",
|
|
18
18
|
"@emotion/react": "^11",
|
|
19
19
|
"hoist-non-react-statics": "^3.3.2",
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-
|
|
24
|
-
"@instructure/ui-decorator": "11.7.4-snapshot-
|
|
25
|
-
"@instructure/ui-
|
|
26
|
-
"@instructure/ui-utils": "11.7.4-snapshot-
|
|
27
|
-
"@instructure/ui-
|
|
20
|
+
"@instructure/console": "11.7.4-snapshot-100",
|
|
21
|
+
"@instructure/ui-color-utils": "11.7.4-snapshot-100",
|
|
22
|
+
"@instructure/shared-types": "11.7.4-snapshot-100",
|
|
23
|
+
"@instructure/ui-i18n": "11.7.4-snapshot-100",
|
|
24
|
+
"@instructure/ui-decorator": "11.7.4-snapshot-100",
|
|
25
|
+
"@instructure/ui-themes": "11.7.4-snapshot-100",
|
|
26
|
+
"@instructure/ui-utils": "11.7.4-snapshot-100",
|
|
27
|
+
"@instructure/ui-react-utils": "11.7.4-snapshot-100"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/hoist-non-react-statics": "^3.3.7",
|
|
34
34
|
"react-dom": "18.3.1",
|
|
35
35
|
"vitest": "^4.1.9",
|
|
36
|
-
"@instructure/ui-babel-preset": "11.7.4-snapshot-
|
|
36
|
+
"@instructure/ui-babel-preset": "11.7.4-snapshot-100"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": ">=18 <=19"
|
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
colorToHsla,
|
|
26
|
+
color2hex,
|
|
27
|
+
colorToHex8
|
|
28
|
+
} from '@instructure/ui-color-utils'
|
|
25
29
|
|
|
26
30
|
type ModifyColor = {
|
|
27
31
|
value: string
|
|
@@ -43,13 +47,11 @@ const modifyLightness = (
|
|
|
43
47
|
? Math.max(0, l - l * amount)
|
|
44
48
|
: Math.min(1, l + (1 - l) * amount)
|
|
45
49
|
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return a < 1
|
|
51
|
-
? `hsla(${hh}, ${ss}%, ${ll}%, ${a})`
|
|
52
|
-
: `hsl(${hh}, ${ss}%, ${ll}%)`
|
|
50
|
+
const formatColor = (h: number, s: number, l: number, a: number): string => {
|
|
51
|
+
const hsla = `hsla(${Math.round(h)}, ${+(s * 100).toFixed(2)}%, ${+(
|
|
52
|
+
l * 100
|
|
53
|
+
).toFixed(2)}%, ${a})`
|
|
54
|
+
return a < 1 ? colorToHex8(hsla) : color2hex(hsla)
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
const isModifyColor = (val: unknown): val is ModifyColor =>
|
|
@@ -63,12 +65,12 @@ const resolveModifyColor = ({ value, modify }: ModifyColor): string => {
|
|
|
63
65
|
if (modify.type === 'darken' || modify.type === 'lighten') {
|
|
64
66
|
const { h, s, l, a } = colorToHsla(value)
|
|
65
67
|
const newL = modifyLightness(l, modify.value, modify.type)
|
|
66
|
-
return
|
|
68
|
+
return formatColor(h, s, newL, a)
|
|
67
69
|
}
|
|
68
70
|
if (modify.type === 'alpha') {
|
|
69
71
|
const { h, s, l } = colorToHsla(value)
|
|
70
72
|
const newA = Math.min(1, Math.max(0, Number(modify.value)))
|
|
71
|
-
return
|
|
73
|
+
return formatColor(h, s, l, newA)
|
|
72
74
|
}
|
|
73
75
|
return value
|
|
74
76
|
}
|
package/src/useComputedTheme.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { useTheme } from '@emotion/react'
|
|
26
|
+
import { applyColorModifiers } from './styleUtils/applyColorModifiers.js'
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* ---
|
|
@@ -40,23 +41,25 @@ import { useTheme } from '@emotion/react'
|
|
|
40
41
|
* `components` and `sharedTokens` of the current theme.
|
|
41
42
|
*/
|
|
42
43
|
export const useComputedTheme = () => {
|
|
43
|
-
|
|
44
|
+
const rawTheme = (useTheme() as any).newTheme
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const primitives = rawTheme?.primitives
|
|
47
|
+
const semantics = applyColorModifiers(rawTheme?.semantics?.(primitives))
|
|
48
|
+
const components = applyColorModifiers(
|
|
49
|
+
Object.keys(rawTheme?.components).reduce(
|
|
50
|
+
(acc, component) => ({
|
|
51
|
+
...acc,
|
|
52
|
+
[component]: rawTheme.components[component]?.(semantics)
|
|
53
|
+
}),
|
|
54
|
+
{}
|
|
53
55
|
)
|
|
54
|
-
|
|
56
|
+
)
|
|
57
|
+
const sharedTokens = applyColorModifiers(rawTheme?.sharedTokens?.(semantics))
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
59
|
+
return {
|
|
60
|
+
primitives,
|
|
61
|
+
semantics,
|
|
62
|
+
components,
|
|
63
|
+
sharedTokens
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/useStyleNew.ts
CHANGED
|
@@ -108,18 +108,21 @@ const useStyleNew = <
|
|
|
108
108
|
const semanticsOverrides = themeOverrideFromProvider?.semantics
|
|
109
109
|
const sharedTokensOverrides = themeOverrideFromProvider?.sharedTokens
|
|
110
110
|
const componentOverridesFromSettingsProvider =
|
|
111
|
-
themeOverrideFromProvider?.components?.[
|
|
111
|
+
themeOverrideFromProvider?.components?.[
|
|
112
|
+
componentId as keyof NewComponentTypes
|
|
113
|
+
]
|
|
112
114
|
|
|
113
115
|
const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides!)
|
|
114
116
|
|
|
115
|
-
const semantics =
|
|
116
|
-
theme.newTheme.semantics?.(primitives),
|
|
117
|
-
semanticsOverrides!
|
|
117
|
+
const semantics = applyColorModifiers(
|
|
118
|
+
mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides!)
|
|
118
119
|
)
|
|
119
120
|
|
|
120
|
-
const sharedTokens =
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const sharedTokens = applyColorModifiers(
|
|
122
|
+
mergeDeep(
|
|
123
|
+
theme.newTheme.sharedTokens?.(semantics),
|
|
124
|
+
sharedTokensOverrides as Record<string, unknown>
|
|
125
|
+
)
|
|
123
126
|
)
|
|
124
127
|
|
|
125
128
|
const baseComponentTheme = applyColorModifiers(
|
package/src/withStyleNew.tsx
CHANGED
|
@@ -132,8 +132,10 @@ const withStyleNew = decorator(
|
|
|
132
132
|
) => {
|
|
133
133
|
const displayName = ComposedComponent.displayName || ComposedComponent.name
|
|
134
134
|
|
|
135
|
-
const
|
|
136
|
-
|
|
135
|
+
const rawComponentId: keyof NewComponentTypes =
|
|
136
|
+
ComposedComponent.componentId?.replace('.', '')
|
|
137
|
+
|
|
138
|
+
const componentId: keyof NewComponentTypes = useTokensFrom ?? rawComponentId
|
|
137
139
|
|
|
138
140
|
const WithStyle: ForwardRefExoticComponent<
|
|
139
141
|
PropsWithoutRef<Props> & RefAttributes<any>
|
|
@@ -188,7 +190,7 @@ const withStyleNew = decorator(
|
|
|
188
190
|
const semanticsOverrides = themeOverride?.semantics
|
|
189
191
|
const sharedTokensOverrides = themeOverride?.sharedTokens
|
|
190
192
|
const componentOverridesFromSettingsProvider =
|
|
191
|
-
themeOverride?.components?.[
|
|
193
|
+
themeOverride?.components?.[rawComponentId] ?? {}
|
|
192
194
|
const componentOverridesFromThemeOverrideProp = (
|
|
193
195
|
componentProps as ThemeOverrideProp
|
|
194
196
|
).themeOverride
|
|
@@ -198,14 +200,15 @@ const withStyleNew = decorator(
|
|
|
198
200
|
primitiveOverrides!
|
|
199
201
|
)
|
|
200
202
|
|
|
201
|
-
const semantics =
|
|
202
|
-
theme.newTheme.semantics?.(primitives),
|
|
203
|
-
semanticsOverrides!
|
|
203
|
+
const semantics = applyColorModifiers(
|
|
204
|
+
mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides!)
|
|
204
205
|
)
|
|
205
206
|
|
|
206
|
-
const sharedTokens =
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
const sharedTokens = applyColorModifiers(
|
|
208
|
+
mergeDeep(
|
|
209
|
+
theme.newTheme.sharedTokens?.(semantics),
|
|
210
|
+
sharedTokensOverrides as Record<string, unknown>
|
|
211
|
+
)
|
|
209
212
|
) as SharedTokens
|
|
210
213
|
// Note: Some components do not have a theme, e.g., FormFieldMessages
|
|
211
214
|
const baseComponentTheme = applyColorModifiers(
|
|
@@ -222,15 +225,23 @@ const withStyleNew = decorator(
|
|
|
222
225
|
componentOverridesFromSettingsProvider as Record<string, unknown>
|
|
223
226
|
)
|
|
224
227
|
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
// @ts-ignore TODO-theme-types: fix typing
|
|
228
|
-
typeof componentOverridesFromThemeOverrideProp === 'function'
|
|
228
|
+
const resolvedComponentOverrideFromThemeOverrideProp =
|
|
229
|
+
(typeof componentOverridesFromThemeOverrideProp === 'function'
|
|
229
230
|
? componentOverridesFromThemeOverrideProp(
|
|
230
231
|
componentThemeFromSettingsProvider,
|
|
231
232
|
themeInContext
|
|
232
233
|
)
|
|
233
|
-
: componentOverridesFromThemeOverrideProp
|
|
234
|
+
: componentOverridesFromThemeOverrideProp) ?? {}
|
|
235
|
+
|
|
236
|
+
const componentTheme = mergeDeep(
|
|
237
|
+
componentThemeFromSettingsProvider,
|
|
238
|
+
// @ts-ignore TODO-theme-types: fix typing
|
|
239
|
+
resolvedComponentOverrideFromThemeOverrideProp
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
const derivedComponentOverride = mergeDeep(
|
|
243
|
+
componentOverridesFromSettingsProvider,
|
|
244
|
+
resolvedComponentOverrideFromThemeOverrideProp
|
|
234
245
|
)
|
|
235
246
|
|
|
236
247
|
// TODO do not call here generateStyle, it does not receive the extraArgs
|
|
@@ -260,6 +271,7 @@ const withStyleNew = decorator(
|
|
|
260
271
|
{...props}
|
|
261
272
|
makeStyles={makeStyleHandler}
|
|
262
273
|
styles={styles}
|
|
274
|
+
themeOverride={derivedComponentOverride}
|
|
263
275
|
/>
|
|
264
276
|
)
|
|
265
277
|
})
|