@instructure/emotion 8.23.1-snapshot.9 → 8.24.1-snapshot.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +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
+ # [8.24.0](https://github.com/instructure/instructure-ui/compare/v8.23.0...v8.24.0) (2022-04-26)
7
+
8
+ ### Features
9
+
10
+ - **theme-registry:** add `theme-registry` pacakge ([63216ef](https://github.com/instructure/instructure-ui/commit/63216ef58cfa3d1d61f85f1d9784cddffeddad72))
11
+
6
12
  # [8.23.0](https://github.com/instructure/instructure-ui/compare/v8.22.0...v8.23.0) (2022-04-07)
7
13
 
8
14
  **Note:** Version bump only for package @instructure/emotion
package/README.md CHANGED
@@ -24,12 +24,6 @@ With this framework, each UI component can be used in isolation and support mult
24
24
 
25
25
  7. Use a popular, well maintained and broadly adopted JS design and theming library that supports runtime theme switching ([Emotion](https://emotion.sh/)).
26
26
 
27
- ### Installation
28
-
29
- ```sh
30
- yarn add @instructure/emotion
31
- ```
32
-
33
27
  ### Usage
34
28
 
35
29
  Make a component themeable with the [withStyle](#withStyle) decorator. It adds a `makeStyles` function and the generated `styles` object to the decorated Component's props.
@@ -22,17 +22,15 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
  import React from 'react';
25
- import { merge, cloneDeep } from 'lodash';
26
25
  import { ThemeProvider } from '@emotion/react';
27
- import { canvas } from '@instructure/ui-themes';
28
- const baseThemeProps = ['borders', 'breakpoints', 'colors', 'forms', 'media', 'shadows', 'spacing', 'stacking', 'transitions', 'typography'];
26
+ import { getTheme } from '../getTheme';
27
+
29
28
  /**
30
29
  * ---
31
30
  * category: components/utilities
32
31
  * ---
33
32
  * @module EmotionThemeProvider
34
33
  */
35
-
36
34
  function EmotionThemeProvider(_ref) {
37
35
  let children = _ref.children,
38
36
  _ref$theme = _ref.theme,
@@ -45,67 +43,5 @@ function EmotionThemeProvider(_ref) {
45
43
  EmotionThemeProvider.defaultProps = {
46
44
  theme: {}
47
45
  };
48
- /**
49
- * Gives back the theme object for the the provider.
50
- *
51
- * If a valid InstUI theme is given, it just returns the theme.
52
- *
53
- * If an override object is given, it returns the ancestor theme and
54
- * the overrides merged together.
55
- *
56
- * @param {object} themeOrOverride - A full theme or an override object
57
- * @returns {function} A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
58
- * @module getTheme
59
- */
60
-
61
- const getTheme = themeOrOverride => function () {
62
- var _themeOrOverride, _themeOrOverride$them;
63
-
64
- let ancestorTheme = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
65
-
66
- try {
67
- // If a valid InstUI theme is given, it just returns the theme.
68
- if (isBaseTheme(themeOrOverride)) {
69
- return themeOrOverride;
70
- }
71
- } catch {
72
- // If the prop passed is not an Object, it will throw an error.
73
- // We are using this fail-safe here for the non-TS users,
74
- // because the whole page can break without a theme.
75
- if (process.env.NODE_ENV !== 'production') {} // eslint-disable-next-line no-param-reassign
76
-
77
-
78
- themeOrOverride = {};
79
- } // we need to clone the ancestor theme not to override it
80
-
81
-
82
- let currentTheme;
83
-
84
- if (Object.keys(ancestorTheme).length === 0) {
85
- if (process.env.NODE_ENV !== 'production') {}
86
-
87
- currentTheme = cloneDeep(canvas);
88
- } else {
89
- currentTheme = cloneDeep(ancestorTheme);
90
- }
91
-
92
- const themeName = currentTheme.key; // we pick the overrides for the current theme from the override object
93
-
94
- const currentThemeOverrides = ((_themeOrOverride = themeOrOverride) === null || _themeOrOverride === void 0 ? void 0 : (_themeOrOverride$them = _themeOrOverride.themeOverrides) === null || _themeOrOverride$them === void 0 ? void 0 : _themeOrOverride$them[themeName]) || {};
95
- return merge({}, currentTheme, merge({}, themeOrOverride, currentThemeOverrides));
96
- };
97
-
98
- const isBaseTheme = theme => {
99
- if (Array.isArray(theme) || typeof theme === 'function') {
100
- throw new Error();
101
- }
102
-
103
- try {
104
- return 'key' in theme && baseThemeProps.every(prop => prop in theme);
105
- } catch {
106
- throw new Error();
107
- }
108
- };
109
-
110
46
  export default EmotionThemeProvider;
111
- export { EmotionThemeProvider, getTheme };
47
+ export { EmotionThemeProvider };
@@ -26,7 +26,7 @@ import PropTypes from 'prop-types';
26
26
  import { ThemeProvider } from '@emotion/react';
27
27
  import { TextDirectionContext } from '@instructure/ui-i18n';
28
28
  import { DeterministicIdContextProvider, getElementType } from '@instructure/ui-react-utils';
29
- import { getTheme } from '../EmotionThemeProvider';
29
+ import { getTheme } from '../getTheme';
30
30
 
31
31
  /**
32
32
  * ---
package/es/getTheme.js ADDED
@@ -0,0 +1,84 @@
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 { merge, cloneDeep } from 'lodash';
25
+ import { canvas } from '@instructure/ui-themes';
26
+ import { ThemeRegistry } from '@instructure/theme-registry';
27
+ import { isBaseTheme } from '@instructure/ui-utils';
28
+
29
+ /**
30
+ * ---
31
+ * private: true
32
+ * ---
33
+ * Gives back the theme object for the the provider.
34
+ *
35
+ * If a valid InstUI theme is given, it just returns the theme.
36
+ *
37
+ * If an override object is given, it returns the ancestor theme and
38
+ * the overrides merged together.
39
+ *
40
+ * @param {object} themeOrOverride - A full theme or an override object
41
+ * @returns {function} A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
42
+ */
43
+ const getTheme = themeOrOverride => function () {
44
+ var _themeOrOverride, _themeOrOverride$them;
45
+
46
+ let ancestorTheme = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
47
+
48
+ try {
49
+ // If a valid InstUI theme is given, it just returns the theme.
50
+ if (isBaseTheme(themeOrOverride)) {
51
+ return themeOrOverride;
52
+ }
53
+ } catch {
54
+ // If the prop passed is not an Object, it will throw an error.
55
+ // We are using this fail-safe here for the non-TS users,
56
+ // because the whole page can break without a theme.
57
+ if (process.env.NODE_ENV !== 'production') {} // eslint-disable-next-line no-param-reassign
58
+
59
+
60
+ themeOrOverride = {};
61
+ } // we need to clone the ancestor theme not to override it
62
+
63
+
64
+ let currentTheme;
65
+
66
+ if (Object.keys(ancestorTheme).length === 0) {
67
+ const globalTheme = ThemeRegistry.getCurrentTheme();
68
+
69
+ if (process.env.NODE_ENV !== 'production' && !globalTheme) {}
70
+
71
+ currentTheme = cloneDeep(globalTheme || canvas);
72
+ } else {
73
+ currentTheme = cloneDeep(ancestorTheme);
74
+ }
75
+
76
+ const themeName = currentTheme.key; // we pick the overrides for the current theme from the override object
77
+
78
+ const currentThemeOverrides = ((_themeOrOverride = themeOrOverride) === null || _themeOrOverride === void 0 ? void 0 : (_themeOrOverride$them = _themeOrOverride.themeOverrides) === null || _themeOrOverride$them === void 0 ? void 0 : _themeOrOverride$them[themeName]) || themeOrOverride.themeOverrides || {};
79
+ const finalTheme = merge({}, currentTheme, merge({}, themeOrOverride, currentThemeOverrides));
80
+ return finalTheme;
81
+ };
82
+
83
+ export default getTheme;
84
+ export { getTheme };
package/es/useTheme.js CHANGED
@@ -24,19 +24,27 @@
24
24
  import { useTheme as useEmotionTheme } from '@emotion/react';
25
25
  import { canvas } from '@instructure/ui-themes';
26
26
  import { isEmpty } from '@instructure/ui-utils';
27
+ import { ThemeRegistry } from '@instructure/theme-registry';
27
28
 
28
29
  /**
29
30
  * ---
30
31
  * private: true
31
32
  * ---
32
33
  * A hook that will return the currently applied theme object from the nearest Context.
33
- * If there is no theme provided to the Context it will return the default `canvas` theme.
34
+ * If there is no Context, then it tries to get the current theme from the global ThemeRegistry.
35
+ * If there is no theme provided to the Context and ThemeRegistry it will return the default `canvas` theme.
34
36
  * @returns {object} the theme object
35
37
  */
36
38
  const useTheme = () => {
37
39
  let theme = useEmotionTheme();
38
40
 
39
41
  if (isEmpty(theme)) {
42
+ const globalTheme = ThemeRegistry.getCurrentTheme();
43
+
44
+ if (globalTheme) {
45
+ return globalTheme;
46
+ }
47
+
40
48
  if (process.env.NODE_ENV !== 'production') {}
41
49
 
42
50
  theme = canvas;
@@ -6,15 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.EmotionThemeProvider = EmotionThemeProvider;
9
- exports.getTheme = exports.default = void 0;
9
+ exports.default = void 0;
10
10
 
11
11
  var _react = _interopRequireDefault(require("react"));
12
12
 
13
- var _lodash = require("lodash");
14
-
15
13
  var _react2 = require("@emotion/react");
16
14
 
17
- var _uiThemes = require("@instructure/ui-themes");
15
+ var _getTheme = require("../getTheme");
18
16
 
19
17
  /*
20
18
  * The MIT License (MIT)
@@ -39,89 +37,24 @@ var _uiThemes = require("@instructure/ui-themes");
39
37
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
38
  * SOFTWARE.
41
39
  */
42
- const baseThemeProps = ['borders', 'breakpoints', 'colors', 'forms', 'media', 'shadows', 'spacing', 'stacking', 'transitions', 'typography'];
40
+
43
41
  /**
44
42
  * ---
45
43
  * category: components/utilities
46
44
  * ---
47
45
  * @module EmotionThemeProvider
48
46
  */
49
-
50
47
  function EmotionThemeProvider(_ref) {
51
48
  let children = _ref.children,
52
49
  _ref$theme = _ref.theme,
53
50
  theme = _ref$theme === void 0 ? {} : _ref$theme;
54
51
  return /*#__PURE__*/_react.default.createElement(_react2.ThemeProvider, {
55
- theme: getTheme(theme)
52
+ theme: (0, _getTheme.getTheme)(theme)
56
53
  }, children);
57
54
  }
58
55
 
59
56
  EmotionThemeProvider.defaultProps = {
60
57
  theme: {}
61
58
  };
62
- /**
63
- * Gives back the theme object for the the provider.
64
- *
65
- * If a valid InstUI theme is given, it just returns the theme.
66
- *
67
- * If an override object is given, it returns the ancestor theme and
68
- * the overrides merged together.
69
- *
70
- * @param {object} themeOrOverride - A full theme or an override object
71
- * @returns {function} A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
72
- * @module getTheme
73
- */
74
-
75
- const getTheme = themeOrOverride => function () {
76
- var _themeOrOverride, _themeOrOverride$them;
77
-
78
- let ancestorTheme = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
79
-
80
- try {
81
- // If a valid InstUI theme is given, it just returns the theme.
82
- if (isBaseTheme(themeOrOverride)) {
83
- return themeOrOverride;
84
- }
85
- } catch {
86
- // If the prop passed is not an Object, it will throw an error.
87
- // We are using this fail-safe here for the non-TS users,
88
- // because the whole page can break without a theme.
89
- if (process.env.NODE_ENV !== 'production') {} // eslint-disable-next-line no-param-reassign
90
-
91
-
92
- themeOrOverride = {};
93
- } // we need to clone the ancestor theme not to override it
94
-
95
-
96
- let currentTheme;
97
-
98
- if (Object.keys(ancestorTheme).length === 0) {
99
- if (process.env.NODE_ENV !== 'production') {}
100
-
101
- currentTheme = (0, _lodash.cloneDeep)(_uiThemes.canvas);
102
- } else {
103
- currentTheme = (0, _lodash.cloneDeep)(ancestorTheme);
104
- }
105
-
106
- const themeName = currentTheme.key; // we pick the overrides for the current theme from the override object
107
-
108
- const currentThemeOverrides = ((_themeOrOverride = themeOrOverride) === null || _themeOrOverride === void 0 ? void 0 : (_themeOrOverride$them = _themeOrOverride.themeOverrides) === null || _themeOrOverride$them === void 0 ? void 0 : _themeOrOverride$them[themeName]) || {};
109
- return (0, _lodash.merge)({}, currentTheme, (0, _lodash.merge)({}, themeOrOverride, currentThemeOverrides));
110
- };
111
-
112
- exports.getTheme = getTheme;
113
-
114
- const isBaseTheme = theme => {
115
- if (Array.isArray(theme) || typeof theme === 'function') {
116
- throw new Error();
117
- }
118
-
119
- try {
120
- return 'key' in theme && baseThemeProps.every(prop => prop in theme);
121
- } catch {
122
- throw new Error();
123
- }
124
- };
125
-
126
59
  var _default = EmotionThemeProvider;
127
60
  exports.default = _default;
@@ -22,7 +22,7 @@ var _DeterministicIdContextProvider = require("@instructure/ui-react-utils/lib/D
22
22
 
23
23
  var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
24
24
 
25
- var _EmotionThemeProvider = require("../EmotionThemeProvider");
25
+ var _getTheme = require("../getTheme");
26
26
 
27
27
  /*
28
28
  * The MIT License (MIT)
@@ -69,7 +69,7 @@ function InstUISettingsProvider(_ref) {
69
69
  let providers = /*#__PURE__*/_react.default.createElement(_DeterministicIdContextProvider.DeterministicIdContextProvider, {
70
70
  instanceCounterMap: instanceCounterMap
71
71
  }, /*#__PURE__*/_react.default.createElement(_react2.ThemeProvider, {
72
- theme: (0, _EmotionThemeProvider.getTheme)(theme)
72
+ theme: (0, _getTheme.getTheme)(theme)
73
73
  }, /*#__PURE__*/_react.default.createElement(_TextDirectionContext.TextDirectionContext.Provider, {
74
74
  value: finalDir
75
75
  }, children)));
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTheme = exports.default = void 0;
7
+
8
+ var _lodash = require("lodash");
9
+
10
+ var _uiThemes = require("@instructure/ui-themes");
11
+
12
+ var _themeRegistry = require("@instructure/theme-registry");
13
+
14
+ var _isBaseTheme = require("@instructure/ui-utils/lib/isBaseTheme.js");
15
+
16
+ /*
17
+ * The MIT License (MIT)
18
+ *
19
+ * Copyright (c) 2015 - present Instructure, Inc.
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ * of this software and associated documentation files (the "Software"), to deal
23
+ * in the Software without restriction, including without limitation the rights
24
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ * copies of the Software, and to permit persons to whom the Software is
26
+ * furnished to do so, subject to the following conditions:
27
+ *
28
+ * The above copyright notice and this permission notice shall be included in all
29
+ * copies or substantial portions of the Software.
30
+ *
31
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ * SOFTWARE.
38
+ */
39
+
40
+ /**
41
+ * ---
42
+ * private: true
43
+ * ---
44
+ * Gives back the theme object for the the provider.
45
+ *
46
+ * If a valid InstUI theme is given, it just returns the theme.
47
+ *
48
+ * If an override object is given, it returns the ancestor theme and
49
+ * the overrides merged together.
50
+ *
51
+ * @param {object} themeOrOverride - A full theme or an override object
52
+ * @returns {function} A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
53
+ */
54
+ const getTheme = themeOrOverride => function () {
55
+ var _themeOrOverride, _themeOrOverride$them;
56
+
57
+ let ancestorTheme = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
58
+
59
+ try {
60
+ // If a valid InstUI theme is given, it just returns the theme.
61
+ if ((0, _isBaseTheme.isBaseTheme)(themeOrOverride)) {
62
+ return themeOrOverride;
63
+ }
64
+ } catch {
65
+ // If the prop passed is not an Object, it will throw an error.
66
+ // We are using this fail-safe here for the non-TS users,
67
+ // because the whole page can break without a theme.
68
+ if (process.env.NODE_ENV !== 'production') {} // eslint-disable-next-line no-param-reassign
69
+
70
+
71
+ themeOrOverride = {};
72
+ } // we need to clone the ancestor theme not to override it
73
+
74
+
75
+ let currentTheme;
76
+
77
+ if (Object.keys(ancestorTheme).length === 0) {
78
+ const globalTheme = _themeRegistry.ThemeRegistry.getCurrentTheme();
79
+
80
+ if (process.env.NODE_ENV !== 'production' && !globalTheme) {}
81
+
82
+ currentTheme = (0, _lodash.cloneDeep)(globalTheme || _uiThemes.canvas);
83
+ } else {
84
+ currentTheme = (0, _lodash.cloneDeep)(ancestorTheme);
85
+ }
86
+
87
+ const themeName = currentTheme.key; // we pick the overrides for the current theme from the override object
88
+
89
+ const currentThemeOverrides = ((_themeOrOverride = themeOrOverride) === null || _themeOrOverride === void 0 ? void 0 : (_themeOrOverride$them = _themeOrOverride.themeOverrides) === null || _themeOrOverride$them === void 0 ? void 0 : _themeOrOverride$them[themeName]) || themeOrOverride.themeOverrides || {};
90
+ const finalTheme = (0, _lodash.merge)({}, currentTheme, (0, _lodash.merge)({}, themeOrOverride, currentThemeOverrides));
91
+ return finalTheme;
92
+ };
93
+
94
+ exports.getTheme = getTheme;
95
+ var _default = getTheme;
96
+ exports.default = _default;
package/lib/useTheme.js CHANGED
@@ -11,6 +11,8 @@ var _uiThemes = require("@instructure/ui-themes");
11
11
 
12
12
  var _isEmpty = require("@instructure/ui-utils/lib/isEmpty.js");
13
13
 
14
+ var _themeRegistry = require("@instructure/theme-registry");
15
+
14
16
  /*
15
17
  * The MIT License (MIT)
16
18
  *
@@ -40,13 +42,20 @@ var _isEmpty = require("@instructure/ui-utils/lib/isEmpty.js");
40
42
  * private: true
41
43
  * ---
42
44
  * A hook that will return the currently applied theme object from the nearest Context.
43
- * If there is no theme provided to the Context it will return the default `canvas` theme.
45
+ * If there is no Context, then it tries to get the current theme from the global ThemeRegistry.
46
+ * If there is no theme provided to the Context and ThemeRegistry it will return the default `canvas` theme.
44
47
  * @returns {object} the theme object
45
48
  */
46
49
  const useTheme = () => {
47
50
  let theme = (0, _react.useTheme)();
48
51
 
49
52
  if ((0, _isEmpty.isEmpty)(theme)) {
53
+ const globalTheme = _themeRegistry.ThemeRegistry.getCurrentTheme();
54
+
55
+ if (globalTheme) {
56
+ return globalTheme;
57
+ }
58
+
50
59
  if (process.env.NODE_ENV !== 'production') {}
51
60
 
52
61
  theme = _uiThemes.canvas;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/emotion",
3
- "version": "8.23.1-snapshot.9+11828d0b3",
3
+ "version": "8.24.1-snapshot.17+0604ec59c",
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",
@@ -25,21 +25,22 @@
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.13.10",
27
27
  "@emotion/react": "^11",
28
- "@instructure/console": "8.23.1-snapshot.9+11828d0b3",
29
- "@instructure/shared-types": "8.23.1-snapshot.9+11828d0b3",
30
- "@instructure/ui-decorator": "8.23.1-snapshot.9+11828d0b3",
31
- "@instructure/ui-i18n": "8.23.1-snapshot.9+11828d0b3",
32
- "@instructure/ui-react-utils": "8.23.1-snapshot.9+11828d0b3",
33
- "@instructure/ui-themes": "8.23.1-snapshot.9+11828d0b3",
34
- "@instructure/ui-utils": "8.23.1-snapshot.9+11828d0b3",
28
+ "@instructure/console": "8.24.1-snapshot.17+0604ec59c",
29
+ "@instructure/shared-types": "8.24.1-snapshot.17+0604ec59c",
30
+ "@instructure/theme-registry": "8.24.1-snapshot.17+0604ec59c",
31
+ "@instructure/ui-decorator": "8.24.1-snapshot.17+0604ec59c",
32
+ "@instructure/ui-i18n": "8.24.1-snapshot.17+0604ec59c",
33
+ "@instructure/ui-react-utils": "8.24.1-snapshot.17+0604ec59c",
34
+ "@instructure/ui-themes": "8.24.1-snapshot.17+0604ec59c",
35
+ "@instructure/ui-utils": "8.24.1-snapshot.17+0604ec59c",
35
36
  "emotion-theming": "^11",
36
37
  "hoist-non-react-statics": "^3.3.2",
37
38
  "lodash": "^4",
38
39
  "prop-types": "^15"
39
40
  },
40
41
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "8.23.1-snapshot.9+11828d0b3",
42
- "@instructure/ui-test-utils": "8.23.1-snapshot.9+11828d0b3",
42
+ "@instructure/ui-babel-preset": "8.24.1-snapshot.17+0604ec59c",
43
+ "@instructure/ui-test-utils": "8.24.1-snapshot.17+0604ec59c",
43
44
  "@types/lodash": "^4.14.171",
44
45
  "cpy-cli": "^3.1.1"
45
46
  },
@@ -50,5 +51,5 @@
50
51
  "access": "public"
51
52
  },
52
53
  "sideEffects": false,
53
- "gitHead": "11828d0b32844a522d267e189c8bc52aa928843a"
54
+ "gitHead": "0604ec59c560ca2868fdac84d6f4948f92d38d5b"
54
55
  }
@@ -23,38 +23,15 @@
23
23
  */
24
24
 
25
25
  import React from 'react'
26
- import { merge, cloneDeep } from 'lodash'
27
26
  import { ThemeProvider } from '@emotion/react'
28
27
 
29
- import { canvas } from '@instructure/ui-themes'
30
-
31
- import type {
32
- BaseTheme,
33
- BaseThemeVariableKeys
34
- } from '@instructure/shared-types'
35
- import type {
36
- Overrides,
37
- ThemeOrOverride,
38
- SpecificThemeOverride
39
- } from '../EmotionTypes'
28
+ import type { ThemeOrOverride } from '../EmotionTypes'
29
+ import { getTheme } from '../getTheme'
40
30
 
41
31
  type ThemeProviderProps = {
42
32
  theme?: ThemeOrOverride
43
33
  }
44
34
 
45
- const baseThemeProps: BaseThemeVariableKeys = [
46
- 'borders',
47
- 'breakpoints',
48
- 'colors',
49
- 'forms',
50
- 'media',
51
- 'shadows',
52
- 'spacing',
53
- 'stacking',
54
- 'transitions',
55
- 'typography'
56
- ]
57
-
58
35
  /**
59
36
  * ---
60
37
  * category: components/utilities
@@ -69,83 +46,5 @@ function EmotionThemeProvider({
69
46
  }
70
47
  EmotionThemeProvider.defaultProps = { theme: {} }
71
48
 
72
- /**
73
- * Gives back the theme object for the the provider.
74
- *
75
- * If a valid InstUI theme is given, it just returns the theme.
76
- *
77
- * If an override object is given, it returns the ancestor theme and
78
- * the overrides merged together.
79
- *
80
- * @param {object} themeOrOverride - A full theme or an override object
81
- * @returns {function} A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
82
- * @module getTheme
83
- */
84
- const getTheme =
85
- (themeOrOverride: ThemeOrOverride) =>
86
- (ancestorTheme = {} as BaseTheme) => {
87
- try {
88
- // If a valid InstUI theme is given, it just returns the theme.
89
- if (isBaseTheme(themeOrOverride)) {
90
- return themeOrOverride
91
- }
92
- } catch {
93
- // If the prop passed is not an Object, it will throw an error.
94
- // We are using this fail-safe here for the non-TS users,
95
- // because the whole page can break without a theme.
96
- if (process.env.NODE_ENV !== 'production') {
97
- console.warn(
98
- 'The `theme` property provided to EmotionThemeProvider is not a valid InstUI theme object.\ntheme: ',
99
- themeOrOverride
100
- )
101
- }
102
- // eslint-disable-next-line no-param-reassign
103
- themeOrOverride = {}
104
- }
105
-
106
- // we need to clone the ancestor theme not to override it
107
- let currentTheme
108
-
109
- if (Object.keys(ancestorTheme).length === 0) {
110
- if (process.env.NODE_ENV !== 'production') {
111
- console.warn(
112
- 'No theme provided for [EmotionThemeProvider], using default `canvas` theme.'
113
- )
114
- }
115
- currentTheme = cloneDeep(canvas)
116
- } else {
117
- currentTheme = cloneDeep(ancestorTheme)
118
- }
119
-
120
- const themeName = currentTheme.key
121
-
122
- // we pick the overrides for the current theme from the override object
123
- const currentThemeOverrides =
124
- (
125
- (themeOrOverride as Overrides)?.themeOverrides as SpecificThemeOverride
126
- )?.[themeName] || {}
127
-
128
- return merge(
129
- {},
130
- currentTheme,
131
- merge({}, themeOrOverride, currentThemeOverrides)
132
- )
133
- }
134
-
135
- const isBaseTheme = (theme: ThemeOrOverride): theme is BaseTheme => {
136
- if (Array.isArray(theme) || typeof theme === 'function') {
137
- throw new Error()
138
- }
139
-
140
- try {
141
- return (
142
- 'key' in (theme as BaseTheme) &&
143
- baseThemeProps.every((prop) => prop in theme)
144
- )
145
- } catch {
146
- throw new Error()
147
- }
148
- }
149
-
150
49
  export default EmotionThemeProvider
151
- export { EmotionThemeProvider, getTheme }
50
+ export { EmotionThemeProvider }
@@ -32,7 +32,7 @@ import {
32
32
  getElementType
33
33
  } from '@instructure/ui-react-utils'
34
34
 
35
- import { getTheme } from '../EmotionThemeProvider'
35
+ import { getTheme } from '../getTheme'
36
36
 
37
37
  import type { ThemeOrOverride } from '../EmotionTypes'
38
38
  import type { DeterministicIdProviderValue } from '@instructure/ui-react-utils'