@instructure/emotion 11.7.3-snapshot-4 → 11.7.3-snapshot-7

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 CHANGED
@@ -3,7 +3,7 @@
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.3-snapshot-4](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-4) (2026-04-28)
6
+ ## [11.7.3-snapshot-7](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-7) (2026-04-29)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/emotion
9
9
 
@@ -52,7 +52,6 @@ function InstUISettingsProvider({
52
52
  * For backward compatibility reasons, the old way of passing a partial theme to the theme prop is still supported, however only for
53
53
  * legacy (pre v11_7) components. Overriding the newTheme this way could break the system.
54
54
  */
55
-
56
55
  let providers = _jsx(DeterministicIdContextProvider, {
57
56
  instanceCounterMap: instanceCounterMap,
58
57
  children: _jsx(ThemeProvider, {
package/es/getTheme.js CHANGED
@@ -35,7 +35,10 @@ import { isBaseTheme, mergeDeep } from '@instructure/ui-utils';
35
35
  * the overrides merged together.
36
36
  *
37
37
  * @param themeOrLegacyOverride - A full theme or an override object
38
- * @param themeOverride - if provided, it means it's a new theming-system override. This will be merged into theme.themeOverride and will be treated separately from the old way of applying overrides. This override will be applied in the withStyle.ts decorator
38
+ * @param themeOverride - if provided, it means it's a new theming-system override.
39
+ * This will be merged into theme.themeOverride and will be treated separately
40
+ * from the old way of applying overrides. This override will be applied in the
41
+ * `withStyle.ts` decorator
39
42
  * @returns A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
40
43
  * This function is called by Emotion on theme provider creation, where
41
44
  * `ancestorTheme` is a theme object from an ancestor `ThemeProvider`
package/es/useStyle.js CHANGED
@@ -27,13 +27,8 @@ import { mergeDeep } from '@instructure/ui-utils';
27
27
  // returns the second parameter of a function
28
28
 
29
29
  /**
30
- * Type for a theme override
30
+ * new useStyle syntax, use this with v11.7+ themes
31
31
  */
32
-
33
- /**
34
- * new useStyle syntax, use this with v12 themes
35
- */
36
-
37
32
  // TODO: improve useStyle to handle generateStyle functions that don't
38
33
  // have a theme.
39
34
  const useStyle = useStyleParams => {
@@ -50,18 +45,14 @@ const useStyle = useStyleParams => {
50
45
  // resolving the theming functions and applying the overrides
51
46
  const primitiveOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.primitives;
52
47
  const semanticsOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.semantics;
53
- // @ts-ignore TODO-theme-types: fix typing
54
48
  const sharedTokensOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.sharedTokens;
55
- const componentOverridesFromSettingsProvider = // @ts-ignore TODO-theme-types: fix typing
56
- themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : (_themeOverrideFromPro = themeOverrideFromProvider.components) === null || _themeOverrideFromPro === void 0 ? void 0 : _themeOverrideFromPro[componentWithTokensId];
49
+ const componentOverridesFromSettingsProvider = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : (_themeOverrideFromPro = themeOverrideFromProvider.components) === null || _themeOverrideFromPro === void 0 ? void 0 : _themeOverrideFromPro[componentWithTokensId];
57
50
  const primitives = mergeDeep(themeInContext.newTheme.primitives, primitiveOverrides);
58
51
  const semantics = mergeDeep((_themeInContext$newTh = (_themeInContext$newTh2 = themeInContext.newTheme).semantics) === null || _themeInContext$newTh === void 0 ? void 0 : _themeInContext$newTh.call(_themeInContext$newTh2, primitives), semanticsOverrides);
59
52
  const sharedTokens = mergeDeep((_themeInContext$newTh3 = (_themeInContext$newTh4 = themeInContext.newTheme).sharedTokens) === null || _themeInContext$newTh3 === void 0 ? void 0 : _themeInContext$newTh3.call(_themeInContext$newTh4, semantics), sharedTokensOverrides);
60
53
  const baseComponentTheme = (_themeInContext$newTh5 = (_themeInContext$newTh6 = themeInContext.newTheme.components)[componentWithTokensId]) === null || _themeInContext$newTh5 === void 0 ? void 0 : _themeInContext$newTh5.call(_themeInContext$newTh6, semantics);
61
54
  const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
62
- const componentTheme = mergeDeep(componentThemeFromSettingsProvider,
63
- // @ts-ignore TODO-theme-types: fix typing
64
- typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
55
+ const componentTheme = mergeDeep(componentThemeFromSettingsProvider, typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
65
56
 
66
57
  // @ts-ignore TODO-theme-types: fix typing
67
58
  return generateStyle(componentTheme, params, sharedTokens);
package/es/withStyle.js CHANGED
@@ -127,14 +127,13 @@ const withStyle = decorator((ComposedComponent, generateStyle, useTokensFrom, fr
127
127
  // resolving the theming functions and applying the overrides
128
128
  const primitiveOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.primitives;
129
129
  const semanticsOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.semantics;
130
- // @ts-ignore TODO-theme-types: fix typing
131
130
  const sharedTokensOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.sharedTokens;
132
- const componentOverridesFromSettingsProvider = // @ts-ignore TODO-theme-types: fix typing
133
- themeOverride === null || themeOverride === void 0 ? void 0 : (_themeOverride$compon = themeOverride.components) === null || _themeOverride$compon === void 0 ? void 0 : _themeOverride$compon[componentId];
131
+ const componentOverridesFromSettingsProvider = themeOverride === null || themeOverride === void 0 ? void 0 : (_themeOverride$compon = themeOverride.components) === null || _themeOverride$compon === void 0 ? void 0 : _themeOverride$compon[componentId];
134
132
  const componentOverridesFromThemeOverrideProp = componentProps.themeOverride;
135
133
  const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides);
136
134
  const semantics = mergeDeep((_theme$newTheme$seman = (_theme$newTheme = theme.newTheme).semantics) === null || _theme$newTheme$seman === void 0 ? void 0 : _theme$newTheme$seman.call(_theme$newTheme, primitives), semanticsOverrides);
137
135
  const sharedTokens = mergeDeep((_theme$newTheme$share = (_theme$newTheme2 = theme.newTheme).sharedTokens) === null || _theme$newTheme$share === void 0 ? void 0 : _theme$newTheme$share.call(_theme$newTheme2, semantics), sharedTokensOverrides);
136
+ // Note: Some components do not have a theme, e.g., FormFieldMessages
138
137
  const baseComponentTheme = (_theme$newTheme$compo = (_theme$newTheme$compo2 = theme.newTheme.components)[componentId]) === null || _theme$newTheme$compo === void 0 ? void 0 : _theme$newTheme$compo.call(_theme$newTheme$compo2, semantics);
139
138
  const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
140
139
  const componentTheme = mergeDeep(componentThemeFromSettingsProvider,
@@ -59,7 +59,6 @@ function InstUISettingsProvider({
59
59
  * For backward compatibility reasons, the old way of passing a partial theme to the theme prop is still supported, however only for
60
60
  * legacy (pre v11_7) components. Overriding the newTheme this way could break the system.
61
61
  */
62
-
63
62
  let providers = (0, _jsxRuntime.jsx)(_DeterministicIdContextProvider.DeterministicIdContextProvider, {
64
63
  instanceCounterMap: instanceCounterMap,
65
64
  children: (0, _jsxRuntime.jsx)(_react2.ThemeProvider, {
package/lib/getTheme.js CHANGED
@@ -44,7 +44,10 @@ var _mergeDeep = require("@instructure/ui-utils/lib/mergeDeep.js");
44
44
  * the overrides merged together.
45
45
  *
46
46
  * @param themeOrLegacyOverride - A full theme or an override object
47
- * @param themeOverride - if provided, it means it's a new theming-system override. This will be merged into theme.themeOverride and will be treated separately from the old way of applying overrides. This override will be applied in the withStyle.ts decorator
47
+ * @param themeOverride - if provided, it means it's a new theming-system override.
48
+ * This will be merged into theme.themeOverride and will be treated separately
49
+ * from the old way of applying overrides. This override will be applied in the
50
+ * `withStyle.ts` decorator
48
51
  * @returns A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
49
52
  * This function is called by Emotion on theme provider creation, where
50
53
  * `ancestorTheme` is a theme object from an ancestor `ThemeProvider`
package/lib/useStyle.js CHANGED
@@ -33,13 +33,8 @@ var _mergeDeep = require("@instructure/ui-utils/lib/mergeDeep.js");
33
33
  // returns the second parameter of a function
34
34
 
35
35
  /**
36
- * Type for a theme override
36
+ * new useStyle syntax, use this with v11.7+ themes
37
37
  */
38
-
39
- /**
40
- * new useStyle syntax, use this with v12 themes
41
- */
42
-
43
38
  // TODO: improve useStyle to handle generateStyle functions that don't
44
39
  // have a theme.
45
40
  const useStyle = useStyleParams => {
@@ -56,18 +51,14 @@ const useStyle = useStyleParams => {
56
51
  // resolving the theming functions and applying the overrides
57
52
  const primitiveOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.primitives;
58
53
  const semanticsOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.semantics;
59
- // @ts-ignore TODO-theme-types: fix typing
60
54
  const sharedTokensOverrides = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : themeOverrideFromProvider.sharedTokens;
61
- const componentOverridesFromSettingsProvider = // @ts-ignore TODO-theme-types: fix typing
62
- themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : (_themeOverrideFromPro = themeOverrideFromProvider.components) === null || _themeOverrideFromPro === void 0 ? void 0 : _themeOverrideFromPro[componentWithTokensId];
55
+ const componentOverridesFromSettingsProvider = themeOverrideFromProvider === null || themeOverrideFromProvider === void 0 ? void 0 : (_themeOverrideFromPro = themeOverrideFromProvider.components) === null || _themeOverrideFromPro === void 0 ? void 0 : _themeOverrideFromPro[componentWithTokensId];
63
56
  const primitives = (0, _mergeDeep.mergeDeep)(themeInContext.newTheme.primitives, primitiveOverrides);
64
57
  const semantics = (0, _mergeDeep.mergeDeep)((_themeInContext$newTh = (_themeInContext$newTh2 = themeInContext.newTheme).semantics) === null || _themeInContext$newTh === void 0 ? void 0 : _themeInContext$newTh.call(_themeInContext$newTh2, primitives), semanticsOverrides);
65
58
  const sharedTokens = (0, _mergeDeep.mergeDeep)((_themeInContext$newTh3 = (_themeInContext$newTh4 = themeInContext.newTheme).sharedTokens) === null || _themeInContext$newTh3 === void 0 ? void 0 : _themeInContext$newTh3.call(_themeInContext$newTh4, semantics), sharedTokensOverrides);
66
59
  const baseComponentTheme = (_themeInContext$newTh5 = (_themeInContext$newTh6 = themeInContext.newTheme.components)[componentWithTokensId]) === null || _themeInContext$newTh5 === void 0 ? void 0 : _themeInContext$newTh5.call(_themeInContext$newTh6, semantics);
67
60
  const componentThemeFromSettingsProvider = (0, _mergeDeep.mergeDeep)(baseComponentTheme, componentOverridesFromSettingsProvider);
68
- const componentTheme = (0, _mergeDeep.mergeDeep)(componentThemeFromSettingsProvider,
69
- // @ts-ignore TODO-theme-types: fix typing
70
- typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
61
+ const componentTheme = (0, _mergeDeep.mergeDeep)(componentThemeFromSettingsProvider, typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
71
62
 
72
63
  // @ts-ignore TODO-theme-types: fix typing
73
64
  return generateStyle(componentTheme, params, sharedTokens);
package/lib/withStyle.js CHANGED
@@ -138,14 +138,13 @@ const withStyle = exports.withStyle = (0, _decorator.decorator)((ComposedCompone
138
138
  // resolving the theming functions and applying the overrides
139
139
  const primitiveOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.primitives;
140
140
  const semanticsOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.semantics;
141
- // @ts-ignore TODO-theme-types: fix typing
142
141
  const sharedTokensOverrides = themeOverride === null || themeOverride === void 0 ? void 0 : themeOverride.sharedTokens;
143
- const componentOverridesFromSettingsProvider = // @ts-ignore TODO-theme-types: fix typing
144
- themeOverride === null || themeOverride === void 0 ? void 0 : (_themeOverride$compon = themeOverride.components) === null || _themeOverride$compon === void 0 ? void 0 : _themeOverride$compon[componentId];
142
+ const componentOverridesFromSettingsProvider = themeOverride === null || themeOverride === void 0 ? void 0 : (_themeOverride$compon = themeOverride.components) === null || _themeOverride$compon === void 0 ? void 0 : _themeOverride$compon[componentId];
145
143
  const componentOverridesFromThemeOverrideProp = componentProps.themeOverride;
146
144
  const primitives = (0, _mergeDeep.mergeDeep)(theme.newTheme.primitives, primitiveOverrides);
147
145
  const semantics = (0, _mergeDeep.mergeDeep)((_theme$newTheme$seman = (_theme$newTheme = theme.newTheme).semantics) === null || _theme$newTheme$seman === void 0 ? void 0 : _theme$newTheme$seman.call(_theme$newTheme, primitives), semanticsOverrides);
148
146
  const sharedTokens = (0, _mergeDeep.mergeDeep)((_theme$newTheme$share = (_theme$newTheme2 = theme.newTheme).sharedTokens) === null || _theme$newTheme$share === void 0 ? void 0 : _theme$newTheme$share.call(_theme$newTheme2, semantics), sharedTokensOverrides);
147
+ // Note: Some components do not have a theme, e.g., FormFieldMessages
149
148
  const baseComponentTheme = (_theme$newTheme$compo = (_theme$newTheme$compo2 = theme.newTheme.components)[componentId]) === null || _theme$newTheme$compo === void 0 ? void 0 : _theme$newTheme$compo.call(_theme$newTheme$compo2, semantics);
150
149
  const componentThemeFromSettingsProvider = (0, _mergeDeep.mergeDeep)(baseComponentTheme, componentOverridesFromSettingsProvider);
151
150
  const componentTheme = (0, _mergeDeep.mergeDeep)(componentThemeFromSettingsProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/emotion",
3
- "version": "11.7.3-snapshot-4",
3
+ "version": "11.7.3-snapshot-7",
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.27.6",
18
18
  "@emotion/react": "^11",
19
19
  "hoist-non-react-statics": "^3.3.2",
20
- "@instructure/console": "11.7.3-snapshot-4",
21
- "@instructure/shared-types": "11.7.3-snapshot-4",
22
- "@instructure/ui-color-utils": "11.7.3-snapshot-4",
23
- "@instructure/ui-i18n": "11.7.3-snapshot-4",
24
- "@instructure/ui-decorator": "11.7.3-snapshot-4",
25
- "@instructure/ui-react-utils": "11.7.3-snapshot-4",
26
- "@instructure/ui-themes": "11.7.3-snapshot-4",
27
- "@instructure/ui-utils": "11.7.3-snapshot-4"
20
+ "@instructure/console": "11.7.3-snapshot-7",
21
+ "@instructure/ui-color-utils": "11.7.3-snapshot-7",
22
+ "@instructure/ui-decorator": "11.7.3-snapshot-7",
23
+ "@instructure/shared-types": "11.7.3-snapshot-7",
24
+ "@instructure/ui-i18n": "11.7.3-snapshot-7",
25
+ "@instructure/ui-react-utils": "11.7.3-snapshot-7",
26
+ "@instructure/ui-themes": "11.7.3-snapshot-7",
27
+ "@instructure/ui-utils": "11.7.3-snapshot-7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@testing-library/jest-dom": "^6.6.3",
@@ -32,7 +32,7 @@
32
32
  "@testing-library/user-event": "^14.6.1",
33
33
  "react-dom": "18.3.1",
34
34
  "vitest": "^3.2.2",
35
- "@instructure/ui-babel-preset": "11.7.3-snapshot-4"
35
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-7"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=18 <=19"
@@ -32,22 +32,61 @@ import { getTheme } from '../getTheme'
32
32
 
33
33
  import type { ThemeOrLegacyOverride } from '../EmotionTypes'
34
34
  import type { DeterministicIdProviderValue } from '@instructure/ui-react-utils'
35
+ import type { NewThemeOverrideObject, Theme } from '@instructure/ui-themes'
35
36
  declare const process: Record<string, any> | undefined
36
37
 
37
38
  type InstUIProviderProps = {
38
39
  children?: React.ReactNode
39
40
 
40
41
  /**
41
- * A full theme or an override object
42
+ * A full theme or an override object. The override only works for legacy
43
+ * (v11.6 or earlier) themes, for newer ones use the `themeOverride` prop.
42
44
  */
43
45
  theme?: ThemeOrLegacyOverride
44
46
 
45
- // TODO-theme-types: fix override typing
46
- // TODO explain the usage of this override object. It will be deep merged into theme.themeOverride and the shape has to be a partial of the "newTheme" object
47
47
  /**
48
- * An override object for the new theming system.
48
+ * An override object for the new theming system. It will be deep merged into
49
+ * the theme. One can override primitives, semantics and individual component's
50
+ * themes, for example:
51
+ * ```js
52
+ * themeOverride={{
53
+ * semantics: {
54
+ * color: {
55
+ * stroke: {
56
+ * error: 'purple'
57
+ * }
58
+ * }
59
+ * },
60
+ * primitives: {
61
+ * color: {
62
+ * blue: {
63
+ * blue100: 'yellow'
64
+ * }
65
+ * }
66
+ * },
67
+ * components: {
68
+ * Alert: {
69
+ * background: 'brown',
70
+ * infoIconBackground: 'darkblue',
71
+ * borderWidth: '0.5rem'
72
+ * },
73
+ * Pill: {
74
+ * baseTextColor: 'purple',
75
+ * baseBorderColor: 'purple'
76
+ * }
77
+ * },
78
+ * sharedTokens: {
79
+ * focusOutline: {
80
+ * width: '0.55rem',
81
+ * infoColor: 'deeppink'
82
+ * }
83
+ * }
84
+ * }}
85
+ * ```
49
86
  */
50
- themeOverride?: any
87
+ themeOverride?:
88
+ | NewThemeOverrideObject
89
+ | ((theme: Theme) => NewThemeOverrideObject)
51
90
 
52
91
  /**
53
92
  * @deprecated the `instanceCounterMap` prop is deprecated. You don't need to supply the
@@ -100,7 +139,6 @@ function InstUISettingsProvider({
100
139
  * For backward compatibility reasons, the old way of passing a partial theme to the theme prop is still supported, however only for
101
140
  * legacy (pre v11_7) components. Overriding the newTheme this way could break the system.
102
141
  */
103
-
104
142
  let providers = (
105
143
  <DeterministicIdContextProvider instanceCounterMap={instanceCounterMap}>
106
144
  <ThemeProvider theme={getTheme(theme, themeOverride)}>
@@ -120,3 +158,4 @@ function InstUISettingsProvider({
120
158
 
121
159
  export default InstUISettingsProvider
122
160
  export { InstUISettingsProvider }
161
+ export type { InstUIProviderProps }
@@ -29,7 +29,7 @@ import type {
29
29
  } from './EmotionTypes'
30
30
  import type { ComponentTheme } from '@instructure/shared-types'
31
31
  import { ThemeOverrideProp } from './withStyle'
32
- import { ThemeOverrideValue } from './useStyle'
32
+ import type { NewComponentTypes } from '@instructure/ui-themes'
33
33
 
34
34
  type ComponentName = keyof ComponentOverride | undefined
35
35
 
@@ -51,8 +51,10 @@ const getComponentThemeOverride = (
51
51
  theme: ThemeOverride,
52
52
  displayName: string,
53
53
  componentId?: string,
54
- // ThemeOverrideProp is the old type, ThemeOverrideValue is the new one
55
- themeOverride?: ThemeOverrideProp['themeOverride'] | ThemeOverrideValue,
54
+ // ThemeOverrideProp['themeOverride'] is the old type
55
+ themeOverride?:
56
+ | ThemeOverrideProp['themeOverride']
57
+ | ReturnType<NewComponentTypes[keyof NewComponentTypes]>,
56
58
  componentTheme?: ComponentTheme
57
59
  ): Partial<ComponentTheme> => {
58
60
  const name = displayName as ComponentName
package/src/getTheme.ts CHANGED
@@ -24,13 +24,14 @@
24
24
  import canvas from '@instructure/ui-themes'
25
25
  import { isBaseTheme, mergeDeep } from '@instructure/ui-utils'
26
26
 
27
- import type { BaseTheme } from '@instructure/shared-types'
27
+ import type { Theme } from '@instructure/ui-themes'
28
28
 
29
29
  import type {
30
30
  Overrides,
31
31
  ThemeOrLegacyOverride,
32
32
  SpecificThemeOverride
33
33
  } from './EmotionTypes'
34
+ import { InstUIProviderProps } from './InstUISettingsProvider'
34
35
  declare const process: Record<string, any> | undefined
35
36
 
36
37
  /**
@@ -45,14 +46,20 @@ declare const process: Record<string, any> | undefined
45
46
  * the overrides merged together.
46
47
  *
47
48
  * @param themeOrLegacyOverride - A full theme or an override object
48
- * @param themeOverride - if provided, it means it's a new theming-system override. This will be merged into theme.themeOverride and will be treated separately from the old way of applying overrides. This override will be applied in the withStyle.ts decorator
49
+ * @param themeOverride - if provided, it means it's a new theming-system override.
50
+ * This will be merged into theme.themeOverride and will be treated separately
51
+ * from the old way of applying overrides. This override will be applied in the
52
+ * `withStyle.ts` decorator
49
53
  * @returns A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
50
54
  * This function is called by Emotion on theme provider creation, where
51
55
  * `ancestorTheme` is a theme object from an ancestor `ThemeProvider`
52
56
  */
53
57
  const getTheme =
54
- (themeOrLegacyOverride: ThemeOrLegacyOverride, themeOverride?: any) =>
55
- (ancestorTheme = {} as BaseTheme) => {
58
+ (
59
+ themeOrLegacyOverride: ThemeOrLegacyOverride,
60
+ themeOverride?: InstUIProviderProps['themeOverride']
61
+ ) =>
62
+ (ancestorTheme = {} as Theme) => {
56
63
  // we need to clone the ancestor theme not to override it
57
64
  let currentTheme
58
65
  if (Object.keys(ancestorTheme).length === 0) {
package/src/index.ts CHANGED
@@ -44,9 +44,10 @@ export { useStyleLegacy } from './useStyleLegacy'
44
44
  export { useStyle } from './useStyle'
45
45
  export { useTheme } from './useTheme'
46
46
 
47
+ export type { InstUIProviderProps } from './InstUISettingsProvider'
47
48
  export type { ComponentStyle, StyleObject, Overrides } from './EmotionTypes'
48
- export type { WithStyleProps } from './withStyleLegacy'
49
- export type { ThemeOverrideValue } from './useStyle'
49
+ export type { WithStyleProps } from './withStyle'
50
+ export type { NewThemeOverrideProp } from './useStyle'
50
51
  export type {
51
52
  SpacingValues,
52
53
  Spacing,
package/src/useStyle.ts CHANGED
@@ -25,8 +25,8 @@
25
25
  import { useTheme } from './useTheme'
26
26
  import { mergeDeep } from '@instructure/ui-utils'
27
27
  import type {
28
- SharedTokens,
29
28
  NewComponentTypes,
29
+ SharedTokens,
30
30
  Theme
31
31
  } from '@instructure/ui-themes'
32
32
 
@@ -34,89 +34,84 @@ import type {
34
34
  type SecondParameter<T extends (...args: any) => any> =
35
35
  Parameters<T>[1] extends undefined ? never : Parameters<T>[1]
36
36
 
37
- type GenerateStyleParams =
38
- | ((componentTheme: any, params: any, sharedTokens: SharedTokens) => any)
39
- | ((componentTheme: any, params: any) => any)
40
- | ((componentTheme: any) => any)
37
+ type NewThemeOverrideProp<
38
+ ComponentTheme extends ReturnType<NewComponentTypes[keyof NewComponentTypes]>
39
+ > = {
40
+ themeOverride?:
41
+ | Partial<ComponentTheme>
42
+ | ((compTheme: ComponentTheme, theme: Theme) => Partial<ComponentTheme>)
43
+ }
41
44
 
42
- /**
43
- * Type for a theme override
44
- */
45
- type ThemeOverrideValue =
46
- | Partial<Theme>
45
+ type GenerateStyleFn<ComponentTheme> =
47
46
  | ((
48
- componentTheme: Theme,
49
- currentTheme: NewComponentTypes[keyof NewComponentTypes]
50
- ) => Partial<Theme>)
47
+ componentTheme: ComponentTheme,
48
+ params: any,
49
+ sharedTokens: SharedTokens
50
+ ) => any)
51
+ | ((componentTheme: ComponentTheme, params: any) => any)
52
+ | ((componentTheme: ComponentTheme) => any)
51
53
 
52
54
  /**
53
- * new useStyle syntax, use this with v12 themes
55
+ * new useStyle syntax, use this with v11.7+ themes
54
56
  */
55
-
56
57
  // TODO: improve useStyle to handle generateStyle functions that don't
57
58
  // have a theme.
58
- const useStyle = <P extends GenerateStyleParams>(useStyleParams: {
59
- generateStyle: P
60
- params?: SecondParameter<P>
59
+ const useStyle = <
60
+ ComponentTheme extends ReturnType<NewComponentTypes[keyof NewComponentTypes]>,
61
+ GenerateStyle extends GenerateStyleFn<ComponentTheme>
62
+ >(useStyleParams: {
63
+ generateStyle: GenerateStyle
64
+ params?: SecondParameter<GenerateStyle>
61
65
  // needs to be a string too because it might be a child component
62
66
  componentId: keyof NewComponentTypes | string
63
- themeOverride: ThemeOverrideValue | undefined
67
+ themeOverride?: NewThemeOverrideProp<ComponentTheme>['themeOverride']
64
68
  displayName?: string
65
- //in case of a child component needed to use it's parent's tokens, provide parent's name
69
+ //in case of a child component needed to use its parent's tokens, provide parent's name
66
70
  useTokensFrom?: keyof NewComponentTypes
67
- }): ReturnType<P> => {
71
+ }): ReturnType<GenerateStyle> => {
68
72
  const { generateStyle, params, componentId, themeOverride } = useStyleParams
69
73
  const useTokensFrom = useStyleParams.useTokensFrom
70
74
  const themeInContext = useTheme() as Theme
71
75
 
72
76
  const themeOverrideFromProvider = themeInContext.themeOverride
73
- const componentWithTokensId = useTokensFrom ?? componentId
77
+ const componentWithTokensId =
78
+ useTokensFrom ?? (componentId as keyof NewComponentTypes)
74
79
 
75
80
  // resolving the theming functions and applying the overrides
76
81
  const primitiveOverrides = themeOverrideFromProvider?.primitives
77
82
  const semanticsOverrides = themeOverrideFromProvider?.semantics
78
- // @ts-ignore TODO-theme-types: fix typing
79
83
  const sharedTokensOverrides = themeOverrideFromProvider?.sharedTokens
80
84
  const componentOverridesFromSettingsProvider =
81
- // @ts-ignore TODO-theme-types: fix typing
82
- themeOverrideFromProvider?.components?.[
83
- componentWithTokensId as keyof NewComponentTypes
84
- ]
85
+ themeOverrideFromProvider?.components?.[componentWithTokensId]
85
86
 
86
87
  const primitives = mergeDeep(
87
88
  themeInContext.newTheme.primitives,
88
- primitiveOverrides
89
+ primitiveOverrides!
89
90
  )
90
91
 
91
92
  const semantics = mergeDeep(
92
93
  themeInContext.newTheme.semantics?.(primitives),
93
- semanticsOverrides
94
+ semanticsOverrides!
94
95
  )
95
96
 
96
97
  const sharedTokens = mergeDeep(
97
98
  themeInContext.newTheme.sharedTokens?.(semantics),
98
- sharedTokensOverrides
99
+ sharedTokensOverrides as Record<string, unknown>
99
100
  )
100
101
 
101
102
  const baseComponentTheme =
102
- themeInContext.newTheme.components[
103
- componentWithTokensId as keyof NewComponentTypes
104
- ]?.(semantics)
103
+ themeInContext.newTheme.components[componentWithTokensId]?.(semantics)
105
104
 
106
105
  const componentThemeFromSettingsProvider = mergeDeep(
107
106
  baseComponentTheme,
108
- componentOverridesFromSettingsProvider
109
- )
107
+ componentOverridesFromSettingsProvider as Record<string, unknown>
108
+ ) as ComponentTheme
110
109
 
111
110
  const componentTheme = mergeDeep(
112
111
  componentThemeFromSettingsProvider,
113
- // @ts-ignore TODO-theme-types: fix typing
114
112
  typeof themeOverride === 'function'
115
- ? themeOverride(
116
- componentThemeFromSettingsProvider as Theme,
117
- themeInContext as any
118
- )
119
- : themeOverride
113
+ ? themeOverride(componentThemeFromSettingsProvider, themeInContext)
114
+ : themeOverride!
120
115
  )
121
116
 
122
117
  // @ts-ignore TODO-theme-types: fix typing
@@ -125,4 +120,4 @@ const useStyle = <P extends GenerateStyleParams>(useStyleParams: {
125
120
 
126
121
  export default useStyle
127
122
  export { useStyle }
128
- export type { ThemeOverrideValue }
123
+ export type { NewThemeOverrideProp }