@telus-uds/components-base 1.72.0 → 1.73.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 +20 -2
- package/lib/Box/Box.js +17 -6
- package/lib/FlexGrid/Col/Col.js +42 -19
- package/lib/FlexGrid/FlexGrid.js +40 -17
- package/lib/FlexGrid/Row/Row.js +45 -22
- package/lib/Listbox/ListboxGroup.js +7 -1
- package/lib/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib/Notification/Notification.js +13 -5
- package/lib/OrderedList/ItemBase.js +7 -1
- package/lib/Responsive/Responsive.js +24 -14
- package/lib/Responsive/ResponsiveProp.js +46 -0
- package/lib/Responsive/ResponsiveWithMediaQueryStyleSheet.js +72 -0
- package/lib/ThemeProvider/ThemeProvider.js +5 -2
- package/lib/ThemeProvider/index.js +9 -1
- package/lib/ThemeProvider/useResponsiveThemeTokens.js +89 -0
- package/lib/Typography/Typography.js +48 -22
- package/lib/server.js +40 -0
- package/lib/utils/ssr-media-query/utils/create-media-query-styles.js +39 -6
- package/lib-module/Box/Box.js +17 -6
- package/lib-module/FlexGrid/Col/Col.js +42 -19
- package/lib-module/FlexGrid/FlexGrid.js +40 -17
- package/lib-module/FlexGrid/Row/Row.js +45 -22
- package/lib-module/Listbox/ListboxGroup.js +7 -1
- package/lib-module/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib-module/Notification/Notification.js +13 -5
- package/lib-module/OrderedList/ItemBase.js +7 -1
- package/lib-module/Responsive/Responsive.js +24 -15
- package/lib-module/Responsive/ResponsiveProp.js +39 -0
- package/lib-module/Responsive/ResponsiveWithMediaQueryStyleSheet.js +64 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +5 -2
- package/lib-module/ThemeProvider/index.js +1 -0
- package/lib-module/ThemeProvider/useResponsiveThemeTokens.js +81 -0
- package/lib-module/Typography/Typography.js +50 -24
- package/lib-module/server.js +4 -0
- package/lib-module/utils/ssr-media-query/utils/create-media-query-styles.js +36 -6
- package/package.json +13 -2
- package/src/Box/Box.jsx +35 -17
- package/src/FlexGrid/Col/Col.jsx +42 -13
- package/src/FlexGrid/FlexGrid.jsx +40 -11
- package/src/FlexGrid/Row/Row.jsx +40 -16
- package/src/Listbox/ListboxGroup.jsx +9 -2
- package/src/MultiSelectFilter/MultiSelectFilter.jsx +2 -0
- package/src/Notification/Notification.jsx +15 -3
- package/src/OrderedList/ItemBase.jsx +14 -2
- package/src/Responsive/Responsive.jsx +24 -11
- package/src/Responsive/ResponsiveProp.jsx +33 -0
- package/src/Responsive/ResponsiveWithMediaQueryStyleSheet.jsx +58 -0
- package/src/ThemeProvider/ThemeProvider.jsx +5 -2
- package/src/ThemeProvider/index.js +1 -0
- package/src/ThemeProvider/useResponsiveThemeTokens.js +85 -0
- package/src/Typography/Typography.jsx +72 -24
- package/src/server.js +4 -0
- package/src/utils/ssr-media-query/utils/create-media-query-styles.js +21 -6
|
@@ -27,7 +27,8 @@ const defaultThemeOptions = {
|
|
|
27
27
|
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
28
28
|
forceZIndex: true,
|
|
29
29
|
// TODO: switch `enableHelmetSSR` to be false by default in the next major version
|
|
30
|
-
enableHelmetSSR: true
|
|
30
|
+
enableHelmetSSR: true,
|
|
31
|
+
enableMediaQueryStyleSheet: false
|
|
31
32
|
};
|
|
32
33
|
const ThemeProvider = _ref => {
|
|
33
34
|
let {
|
|
@@ -82,12 +83,14 @@ ThemeProvider.propTypes = {
|
|
|
82
83
|
* - `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be
|
|
83
84
|
* disabled unless a web app has been specifically configured to stop React Helmet accumulating
|
|
84
85
|
* instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet
|
|
86
|
+
* - `enableMediaQueryStyleSheet`: enables the use of Media Query StyleSheet.
|
|
85
87
|
*/
|
|
86
88
|
themeOptions: _propTypes.default.shape({
|
|
87
89
|
forceAbsoluteFontSizing: _propTypes.default.bool,
|
|
88
90
|
forceZIndex: _propTypes.default.bool,
|
|
89
91
|
enableHelmetSSR: _propTypes.default.bool,
|
|
90
|
-
contentMaxWidth: _responsiveProps.default.getTypeOptionallyByViewport(_propTypes.default.number)
|
|
92
|
+
contentMaxWidth: _responsiveProps.default.getTypeOptionallyByViewport(_propTypes.default.number),
|
|
93
|
+
enableMediaQueryStyleSheet: _propTypes.default.bool
|
|
91
94
|
})
|
|
92
95
|
};
|
|
93
96
|
var _default = ThemeProvider;
|
|
@@ -5,9 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
useTheme: true,
|
|
8
|
-
useSetTheme: true
|
|
8
|
+
useSetTheme: true,
|
|
9
|
+
useResponsiveThemeTokens: true
|
|
9
10
|
};
|
|
10
11
|
exports.default = void 0;
|
|
12
|
+
Object.defineProperty(exports, "useResponsiveThemeTokens", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useResponsiveThemeTokens.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
11
18
|
Object.defineProperty(exports, "useSetTheme", {
|
|
12
19
|
enumerable: true,
|
|
13
20
|
get: function () {
|
|
@@ -23,6 +30,7 @@ Object.defineProperty(exports, "useTheme", {
|
|
|
23
30
|
var _ThemeProvider = _interopRequireDefault(require("./ThemeProvider"));
|
|
24
31
|
var _useTheme = _interopRequireDefault(require("./useTheme"));
|
|
25
32
|
var _useSetTheme = _interopRequireDefault(require("./useSetTheme"));
|
|
33
|
+
var _useResponsiveThemeTokens = _interopRequireDefault(require("./useResponsiveThemeTokens"));
|
|
26
34
|
var _useThemeTokens = require("./useThemeTokens");
|
|
27
35
|
Object.keys(_useThemeTokens).forEach(function (key) {
|
|
28
36
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _systemConstants = require("@telus-uds/system-constants");
|
|
8
|
+
var _useTheme = _interopRequireDefault(require("./useTheme"));
|
|
9
|
+
var _utils = require("./utils");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const getResponsiveThemeTokens = function (_ref, tokensProp) {
|
|
12
|
+
let {
|
|
13
|
+
rules = [],
|
|
14
|
+
tokens: defaultThemeTokens = {}
|
|
15
|
+
} = _ref;
|
|
16
|
+
let variants = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
17
|
+
let states = arguments.length > 3 ? arguments[3] : undefined;
|
|
18
|
+
const appearances = (0, _utils.mergeAppearances)(variants, states);
|
|
19
|
+
const tokensByViewport = Object.fromEntries(_systemConstants.viewports.keys.map(viewport => [viewport, {
|
|
20
|
+
...defaultThemeTokens
|
|
21
|
+
}]));
|
|
22
|
+
|
|
23
|
+
// Go through each rule and collect them for the corresponding viewport if they apply
|
|
24
|
+
rules.forEach(rule => {
|
|
25
|
+
if (doesRuleApply(rule, appearances)) {
|
|
26
|
+
// If the rule does not have a viewport specified, we collect it in all viewports
|
|
27
|
+
let targetViewports = rule.if.viewport || _systemConstants.viewports.keys;
|
|
28
|
+
if (!Array.isArray(targetViewports)) {
|
|
29
|
+
targetViewports = [targetViewports];
|
|
30
|
+
}
|
|
31
|
+
targetViewports.forEach(viewport => {
|
|
32
|
+
tokensByViewport[viewport] = {
|
|
33
|
+
...tokensByViewport[viewport],
|
|
34
|
+
...rule.tokens
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.keys(tokensByViewport).forEach(viewport => {
|
|
40
|
+
tokensByViewport[viewport] = (0, _utils.resolveThemeTokens)(tokensByViewport[viewport], appearances, tokensProp);
|
|
41
|
+
});
|
|
42
|
+
return tokensByViewport;
|
|
43
|
+
};
|
|
44
|
+
const doesRuleApply = (rule, appearances) => Object.entries(rule.if).every(condition => doesConditionApply(condition, appearances));
|
|
45
|
+
const doesConditionApply = (_ref2, appearances) => {
|
|
46
|
+
let [key, value] = _ref2;
|
|
47
|
+
if (key === 'viewport') {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
// use null rather than undefined so we can serialise the value in themes
|
|
51
|
+
const appearanceValue = appearances[key] ?? null;
|
|
52
|
+
return Array.isArray(value) ? value.includes(appearanceValue) : value === appearanceValue;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {import('../utils/props/tokens.js').TokensSet} TokensSet
|
|
57
|
+
* @typedef {import('../utils/props/tokens.js').TokensProp} TokensProp
|
|
58
|
+
* @typedef {import('../utils/props/variantProp').AppearanceSet} AppearanceSet
|
|
59
|
+
*
|
|
60
|
+
* Returns a complete set of tokens for a component for each viewport based on which of the
|
|
61
|
+
* component's theme rules apply to the current set of theme appearances.
|
|
62
|
+
* Pass the returned output to createMediaQueryStyles to generate media query styles for use inside
|
|
63
|
+
* the media query stylesheet from './utils/ssr-media-query'.
|
|
64
|
+
*
|
|
65
|
+
* @typedef {Object} ResponsiveObject
|
|
66
|
+
* @property {TokensSet} xs
|
|
67
|
+
* @property {TokensSet} sm
|
|
68
|
+
* @property {TokensSet} md
|
|
69
|
+
* @property {TokensSet} lg
|
|
70
|
+
* @property {TokensSet} xl
|
|
71
|
+
*
|
|
72
|
+
* @param { string } componentName
|
|
73
|
+
* @param { TokensProp } tokens
|
|
74
|
+
* @param { AppearanceSet } variants
|
|
75
|
+
* @param { AppearanceSet } states
|
|
76
|
+
* @returns { ResponsiveObject }
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
const useResponsiveThemeTokens = function (componentName) {
|
|
80
|
+
let tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
81
|
+
let variants = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
82
|
+
let states = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
83
|
+
const theme = (0, _useTheme.default)();
|
|
84
|
+
const componentTheme = (0, _utils.getComponentTheme)(theme, componentName);
|
|
85
|
+
const themeTokens = getResponsiveThemeTokens(componentTheme, tokens, variants, states);
|
|
86
|
+
return themeTokens;
|
|
87
|
+
};
|
|
88
|
+
var _default = useResponsiveThemeTokens;
|
|
89
|
+
exports.default = _default;
|
|
@@ -9,9 +9,9 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _Text = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Text"));
|
|
10
10
|
var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
11
11
|
var _ThemeProvider = require("../ThemeProvider");
|
|
12
|
-
var _ViewportProvider = require("../ViewportProvider");
|
|
13
12
|
var _utils = require("../ThemeProvider/utils");
|
|
14
13
|
var _utils2 = require("../utils");
|
|
14
|
+
var _ViewportProvider = require("../ViewportProvider");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -29,7 +29,8 @@ const selectTextStyles = (_ref, themeOptions) => {
|
|
|
29
29
|
fontName,
|
|
30
30
|
textAlign,
|
|
31
31
|
textTransform,
|
|
32
|
-
letterSpacing
|
|
32
|
+
letterSpacing,
|
|
33
|
+
textDecorationLine
|
|
33
34
|
} = _ref;
|
|
34
35
|
return (0, _utils.applyTextStyles)({
|
|
35
36
|
fontWeight,
|
|
@@ -40,7 +41,8 @@ const selectTextStyles = (_ref, themeOptions) => {
|
|
|
40
41
|
themeOptions,
|
|
41
42
|
textAlign,
|
|
42
43
|
textTransform,
|
|
43
|
-
letterSpacing
|
|
44
|
+
letterSpacing,
|
|
45
|
+
textDecorationLine
|
|
44
46
|
});
|
|
45
47
|
};
|
|
46
48
|
|
|
@@ -60,23 +62,48 @@ const Typography = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
|
60
62
|
...rest
|
|
61
63
|
} = _ref2;
|
|
62
64
|
const viewport = (0, _ViewportProvider.useViewport)();
|
|
63
|
-
const {
|
|
64
|
-
superScriptFontSize,
|
|
65
|
-
...themeTokens
|
|
66
|
-
} = (0, _ThemeProvider.useThemeTokens)('Typography', tokens, variant, {
|
|
67
|
-
viewport
|
|
68
|
-
});
|
|
69
65
|
const {
|
|
70
66
|
themeOptions
|
|
71
67
|
} = (0, _ThemeProvider.useTheme)();
|
|
68
|
+
const {
|
|
69
|
+
enableMediaQueryStyleSheet
|
|
70
|
+
} = themeOptions;
|
|
71
|
+
const useTokens = enableMediaQueryStyleSheet ? _ThemeProvider.useResponsiveThemeTokens : _ThemeProvider.useThemeTokens;
|
|
72
|
+
const themeTokens = useTokens('Typography', tokens, variant);
|
|
73
|
+
const maxFontSizeMultiplier = enableMediaQueryStyleSheet ? (0, _utils2.getMaxFontMultiplier)(themeTokens[viewport]) : (0, _utils2.getMaxFontMultiplier)(themeTokens);
|
|
74
|
+
const textDecorationLine = strikeThrough ? 'line-through' : 'none';
|
|
75
|
+
let textStyles;
|
|
76
|
+
let mediaIds;
|
|
77
|
+
if (enableMediaQueryStyleSheet) {
|
|
78
|
+
const transformedThemeTokens = Object.entries(themeTokens).reduce((acc, _ref3) => {
|
|
79
|
+
let [vp, viewportTokens] = _ref3;
|
|
80
|
+
acc[vp] = selectTextStyles({
|
|
81
|
+
textAlign: align,
|
|
82
|
+
textDecorationLine,
|
|
83
|
+
...viewportTokens
|
|
84
|
+
}, themeOptions);
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
const mediaQueryStyles = (0, _utils2.createMediaQueryStyles)(transformedThemeTokens);
|
|
88
|
+
const {
|
|
89
|
+
ids,
|
|
90
|
+
styles
|
|
91
|
+
} = _utils2.StyleSheet.create({
|
|
92
|
+
text: mediaQueryStyles
|
|
93
|
+
});
|
|
94
|
+
textStyles = styles.text;
|
|
95
|
+
mediaIds = ids.text;
|
|
96
|
+
} else {
|
|
97
|
+
textStyles = selectTextStyles({
|
|
98
|
+
textAlign: align,
|
|
99
|
+
textDecorationLine,
|
|
100
|
+
...themeTokens
|
|
101
|
+
}, themeOptions);
|
|
102
|
+
}
|
|
72
103
|
const resolvedTextProps = {
|
|
73
104
|
...selectTextProps(rest),
|
|
74
|
-
style: selectTextStyles(align ? {
|
|
75
|
-
...themeTokens,
|
|
76
|
-
textAlign: align
|
|
77
|
-
} : themeTokens, themeOptions),
|
|
78
105
|
dataSet,
|
|
79
|
-
maxFontSizeMultiplier
|
|
106
|
+
maxFontSizeMultiplier
|
|
80
107
|
};
|
|
81
108
|
const containerProps = {
|
|
82
109
|
accessibilityRole,
|
|
@@ -87,7 +114,7 @@ const Typography = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
|
87
114
|
if (typeof child === 'object' && ((child === null || child === void 0 ? void 0 : child.type) === 'sub' || (child === null || child === void 0 ? void 0 : child.type) === 'sup')) {
|
|
88
115
|
var _child$props;
|
|
89
116
|
const childStyles = (child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.style) || {};
|
|
90
|
-
const supFontSize = childStyles.fontSize ?? superScriptFontSize;
|
|
117
|
+
const supFontSize = childStyles.fontSize ?? themeTokens.superScriptFontSize;
|
|
91
118
|
const sanitizedChild = /*#__PURE__*/_react.default.cloneElement(child, {
|
|
92
119
|
style: {
|
|
93
120
|
...childStyles,
|
|
@@ -107,19 +134,15 @@ const Typography = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
|
107
134
|
}
|
|
108
135
|
return resetTagStyling(children);
|
|
109
136
|
};
|
|
110
|
-
const textDecorationLine = strikeThrough ? 'line-through' : 'none';
|
|
111
|
-
const textStyles = resolvedTextProps.style ? {
|
|
112
|
-
...resolvedTextProps.style,
|
|
113
|
-
textDecorationLine
|
|
114
|
-
} : {
|
|
115
|
-
textDecorationLine
|
|
116
|
-
};
|
|
117
137
|
return block ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
118
138
|
ref: ref,
|
|
119
139
|
...containerProps,
|
|
120
140
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
|
|
121
141
|
...resolvedTextProps,
|
|
122
142
|
style: textStyles,
|
|
143
|
+
dataSet: mediaIds && {
|
|
144
|
+
media: mediaIds
|
|
145
|
+
},
|
|
123
146
|
children: sanitizeChildren(children)
|
|
124
147
|
})
|
|
125
148
|
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
|
|
@@ -127,6 +150,9 @@ const Typography = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
|
127
150
|
...containerProps,
|
|
128
151
|
...resolvedTextProps,
|
|
129
152
|
style: textStyles,
|
|
153
|
+
dataSet: mediaIds && {
|
|
154
|
+
media: mediaIds
|
|
155
|
+
},
|
|
130
156
|
children: sanitizeChildren(children)
|
|
131
157
|
});
|
|
132
158
|
});
|
package/lib/server.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "getComponentTheme", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _themeTokens.getComponentTheme;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getThemeTokens", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _themeTokens.getThemeTokens;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "getTokensPropType", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _tokens.getTokensPropType;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "htmlAttrs", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _htmlAttrs.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "selectSystemProps", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _selectSystemProps.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _selectSystemProps = _interopRequireDefault(require("./utils/props/selectSystemProps"));
|
|
37
|
+
var _tokens = require("./utils/props/tokens");
|
|
38
|
+
var _htmlAttrs = _interopRequireDefault(require("./utils/htmlAttrs"));
|
|
39
|
+
var _themeTokens = require("./ThemeProvider/utils/theme-tokens");
|
|
40
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -5,20 +5,53 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _systemConstants = require("@telus-uds/system-constants");
|
|
8
|
+
const inherit = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
xs,
|
|
11
|
+
sm = xs,
|
|
12
|
+
md = sm,
|
|
13
|
+
lg = md,
|
|
14
|
+
xl = lg
|
|
15
|
+
} = _ref;
|
|
16
|
+
return {
|
|
17
|
+
xs,
|
|
18
|
+
sm,
|
|
19
|
+
md,
|
|
20
|
+
lg,
|
|
21
|
+
xl
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
8
25
|
/**
|
|
9
26
|
* @typedef { Object } CssStyles
|
|
10
|
-
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef { Object } ViewportStyles
|
|
31
|
+
* @property { CssStyles } xs - The CSS styles for the "xs" viewport (required).
|
|
32
|
+
* @property { CssStyles } [sm] - Optional styles for the "sm" viewport. Inherits from "xs" if not specified.
|
|
33
|
+
* @property { CssStyles } [md] - Optional styles for the "md" viewport. Inherits from "sm" if not specified.
|
|
34
|
+
* @property { CssStyles } [lg] - Optional styles for the "lg" viewport. Inherits from "md" if not specified.
|
|
35
|
+
* @property { CssStyles } [xl] - Optional styles for the "xl" viewport. Inherits from "lg" if not specified.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
11
39
|
* @typedef { Record<String, CssStyles> } MediaQueryStyles
|
|
12
40
|
*/
|
|
41
|
+
|
|
13
42
|
/**
|
|
14
43
|
* Generates media query styles based on specified viewport styles.
|
|
15
|
-
* @param {
|
|
16
|
-
* @
|
|
44
|
+
* @param { Object } viewportStyles - The styles for different viewports.
|
|
45
|
+
* @param { boolean } [shouldInherit=true] - Flag indicating whether to inherit styles.
|
|
46
|
+
* @returns { Object } - The media query styles.
|
|
17
47
|
*/
|
|
48
|
+
|
|
18
49
|
function createMediaQueryStyles(viewportStyles) {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
50
|
+
let shouldInherit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
51
|
+
const effectiveStyles = shouldInherit ? inherit(viewportStyles) : viewportStyles;
|
|
52
|
+
const viewportsArray = _systemConstants.viewports.keys;
|
|
53
|
+
const mediaQueries = Object.entries(effectiveStyles).reduce((acc, _ref2) => {
|
|
54
|
+
let [viewport, styles] = _ref2;
|
|
22
55
|
const minWidth = _systemConstants.viewports.map.get(viewport);
|
|
23
56
|
const nextViewport = viewportsArray[viewportsArray.indexOf(viewport) + 1];
|
|
24
57
|
const maxWidth = _systemConstants.viewports.map.get(nextViewport);
|
package/lib-module/Box/Box.js
CHANGED
|
@@ -2,6 +2,7 @@ import React, { forwardRef } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import View from "react-native-web/dist/exports/View";
|
|
4
4
|
import ScrollView from "react-native-web/dist/exports/ScrollView";
|
|
5
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
5
6
|
import { useThemeTokens } from '../ThemeProvider';
|
|
6
7
|
import { a11yProps, getA11yPropsFromHtmlTag, getTokensPropType, layoutTags, selectSystemProps, spacingProps, useSpacingScale, variantProp, viewProps } from '../utils';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -14,7 +15,7 @@ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, vie
|
|
|
14
15
|
* @typedef {import('../utils/props/spacingProps.js').SpacingOptions} SpacingOptions
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
const selectBoxStyles = _ref => {
|
|
18
|
+
const selectBoxStyles = (_ref, customGradient) => {
|
|
18
19
|
let {
|
|
19
20
|
backgroundColor,
|
|
20
21
|
gradient,
|
|
@@ -40,7 +41,11 @@ const selectBoxStyles = _ref => {
|
|
|
40
41
|
angle,
|
|
41
42
|
stops: [stopOne, stopTwo]
|
|
42
43
|
} = gradient;
|
|
43
|
-
|
|
44
|
+
if (Platform.OS === 'web') {
|
|
45
|
+
styles.backgroundImage = `linear-gradient(${angle}deg, ${stopOne.color}, 75%, ${stopTwo.color})`;
|
|
46
|
+
} else if (customGradient && Platform.OS !== 'web') {
|
|
47
|
+
styles.colors = [stopOne.color, stopTwo.color];
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
50
|
const paddings = ['paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom'];
|
|
46
51
|
// Only set on styles if token provided because we spread this object after the spacing scale values
|
|
@@ -135,6 +140,7 @@ const Box = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
135
140
|
accessibilityRole,
|
|
136
141
|
testID,
|
|
137
142
|
dataSet,
|
|
143
|
+
customGradient,
|
|
138
144
|
...rest
|
|
139
145
|
} = _ref2;
|
|
140
146
|
const props = {
|
|
@@ -149,8 +155,9 @@ const Box = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
149
155
|
paddingRight: useSpacingScale(right),
|
|
150
156
|
paddingTop: useSpacingScale(top),
|
|
151
157
|
paddingBottom: useSpacingScale(bottom),
|
|
152
|
-
...selectBoxStyles(themeTokens)
|
|
158
|
+
...selectBoxStyles(themeTokens, customGradient)
|
|
153
159
|
};
|
|
160
|
+
const childrenToRender = typeof customGradient === 'function' ? customGradient(styles.colors, styles)(children) : children;
|
|
154
161
|
if (scroll) {
|
|
155
162
|
const scrollProps = typeof scroll === 'object' ? scroll : {};
|
|
156
163
|
scrollProps.contentContainerStyle = [styles, scrollProps.contentContainerStyle];
|
|
@@ -160,7 +167,7 @@ const Box = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
160
167
|
testID: testID,
|
|
161
168
|
dataSet: dataSet,
|
|
162
169
|
ref: ref,
|
|
163
|
-
children:
|
|
170
|
+
children: childrenToRender
|
|
164
171
|
});
|
|
165
172
|
}
|
|
166
173
|
return /*#__PURE__*/_jsx(View, {
|
|
@@ -169,7 +176,7 @@ const Box = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
169
176
|
testID: testID,
|
|
170
177
|
dataSet: dataSet,
|
|
171
178
|
ref: ref,
|
|
172
|
-
children:
|
|
179
|
+
children: childrenToRender
|
|
173
180
|
});
|
|
174
181
|
});
|
|
175
182
|
Box.displayName = 'Box';
|
|
@@ -253,6 +260,10 @@ Box.propTypes = {
|
|
|
253
260
|
/**
|
|
254
261
|
* Box accepts any content as children.
|
|
255
262
|
*/
|
|
256
|
-
children: PropTypes.node.isRequired
|
|
263
|
+
children: PropTypes.node.isRequired,
|
|
264
|
+
/**
|
|
265
|
+
Use this prop if need to add a custom gradient for mobile
|
|
266
|
+
*/
|
|
267
|
+
customGradient: PropTypes.func
|
|
257
268
|
};
|
|
258
269
|
export default Box;
|
|
@@ -4,6 +4,8 @@ import Platform from "react-native-web/dist/exports/Platform";
|
|
|
4
4
|
import GutterContext from '../providers/GutterContext';
|
|
5
5
|
import applyInheritance from '../helpers';
|
|
6
6
|
import { responsiveProps, BaseView, StyleSheet, createMediaQueryStyles } from '../../utils';
|
|
7
|
+
import { useViewport } from '../../ViewportProvider';
|
|
8
|
+
import { useTheme } from '../../ThemeProvider';
|
|
7
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
10
|
const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
9
11
|
let {
|
|
@@ -23,6 +25,12 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
23
25
|
...viewProps
|
|
24
26
|
} = _ref;
|
|
25
27
|
const gutter = useContext(GutterContext);
|
|
28
|
+
const viewport = useViewport();
|
|
29
|
+
const {
|
|
30
|
+
themeOptions: {
|
|
31
|
+
enableMediaQueryStyleSheet
|
|
32
|
+
}
|
|
33
|
+
} = useTheme();
|
|
26
34
|
const hiddenLevels = applyInheritance([xs, sm, md, lg, xl]);
|
|
27
35
|
const getHorizontalAlignLevel = () => {
|
|
28
36
|
if (typeof horizontalAlign === 'object') {
|
|
@@ -86,7 +94,15 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
86
94
|
lg: offsetsWithIheritance[3],
|
|
87
95
|
xl: offsetsWithIheritance[4]
|
|
88
96
|
};
|
|
89
|
-
const
|
|
97
|
+
const staticStyles = {
|
|
98
|
+
flexGrow: 1,
|
|
99
|
+
flexShrink: 0,
|
|
100
|
+
flexBasis: 'auto',
|
|
101
|
+
maxWidth: '100%',
|
|
102
|
+
paddingLeft: gutter ? 16 : 0,
|
|
103
|
+
paddingRight: gutter ? 16 : 0
|
|
104
|
+
};
|
|
105
|
+
const stylesByViewport = {
|
|
90
106
|
xs: {
|
|
91
107
|
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
92
108
|
textAlign: horizontalAlignLevel[0],
|
|
@@ -117,27 +133,34 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
117
133
|
...calculateWidth(sizes.xl),
|
|
118
134
|
...calculateOffset(offsets.xl)
|
|
119
135
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
136
|
+
};
|
|
137
|
+
let colStyles;
|
|
138
|
+
let mediaIds;
|
|
139
|
+
if (enableMediaQueryStyleSheet) {
|
|
140
|
+
const mediaQueryStyles = createMediaQueryStyles(stylesByViewport);
|
|
141
|
+
const {
|
|
142
|
+
ids,
|
|
143
|
+
styles
|
|
144
|
+
} = StyleSheet.create({
|
|
145
|
+
col: {
|
|
146
|
+
...staticStyles,
|
|
147
|
+
...mediaQueryStyles
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
colStyles = styles.col;
|
|
151
|
+
mediaIds = ids.col;
|
|
152
|
+
} else {
|
|
153
|
+
colStyles = {
|
|
154
|
+
...staticStyles,
|
|
155
|
+
...stylesByViewport[viewport]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
135
158
|
return /*#__PURE__*/_jsx(BaseView, {
|
|
136
159
|
ref: ref,
|
|
137
160
|
...viewProps,
|
|
138
|
-
style:
|
|
139
|
-
dataSet: {
|
|
140
|
-
media:
|
|
161
|
+
style: colStyles,
|
|
162
|
+
dataSet: mediaIds && {
|
|
163
|
+
media: mediaIds
|
|
141
164
|
},
|
|
142
165
|
children: children
|
|
143
166
|
});
|
|
@@ -6,6 +6,8 @@ import Row from './Row';
|
|
|
6
6
|
import Col from './Col';
|
|
7
7
|
import GutterContext from './providers/GutterContext';
|
|
8
8
|
import applyInheritance from './helpers';
|
|
9
|
+
import { useTheme } from '../ThemeProvider';
|
|
10
|
+
import { useViewport } from '../ViewportProvider';
|
|
9
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
12
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
11
13
|
|
|
@@ -29,7 +31,15 @@ const FlexGrid = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
29
31
|
...rest
|
|
30
32
|
} = _ref;
|
|
31
33
|
const reverseLevel = applyInheritance([xsReverse, smReverse, mdReverse, lgReverse, xlReverse]);
|
|
32
|
-
const
|
|
34
|
+
const viewport = useViewport();
|
|
35
|
+
const {
|
|
36
|
+
themeOptions: {
|
|
37
|
+
enableMediaQueryStyleSheet
|
|
38
|
+
}
|
|
39
|
+
} = useTheme();
|
|
40
|
+
let flexgridStyles;
|
|
41
|
+
let mediaIds;
|
|
42
|
+
const stylesByViewport = {
|
|
33
43
|
xs: {
|
|
34
44
|
flexDirection: reverseLevel[0] ? 'column-reverse' : 'column'
|
|
35
45
|
},
|
|
@@ -49,19 +59,32 @@ const FlexGrid = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
49
59
|
maxWidth: limitWidth && viewports.map.get('xl'),
|
|
50
60
|
flexDirection: reverseLevel[4] ? 'column-reverse' : 'column'
|
|
51
61
|
}
|
|
52
|
-
}
|
|
53
|
-
const {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
};
|
|
63
|
+
const staticStyles = {
|
|
64
|
+
flexWrap: 'wrap',
|
|
65
|
+
width: outsideGutter ? '100%' : 'auto',
|
|
66
|
+
marginVertical: 0,
|
|
67
|
+
marginHorizontal: outsideGutter ? 'auto' : -16
|
|
68
|
+
};
|
|
69
|
+
if (enableMediaQueryStyleSheet) {
|
|
70
|
+
const mediaQueryStyles = createMediaQueryStyles(stylesByViewport);
|
|
71
|
+
const {
|
|
72
|
+
ids,
|
|
73
|
+
styles
|
|
74
|
+
} = StyleSheet.create({
|
|
75
|
+
flexgrid: {
|
|
76
|
+
...staticStyles,
|
|
77
|
+
...mediaQueryStyles
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
flexgridStyles = styles.flexgrid;
|
|
81
|
+
mediaIds = ids.flexgrid;
|
|
82
|
+
} else {
|
|
83
|
+
flexgridStyles = {
|
|
84
|
+
...staticStyles,
|
|
85
|
+
...stylesByViewport[viewport]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
65
88
|
const props = {
|
|
66
89
|
accessibilityRole,
|
|
67
90
|
...getA11yPropsFromHtmlTag(tag, accessibilityRole),
|
|
@@ -72,9 +95,9 @@ const FlexGrid = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
72
95
|
children: /*#__PURE__*/_jsx(BaseView, {
|
|
73
96
|
ref: ref,
|
|
74
97
|
...props,
|
|
75
|
-
style:
|
|
76
|
-
dataSet: {
|
|
77
|
-
media:
|
|
98
|
+
style: flexgridStyles,
|
|
99
|
+
dataSet: mediaIds && {
|
|
100
|
+
media: mediaIds
|
|
78
101
|
},
|
|
79
102
|
children: children
|
|
80
103
|
})
|