@instructure/emotion 11.7.4-snapshot-11 → 11.7.4-snapshot-49
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 +5 -2
- package/LICENSE.md +1 -0
- package/es/InstUISettingsProvider/index.js +1 -1
- package/es/index.js +9 -9
- package/es/styleUtils/applyColorModifiers.js +83 -0
- package/es/styleUtils/index.js +8 -7
- package/es/styleUtils/mirrorShorthandCorners.js +1 -1
- package/es/styleUtils/mirrorShorthandEdges.js +1 -1
- package/es/useStyle.js +7 -2
- package/es/useStyleNew.js +5 -3
- package/es/withStyle.js +10 -3
- package/es/withStyleNew.js +18 -40
- package/lib/InstUISettingsProvider/index.js +1 -1
- package/lib/index.js +17 -17
- package/lib/styleUtils/applyColorModifiers.js +90 -0
- package/lib/styleUtils/index.js +7 -7
- package/lib/styleUtils/mirrorShorthandCorners.js +1 -1
- package/lib/styleUtils/mirrorShorthandEdges.js +1 -1
- package/lib/useStyle.js +2 -2
- package/lib/useStyleNew.js +4 -3
- package/lib/withStyle.js +7 -3
- package/lib/withStyleNew.js +15 -40
- package/package.json +10 -10
- package/src/InstUISettingsProvider/README.md +4 -1
- package/src/InstUISettingsProvider/index.tsx +1 -1
- package/src/getComponentThemeOverride.ts +1 -1
- package/src/getTheme.ts +1 -1
- package/src/index.ts +9 -9
- package/src/styleUtils/applyColorModifiers.ts +108 -0
- package/src/styleUtils/index.ts +7 -7
- package/src/styleUtils/mirrorShorthandCorners.ts +1 -1
- package/src/styleUtils/mirrorShorthandEdges.ts +1 -1
- package/src/useStyle.ts +2 -2
- package/src/useStyleNew.ts +7 -4
- package/src/withStyle.tsx +7 -3
- package/src/withStyleNew.tsx +22 -46
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/getComponentThemeOverride.d.ts +1 -1
- package/types/getComponentThemeOverride.d.ts.map +1 -1
- package/types/getTheme.d.ts +1 -1
- package/types/getTheme.d.ts.map +1 -1
- package/types/index.d.ts +9 -9
- package/types/index.d.ts.map +1 -1
- package/types/styleUtils/applyColorModifiers.d.ts +18 -0
- package/types/styleUtils/applyColorModifiers.d.ts.map +1 -0
- package/types/styleUtils/index.d.ts +7 -7
- package/types/styleUtils/index.d.ts.map +1 -1
- package/types/styleUtils/mirrorShorthandCorners.d.ts +1 -1
- package/types/styleUtils/mirrorShorthandCorners.d.ts.map +1 -1
- package/types/styleUtils/mirrorShorthandEdges.d.ts +1 -1
- package/types/styleUtils/mirrorShorthandEdges.d.ts.map +1 -1
- package/types/useStyleNew.d.ts.map +1 -1
- package/types/withStyle.d.ts +5 -1
- package/types/withStyle.d.ts.map +1 -1
- package/types/withStyleNew.d.ts +11 -37
- package/types/withStyleNew.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
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-49](https://github.com/instructure/instructure-ui/compare/v11.7.3...v11.7.4-snapshot-49) (2026-06-17)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **ui-scripts:** refactor theme type generation and fix token fetching script ([ab0536f](https://github.com/instructure/instructure-ui/commit/ab0536f81ffe9ae60f8b8cdc5038f4f323314416))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/LICENSE.md
CHANGED
|
@@ -26,7 +26,7 @@ import { useContext } from 'react';
|
|
|
26
26
|
import { ThemeProvider } from '@emotion/react';
|
|
27
27
|
import { TextDirectionContext } from '@instructure/ui-i18n';
|
|
28
28
|
import { DeterministicIdContextProvider } from '@instructure/ui-react-utils';
|
|
29
|
-
import { getTheme } from
|
|
29
|
+
import { getTheme } from '../getTheme.js';
|
|
30
30
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
31
31
|
/**
|
|
32
32
|
* ---
|
package/es/index.js
CHANGED
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
/// <reference types="@emotion/react/types/css-prop" />
|
|
25
25
|
|
|
26
26
|
export * from '@emotion/react';
|
|
27
|
-
export { useComputedTheme } from
|
|
28
|
-
export { InstUISettingsProvider } from
|
|
29
|
-
export { withStyle } from
|
|
30
|
-
export { getComponentThemeOverride } from
|
|
31
|
-
export { withStyleNew } from
|
|
32
|
-
export { ThemeablePropValues, makeThemeVars, getShorthandPropValue, mirrorShorthandCorners, mirrorShorthandEdges, calcSpacingFromShorthand, calcFocusOutlineStyles } from
|
|
33
|
-
export { useStyle } from
|
|
34
|
-
export { useStyleNew } from
|
|
35
|
-
export { useTheme } from
|
|
27
|
+
export { useComputedTheme } from './useComputedTheme.js';
|
|
28
|
+
export { InstUISettingsProvider } from './InstUISettingsProvider/index.js';
|
|
29
|
+
export { withStyle } from './withStyle.js';
|
|
30
|
+
export { getComponentThemeOverride } from './getComponentThemeOverride.js';
|
|
31
|
+
export { withStyleNew } from './withStyleNew.js';
|
|
32
|
+
export { ThemeablePropValues, makeThemeVars, getShorthandPropValue, mirrorShorthandCorners, mirrorShorthandEdges, calcSpacingFromShorthand, calcFocusOutlineStyles } from './styleUtils/index.js';
|
|
33
|
+
export { useStyle } from './useStyle.js';
|
|
34
|
+
export { useStyleNew } from './useStyleNew.js';
|
|
35
|
+
export { useTheme } from './useTheme.js';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import { colorToHsla } from '@instructure/ui-color-utils';
|
|
25
|
+
// Matches Tokens Studio's HSL modifier math: move L by `amount` (0–1) of the
|
|
26
|
+
// remaining distance toward the endpoint, so the step shrinks as it approaches
|
|
27
|
+
// black/white and never overshoots.
|
|
28
|
+
const modifyLightness = (l, amount, type) => type === 'darken' ? Math.max(0, l - l * amount) : Math.min(1, l + (1 - l) * amount);
|
|
29
|
+
const formatHsla = (h, s, l, a) => {
|
|
30
|
+
const hh = Math.round(h);
|
|
31
|
+
const ss = +(s * 100).toFixed(2);
|
|
32
|
+
const ll = +(l * 100).toFixed(2);
|
|
33
|
+
return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
|
|
34
|
+
};
|
|
35
|
+
const isModifyColor = val => typeof val === 'object' && val !== null && typeof val.value === 'string' && typeof val.modify === 'object' && val.modify !== null;
|
|
36
|
+
const resolveModifyColor = ({
|
|
37
|
+
value,
|
|
38
|
+
modify
|
|
39
|
+
}) => {
|
|
40
|
+
if (modify.type === 'darken' || modify.type === 'lighten') {
|
|
41
|
+
const {
|
|
42
|
+
h,
|
|
43
|
+
s,
|
|
44
|
+
l,
|
|
45
|
+
a
|
|
46
|
+
} = colorToHsla(value);
|
|
47
|
+
const newL = modifyLightness(l, modify.value, modify.type);
|
|
48
|
+
return formatHsla(h, s, newL, a);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resolves a component theme object by applying color modifiers to any entries
|
|
55
|
+
* shaped as `{ value, modify: { type, value } }`. Entries with `modify.type` of
|
|
56
|
+
* `'darken'` or `'lighten'` are transformed in HSL space using the same math
|
|
57
|
+
* Tokens Studio applies (`space: "hsl"`): `amount` is a 0–1 fraction of the
|
|
58
|
+
* remaining distance to black/white. Plain values and unrecognized modifier
|
|
59
|
+
* types are passed through unchanged. Nested plain objects are walked
|
|
60
|
+
* recursively so modifiers anywhere in the tree get resolved.
|
|
61
|
+
*
|
|
62
|
+
* @param componentTheme - Theme map whose values can be CSS strings, `ModifyColor`
|
|
63
|
+
* objects, or nested theme objects containing the same.
|
|
64
|
+
* @returns A new theme object mirroring the input shape, with every `ModifyColor`
|
|
65
|
+
* collapsed to its final resolved color string.
|
|
66
|
+
*/
|
|
67
|
+
const applyColorModifiers = componentTheme => {
|
|
68
|
+
if (componentTheme == null) return {};
|
|
69
|
+
const result = {};
|
|
70
|
+
for (const key of Object.keys(componentTheme)) {
|
|
71
|
+
const entry = componentTheme[key];
|
|
72
|
+
if (isModifyColor(entry)) {
|
|
73
|
+
result[key] = resolveModifyColor(entry);
|
|
74
|
+
} else if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
|
|
75
|
+
result[key] = applyColorModifiers(entry);
|
|
76
|
+
} else {
|
|
77
|
+
result[key] = entry;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
export default applyColorModifiers;
|
|
83
|
+
export { applyColorModifiers };
|
package/es/styleUtils/index.js
CHANGED
|
@@ -21,10 +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
|
-
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
24
|
+
|
|
25
|
+
export { ThemeablePropValues } from './ThemeablePropValues.js';
|
|
26
|
+
export { makeThemeVars } from './makeThemeVars.js';
|
|
27
|
+
export { getShorthandPropValue } from './getShorthandPropValue.js';
|
|
28
|
+
export { mirrorShorthandCorners } from './mirrorShorthandCorners.js';
|
|
29
|
+
export { mirrorShorthandEdges } from './mirrorShorthandEdges.js';
|
|
30
|
+
export { calcSpacingFromShorthand } from './calcSpacingFromShorthand.js';
|
|
31
|
+
export { calcFocusOutlineStyles } from './calcFocusOutlineStyles.js';
|
|
@@ -21,6 +21,6 @@
|
|
|
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 { mirrorShorthandCorners } from
|
|
24
|
+
import { mirrorShorthandCorners } from './mirrorShorthand.js';
|
|
25
25
|
export default mirrorShorthandCorners;
|
|
26
26
|
export { mirrorShorthandCorners };
|
|
@@ -21,6 +21,6 @@
|
|
|
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 { mirrorShorthandEdges } from
|
|
24
|
+
import { mirrorShorthandEdges } from './mirrorShorthand.js';
|
|
25
25
|
export default mirrorShorthandEdges;
|
|
26
26
|
export { mirrorShorthandEdges };
|
package/es/useStyle.js
CHANGED
|
@@ -21,10 +21,15 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
import {
|
|
24
|
+
|
|
25
|
+
import { useTheme } from './useTheme.js';
|
|
26
|
+
import { getComponentThemeOverride } from './getComponentThemeOverride.js';
|
|
27
|
+
|
|
28
|
+
// returns the second parameter of a function
|
|
29
|
+
|
|
26
30
|
// TODO this is only used by the old themes, remove when everything uses the new
|
|
27
31
|
// theming system
|
|
32
|
+
|
|
28
33
|
/*
|
|
29
34
|
* This is only used by the **old themes**, remove when everything uses the new
|
|
30
35
|
* theming system (InstUI v12)
|
package/es/useStyleNew.js
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
import { useTheme } from './useTheme.js';
|
|
25
26
|
import { mergeDeep } from '@instructure/ui-utils';
|
|
27
|
+
import { applyColorModifiers } from './styleUtils/applyColorModifiers.js';
|
|
26
28
|
|
|
27
29
|
// returns the second parameter of a function
|
|
28
30
|
|
|
@@ -64,11 +66,11 @@ const useStyleNew = useStyleParams => {
|
|
|
64
66
|
const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides);
|
|
65
67
|
const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
66
68
|
const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
67
|
-
const baseComponentTheme = generateComponentTheme ? generateComponentTheme({
|
|
69
|
+
const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
|
|
68
70
|
primitives,
|
|
69
71
|
semantics,
|
|
70
72
|
sharedTokens
|
|
71
|
-
}) : theme.newTheme.components[componentWithTokensId]?.(semantics);
|
|
73
|
+
}) : theme.newTheme.components[componentWithTokensId]?.(semantics));
|
|
72
74
|
const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
|
|
73
75
|
const componentTheme = mergeDeep(componentThemeFromSettingsProvider, typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
|
|
74
76
|
|
package/es/withStyle.js
CHANGED
|
@@ -27,9 +27,12 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
27
27
|
import { deepEqual as isEqual } from '@instructure/ui-utils';
|
|
28
28
|
import { warn } from '@instructure/console';
|
|
29
29
|
import { decorator } from '@instructure/ui-decorator';
|
|
30
|
-
import { getComponentThemeOverride } from
|
|
31
|
-
import { useTheme } from
|
|
30
|
+
import { getComponentThemeOverride } from './getComponentThemeOverride.js';
|
|
31
|
+
import { useTheme } from './useTheme.js';
|
|
32
|
+
|
|
33
|
+
// Extract is needed because it would allow number otherwise
|
|
32
34
|
// https://stackoverflow.com/a/51808262/319473
|
|
35
|
+
|
|
33
36
|
// Unique name of an InstUI component
|
|
34
37
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
35
38
|
const defaultValues = {
|
|
@@ -41,7 +44,11 @@ const defaultValues = {
|
|
|
41
44
|
* ---
|
|
42
45
|
* category: utilities/themes
|
|
43
46
|
* ---
|
|
44
|
-
*
|
|
47
|
+
* Legacy decorator for the pre-v11.7 theming system. New components should use
|
|
48
|
+
* `withStyleNew` instead. Override patterns for components decorated with
|
|
49
|
+
* `withStyle` are documented on the
|
|
50
|
+
* [Legacy theme overrides](/#legacy-theme-overrides) docs page.
|
|
51
|
+
*
|
|
45
52
|
* TODO delete when the theme migration is complete
|
|
46
53
|
*/
|
|
47
54
|
const withStyle = decorator((ComposedComponent, generateStyle, generateComponentTheme) => {
|
package/es/withStyleNew.js
CHANGED
|
@@ -27,8 +27,12 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
27
27
|
import { deepEqual as isEqual, mergeDeep } from '@instructure/ui-utils';
|
|
28
28
|
import { warn } from '@instructure/console';
|
|
29
29
|
import { decorator } from '@instructure/ui-decorator';
|
|
30
|
-
import { useTheme } from
|
|
30
|
+
import { useTheme } from './useTheme.js';
|
|
31
|
+
import { applyColorModifiers } from './styleUtils/applyColorModifiers.js';
|
|
32
|
+
|
|
33
|
+
// Extract is needed because it would allow number otherwise
|
|
31
34
|
// https://stackoverflow.com/a/51808262/319473
|
|
35
|
+
|
|
32
36
|
// Unique name of an InstUI component
|
|
33
37
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
34
38
|
const defaultValues = {
|
|
@@ -41,11 +45,9 @@ const defaultValues = {
|
|
|
41
45
|
* category: utilities/themes
|
|
42
46
|
* ---
|
|
43
47
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* As a HOC:
|
|
48
|
+
* Decorator (or HOC) that makes a component themeable using InstUI's new
|
|
49
|
+
* theming system. Injects a `makeStyles` function and the
|
|
50
|
+
* generated `styles` object as props.
|
|
49
51
|
*
|
|
50
52
|
* ```js-code
|
|
51
53
|
* import { withStyleNew } from '@instructure/emotion'
|
|
@@ -54,42 +56,18 @@ const defaultValues = {
|
|
|
54
56
|
* export default withStyleNew(generateStyle)(ExampleComponent)
|
|
55
57
|
* ```
|
|
56
58
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* ### Applying themes
|
|
61
|
-
*
|
|
62
|
-
* A themeable component’s theme can be configured via wrapping it in an
|
|
63
|
-
* [InstUISettingsProvider](InstUISettingsProvider) component, and/or set
|
|
64
|
-
* explicitly via its `themeOverride` prop.
|
|
59
|
+
* Optionally pass a `useTokensFrom` key as the second argument to consume
|
|
60
|
+
* another component's tokens (e.g. `withStyleNew(generateStyle, 'BaseButton')`).
|
|
65
61
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* With the `themeOverride` prop you can directly set/override the component theme variables declared in theme.js. It accepts an object or a function. The function has the component's theme and the currently active main theme as its parameter.
|
|
70
|
-
*
|
|
71
|
-
* See more about the overrides on the [Using theme overrides](/#using-theme-overrides) docs page.
|
|
72
|
-
*
|
|
73
|
-
* ```jsx-code
|
|
74
|
-
* {// global theme override}
|
|
75
|
-
* <InstUISettingsProvider theme={{
|
|
76
|
-
* colors: { backgroundMedium: '#888' }
|
|
77
|
-
* }}>
|
|
78
|
-
* {// component theme override}
|
|
79
|
-
* <ExampleComponent themeOverride={{ hoverColor: '#eee' }} />
|
|
80
|
-
*
|
|
81
|
-
* {// component theme override with function}
|
|
82
|
-
* <ExampleComponent themeOverride={(componentTheme, currentTheme) => ({
|
|
83
|
-
* hoverBackground: componentTheme.background,
|
|
84
|
-
* activeBackground: currentTheme.colors.backgroundBrand
|
|
85
|
-
* })} />
|
|
86
|
-
* </InstUISettingsProvider>
|
|
87
|
-
* ```
|
|
62
|
+
* Override patterns (provider-scoped, per-component, primitives / semantics /
|
|
63
|
+
* sharedTokens layers, priority rules) are documented on the
|
|
64
|
+
* [New theme overrides](/#new-theme-overrides) docs page.
|
|
88
65
|
*
|
|
89
66
|
* @module withStyleNew
|
|
90
67
|
*
|
|
91
|
-
* @param {function} generateStyle -
|
|
92
|
-
* @
|
|
68
|
+
* @param {function} generateStyle - Returns the component's style object
|
|
69
|
+
* @param {string} [useTokensFrom] - Key of another component whose tokens this one should consume
|
|
70
|
+
* @returns {ReactElement} The decorated component
|
|
93
71
|
*/
|
|
94
72
|
const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom, frozenTheme, generateComponentTheme) => {
|
|
95
73
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
@@ -131,11 +109,11 @@ const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom,
|
|
|
131
109
|
const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
132
110
|
const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
133
111
|
// Note: Some components do not have a theme, e.g., FormFieldMessages
|
|
134
|
-
const baseComponentTheme = generateComponentTheme ? generateComponentTheme({
|
|
112
|
+
const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
|
|
135
113
|
primitives,
|
|
136
114
|
semantics,
|
|
137
115
|
sharedTokens
|
|
138
|
-
}) : theme.newTheme.components[componentId]?.(semantics);
|
|
116
|
+
}) : theme.newTheme.components[componentId]?.(semantics));
|
|
139
117
|
const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
|
|
140
118
|
const componentTheme = mergeDeep(componentThemeFromSettingsProvider,
|
|
141
119
|
// @ts-ignore TODO-theme-types: fix typing
|
|
@@ -9,7 +9,7 @@ var _react = require("react");
|
|
|
9
9
|
var _react2 = require("@emotion/react");
|
|
10
10
|
var _TextDirectionContext = require("@instructure/ui-i18n/lib/TextDirectionContext.js");
|
|
11
11
|
var _DeterministicIdContextProvider = require("@instructure/ui-react-utils/lib/DeterministicIdContext/DeterministicIdContextProvider.js");
|
|
12
|
-
var _getTheme = require("../getTheme");
|
|
12
|
+
var _getTheme = require("../getTheme.js");
|
|
13
13
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
14
14
|
/*
|
|
15
15
|
* The MIT License (MIT)
|
package/lib/index.js
CHANGED
|
@@ -23,25 +23,25 @@ var _exportNames = {
|
|
|
23
23
|
Object.defineProperty(exports, "InstUISettingsProvider", {
|
|
24
24
|
enumerable: true,
|
|
25
25
|
get: function () {
|
|
26
|
-
return
|
|
26
|
+
return _index.InstUISettingsProvider;
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
Object.defineProperty(exports, "ThemeablePropValues", {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
get: function () {
|
|
32
|
-
return
|
|
32
|
+
return _index2.ThemeablePropValues;
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "calcFocusOutlineStyles", {
|
|
36
36
|
enumerable: true,
|
|
37
37
|
get: function () {
|
|
38
|
-
return
|
|
38
|
+
return _index2.calcFocusOutlineStyles;
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
Object.defineProperty(exports, "calcSpacingFromShorthand", {
|
|
42
42
|
enumerable: true,
|
|
43
43
|
get: function () {
|
|
44
|
-
return
|
|
44
|
+
return _index2.calcSpacingFromShorthand;
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
Object.defineProperty(exports, "getComponentThemeOverride", {
|
|
@@ -53,25 +53,25 @@ Object.defineProperty(exports, "getComponentThemeOverride", {
|
|
|
53
53
|
Object.defineProperty(exports, "getShorthandPropValue", {
|
|
54
54
|
enumerable: true,
|
|
55
55
|
get: function () {
|
|
56
|
-
return
|
|
56
|
+
return _index2.getShorthandPropValue;
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
Object.defineProperty(exports, "makeThemeVars", {
|
|
60
60
|
enumerable: true,
|
|
61
61
|
get: function () {
|
|
62
|
-
return
|
|
62
|
+
return _index2.makeThemeVars;
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
Object.defineProperty(exports, "mirrorShorthandCorners", {
|
|
66
66
|
enumerable: true,
|
|
67
67
|
get: function () {
|
|
68
|
-
return
|
|
68
|
+
return _index2.mirrorShorthandCorners;
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
Object.defineProperty(exports, "mirrorShorthandEdges", {
|
|
72
72
|
enumerable: true,
|
|
73
73
|
get: function () {
|
|
74
|
-
return
|
|
74
|
+
return _index2.mirrorShorthandEdges;
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
Object.defineProperty(exports, "useComputedTheme", {
|
|
@@ -122,12 +122,12 @@ Object.keys(_react).forEach(function (key) {
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
|
-
var _useComputedTheme = require("./useComputedTheme");
|
|
126
|
-
var
|
|
127
|
-
var _withStyle = require("./withStyle");
|
|
128
|
-
var _getComponentThemeOverride = require("./getComponentThemeOverride");
|
|
129
|
-
var _withStyleNew = require("./withStyleNew");
|
|
130
|
-
var
|
|
131
|
-
var _useStyle = require("./useStyle");
|
|
132
|
-
var _useStyleNew = require("./useStyleNew");
|
|
133
|
-
var _useTheme = require("./useTheme");
|
|
125
|
+
var _useComputedTheme = require("./useComputedTheme.js");
|
|
126
|
+
var _index = require("./InstUISettingsProvider/index.js");
|
|
127
|
+
var _withStyle = require("./withStyle.js");
|
|
128
|
+
var _getComponentThemeOverride = require("./getComponentThemeOverride.js");
|
|
129
|
+
var _withStyleNew = require("./withStyleNew.js");
|
|
130
|
+
var _index2 = require("./styleUtils/index.js");
|
|
131
|
+
var _useStyle = require("./useStyle.js");
|
|
132
|
+
var _useStyleNew = require("./useStyleNew.js");
|
|
133
|
+
var _useTheme = require("./useTheme.js");
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.applyColorModifiers = void 0;
|
|
7
|
+
var _uiColorUtils = require("@instructure/ui-color-utils");
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// Matches Tokens Studio's HSL modifier math: move L by `amount` (0–1) of the
|
|
33
|
+
// remaining distance toward the endpoint, so the step shrinks as it approaches
|
|
34
|
+
// black/white and never overshoots.
|
|
35
|
+
const modifyLightness = (l, amount, type) => type === 'darken' ? Math.max(0, l - l * amount) : Math.min(1, l + (1 - l) * amount);
|
|
36
|
+
const formatHsla = (h, s, l, a) => {
|
|
37
|
+
const hh = Math.round(h);
|
|
38
|
+
const ss = +(s * 100).toFixed(2);
|
|
39
|
+
const ll = +(l * 100).toFixed(2);
|
|
40
|
+
return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
|
|
41
|
+
};
|
|
42
|
+
const isModifyColor = val => typeof val === 'object' && val !== null && typeof val.value === 'string' && typeof val.modify === 'object' && val.modify !== null;
|
|
43
|
+
const resolveModifyColor = ({
|
|
44
|
+
value,
|
|
45
|
+
modify
|
|
46
|
+
}) => {
|
|
47
|
+
if (modify.type === 'darken' || modify.type === 'lighten') {
|
|
48
|
+
const {
|
|
49
|
+
h,
|
|
50
|
+
s,
|
|
51
|
+
l,
|
|
52
|
+
a
|
|
53
|
+
} = (0, _uiColorUtils.colorToHsla)(value);
|
|
54
|
+
const newL = modifyLightness(l, modify.value, modify.type);
|
|
55
|
+
return formatHsla(h, s, newL, a);
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolves a component theme object by applying color modifiers to any entries
|
|
62
|
+
* shaped as `{ value, modify: { type, value } }`. Entries with `modify.type` of
|
|
63
|
+
* `'darken'` or `'lighten'` are transformed in HSL space using the same math
|
|
64
|
+
* Tokens Studio applies (`space: "hsl"`): `amount` is a 0–1 fraction of the
|
|
65
|
+
* remaining distance to black/white. Plain values and unrecognized modifier
|
|
66
|
+
* types are passed through unchanged. Nested plain objects are walked
|
|
67
|
+
* recursively so modifiers anywhere in the tree get resolved.
|
|
68
|
+
*
|
|
69
|
+
* @param componentTheme - Theme map whose values can be CSS strings, `ModifyColor`
|
|
70
|
+
* objects, or nested theme objects containing the same.
|
|
71
|
+
* @returns A new theme object mirroring the input shape, with every `ModifyColor`
|
|
72
|
+
* collapsed to its final resolved color string.
|
|
73
|
+
*/
|
|
74
|
+
const applyColorModifiers = componentTheme => {
|
|
75
|
+
if (componentTheme == null) return {};
|
|
76
|
+
const result = {};
|
|
77
|
+
for (const key of Object.keys(componentTheme)) {
|
|
78
|
+
const entry = componentTheme[key];
|
|
79
|
+
if (isModifyColor(entry)) {
|
|
80
|
+
result[key] = resolveModifyColor(entry);
|
|
81
|
+
} else if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
|
|
82
|
+
result[key] = applyColorModifiers(entry);
|
|
83
|
+
} else {
|
|
84
|
+
result[key] = entry;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
exports.applyColorModifiers = applyColorModifiers;
|
|
90
|
+
var _default = exports.default = applyColorModifiers;
|
package/lib/styleUtils/index.js
CHANGED
|
@@ -45,10 +45,10 @@ Object.defineProperty(exports, "mirrorShorthandEdges", {
|
|
|
45
45
|
return _mirrorShorthandEdges.mirrorShorthandEdges;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
var _ThemeablePropValues = require("./ThemeablePropValues");
|
|
49
|
-
var _makeThemeVars = require("./makeThemeVars");
|
|
50
|
-
var _getShorthandPropValue = require("./getShorthandPropValue");
|
|
51
|
-
var _mirrorShorthandCorners = require("./mirrorShorthandCorners");
|
|
52
|
-
var _mirrorShorthandEdges = require("./mirrorShorthandEdges");
|
|
53
|
-
var _calcSpacingFromShorthand = require("./calcSpacingFromShorthand");
|
|
54
|
-
var _calcFocusOutlineStyles = require("./calcFocusOutlineStyles");
|
|
48
|
+
var _ThemeablePropValues = require("./ThemeablePropValues.js");
|
|
49
|
+
var _makeThemeVars = require("./makeThemeVars.js");
|
|
50
|
+
var _getShorthandPropValue = require("./getShorthandPropValue.js");
|
|
51
|
+
var _mirrorShorthandCorners = require("./mirrorShorthandCorners.js");
|
|
52
|
+
var _mirrorShorthandEdges = require("./mirrorShorthandEdges.js");
|
|
53
|
+
var _calcSpacingFromShorthand = require("./calcSpacingFromShorthand.js");
|
|
54
|
+
var _calcFocusOutlineStyles = require("./calcFocusOutlineStyles.js");
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "mirrorShorthandCorners", {
|
|
|
10
10
|
return _mirrorShorthand.mirrorShorthandCorners;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
var _mirrorShorthand = require("./mirrorShorthand");
|
|
13
|
+
var _mirrorShorthand = require("./mirrorShorthand.js");
|
|
14
14
|
/*
|
|
15
15
|
* The MIT License (MIT)
|
|
16
16
|
*
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "mirrorShorthandEdges", {
|
|
|
10
10
|
return _mirrorShorthand.mirrorShorthandEdges;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
var _mirrorShorthand = require("./mirrorShorthand");
|
|
13
|
+
var _mirrorShorthand = require("./mirrorShorthand.js");
|
|
14
14
|
/*
|
|
15
15
|
* The MIT License (MIT)
|
|
16
16
|
*
|
package/lib/useStyle.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useStyle = exports.default = void 0;
|
|
7
|
-
var _useTheme = require("./useTheme");
|
|
8
|
-
var _getComponentThemeOverride = require("./getComponentThemeOverride");
|
|
7
|
+
var _useTheme = require("./useTheme.js");
|
|
8
|
+
var _getComponentThemeOverride = require("./getComponentThemeOverride.js");
|
|
9
9
|
/*
|
|
10
10
|
* The MIT License (MIT)
|
|
11
11
|
*
|
package/lib/useStyleNew.js
CHANGED
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useStyleNew = exports.default = void 0;
|
|
7
|
-
var _useTheme = require("./useTheme");
|
|
7
|
+
var _useTheme = require("./useTheme.js");
|
|
8
8
|
var _mergeDeep = require("@instructure/ui-utils/lib/mergeDeep.js");
|
|
9
|
+
var _applyColorModifiers = require("./styleUtils/applyColorModifiers.js");
|
|
9
10
|
/*
|
|
10
11
|
* The MIT License (MIT)
|
|
11
12
|
*
|
|
@@ -70,11 +71,11 @@ const useStyleNew = useStyleParams => {
|
|
|
70
71
|
const primitives = (0, _mergeDeep.mergeDeep)(theme.newTheme.primitives, primitiveOverrides);
|
|
71
72
|
const semantics = (0, _mergeDeep.mergeDeep)(theme.newTheme.semantics?.(primitives), semanticsOverrides);
|
|
72
73
|
const sharedTokens = (0, _mergeDeep.mergeDeep)(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
|
|
73
|
-
const baseComponentTheme = generateComponentTheme ? generateComponentTheme({
|
|
74
|
+
const baseComponentTheme = (0, _applyColorModifiers.applyColorModifiers)(generateComponentTheme ? generateComponentTheme({
|
|
74
75
|
primitives,
|
|
75
76
|
semantics,
|
|
76
77
|
sharedTokens
|
|
77
|
-
}) : theme.newTheme.components[componentWithTokensId]?.(semantics);
|
|
78
|
+
}) : theme.newTheme.components[componentWithTokensId]?.(semantics));
|
|
78
79
|
const componentThemeFromSettingsProvider = (0, _mergeDeep.mergeDeep)(baseComponentTheme, componentOverridesFromSettingsProvider);
|
|
79
80
|
const componentTheme = (0, _mergeDeep.mergeDeep)(componentThemeFromSettingsProvider, typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
|
|
80
81
|
|
package/lib/withStyle.js
CHANGED
|
@@ -10,8 +10,8 @@ var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-stat
|
|
|
10
10
|
var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
|
|
11
11
|
var _console = require("@instructure/console");
|
|
12
12
|
var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
|
|
13
|
-
var _getComponentThemeOverride = require("./getComponentThemeOverride");
|
|
14
|
-
var _useTheme = require("./useTheme");
|
|
13
|
+
var _getComponentThemeOverride = require("./getComponentThemeOverride.js");
|
|
14
|
+
var _useTheme = require("./useTheme.js");
|
|
15
15
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
16
16
|
/*
|
|
17
17
|
* The MIT License (MIT)
|
|
@@ -51,7 +51,11 @@ const defaultValues = {
|
|
|
51
51
|
* ---
|
|
52
52
|
* category: utilities/themes
|
|
53
53
|
* ---
|
|
54
|
-
*
|
|
54
|
+
* Legacy decorator for the pre-v11.7 theming system. New components should use
|
|
55
|
+
* `withStyleNew` instead. Override patterns for components decorated with
|
|
56
|
+
* `withStyle` are documented on the
|
|
57
|
+
* [Legacy theme overrides](/#legacy-theme-overrides) docs page.
|
|
58
|
+
*
|
|
55
59
|
* TODO delete when the theme migration is complete
|
|
56
60
|
*/
|
|
57
61
|
const withStyle = exports.withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, generateComponentTheme) => {
|