@instructure/emotion 11.6.0 → 11.6.1-pr-snapshot-1779894247159

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,14 @@
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.6.1-pr-snapshot-1779894247159](https://github.com/instructure/instructure-ui/compare/v11.6.0...v11.6.1-pr-snapshot-1779894247159) (2026-05-27)
7
+
8
+ **Note:** Version bump only for package @instructure/emotion
9
+
10
+
11
+
12
+
13
+
6
14
  # [11.6.0](https://github.com/instructure/instructure-ui/compare/v11.5.0...v11.6.0) (2026-02-18)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/emotion
@@ -1,9 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mapSpacingToShorthand = mapSpacingToShorthand;
7
1
  /*
8
2
  * The MIT License (MIT)
9
3
  *
@@ -28,8 +22,16 @@ exports.mapSpacingToShorthand = mapSpacingToShorthand;
28
22
  * SOFTWARE.
29
23
  */
30
24
 
31
- function mapSpacingToShorthand(value, spacingMap) {
32
- const splitMargin = value === null || value === void 0 ? void 0 : value.split(' ');
33
- const cssMargin = splitMargin ? splitMargin.map(m => spacingMap[m] || m).join(' ') : '0';
34
- return cssMargin;
35
- }
25
+ module.exports = {
26
+ presets: [
27
+ [
28
+ require('@instructure/ui-babel-preset'),
29
+ {
30
+ coverage: Boolean(process.env.COVERAGE),
31
+ esModules: Boolean(process.env.ES_MODULES),
32
+ removeConsole: process.env.NODE_ENV === 'production',
33
+ transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
34
+ }
35
+ ]
36
+ ]
37
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@instructure/emotion",
3
- "version": "11.6.0",
3
+ "version": "11.6.1-pr-snapshot-1779894247159",
4
+ "type": "module",
4
5
  "description": "A UI component library made by Instructure Inc.",
5
6
  "author": "Instructure, Inc. Engineering and Product Design",
6
7
  "module": "./es/index.js",
7
- "main": "./lib/index.js",
8
8
  "types": "./types/index.d.ts",
9
9
  "repository": {
10
10
  "type": "git",
@@ -17,13 +17,13 @@
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.6.0",
21
- "@instructure/shared-types": "11.6.0",
22
- "@instructure/ui-decorator": "11.6.0",
23
- "@instructure/ui-i18n": "11.6.0",
24
- "@instructure/ui-react-utils": "11.6.0",
25
- "@instructure/ui-themes": "11.6.0",
26
- "@instructure/ui-utils": "11.6.0"
20
+ "@instructure/console": "11.6.1-pr-snapshot-1779894247159",
21
+ "@instructure/ui-decorator": "11.6.1-pr-snapshot-1779894247159",
22
+ "@instructure/ui-i18n": "11.6.1-pr-snapshot-1779894247159",
23
+ "@instructure/shared-types": "11.6.1-pr-snapshot-1779894247159",
24
+ "@instructure/ui-react-utils": "11.6.1-pr-snapshot-1779894247159",
25
+ "@instructure/ui-themes": "11.6.1-pr-snapshot-1779894247159",
26
+ "@instructure/ui-utils": "11.6.1-pr-snapshot-1779894247159"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@testing-library/jest-dom": "^6.6.3",
@@ -31,7 +31,7 @@
31
31
  "@testing-library/user-event": "^14.6.1",
32
32
  "react-dom": "18.3.1",
33
33
  "vitest": "^3.2.2",
34
- "@instructure/ui-babel-preset": "11.6.0"
34
+ "@instructure/ui-babel-preset": "11.6.1-pr-snapshot-1779894247159"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=18 <=19"
@@ -44,10 +44,8 @@
44
44
  ".": {
45
45
  "types": "./types/index.d.ts",
46
46
  "import": "./es/index.js",
47
- "require": "./lib/index.js",
48
47
  "default": "./es/index.js"
49
48
  },
50
- "./lib/*": "./lib/*",
51
49
  "./es/*": "./es/*",
52
50
  "./types/*": "./types/*",
53
51
  "./package.json": "./package.json",
@@ -57,7 +55,7 @@
57
55
  "lint": "ui-scripts lint",
58
56
  "lint:fix": "ui-scripts lint --fix",
59
57
  "clean": "ui-scripts clean",
60
- "build": "ui-scripts build --modules es,cjs",
58
+ "build": "ui-scripts build",
61
59
  "build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
62
60
  "build:types": "tsc -p tsconfig.build.json ",
63
61
  "ts:check": "tsc -p tsconfig.build.json"
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InstUISettingsProvider = InstUISettingsProvider;
7
- exports.default = void 0;
8
- var _react = require("react");
9
- var _react2 = require("@emotion/react");
10
- var _TextDirectionContext = require("@instructure/ui-i18n/lib/TextDirectionContext.js");
11
- var _DeterministicIdContextProvider = require("@instructure/ui-react-utils/lib/DeterministicIdContext/DeterministicIdContextProvider.js");
12
- var _getTheme = require("../getTheme");
13
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
14
- /*
15
- * The MIT License (MIT)
16
- *
17
- * Copyright (c) 2015 - present Instructure, Inc.
18
- *
19
- * Permission is hereby granted, free of charge, to any person obtaining a copy
20
- * of this software and associated documentation files (the "Software"), to deal
21
- * in the Software without restriction, including without limitation the rights
22
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
- * copies of the Software, and to permit persons to whom the Software is
24
- * furnished to do so, subject to the following conditions:
25
- *
26
- * The above copyright notice and this permission notice shall be included in all
27
- * copies or substantial portions of the Software.
28
- *
29
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
- * SOFTWARE.
36
- */
37
-
38
- /**
39
- * ---
40
- * category: components
41
- * ---
42
- * @module InstUISettingsProvider
43
- */
44
- function InstUISettingsProvider({
45
- children,
46
- theme = {},
47
- dir,
48
- instanceCounterMap
49
- }) {
50
- const finalDir = dir || (0, _react.useContext)(_TextDirectionContext.TextDirectionContext);
51
- if (process.env.NODE_ENV !== 'production' && finalDir === 'auto') {}
52
- let providers = (0, _jsxRuntime.jsx)(_DeterministicIdContextProvider.DeterministicIdContextProvider, {
53
- instanceCounterMap: instanceCounterMap,
54
- children: (0, _jsxRuntime.jsx)(_react2.ThemeProvider, {
55
- theme: (0, _getTheme.getTheme)(theme),
56
- children: (0, _jsxRuntime.jsx)(_TextDirectionContext.TextDirectionContext.Provider, {
57
- value: finalDir,
58
- children: children
59
- })
60
- })
61
- });
62
- if (dir) {
63
- providers = (0, _jsxRuntime.jsx)("span", {
64
- dir: finalDir,
65
- children: providers
66
- });
67
- }
68
- return providers;
69
- }
70
- var _default = exports.default = InstUISettingsProvider;
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getComponentThemeOverride = exports.default = void 0;
7
- /*
8
- * The MIT License (MIT)
9
- *
10
- * Copyright (c) 2015 - present Instructure, Inc.
11
- *
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy
13
- * of this software and associated documentation files (the "Software"), to deal
14
- * in the Software without restriction, including without limitation the rights
15
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- * copies of the Software, and to permit persons to whom the Software is
17
- * furnished to do so, subject to the following conditions:
18
- *
19
- * The above copyright notice and this permission notice shall be included in all
20
- * copies or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- * SOFTWARE.
29
- */
30
-
31
- /**
32
- * ---
33
- * private: true
34
- * ---
35
- * This is a utility function which calculates the correct component theme
36
- * based on every possible override there is.
37
-
38
- * @param theme - Theme object
39
- * @param displayName - Name of the component
40
- * @param componentId - componentId of the component
41
- * @param props - The component's props object
42
- * @param componentTheme - The component's default theme
43
- * @returns The calculated theme override object
44
- */
45
- const getComponentThemeOverride = (theme, displayName, componentId, props, componentTheme) => {
46
- const name = displayName;
47
- const id = componentId;
48
- const themeOverride = props ? props.themeOverride : void 0;
49
- const _ref = theme,
50
- componentOverrides = _ref.componentOverrides;
51
- let overridesFromTheme = {};
52
- let overrideFromComponent = {};
53
- if (componentOverrides) {
54
- overridesFromTheme = name && componentOverrides[name] || id && componentOverrides[id] || {};
55
- }
56
- if (themeOverride) {
57
- if (typeof themeOverride === 'function') {
58
- overrideFromComponent = themeOverride(componentTheme || {},
59
- // the `theme` technically could be a partial theme / override object too,
60
- // but we want to display all possible options
61
- theme);
62
- } else {
63
- overrideFromComponent = themeOverride;
64
- }
65
- }
66
- return {
67
- ...overridesFromTheme,
68
- ...overrideFromComponent
69
- };
70
- };
71
- exports.getComponentThemeOverride = getComponentThemeOverride;
72
- var _default = exports.default = getComponentThemeOverride;
package/lib/getTheme.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getTheme = exports.default = void 0;
8
- var _uiThemes = _interopRequireDefault(require("@instructure/ui-themes"));
9
- var _isBaseTheme = require("@instructure/ui-utils/lib/isBaseTheme.js");
10
- var _mergeDeep = require("@instructure/ui-utils/lib/mergeDeep.js");
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- /**
36
- * ---
37
- * private: true
38
- * ---
39
- * Gives back the theme object for the provider.
40
- *
41
- * If a valid InstUI theme is given, it just returns the theme.
42
- *
43
- * If an override object is given, it returns the ancestor theme and
44
- * the overrides merged together.
45
- *
46
- * @param themeOrOverride - A full theme or an override object
47
- * @returns A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
48
- * This function is called by Emotion on theme provider creation, where
49
- * `ancestorTheme` is a theme object from an ancestor `ThemeProvider`
50
- */
51
- const getTheme = themeOrOverride => (ancestorTheme = {}) => {
52
- var _resolvedThemeOrOverr;
53
- // we need to clone the ancestor theme not to override it
54
- let currentTheme;
55
- if (Object.keys(ancestorTheme).length === 0) {
56
- if (process.env.NODE_ENV !== 'production') {}
57
- currentTheme = _uiThemes.default;
58
- } else {
59
- currentTheme = ancestorTheme;
60
- }
61
- let resolvedThemeOrOverride = themeOrOverride;
62
- if (typeof resolvedThemeOrOverride === 'function') {
63
- resolvedThemeOrOverride = resolvedThemeOrOverride(currentTheme);
64
- }
65
- try {
66
- // If a valid InstUI theme is given, it just returns the theme.
67
- if ((0, _isBaseTheme.isBaseTheme)(resolvedThemeOrOverride)) {
68
- return resolvedThemeOrOverride;
69
- }
70
- } catch {
71
- // If the prop passed is not an Object, it will throw an error.
72
- // We are using this fail-safe here for the non-TS users,
73
- // because the whole page can break without a theme.
74
- if (process.env.NODE_ENV !== 'production') {}
75
- resolvedThemeOrOverride = {};
76
- }
77
- const themeName = currentTheme.key;
78
-
79
- // we pick the overrides for the current theme from the override object
80
- const specificOverrides = (_resolvedThemeOrOverr = resolvedThemeOrOverride) === null || _resolvedThemeOrOverr === void 0 ? void 0 : _resolvedThemeOrOverr.themeOverrides;
81
- const currentThemeOverrides = (specificOverrides === null || specificOverrides === void 0 ? void 0 : specificOverrides[themeName]) || specificOverrides || {};
82
- return (0, _mergeDeep.mergeDeep)(currentTheme, resolvedThemeOrOverride, currentThemeOverrides);
83
- };
84
- exports.getTheme = getTheme;
85
- var _default = exports.default = getTheme;
package/lib/index.js DELETED
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- InstUISettingsProvider: true,
8
- withStyle: true,
9
- ThemeablePropValues: true,
10
- makeThemeVars: true,
11
- getShorthandPropValue: true,
12
- mirrorShorthandCorners: true,
13
- mirrorShorthandEdges: true,
14
- mapSpacingToShorthand: true,
15
- useStyle: true,
16
- useTheme: true
17
- };
18
- Object.defineProperty(exports, "InstUISettingsProvider", {
19
- enumerable: true,
20
- get: function () {
21
- return _InstUISettingsProvider.InstUISettingsProvider;
22
- }
23
- });
24
- Object.defineProperty(exports, "ThemeablePropValues", {
25
- enumerable: true,
26
- get: function () {
27
- return _styleUtils.ThemeablePropValues;
28
- }
29
- });
30
- Object.defineProperty(exports, "getShorthandPropValue", {
31
- enumerable: true,
32
- get: function () {
33
- return _styleUtils.getShorthandPropValue;
34
- }
35
- });
36
- Object.defineProperty(exports, "makeThemeVars", {
37
- enumerable: true,
38
- get: function () {
39
- return _styleUtils.makeThemeVars;
40
- }
41
- });
42
- Object.defineProperty(exports, "mapSpacingToShorthand", {
43
- enumerable: true,
44
- get: function () {
45
- return _styleUtils.mapSpacingToShorthand;
46
- }
47
- });
48
- Object.defineProperty(exports, "mirrorShorthandCorners", {
49
- enumerable: true,
50
- get: function () {
51
- return _styleUtils.mirrorShorthandCorners;
52
- }
53
- });
54
- Object.defineProperty(exports, "mirrorShorthandEdges", {
55
- enumerable: true,
56
- get: function () {
57
- return _styleUtils.mirrorShorthandEdges;
58
- }
59
- });
60
- Object.defineProperty(exports, "useStyle", {
61
- enumerable: true,
62
- get: function () {
63
- return _useStyle.useStyle;
64
- }
65
- });
66
- Object.defineProperty(exports, "useTheme", {
67
- enumerable: true,
68
- get: function () {
69
- return _useTheme.useTheme;
70
- }
71
- });
72
- Object.defineProperty(exports, "withStyle", {
73
- enumerable: true,
74
- get: function () {
75
- return _withStyle.withStyle;
76
- }
77
- });
78
- var _react = require("@emotion/react");
79
- Object.keys(_react).forEach(function (key) {
80
- if (key === "default" || key === "__esModule") return;
81
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
82
- if (key in exports && exports[key] === _react[key]) return;
83
- Object.defineProperty(exports, key, {
84
- enumerable: true,
85
- get: function () {
86
- return _react[key];
87
- }
88
- });
89
- });
90
- var _InstUISettingsProvider = require("./InstUISettingsProvider");
91
- var _withStyle = require("./withStyle");
92
- var _styleUtils = require("./styleUtils");
93
- var _useStyle = require("./useStyle");
94
- var _useTheme = require("./useTheme");
package/lib/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,104 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.ThemeablePropValues = void 0;
7
- /*
8
- * The MIT License (MIT)
9
- *
10
- * Copyright (c) 2015 - present Instructure, Inc.
11
- *
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy
13
- * of this software and associated documentation files (the "Software"), to deal
14
- * in the Software without restriction, including without limitation the rights
15
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- * copies of the Software, and to permit persons to whom the Software is
17
- * furnished to do so, subject to the following conditions:
18
- *
19
- * The above copyright notice and this permission notice shall be included in all
20
- * copies or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- * SOFTWARE.
29
- */
30
-
31
- const ThemeablePropValues = exports.ThemeablePropValues = {
32
- SHADOW_TYPES: {
33
- resting: 'resting',
34
- above: 'above',
35
- topmost: 'topmost',
36
- none: 'none'
37
- },
38
- STACKING_TYPES: {
39
- deepest: 'deepest',
40
- below: 'below',
41
- resting: 'resting',
42
- above: 'above',
43
- topmost: 'topmost'
44
- },
45
- BORDER_WIDTHS: {
46
- 0: '0',
47
- none: 'none',
48
- small: 'small',
49
- medium: 'medium',
50
- large: 'large'
51
- },
52
- BORDER_RADII: {
53
- 0: '0',
54
- none: 'none',
55
- small: 'small',
56
- medium: 'medium',
57
- large: 'large',
58
- circle: 'circle',
59
- pill: 'pill'
60
- },
61
- BACKGROUNDS: {
62
- default: 'default',
63
- inverse: 'inverse',
64
- transparent: 'transparent'
65
- },
66
- SIZES: {
67
- xSmall: 'x-small',
68
- small: 'small',
69
- medium: 'medium',
70
- large: 'large',
71
- xLarge: 'x-large'
72
- },
73
- SPACING: {
74
- 0: '0',
75
- none: 'none',
76
- auto: 'auto',
77
- xxxSmall: 'xxx-small',
78
- xxSmall: 'xx-small',
79
- xSmall: 'x-small',
80
- small: 'small',
81
- mediumSmall: 'mediumSmall',
82
- medium: 'medium',
83
- large: 'large',
84
- xLarge: 'x-large',
85
- xxLarge: 'xx-large'
86
- }
87
- };
88
-
89
- // SPACING
90
-
91
- // adding `(string & {})` allows to use any string while still allowing specific string values to be suggested by IDEs
92
-
93
- // SHADOW_TYPES
94
-
95
- // STACKING_TYPES
96
-
97
- // BACKGROUNDS
98
-
99
- // BORDER_RADII
100
-
101
- // TODO type better for actual values like '12px'
102
-
103
- // BORDER_WIDTHS
104
- var _default = exports.default = ThemeablePropValues;
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.getShorthandPropValue = getShorthandPropValue;
8
- var _isEmpty = require("@instructure/ui-utils/lib/isEmpty.js");
9
- var _camelize = require("@instructure/ui-utils/lib/camelize.js");
10
- var _console = require("@instructure/console");
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- /**
36
- * ---
37
- * category: utilities/themes
38
- * ---
39
- * Gets prop values from a theme object for the given values.
40
- * @module getShorthandPropValue
41
- *
42
- * @param componentName The name of the component (just for error messages)
43
- * @param componentTheme A theme object of keys and values
44
- * @param propValue A space delimited string of values e.g. `"small large none"`
45
- * @param propName A prefix to combine with each propValue
46
- * @param matchCSSUnits Match valid CSS strings too like `1rem`. It's a simple
47
- * matcher, just checks whether the given string starts with a number and ends
48
- * with a string, e.g. `4rem`, `.5em`, `2.6px`, `5foo`
49
- * @returns A space-delimited string with the following values:
50
- * - `0` for the `0` or `none` `propValue`
51
- * - `auto` for the `auto` `propValue`
52
- * - `100%` for the `circle` `propValue`
53
- * - `999em` for the `pill` `propValue`
54
- * - The value in the theme object for the `${propName}-{nth propValue}` key, e.g.
55
- * `small` will be `0.2rem`
56
- */
57
- function getShorthandPropValue(componentName, componentTheme, propValue, propName, matchCSSUnits = false) {
58
- if (typeof propValue !== 'string' || (0, _isEmpty.isEmpty)(componentTheme)) {
59
- return;
60
- }
61
- return propValue.split(' ').map(shortHandValue => {
62
- if (shortHandValue === 'auto' || shortHandValue === '0') {
63
- return shortHandValue;
64
- } else if (shortHandValue === 'none') {
65
- return '0';
66
- } else if (shortHandValue === 'circle') {
67
- return '100%';
68
- } else if (shortHandValue === 'pill') {
69
- return '999em';
70
- } else if (matchCSSUnits) {
71
- // try to match it as a CSS unit
72
- // matches [number][string] like '4rem', '.5em', '2.6px'
73
- if (shortHandValue.match(/^([+-]?(\d+\.?\d*|\.\d+))([a-zA-Z]+)$/)) {
74
- return shortHandValue;
75
- }
76
- }
77
- const themeVariableName = (0, _camelize.camelize)(`${propName}-${shortHandValue}`);
78
- const themeVariableValue = componentTheme[themeVariableName];
79
- (0, _console.logError)(typeof themeVariableValue !== 'undefined', `[${componentName}] '${themeVariableName}' is an invalid '${propName}' value.`);
80
- return themeVariableValue || '0';
81
- }).join(' ').trim();
82
- }
83
- var _default = exports.default = getShorthandPropValue;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ThemeablePropValues", {
7
- enumerable: true,
8
- get: function () {
9
- return _ThemeablePropValues.ThemeablePropValues;
10
- }
11
- });
12
- Object.defineProperty(exports, "getShorthandPropValue", {
13
- enumerable: true,
14
- get: function () {
15
- return _getShorthandPropValue.getShorthandPropValue;
16
- }
17
- });
18
- Object.defineProperty(exports, "makeThemeVars", {
19
- enumerable: true,
20
- get: function () {
21
- return _makeThemeVars.makeThemeVars;
22
- }
23
- });
24
- Object.defineProperty(exports, "mapSpacingToShorthand", {
25
- enumerable: true,
26
- get: function () {
27
- return _mapSpacingToShorthand.mapSpacingToShorthand;
28
- }
29
- });
30
- Object.defineProperty(exports, "mirrorShorthandCorners", {
31
- enumerable: true,
32
- get: function () {
33
- return _mirrorShorthandCorners.mirrorShorthandCorners;
34
- }
35
- });
36
- Object.defineProperty(exports, "mirrorShorthandEdges", {
37
- enumerable: true,
38
- get: function () {
39
- return _mirrorShorthandEdges.mirrorShorthandEdges;
40
- }
41
- });
42
- var _ThemeablePropValues = require("./ThemeablePropValues");
43
- var _makeThemeVars = require("./makeThemeVars");
44
- var _getShorthandPropValue = require("./getShorthandPropValue");
45
- var _mirrorShorthandCorners = require("./mirrorShorthandCorners");
46
- var _mirrorShorthandEdges = require("./mirrorShorthandEdges");
47
- var _mapSpacingToShorthand = require("./mapSpacingToShorthand");
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.makeThemeVars = makeThemeVars;
8
- var _camelize = require("@instructure/ui-utils/lib/camelize.js");
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright (c) 2015 - present Instructure, Inc.
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- * copies of the Software, and to permit persons to whom the Software is
19
- * furnished to do so, subject to the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be included in all
22
- * copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- */
32
-
33
- /**
34
- * ---
35
- * category: utilities/themes
36
- * ---
37
- * Given a prefix and a theme object, prepends the object keys with
38
- * the designated prefix and camel cases the concatenation.
39
- * @module makeThemeVars
40
- * @param {String} prefix - a string to prepend to object keys
41
- * @param {Object} vars - an object
42
- * @returns {Object} a modified object with prefixed keys
43
- */
44
- function makeThemeVars(prefix, vars) {
45
- const themeVars = {};
46
- Object.keys(vars).forEach(variable => {
47
- themeVars[(0, _camelize.camelize)(`${prefix}-${String(variable)}`)] = vars[variable];
48
- });
49
- return themeVars;
50
- }
51
- var _default = exports.default = makeThemeVars;
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mirrorShorthandCorners = mirrorShorthandCorners;
7
- exports.mirrorShorthandEdges = mirrorShorthandEdges;
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
- /**
33
- * ---
34
- * category: utilities/themes
35
- * ---
36
- * @module mirrorShorthand
37
- */
38
-
39
- /**
40
- * Mirror shorthand CSS properties for bidirectional text
41
- *
42
- * Given a string representing a CSS shorthand for edges,
43
- * swaps the values such that 4 value syntax is RTL instead
44
- * of LTR.
45
- *
46
- * See the following for further reference:
47
- * https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
48
- *
49
- * @param {String} values - space delimited string values representing a CSS shorthand
50
- * @returns {String} a space delimited CSS shorthand string converted to RTL
51
- */
52
- function mirrorShorthandEdges(values) {
53
- if (typeof values !== 'string') {
54
- return;
55
- }
56
- const valuesArr = values.split(' ');
57
- if (valuesArr.length === 4) {
58
- // swap the 2nd and 4th values
59
- ;
60
- var _ref = [valuesArr[3], valuesArr[1]];
61
- valuesArr[1] = _ref[0];
62
- valuesArr[3] = _ref[1];
63
- }
64
- return valuesArr.join(' ');
65
- }
66
-
67
- /**
68
- * Convert shorthand CSS properties for corners to rtl
69
- *
70
- * Given a string representing a CSS shorthand for corners,
71
- * swaps the values such that 2,3 and 4 value syntax is rtl
72
- * instead of ltr.
73
- *
74
- * See the following for further reference:
75
- * https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
76
- *
77
- * @param {String} values - space delimited string values representing a CSS shorthand
78
- * @returns {String} a space delimited CSS shorthand string converted to RTL
79
- */
80
- function mirrorShorthandCorners(values) {
81
- if (typeof values !== 'string') {
82
- return;
83
- }
84
- const valuesArr = values.split(' ');
85
- if (valuesArr.length === 2) {
86
- // swap the 1st and 2nd values
87
- ;
88
- var _ref2 = [valuesArr[1], valuesArr[0]];
89
- valuesArr[0] = _ref2[0];
90
- valuesArr[1] = _ref2[1];
91
- }
92
- if (valuesArr.length === 3) {
93
- // convert 3 value syntax to 4 value syntax
94
- valuesArr.push(valuesArr[1]);
95
- }
96
- if (valuesArr.length === 4) {
97
- ;
98
- var _ref3 = [valuesArr[1], valuesArr[0], valuesArr[3], valuesArr[2]];
99
- valuesArr[0] = _ref3[0];
100
- valuesArr[1] = _ref3[1];
101
- valuesArr[2] = _ref3[2];
102
- valuesArr[3] = _ref3[3];
103
- }
104
- return valuesArr.join(' ');
105
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "mirrorShorthandCorners", {
8
- enumerable: true,
9
- get: function () {
10
- return _mirrorShorthand.mirrorShorthandCorners;
11
- }
12
- });
13
- var _mirrorShorthand = require("./mirrorShorthand");
14
- /*
15
- * The MIT License (MIT)
16
- *
17
- * Copyright (c) 2015 - present Instructure, Inc.
18
- *
19
- * Permission is hereby granted, free of charge, to any person obtaining a copy
20
- * of this software and associated documentation files (the "Software"), to deal
21
- * in the Software without restriction, including without limitation the rights
22
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
- * copies of the Software, and to permit persons to whom the Software is
24
- * furnished to do so, subject to the following conditions:
25
- *
26
- * The above copyright notice and this permission notice shall be included in all
27
- * copies or substantial portions of the Software.
28
- *
29
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
- * SOFTWARE.
36
- */
37
- var _default = exports.default = _mirrorShorthand.mirrorShorthandCorners;
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "mirrorShorthandEdges", {
8
- enumerable: true,
9
- get: function () {
10
- return _mirrorShorthand.mirrorShorthandEdges;
11
- }
12
- });
13
- var _mirrorShorthand = require("./mirrorShorthand");
14
- /*
15
- * The MIT License (MIT)
16
- *
17
- * Copyright (c) 2015 - present Instructure, Inc.
18
- *
19
- * Permission is hereby granted, free of charge, to any person obtaining a copy
20
- * of this software and associated documentation files (the "Software"), to deal
21
- * in the Software without restriction, including without limitation the rights
22
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
- * copies of the Software, and to permit persons to whom the Software is
24
- * furnished to do so, subject to the following conditions:
25
- *
26
- * The above copyright notice and this permission notice shall be included in all
27
- * copies or substantial portions of the Software.
28
- *
29
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
- * SOFTWARE.
36
- */
37
- var _default = exports.default = _mirrorShorthand.mirrorShorthandEdges;
package/lib/useStyle.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useStyle = exports.default = void 0;
7
- var _useTheme = require("./useTheme");
8
- var _getComponentThemeOverride = require("./getComponentThemeOverride");
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright (c) 2015 - present Instructure, Inc.
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- * copies of the Software, and to permit persons to whom the Software is
19
- * furnished to do so, subject to the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be included in all
22
- * copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- */
32
-
33
- // returns the second parameter of a function
34
-
35
- const useStyle = useStyleParams => {
36
- const generateStyle = useStyleParams.generateStyle,
37
- generateComponentTheme = useStyleParams.generateComponentTheme,
38
- params = useStyleParams.params,
39
- componentId = useStyleParams.componentId,
40
- displayName = useStyleParams.displayName;
41
- const theme = (0, _useTheme.useTheme)();
42
- const baseComponentTheme = generateComponentTheme ? generateComponentTheme(theme) : {};
43
- const themeOverride = (0, _getComponentThemeOverride.getComponentThemeOverride)(theme, displayName ? displayName : componentId || '', componentId, params, baseComponentTheme);
44
- const componentTheme = {
45
- ...baseComponentTheme,
46
- ...themeOverride
47
- };
48
- return generateStyle(componentTheme, params ? params : {});
49
- };
50
- exports.useStyle = useStyle;
51
- var _default = exports.default = useStyle;
package/lib/useTheme.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.useTheme = exports.default = void 0;
8
- var _react = require("@emotion/react");
9
- var _uiThemes = _interopRequireDefault(require("@instructure/ui-themes"));
10
- var _isEmpty = require("@instructure/ui-utils/lib/isEmpty.js");
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- /**
36
- * ---
37
- * private: true
38
- * ---
39
- * A hook that will return the currently applied theme object from the nearest Context.
40
- * If there is no theme provided to the Context, it will return the default `canvas` theme.
41
- * @returns The theme object
42
- */
43
- const useTheme = () => {
44
- // This reads the theme from Emotion's ThemeContext
45
- let theme = (0, _react.useTheme)();
46
- if ((0, _isEmpty.isEmpty)(theme)) {
47
- if (process.env.NODE_ENV !== 'production') {}
48
- theme = _uiThemes.default;
49
- }
50
- return theme;
51
- };
52
- exports.useTheme = useTheme;
53
- var _default = exports.default = useTheme;
package/lib/withStyle.js DELETED
@@ -1,193 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.withStyle = exports.default = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _react = require("react");
10
- var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
11
- var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
12
- var _console = require("@instructure/console");
13
- var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
14
- var _getComponentThemeOverride = require("./getComponentThemeOverride");
15
- var _useTheme = require("./useTheme");
16
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
- /*
18
- * The MIT License (MIT)
19
- *
20
- * Copyright (c) 2015 - present Instructure, Inc.
21
- *
22
- * Permission is hereby granted, free of charge, to any person obtaining a copy
23
- * of this software and associated documentation files (the "Software"), to deal
24
- * in the Software without restriction, including without limitation the rights
25
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
- * copies of the Software, and to permit persons to whom the Software is
27
- * furnished to do so, subject to the following conditions:
28
- *
29
- * The above copyright notice and this permission notice shall be included in all
30
- * copies or substantial portions of the Software.
31
- *
32
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
- * SOFTWARE.
39
- */
40
-
41
- // Extract is needed because it would allow number otherwise
42
- // https://stackoverflow.com/a/51808262/319473
43
-
44
- // Unique name of an InstUI component
45
-
46
- const defaultValues = {
47
- styles: {},
48
- makeStyles: () => {}
49
- };
50
-
51
- /**
52
- * ---
53
- * category: utilities/themes
54
- * ---
55
- *
56
- * A decorator or higher order component that makes a component themeable.
57
- *
58
- * It adds a `makeStyles` function and the generated `styles` object to the decorated Component's props. If it has an own theme, it also adds the `themeOverride` prop to the component.
59
- *
60
- * As a HOC:
61
- *
62
- * ```js-code
63
- * import { withStyle } from '@instructure/emotion'
64
- * import generateStyle from './styles'
65
- * import generateComponentTheme from './theme'
66
- *
67
- * export default withStyle(generateStyle, generateComponentTheme)(ExampleComponent)
68
- * ```
69
- *
70
- * Themeable components inject their themed styles into the document
71
- * when they are mounted.
72
- *
73
- * ### Applying themes
74
- *
75
- * A themeable component’s theme can be configured via wrapping it in an
76
- * [InstUISettingsProvider](InstUISettingsProvider) component, and/or set
77
- * explicitly via its `themeOverride` prop.
78
- *
79
- * InstUISettingsProvider provides a theme object (e.g. the [canvas theme](/#canvas)).
80
- * These variables are mapped to the component's own variables in `theme.js` (see [theming](theming-basics) for more info).
81
- *
82
- * 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.
83
- *
84
- * See more about the overrides on the [Using theme overrides](/#using-theme-overrides) docs page.
85
- *
86
- * ```js-code
87
- * // ExampleComponent/theme.js
88
- * const generateComponentTheme = (theme) => {
89
- * const { colors } = theme
90
- *
91
- * const componentVariables = {
92
- * background: colors?.backgroundMedium,
93
- * color: colors?.textDarkest,
94
- *
95
- * hoverColor: colors?.textLightest,
96
- * hoverBackground: colors?.backgroundDarkest
97
- * }
98
- *
99
- * return componentVariables
100
- * }
101
- * export default generateComponentTheme
102
- * ```
103
- *
104
- * ```jsx-code
105
- * {// global theme override}
106
- * <InstUISettingsProvider theme={{
107
- * colors: { backgroundMedium: '#888' }
108
- * }}>
109
- * {// component theme override}
110
- * <ExampleComponent themeOverride={{ hoverColor: '#eee' }} />
111
- *
112
- * {// component theme override with function}
113
- * <ExampleComponent themeOverride={(componentTheme, currentTheme) => ({
114
- * hoverBackground: componentTheme.background,
115
- * activeBackground: currentTheme.colors.backgroundBrand
116
- * })} />
117
- * </InstUISettingsProvider>
118
- * ```
119
- *
120
- * @module withStyle
121
- *
122
- * @param {function} generateStyle - The function that returns the component's style object
123
- * @param {function} generateComponentTheme - The function that returns the component's theme variables object
124
- * @returns {ReactElement} The decorated WithStyle Component
125
- */
126
- const withStyle = exports.withStyle = (0, _decorator.decorator)((ComposedComponent, generateStyle, generateComponentTheme) => {
127
- const displayName = ComposedComponent.displayName || ComposedComponent.name;
128
- const WithStyle = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
129
- const theme = (0, _useTheme.useTheme)();
130
- if (props.styles) {
131
- (0, _console.warn)(false, `Manually passing the "styles" property is not allowed on the ${displayName} component. Using the default styles calculated by the @withStyle decorator instead.\n`, props.styles);
132
- }
133
- if (props.makeStyles) {
134
- (0, _console.warn)(false, `Manually passing the "makeStyles" property is not allowed on the ${displayName} component. Styles are calculated by the @withStyle decorator.`);
135
- }
136
- const componentProps = {
137
- ...ComposedComponent.defaultProps,
138
- ...props,
139
- ...defaultValues
140
- };
141
- let componentTheme = typeof generateComponentTheme === 'function' ? generateComponentTheme(theme) : {};
142
- const themeOverride = (0, _getComponentThemeOverride.getComponentThemeOverride)(theme, displayName, ComposedComponent.componentId, componentProps, componentTheme);
143
- componentTheme = {
144
- ...componentTheme,
145
- ...themeOverride
146
- };
147
- const _useState = (0, _react.useState)(generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}),
148
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
149
- styles = _useState2[0],
150
- setStyles = _useState2[1];
151
- const makeStyleHandler = extraArgs => {
152
- const calculatedStyles = generateStyle(componentTheme, componentProps, extraArgs);
153
- if (!(0, _deepEqual.deepEqual)(calculatedStyles, styles)) {
154
- setStyles(calculatedStyles);
155
- }
156
- };
157
- return (0, _jsxRuntime.jsx)(ComposedComponent, {
158
- ref: ref,
159
- ...props,
160
- makeStyles: makeStyleHandler,
161
- styles: styles
162
- // passing themeOverrides is needed for components like Button
163
- // that have no makeStyles of their own and only pass themeOverrides
164
- // to the underlying component (e.g.: BaseButton)
165
- ,
166
- themeOverride: themeOverride
167
- });
168
- });
169
- (0, _hoistNonReactStatics.default)(WithStyle, ComposedComponent);
170
-
171
- // added so it can be tested with ReactTestUtils
172
- // more info: https://github.com/facebook/react/issues/13455
173
- WithStyle.originalType = ComposedComponent.originalType || ComposedComponent;
174
- WithStyle.defaultProps = ComposedComponent.defaultProps;
175
- // These static fields exist on InstUI components
176
- WithStyle.allowedProps = ComposedComponent.allowedProps;
177
-
178
- // we are exposing the theme generator for the docs generation
179
- WithStyle.generateComponentTheme = generateComponentTheme;
180
-
181
- // we have to add defaults to makeStyles and styles added by this decorator
182
- // eslint-disable-next-line no-param-reassign
183
- ComposedComponent.defaultProps = {
184
- ...ComposedComponent.defaultProps,
185
- makeStyles: defaultValues.makeStyles,
186
- styles: defaultValues.styles
187
- };
188
- if (process.env.NODE_ENV !== 'production') {
189
- WithStyle.displayName = `WithStyle(${displayName})`;
190
- }
191
- return WithStyle;
192
- });
193
- var _default = exports.default = withStyle;