@telus-uds/components-base 1.20.0 → 1.21.0
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 +14 -2
- package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +1 -0
- package/component-docs.json +6 -2
- package/lib/ThemeProvider/ThemeProvider.js +21 -9
- package/lib/ThemeProvider/utils/styles.js +3 -1
- package/lib/index.js +9 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +21 -9
- package/lib-module/ThemeProvider/utils/styles.js +3 -1
- package/lib-module/index.js +1 -0
- package/package.json +1 -1
- package/src/ThemeProvider/ThemeProvider.jsx +19 -6
- package/src/ThemeProvider/utils/styles.js +3 -1
- package/src/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-base
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 23 Nov 2022 21:41:19 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.21.0
|
|
8
|
+
|
|
9
|
+
Wed, 23 Nov 2022 21:41:19 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Export useHydrationContext, add enableHelmetSSR opt-out (alan.slater@nearform.com)
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- fix: enforce specific font weight rule application (ruslan.bredikhin@nearform.com)
|
|
18
|
+
|
|
7
19
|
## 1.20.0
|
|
8
20
|
|
|
9
|
-
Tue, 08 Nov 2022 01:
|
|
21
|
+
Tue, 08 Nov 2022 01:35:30 GMT
|
|
10
22
|
|
|
11
23
|
### Minor changes
|
|
12
24
|
|
package/component-docs.json
CHANGED
|
@@ -8500,7 +8500,7 @@
|
|
|
8500
8500
|
"props": {
|
|
8501
8501
|
"themeOptions": {
|
|
8502
8502
|
"defaultValue": {
|
|
8503
|
-
"value": "{
|
|
8503
|
+
"value": "{}",
|
|
8504
8504
|
"computed": false
|
|
8505
8505
|
},
|
|
8506
8506
|
"type": {
|
|
@@ -8514,6 +8514,10 @@
|
|
|
8514
8514
|
"name": "bool",
|
|
8515
8515
|
"required": false
|
|
8516
8516
|
},
|
|
8517
|
+
"enableHelmetSSR": {
|
|
8518
|
+
"name": "bool",
|
|
8519
|
+
"required": false
|
|
8520
|
+
},
|
|
8517
8521
|
"contentMaxWidth": {
|
|
8518
8522
|
"name": "custom",
|
|
8519
8523
|
"raw": "responsiveProps.getTypeOptionallyByViewport(PropTypes.number)",
|
|
@@ -8522,7 +8526,7 @@
|
|
|
8522
8526
|
}
|
|
8523
8527
|
},
|
|
8524
8528
|
"required": false,
|
|
8525
|
-
"description": "An object containing options allowing to customize the theming experience:\n\n- `forceAbsoluteFontSizing`: available on web only; when set to true, allows\n using absolute font sizing (in pixels, doesn't scale) instead of the\n relative sizing (in `rem`, scales depending on the browser settings)\n- `contentMaxWidth`: allows configuration of the content max width to be used in components\n such as Footnote and Notification to avoid content to stretch width more then the page's width\n- `forceZIndex`: available on web only, when set to false, sets zIndex on `View` to be `auto`\n and when true, sets zIndex to be `0` (the default from `react-native-web`)"
|
|
8529
|
+
"description": "An object containing options allowing to customize the theming experience:\n\n- `forceAbsoluteFontSizing`: available on web only; when set to true, allows\n using absolute font sizing (in pixels, doesn't scale) instead of the\n relative sizing (in `rem`, scales depending on the browser settings)\n- `contentMaxWidth`: allows configuration of the content max width to be used in components\n such as Footnote and Notification to avoid content to stretch width more then the page's width\n- `forceZIndex`: available on web only, when set to false, sets zIndex on `View` to be `auto`\n and when true, sets zIndex to be `0` (the default from `react-native-web`)\n- `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be\n disabled unless a web app has been specifically configured to stop React Helmet accumulating\n instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet"
|
|
8526
8530
|
},
|
|
8527
8531
|
"children": {
|
|
8528
8532
|
"type": {
|
|
@@ -25,21 +25,29 @@ const uninitialisedError = new Error('Theme context used outside of ThemeProvide
|
|
|
25
25
|
exports.uninitialisedError = uninitialisedError;
|
|
26
26
|
const ThemeContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError);
|
|
27
27
|
exports.ThemeContext = ThemeContext;
|
|
28
|
-
const ThemeSetterContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError);
|
|
28
|
+
const ThemeSetterContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError); // These options default to `true` in v1.x to match legacy defaults and avoid breaking changes.
|
|
29
|
+
// This should change in future major releases to become "opt-in" legacy support.
|
|
30
|
+
|
|
29
31
|
exports.ThemeSetterContext = ThemeSetterContext;
|
|
32
|
+
const defaultThemeOptions = {
|
|
33
|
+
// TODO: switch `forceAbsoluteFontSizing` to be false by default in the next major version
|
|
34
|
+
forceAbsoluteFontSizing: true,
|
|
35
|
+
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
36
|
+
forceZIndex: true,
|
|
37
|
+
// TODO: switch `enableHelmetSSR` to be false by default in the next major version
|
|
38
|
+
enableHelmetSSR: true
|
|
39
|
+
};
|
|
30
40
|
|
|
31
41
|
const ThemeProvider = _ref => {
|
|
32
42
|
let {
|
|
33
43
|
children,
|
|
34
44
|
defaultTheme,
|
|
35
|
-
|
|
36
|
-
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
37
|
-
themeOptions = {
|
|
38
|
-
forceAbsoluteFontSizing: true,
|
|
39
|
-
forceZIndex: true
|
|
40
|
-
}
|
|
45
|
+
themeOptions = {}
|
|
41
46
|
} = _ref;
|
|
42
|
-
const [theme, setTheme] = (0, _react.useState)(defaultTheme);
|
|
47
|
+
const [theme, setTheme] = (0, _react.useState)(defaultTheme);
|
|
48
|
+
const appliedThemeOptions = { ...defaultThemeOptions,
|
|
49
|
+
...themeOptions
|
|
50
|
+
}; // Validate the theme tokens version on every render.
|
|
43
51
|
// This will intentionally break the application when attempting to use an invalid theme.
|
|
44
52
|
// This will surface an incompatibility quickly rather than allowing the potential for strange bugs due to missing or incompatible tokens.
|
|
45
53
|
|
|
@@ -48,7 +56,7 @@ const ThemeProvider = _ref => {
|
|
|
48
56
|
value: setTheme,
|
|
49
57
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeContext.Provider, {
|
|
50
58
|
value: { ...theme,
|
|
51
|
-
themeOptions
|
|
59
|
+
themeOptions: appliedThemeOptions
|
|
52
60
|
},
|
|
53
61
|
children: children
|
|
54
62
|
})
|
|
@@ -73,10 +81,14 @@ ThemeProvider.propTypes = {
|
|
|
73
81
|
* such as Footnote and Notification to avoid content to stretch width more then the page's width
|
|
74
82
|
* - `forceZIndex`: available on web only, when set to false, sets zIndex on `View` to be `auto`
|
|
75
83
|
* and when true, sets zIndex to be `0` (the default from `react-native-web`)
|
|
84
|
+
* - `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be
|
|
85
|
+
* disabled unless a web app has been specifically configured to stop React Helmet accumulating
|
|
86
|
+
* instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet
|
|
76
87
|
*/
|
|
77
88
|
themeOptions: _propTypes.default.shape({
|
|
78
89
|
forceAbsoluteFontSizing: _propTypes.default.bool,
|
|
79
90
|
forceZIndex: _propTypes.default.bool,
|
|
91
|
+
enableHelmetSSR: _propTypes.default.bool,
|
|
80
92
|
contentMaxWidth: _responsiveProps.default.getTypeOptionallyByViewport(_propTypes.default.number)
|
|
81
93
|
})
|
|
82
94
|
};
|
|
@@ -59,7 +59,9 @@ function applyTextStyles(_ref) {
|
|
|
59
59
|
// Don't set undefined font families. May need some validation here that the font is available.
|
|
60
60
|
// Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
|
|
61
61
|
styles.fontFamily = "".concat(fontName).concat(fontWeight).concat(fontStyle);
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (fontWeight) {
|
|
63
65
|
// If using system default font, apply the font weight directly.
|
|
64
66
|
// Font weight support in Android is limited to 'bold' or anything else === 'normal'.
|
|
65
67
|
styles.fontWeight = _Platform.default.OS === 'android' && Number(fontWeight) > 400 ? 'bold' : fontWeight;
|
package/lib/index.js
CHANGED
|
@@ -50,6 +50,7 @@ var _exportNames = {
|
|
|
50
50
|
A11yInfoProvider: true,
|
|
51
51
|
useA11yInfo: true,
|
|
52
52
|
BaseProvider: true,
|
|
53
|
+
useHydrationContext: true,
|
|
53
54
|
ViewportProvider: true,
|
|
54
55
|
useViewport: true,
|
|
55
56
|
ViewportContext: true,
|
|
@@ -387,6 +388,12 @@ Object.defineProperty(exports, "useA11yInfo", {
|
|
|
387
388
|
return _A11yInfoProvider.useA11yInfo;
|
|
388
389
|
}
|
|
389
390
|
});
|
|
391
|
+
Object.defineProperty(exports, "useHydrationContext", {
|
|
392
|
+
enumerable: true,
|
|
393
|
+
get: function () {
|
|
394
|
+
return _HydrationContext.useHydrationContext;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
390
397
|
Object.defineProperty(exports, "useSetTheme", {
|
|
391
398
|
enumerable: true,
|
|
392
399
|
get: function () {
|
|
@@ -636,6 +643,8 @@ var _A11yInfoProvider = _interopRequireWildcard(require("./A11yInfoProvider"));
|
|
|
636
643
|
|
|
637
644
|
var _BaseProvider = _interopRequireDefault(require("./BaseProvider"));
|
|
638
645
|
|
|
646
|
+
var _HydrationContext = require("./BaseProvider/HydrationContext");
|
|
647
|
+
|
|
639
648
|
var _ViewportProvider = _interopRequireWildcard(require("./ViewportProvider"));
|
|
640
649
|
|
|
641
650
|
var _ThemeProvider = _interopRequireWildcard(require("./ThemeProvider"));
|
|
@@ -5,20 +5,28 @@ import responsiveProps from '../utils/props/responsiveProps';
|
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
export const uninitialisedError = new Error('Theme context used outside of ThemeProvider');
|
|
7
7
|
export const ThemeContext = /*#__PURE__*/createContext(uninitialisedError);
|
|
8
|
-
export const ThemeSetterContext = /*#__PURE__*/createContext(uninitialisedError);
|
|
8
|
+
export const ThemeSetterContext = /*#__PURE__*/createContext(uninitialisedError); // These options default to `true` in v1.x to match legacy defaults and avoid breaking changes.
|
|
9
|
+
// This should change in future major releases to become "opt-in" legacy support.
|
|
10
|
+
|
|
11
|
+
const defaultThemeOptions = {
|
|
12
|
+
// TODO: switch `forceAbsoluteFontSizing` to be false by default in the next major version
|
|
13
|
+
forceAbsoluteFontSizing: true,
|
|
14
|
+
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
15
|
+
forceZIndex: true,
|
|
16
|
+
// TODO: switch `enableHelmetSSR` to be false by default in the next major version
|
|
17
|
+
enableHelmetSSR: true
|
|
18
|
+
};
|
|
9
19
|
|
|
10
20
|
const ThemeProvider = _ref => {
|
|
11
21
|
let {
|
|
12
22
|
children,
|
|
13
23
|
defaultTheme,
|
|
14
|
-
|
|
15
|
-
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
16
|
-
themeOptions = {
|
|
17
|
-
forceAbsoluteFontSizing: true,
|
|
18
|
-
forceZIndex: true
|
|
19
|
-
}
|
|
24
|
+
themeOptions = {}
|
|
20
25
|
} = _ref;
|
|
21
|
-
const [theme, setTheme] = useState(defaultTheme);
|
|
26
|
+
const [theme, setTheme] = useState(defaultTheme);
|
|
27
|
+
const appliedThemeOptions = { ...defaultThemeOptions,
|
|
28
|
+
...themeOptions
|
|
29
|
+
}; // Validate the theme tokens version on every render.
|
|
22
30
|
// This will intentionally break the application when attempting to use an invalid theme.
|
|
23
31
|
// This will surface an incompatibility quickly rather than allowing the potential for strange bugs due to missing or incompatible tokens.
|
|
24
32
|
|
|
@@ -27,7 +35,7 @@ const ThemeProvider = _ref => {
|
|
|
27
35
|
value: setTheme,
|
|
28
36
|
children: /*#__PURE__*/_jsx(ThemeContext.Provider, {
|
|
29
37
|
value: { ...theme,
|
|
30
|
-
themeOptions
|
|
38
|
+
themeOptions: appliedThemeOptions
|
|
31
39
|
},
|
|
32
40
|
children: children
|
|
33
41
|
})
|
|
@@ -52,10 +60,14 @@ ThemeProvider.propTypes = {
|
|
|
52
60
|
* such as Footnote and Notification to avoid content to stretch width more then the page's width
|
|
53
61
|
* - `forceZIndex`: available on web only, when set to false, sets zIndex on `View` to be `auto`
|
|
54
62
|
* and when true, sets zIndex to be `0` (the default from `react-native-web`)
|
|
63
|
+
* - `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be
|
|
64
|
+
* disabled unless a web app has been specifically configured to stop React Helmet accumulating
|
|
65
|
+
* instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet
|
|
55
66
|
*/
|
|
56
67
|
themeOptions: PropTypes.shape({
|
|
57
68
|
forceAbsoluteFontSizing: PropTypes.bool,
|
|
58
69
|
forceZIndex: PropTypes.bool,
|
|
70
|
+
enableHelmetSSR: PropTypes.bool,
|
|
59
71
|
contentMaxWidth: responsiveProps.getTypeOptionallyByViewport(PropTypes.number)
|
|
60
72
|
})
|
|
61
73
|
};
|
|
@@ -45,7 +45,9 @@ export function applyTextStyles(_ref) {
|
|
|
45
45
|
// Don't set undefined font families. May need some validation here that the font is available.
|
|
46
46
|
// Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
|
|
47
47
|
styles.fontFamily = "".concat(fontName).concat(fontWeight).concat(fontStyle);
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (fontWeight) {
|
|
49
51
|
// If using system default font, apply the font weight directly.
|
|
50
52
|
// Font weight support in Android is limited to 'bold' or anything else === 'normal'.
|
|
51
53
|
styles.fontWeight = Platform.OS === 'android' && Number(fontWeight) > 400 ? 'bold' : fontWeight;
|
package/lib-module/index.js
CHANGED
|
@@ -50,6 +50,7 @@ export { default as TooltipButton } from './TooltipButton';
|
|
|
50
50
|
export { default as Typography } from './Typography';
|
|
51
51
|
export { default as A11yInfoProvider, useA11yInfo } from './A11yInfoProvider';
|
|
52
52
|
export { default as BaseProvider } from './BaseProvider';
|
|
53
|
+
export { useHydrationContext } from './BaseProvider/HydrationContext';
|
|
53
54
|
export { default as ViewportProvider, useViewport, ViewportContext } from './ViewportProvider';
|
|
54
55
|
export { default as ThemeProvider, useTheme, useSetTheme, useThemeTokens, getThemeTokens, applyOuterBorder, applyTextStyles, applyShadowToken } from './ThemeProvider';
|
|
55
56
|
export * from './utils';
|
package/package.json
CHANGED
|
@@ -8,15 +8,22 @@ export const uninitialisedError = new Error('Theme context used outside of Theme
|
|
|
8
8
|
export const ThemeContext = createContext(uninitialisedError)
|
|
9
9
|
export const ThemeSetterContext = createContext(uninitialisedError)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
// These options default to `true` in v1.x to match legacy defaults and avoid breaking changes.
|
|
12
|
+
// This should change in future major releases to become "opt-in" legacy support.
|
|
13
|
+
const defaultThemeOptions = {
|
|
14
14
|
// TODO: switch `forceAbsoluteFontSizing` to be false by default in the next major version
|
|
15
|
+
forceAbsoluteFontSizing: true,
|
|
15
16
|
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
forceZIndex: true,
|
|
18
|
+
// TODO: switch `enableHelmetSSR` to be false by default in the next major version
|
|
19
|
+
enableHelmetSSR: true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ThemeProvider = ({ children, defaultTheme, themeOptions = {} }) => {
|
|
18
23
|
const [theme, setTheme] = useState(defaultTheme)
|
|
19
24
|
|
|
25
|
+
const appliedThemeOptions = { ...defaultThemeOptions, ...themeOptions }
|
|
26
|
+
|
|
20
27
|
// Validate the theme tokens version on every render.
|
|
21
28
|
// This will intentionally break the application when attempting to use an invalid theme.
|
|
22
29
|
// This will surface an incompatibility quickly rather than allowing the potential for strange bugs due to missing or incompatible tokens.
|
|
@@ -24,7 +31,9 @@ const ThemeProvider = ({
|
|
|
24
31
|
|
|
25
32
|
return (
|
|
26
33
|
<ThemeSetterContext.Provider value={setTheme}>
|
|
27
|
-
<ThemeContext.Provider value={{ ...theme, themeOptions }}>
|
|
34
|
+
<ThemeContext.Provider value={{ ...theme, themeOptions: appliedThemeOptions }}>
|
|
35
|
+
{children}
|
|
36
|
+
</ThemeContext.Provider>
|
|
28
37
|
</ThemeSetterContext.Provider>
|
|
29
38
|
)
|
|
30
39
|
}
|
|
@@ -46,10 +55,14 @@ ThemeProvider.propTypes = {
|
|
|
46
55
|
* such as Footnote and Notification to avoid content to stretch width more then the page's width
|
|
47
56
|
* - `forceZIndex`: available on web only, when set to false, sets zIndex on `View` to be `auto`
|
|
48
57
|
* and when true, sets zIndex to be `0` (the default from `react-native-web`)
|
|
58
|
+
* - `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be
|
|
59
|
+
* disabled unless a web app has been specifically configured to stop React Helmet accumulating
|
|
60
|
+
* instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet
|
|
49
61
|
*/
|
|
50
62
|
themeOptions: PropTypes.shape({
|
|
51
63
|
forceAbsoluteFontSizing: PropTypes.bool,
|
|
52
64
|
forceZIndex: PropTypes.bool,
|
|
65
|
+
enableHelmetSSR: PropTypes.bool,
|
|
53
66
|
contentMaxWidth: responsiveProps.getTypeOptionallyByViewport(PropTypes.number)
|
|
54
67
|
})
|
|
55
68
|
}
|
|
@@ -45,7 +45,9 @@ export function applyTextStyles({
|
|
|
45
45
|
// Don't set undefined font families. May need some validation here that the font is available.
|
|
46
46
|
// Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
|
|
47
47
|
styles.fontFamily = `${fontName}${fontWeight}${fontStyle}`
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (fontWeight) {
|
|
49
51
|
// If using system default font, apply the font weight directly.
|
|
50
52
|
// Font weight support in Android is limited to 'bold' or anything else === 'normal'.
|
|
51
53
|
styles.fontWeight = Platform.OS === 'android' && Number(fontWeight) > 400 ? 'bold' : fontWeight
|
package/src/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export { default as Typography } from './Typography'
|
|
|
51
51
|
|
|
52
52
|
export { default as A11yInfoProvider, useA11yInfo } from './A11yInfoProvider'
|
|
53
53
|
export { default as BaseProvider } from './BaseProvider'
|
|
54
|
+
export { useHydrationContext } from './BaseProvider/HydrationContext'
|
|
54
55
|
export { default as ViewportProvider, useViewport, ViewportContext } from './ViewportProvider'
|
|
55
56
|
export {
|
|
56
57
|
default as ThemeProvider,
|