@telus-uds/components-base 1.69.0 → 1.71.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 +21 -2
- package/jest.setup.js +7 -0
- package/lib/Autocomplete/Autocomplete.js +3 -13
- package/lib/Card/Card.js +68 -7
- package/lib/Card/PressableCardBase.js +2 -0
- package/lib/FlexGrid/Col/Col.js +50 -64
- package/lib/FlexGrid/FlexGrid.js +37 -40
- package/lib/FlexGrid/Row/Row.js +43 -44
- package/lib/Icon/IconText.js +9 -2
- package/lib/Link/LinkBase.js +10 -3
- package/lib/utils/index.js +12 -0
- package/lib/utils/ssr-media-query/create-stylesheet.js +76 -0
- package/lib/utils/ssr-media-query/hash.js +19 -0
- package/lib/utils/ssr-media-query/index.js +19 -0
- package/lib/utils/ssr-media-query/utils/common.js +25 -0
- package/lib/utils/ssr-media-query/utils/create-declaration-block.js +24 -0
- package/lib/utils/ssr-media-query/utils/create-media-query-styles.js +34 -0
- package/lib/utils/ssr-media-query/utils/hyphenate-style-name.js +19 -0
- package/lib/utils/ssr-media-query/utils/inject.js +49 -0
- package/lib/utils/ssr.js +2 -1
- package/lib-module/Autocomplete/Autocomplete.js +3 -13
- package/lib-module/Card/Card.js +71 -8
- package/lib-module/Card/PressableCardBase.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +51 -65
- package/lib-module/FlexGrid/FlexGrid.js +38 -41
- package/lib-module/FlexGrid/Row/Row.js +44 -45
- package/lib-module/Icon/IconText.js +9 -2
- package/lib-module/Link/LinkBase.js +10 -3
- package/lib-module/utils/index.js +1 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet.js +68 -0
- package/lib-module/utils/ssr-media-query/hash.js +13 -0
- package/lib-module/utils/ssr-media-query/index.js +6 -0
- package/lib-module/utils/ssr-media-query/utils/common.js +15 -0
- package/lib-module/utils/ssr-media-query/utils/create-declaration-block.js +16 -0
- package/lib-module/utils/ssr-media-query/utils/create-media-query-styles.js +30 -0
- package/lib-module/utils/ssr-media-query/utils/hyphenate-style-name.js +12 -0
- package/lib-module/utils/ssr-media-query/utils/inject.js +39 -0
- package/lib-module/utils/ssr.js +3 -1
- package/package.json +3 -2
- package/src/Autocomplete/Autocomplete.jsx +14 -21
- package/src/Card/Card.jsx +73 -11
- package/src/Card/PressableCardBase.jsx +2 -0
- package/src/FlexGrid/Col/Col.jsx +48 -80
- package/src/FlexGrid/FlexGrid.jsx +36 -44
- package/src/FlexGrid/Row/Row.jsx +38 -56
- package/src/Icon/IconText.jsx +11 -1
- package/src/Link/ChevronLink.jsx +1 -0
- package/src/Link/LinkBase.jsx +16 -6
- package/src/utils/index.js +1 -1
- package/src/utils/ssr-media-query/create-stylesheet.js +61 -0
- package/src/utils/ssr-media-query/hash.js +16 -0
- package/src/utils/ssr-media-query/index.js +8 -0
- package/src/utils/ssr-media-query/utils/common.js +20 -0
- package/src/utils/ssr-media-query/utils/create-declaration-block.js +21 -0
- package/src/utils/ssr-media-query/utils/create-media-query-styles.js +31 -0
- package/src/utils/ssr-media-query/utils/hyphenate-style-name.js +15 -0
- package/src/utils/ssr-media-query/utils/inject.js +43 -0
- package/src/utils/ssr.jsx +3 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
|
|
8
|
+
var _Dimensions = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Dimensions"));
|
|
9
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
10
|
+
var _inject = require("./utils/inject");
|
|
11
|
+
var _createDeclarationBlock = _interopRequireDefault(require("./utils/create-declaration-block"));
|
|
12
|
+
var _hash = _interopRequireDefault(require("./hash"));
|
|
13
|
+
var _common = require("./utils/common");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
const createStyleSheet = stylesWithQuery => {
|
|
16
|
+
if (!stylesWithQuery) return {
|
|
17
|
+
ids: {},
|
|
18
|
+
styles: {},
|
|
19
|
+
fullStyles: {}
|
|
20
|
+
};
|
|
21
|
+
let cleanStyles;
|
|
22
|
+
let ids = {};
|
|
23
|
+
Object.keys(stylesWithQuery).forEach(key => {
|
|
24
|
+
if (!(stylesWithQuery !== null && stylesWithQuery !== void 0 && stylesWithQuery[key])) return;
|
|
25
|
+
const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(_common.isMediaOrPseudo);
|
|
26
|
+
if (_Platform.default.OS === 'web') {
|
|
27
|
+
cleanStyles = (0, _common.deepClone)(stylesWithQuery);
|
|
28
|
+
mediaQueriesAndPseudoClasses.forEach(query => {
|
|
29
|
+
var _ids;
|
|
30
|
+
const css = (0, _createDeclarationBlock.default)(stylesWithQuery[key][query]);
|
|
31
|
+
const stringHash = `rnmq-${(0, _hash.default)(`${key}${query}${css}`)}`;
|
|
32
|
+
const rule = (0, _common.createCssRule)(query, stringHash, css);
|
|
33
|
+
(0, _inject.addCss)(`${stringHash}`, rule);
|
|
34
|
+
delete cleanStyles[key][query];
|
|
35
|
+
ids = {
|
|
36
|
+
...ids,
|
|
37
|
+
[key]: `${(_ids = ids) !== null && _ids !== void 0 && _ids[key] ? `${ids[key]} ` : ''}${stringHash}`
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
cleanStyles = JSON.parse(JSON.stringify(stylesWithQuery));
|
|
42
|
+
mediaQueriesAndPseudoClasses.forEach(str => {
|
|
43
|
+
if ((0, _common.isMedia)(str)) {
|
|
44
|
+
const mqStr = str.replace('@media', '');
|
|
45
|
+
const {
|
|
46
|
+
width,
|
|
47
|
+
height
|
|
48
|
+
} = _Dimensions.default.get('window');
|
|
49
|
+
const isMatchingMediaQuery = _cssMediaquery.default.match(mqStr, {
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
orientation: width > height ? 'landscape' : 'portrait',
|
|
53
|
+
'aspect-ratio': width / height
|
|
54
|
+
});
|
|
55
|
+
if (isMatchingMediaQuery) {
|
|
56
|
+
cleanStyles = {
|
|
57
|
+
...cleanStyles,
|
|
58
|
+
[key]: {
|
|
59
|
+
...cleanStyles[key],
|
|
60
|
+
...stylesWithQuery[key][str]
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
delete cleanStyles[key][str];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
ids,
|
|
71
|
+
styles: cleanStyles,
|
|
72
|
+
fullStyles: stylesWithQuery
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var _default = createStyleSheet;
|
|
76
|
+
exports.default = _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = hash;
|
|
7
|
+
/* eslint-disable no-bitwise */
|
|
8
|
+
function hash(text) {
|
|
9
|
+
if (!text) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
let hashValue = 5381;
|
|
13
|
+
let index = text.length - 1;
|
|
14
|
+
while (index) {
|
|
15
|
+
hashValue = hashValue * 33 ^ text.charCodeAt(index);
|
|
16
|
+
index -= 1;
|
|
17
|
+
}
|
|
18
|
+
return (hashValue >>> 0).toString(16);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyleSheet = void 0;
|
|
7
|
+
Object.defineProperty(exports, "createMediaQueryStyles", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _createMediaQueryStyles.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _createStylesheet = _interopRequireDefault(require("./create-stylesheet"));
|
|
14
|
+
var _createMediaQueryStyles = _interopRequireDefault(require("./utils/create-media-query-styles"));
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
const StyleSheet = {
|
|
17
|
+
create: _createStylesheet.default
|
|
18
|
+
};
|
|
19
|
+
exports.StyleSheet = StyleSheet;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isPseudo = exports.isMediaOrPseudo = exports.isMedia = exports.deepClone = exports.createCssRule = void 0;
|
|
7
|
+
const isMedia = query => query.indexOf('@media') === 0;
|
|
8
|
+
exports.isMedia = isMedia;
|
|
9
|
+
const isPseudo = query => query.indexOf(':') === 0;
|
|
10
|
+
exports.isPseudo = isPseudo;
|
|
11
|
+
const isMediaOrPseudo = query => isMedia(query) || isPseudo(query);
|
|
12
|
+
exports.isMediaOrPseudo = isMediaOrPseudo;
|
|
13
|
+
const deepClone = obj => JSON.parse(JSON.stringify(obj));
|
|
14
|
+
exports.deepClone = deepClone;
|
|
15
|
+
const createCssRule = (query, stringHash, css) => {
|
|
16
|
+
let rule;
|
|
17
|
+
const dataMediaSelector = `[data-media~="${stringHash}"]`;
|
|
18
|
+
if (isMedia(query)) {
|
|
19
|
+
rule = `${query} {${dataMediaSelector} ${css}}`;
|
|
20
|
+
} else {
|
|
21
|
+
rule = `${dataMediaSelector}${query} ${css}`;
|
|
22
|
+
}
|
|
23
|
+
return rule;
|
|
24
|
+
};
|
|
25
|
+
exports.createCssRule = createCssRule;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createReactDOMStyle = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle"));
|
|
8
|
+
var _prefixStyles = _interopRequireDefault(require("react-native-web/dist/cjs/modules/prefixStyles"));
|
|
9
|
+
var _hyphenateStyleName = _interopRequireDefault(require("./hyphenate-style-name"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const createDeclarationBlock = style => {
|
|
12
|
+
const domStyle = (0, _prefixStyles.default)((0, _createReactDOMStyle.default)(style));
|
|
13
|
+
const declarationsString = Object.keys(domStyle).map(property => {
|
|
14
|
+
const value = domStyle[property];
|
|
15
|
+
const prop = (0, _hyphenateStyleName.default)(property);
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map(v => `${prop}:${v}`).join(';');
|
|
18
|
+
}
|
|
19
|
+
return `${prop}:${value} !important`;
|
|
20
|
+
}).sort().join(';');
|
|
21
|
+
return `{${declarationsString};}`;
|
|
22
|
+
};
|
|
23
|
+
var _default = createDeclarationBlock;
|
|
24
|
+
exports.default = _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* @typedef { Object } CssStyles
|
|
10
|
+
* @typedef { Record<"xs" | "sm" | "md" | "lg" | "xl", CssStyles> } ViewportStyles
|
|
11
|
+
* @typedef { Record<String, CssStyles> } MediaQueryStyles
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generates media query styles based on specified viewport styles.
|
|
15
|
+
* @param {ViewportStyles} viewportStyles
|
|
16
|
+
* @returns { MediaQueryStyles }
|
|
17
|
+
*/
|
|
18
|
+
function createMediaQueryStyles(viewportStyles) {
|
|
19
|
+
const viewportsArray = Object.keys(viewportStyles);
|
|
20
|
+
const mediaQueries = Object.entries(viewportStyles).reduce((acc, _ref) => {
|
|
21
|
+
let [viewport, styles] = _ref;
|
|
22
|
+
const minWidth = _systemConstants.viewports.map.get(viewport);
|
|
23
|
+
const nextViewport = viewportsArray[viewportsArray.indexOf(viewport) + 1];
|
|
24
|
+
const maxWidth = _systemConstants.viewports.map.get(nextViewport);
|
|
25
|
+
const mediaQuery = `@media (min-width: ${minWidth}px)${maxWidth ? ` and (max-width: ${maxWidth}px)` : ''}`;
|
|
26
|
+
return {
|
|
27
|
+
...acc,
|
|
28
|
+
[mediaQuery]: styles
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
|
+
return mediaQueries;
|
|
32
|
+
}
|
|
33
|
+
var _default = createMediaQueryStyles;
|
|
34
|
+
exports.default = _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const uppercasePattern = /[A-Z]/g;
|
|
8
|
+
const msPattern = /^ms-/;
|
|
9
|
+
const cache = {};
|
|
10
|
+
const toHyphenLower = match => `-${match.toLowerCase()}`;
|
|
11
|
+
const hyphenateStyleName = name => {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(cache, name)) {
|
|
13
|
+
return cache[name];
|
|
14
|
+
}
|
|
15
|
+
const hName = name.replace(uppercasePattern, toHyphenLower);
|
|
16
|
+
return cache[name] === msPattern.test(hName) ? `-${hName}` : hName;
|
|
17
|
+
};
|
|
18
|
+
var _default = hyphenateStyleName;
|
|
19
|
+
exports.default = _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasCss = exports.flush = exports.addCss = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const rules = {};
|
|
11
|
+
let styleSheet;
|
|
12
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
13
|
+
styleSheet = (() => {
|
|
14
|
+
const style = document.createElement('style');
|
|
15
|
+
style.id = 'RNMQCSS';
|
|
16
|
+
style.appendChild(document.createTextNode(''));
|
|
17
|
+
document.head.appendChild(style);
|
|
18
|
+
return style.sheet;
|
|
19
|
+
})();
|
|
20
|
+
}
|
|
21
|
+
const hasCss = (id, text) => {
|
|
22
|
+
var _rules$id$text, _rules$id$text$includ;
|
|
23
|
+
return !!rules[id] && !!((_rules$id$text = rules[id].text) !== null && _rules$id$text !== void 0 && (_rules$id$text$includ = _rules$id$text.includes) !== null && _rules$id$text$includ !== void 0 && _rules$id$text$includ.call(_rules$id$text, text));
|
|
24
|
+
};
|
|
25
|
+
exports.hasCss = hasCss;
|
|
26
|
+
const addCss = (id, text) => {
|
|
27
|
+
if (!hasCss(id, text)) {
|
|
28
|
+
var _rules$id;
|
|
29
|
+
rules[id] = (rules === null || rules === void 0 ? void 0 : rules[id]) || {};
|
|
30
|
+
rules[id].text = (((_rules$id = rules[id]) === null || _rules$id === void 0 ? void 0 : _rules$id.text) || '') + text;
|
|
31
|
+
if (styleSheet) {
|
|
32
|
+
styleSheet.insertRule(text, Object.keys(rules).length - 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.addCss = addCss;
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (_Platform.default.OS === 'web') {
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement('style', {
|
|
40
|
+
id: 'rnmq',
|
|
41
|
+
key: 'rnmq',
|
|
42
|
+
dangerouslySetInnerHTML: {
|
|
43
|
+
__html: Object.keys(rules).map(key => rules[key].text).join('\n')
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {};
|
|
48
|
+
};
|
|
49
|
+
exports.flush = flush;
|
package/lib/utils/ssr.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ssrStyles = exports.getSSRStyles = exports.getReactNativeWebSSRStyles = exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _AppRegistry = _interopRequireDefault(require("react-native-web/dist/cjs/exports/AppRegistry"));
|
|
9
|
+
var _inject = require("./ssr-media-query/utils/inject");
|
|
9
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
/** @typedef {import('react').ComponentType} ReactComponent */
|
|
@@ -102,7 +103,7 @@ const ssrStyles = function () {
|
|
|
102
103
|
for (var _len = arguments.length, existingStyles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
103
104
|
existingStyles[_key] = arguments[_key];
|
|
104
105
|
}
|
|
105
|
-
return [...existingStyles, ...styleGetters.flatMap(getter => getter())];
|
|
106
|
+
return [...existingStyles, ...styleGetters.flatMap(getter => getter()), (0, _inject.flush)()];
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
};
|
|
@@ -265,21 +265,11 @@ const Autocomplete = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
265
265
|
}, [nestedSelectedValue, items]);
|
|
266
266
|
const handleClose = event => {
|
|
267
267
|
var _openOverlayRef$curre, _openOverlayRef$curre2;
|
|
268
|
-
if (event.type === 'keydown') {
|
|
269
|
-
if (event.key === 'Escape' || event.key === 27) {
|
|
270
|
-
setIsExpanded(false);
|
|
271
|
-
setNestedSelectedValue(null);
|
|
272
|
-
} else if (event.key === 'ArrowDown' && isExpanded && !isLoading && targetRef !== null && targetRef !== void 0 && targetRef.current) {
|
|
273
|
-
targetRef.current.focus();
|
|
274
|
-
}
|
|
275
|
-
} else if (event.type === 'click' && openOverlayRef !== null && openOverlayRef !== void 0 && openOverlayRef.current && event.target && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre = openOverlayRef.current) !== null && _openOverlayRef$curre !== void 0 && _openOverlayRef$curre.contains(event.target))) {
|
|
276
|
-
setIsExpanded(false);
|
|
277
|
-
} else if (event.type === 'touchstart' && openOverlayRef !== null && openOverlayRef !== void 0 && openOverlayRef.current && event.touches[0].target && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre2 = openOverlayRef.current) !== null && _openOverlayRef$curre2 !== void 0 && _openOverlayRef$curre2.contains(event.touches[0].target))) {
|
|
278
|
-
setIsExpanded(false);
|
|
279
|
-
} else if (Platform.OS === 'web') {
|
|
280
|
-
// needed for dropdown to be collapsed when clicking outside on web
|
|
268
|
+
if (event.type === 'keydown' && (event.key === 'Escape' || event.key === '27') || event.type === 'click' && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre = openOverlayRef.current) !== null && _openOverlayRef$curre !== void 0 && _openOverlayRef$curre.contains(event.target)) || event.type === 'touchstart' && openOverlayRef !== null && openOverlayRef !== void 0 && openOverlayRef.current && event.touches[0].target && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre2 = openOverlayRef.current) !== null && _openOverlayRef$curre2 !== void 0 && _openOverlayRef$curre2.contains(event.touches[0].target))) {
|
|
281
269
|
setIsExpanded(false);
|
|
282
270
|
setNestedSelectedValue(null);
|
|
271
|
+
} else if (event.type === 'keydown' && event.key === 'ArrowDown' && isExpanded && !isLoading && targetRef !== null && targetRef !== void 0 && targetRef.current) {
|
|
272
|
+
targetRef.current.focus();
|
|
283
273
|
}
|
|
284
274
|
};
|
|
285
275
|
const itemsToShow = currentValue ? itemsToSuggest(highlight(isControlled ? items : currentItems, currentValue, resultsTextColor)) : [];
|
package/lib-module/Card/Card.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
3
|
+
import View from "react-native-web/dist/exports/View";
|
|
4
|
+
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider';
|
|
4
5
|
import { getTokensPropType, variantProp } from '../utils';
|
|
5
6
|
import { useViewport } from '../ViewportProvider';
|
|
6
7
|
import { a11yProps, selectSystemProps, viewProps } from '../utils/props';
|
|
7
8
|
import CardBase from './CardBase';
|
|
9
|
+
import PressableCardBase from './PressableCardBase';
|
|
8
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
13
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
10
14
|
|
|
11
15
|
/**
|
|
@@ -62,25 +66,84 @@ const Card = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
62
66
|
tokens,
|
|
63
67
|
variant,
|
|
64
68
|
dataSet,
|
|
69
|
+
onPress,
|
|
70
|
+
interactiveCard,
|
|
65
71
|
...rest
|
|
66
72
|
} = _ref;
|
|
67
73
|
const viewport = useViewport();
|
|
68
74
|
const themeTokens = useThemeTokens('Card', tokens, variant, {
|
|
69
75
|
viewport
|
|
70
76
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const getThemeTokens = useThemeTokensCallback('Card', interactiveCard === null || interactiveCard === void 0 ? void 0 : interactiveCard.tokens, {
|
|
78
|
+
interactive: true,
|
|
79
|
+
...((interactiveCard === null || interactiveCard === void 0 ? void 0 : interactiveCard.variant) || {})
|
|
80
|
+
});
|
|
81
|
+
// When interactive area is present, spacing tokens should only be applied
|
|
82
|
+
// to individual Card sections, not Card as a whole
|
|
83
|
+
const {
|
|
84
|
+
paddingTop,
|
|
85
|
+
paddingBottom,
|
|
86
|
+
paddingLeft,
|
|
87
|
+
paddingRight,
|
|
88
|
+
...restOfTokens
|
|
89
|
+
} = themeTokens;
|
|
90
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
91
|
+
children: /*#__PURE__*/_jsx(CardBase, {
|
|
92
|
+
ref: ref,
|
|
93
|
+
tokens: interactiveCard !== null && interactiveCard !== void 0 && interactiveCard.body ? restOfTokens : themeTokens,
|
|
94
|
+
dataSet: dataSet,
|
|
95
|
+
...selectProps(rest),
|
|
96
|
+
children: interactiveCard !== null && interactiveCard !== void 0 && interactiveCard.body ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
97
|
+
children: [/*#__PURE__*/_jsx(PressableCardBase, {
|
|
98
|
+
ref: ref,
|
|
99
|
+
tokens: getThemeTokens,
|
|
100
|
+
dataSet: dataSet,
|
|
101
|
+
onPress: onPress,
|
|
102
|
+
...selectProps(rest),
|
|
103
|
+
children: interactiveCard === null || interactiveCard === void 0 ? void 0 : interactiveCard.body
|
|
104
|
+
}), children ? /*#__PURE__*/_jsx(View, {
|
|
105
|
+
style: {
|
|
106
|
+
paddingTop,
|
|
107
|
+
paddingBottom,
|
|
108
|
+
paddingLeft,
|
|
109
|
+
paddingRight
|
|
110
|
+
},
|
|
111
|
+
children: children
|
|
112
|
+
}) : null]
|
|
113
|
+
}) : children
|
|
114
|
+
})
|
|
77
115
|
});
|
|
78
116
|
});
|
|
79
117
|
Card.displayName = 'Card';
|
|
80
118
|
Card.propTypes = {
|
|
81
119
|
...selectedSystemPropTypes,
|
|
120
|
+
/**
|
|
121
|
+
* Card content.
|
|
122
|
+
*/
|
|
82
123
|
children: PropTypes.node,
|
|
124
|
+
/**
|
|
125
|
+
* Card tokens.
|
|
126
|
+
*/
|
|
83
127
|
tokens: getTokensPropType('Card'),
|
|
84
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Card variant.
|
|
130
|
+
*/
|
|
131
|
+
variant: variantProp.propType,
|
|
132
|
+
/**
|
|
133
|
+
* Function to call on pressing the card.
|
|
134
|
+
* Note: This is only available when `interactiveCard` prop is used.
|
|
135
|
+
*/
|
|
136
|
+
onPress: PropTypes.func,
|
|
137
|
+
/**
|
|
138
|
+
* Object to set interactive card's properties
|
|
139
|
+
* - body: The body of the interactive card, can be any renderable node
|
|
140
|
+
* - tokens: The tokens to be used for the interactive card
|
|
141
|
+
* - variant: The variant to be used for the interactive card
|
|
142
|
+
*/
|
|
143
|
+
interactiveCard: PropTypes.shape({
|
|
144
|
+
body: PropTypes.node,
|
|
145
|
+
tokens: getTokensPropType('Card'),
|
|
146
|
+
variant: variantProp.propType
|
|
147
|
+
})
|
|
85
148
|
};
|
|
86
149
|
export default Card;
|
|
@@ -28,6 +28,7 @@ const PressableCardBase = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
28
28
|
inactive,
|
|
29
29
|
href,
|
|
30
30
|
hrefAttrs,
|
|
31
|
+
dataSet,
|
|
31
32
|
accessibilityRole = href ? 'link' : undefined,
|
|
32
33
|
...rawRest
|
|
33
34
|
} = _ref;
|
|
@@ -87,6 +88,7 @@ const PressableCardBase = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
87
88
|
onKeyDown: handleKeyDown,
|
|
88
89
|
hrefAttrs: hrefAttrs,
|
|
89
90
|
style: getOuterBorderStyle,
|
|
91
|
+
dataSet: dataSet,
|
|
90
92
|
...selectProps({
|
|
91
93
|
...rest,
|
|
92
94
|
accessibilityRole
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import React, { forwardRef, useContext } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
-
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
-
import { viewports } from '@telus-uds/system-constants';
|
|
6
4
|
import GutterContext from '../providers/GutterContext';
|
|
7
|
-
import { useViewport } from '../../ViewportProvider';
|
|
8
5
|
import applyInheritance from '../helpers';
|
|
9
|
-
import { responsiveProps, BaseView } from '../../utils';
|
|
6
|
+
import { responsiveProps, BaseView, StyleSheet, createMediaQueryStyles } from '../../utils';
|
|
10
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
8
|
const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
12
9
|
let {
|
|
@@ -26,7 +23,6 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
26
23
|
...viewProps
|
|
27
24
|
} = _ref;
|
|
28
25
|
const gutter = useContext(GutterContext);
|
|
29
|
-
const viewPort = useViewport();
|
|
30
26
|
const hiddenLevels = applyInheritance([xs, sm, md, lg, xl]);
|
|
31
27
|
const getHorizontalAlignLevel = () => {
|
|
32
28
|
if (typeof horizontalAlign === 'object') {
|
|
@@ -67,60 +63,11 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
67
63
|
}
|
|
68
64
|
return {};
|
|
69
65
|
};
|
|
70
|
-
const sizeStyles = sizes => {
|
|
71
|
-
const currViewport = Object.keys(sizes).find(key => key.startsWith(viewPort));
|
|
72
|
-
const currSize = sizes[currViewport];
|
|
73
|
-
return {
|
|
74
|
-
...calculateWidth(currSize)
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
const offsetStyles = offsets => {
|
|
78
|
-
const currViewport = Object.keys(offsets).find(key => key.startsWith(viewPort));
|
|
79
|
-
const currOffset = offsets[currViewport];
|
|
80
|
-
return {
|
|
81
|
-
...calculateOffset(currOffset)
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const gutterPadding = {
|
|
85
|
-
paddingLeft: gutter ? 16 : 0,
|
|
86
|
-
paddingRight: gutter ? 16 : 0
|
|
87
|
-
};
|
|
88
|
-
let hidingStyles = {};
|
|
89
66
|
|
|
90
67
|
// TODO: consider setting this to always 'flex' in a major release.
|
|
91
68
|
// `display: block` is invalid in native apps.
|
|
92
69
|
// See https://telusdigital.atlassian.net/browse/UDS1-92
|
|
93
70
|
const shown = !flex && Platform.OS === 'web' ? 'block' : 'flex';
|
|
94
|
-
if (viewPort === viewports.xs) {
|
|
95
|
-
hidingStyles = {
|
|
96
|
-
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
97
|
-
textAlign: horizontalAlignLevel[0]
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if (viewPort === viewports.sm) {
|
|
101
|
-
hidingStyles = {
|
|
102
|
-
display: hiddenLevels[1] === 0 ? 'none' : shown,
|
|
103
|
-
textAlign: horizontalAlignLevel[1]
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (viewPort === viewports.md) {
|
|
107
|
-
hidingStyles = {
|
|
108
|
-
display: hiddenLevels[2] === 0 ? 'none' : shown,
|
|
109
|
-
textAlign: horizontalAlignLevel[2]
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
if (viewPort === viewports.lg) {
|
|
113
|
-
hidingStyles = {
|
|
114
|
-
display: hiddenLevels[3] === 0 ? 'none' : shown,
|
|
115
|
-
textAlign: horizontalAlignLevel[3]
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (viewPort === viewports.xl) {
|
|
119
|
-
hidingStyles = {
|
|
120
|
-
display: hiddenLevels[4] === 0 ? 'none' : shown,
|
|
121
|
-
textAlign: horizontalAlignLevel[4]
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
71
|
const sizesArray = [xs, sm, md, lg, xl];
|
|
125
72
|
const offSetsArray = [xsOffset, smOffset, mdOffset, lgOffset, xlOffset];
|
|
126
73
|
const sizesWithIheritance = applyInheritance(sizesArray);
|
|
@@ -139,24 +86,63 @@ const Col = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
139
86
|
lg: offsetsWithIheritance[3],
|
|
140
87
|
xl: offsetsWithIheritance[4]
|
|
141
88
|
};
|
|
89
|
+
const mediaQueryStyles = createMediaQueryStyles({
|
|
90
|
+
xs: {
|
|
91
|
+
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
92
|
+
textAlign: horizontalAlignLevel[0],
|
|
93
|
+
...calculateWidth(sizes.xs),
|
|
94
|
+
...calculateOffset(offsets.xs)
|
|
95
|
+
},
|
|
96
|
+
sm: {
|
|
97
|
+
display: hiddenLevels[1] === 0 ? 'none' : shown,
|
|
98
|
+
textAlign: horizontalAlignLevel[1],
|
|
99
|
+
...calculateWidth(sizes.sm),
|
|
100
|
+
...calculateOffset(offsets.sm)
|
|
101
|
+
},
|
|
102
|
+
md: {
|
|
103
|
+
display: hiddenLevels[2] === 0 ? 'none' : shown,
|
|
104
|
+
textAlign: horizontalAlignLevel[2],
|
|
105
|
+
...calculateWidth(sizes.md),
|
|
106
|
+
...calculateOffset(offsets.md)
|
|
107
|
+
},
|
|
108
|
+
lg: {
|
|
109
|
+
display: hiddenLevels[3] === 0 ? 'none' : shown,
|
|
110
|
+
textAlign: horizontalAlignLevel[3],
|
|
111
|
+
...calculateWidth(sizes.lg),
|
|
112
|
+
...calculateOffset(offsets.lg)
|
|
113
|
+
},
|
|
114
|
+
xl: {
|
|
115
|
+
display: hiddenLevels[4] === 0 ? 'none' : shown,
|
|
116
|
+
textAlign: horizontalAlignLevel[4],
|
|
117
|
+
...calculateWidth(sizes.xl),
|
|
118
|
+
...calculateOffset(offsets.xl)
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const {
|
|
122
|
+
ids,
|
|
123
|
+
styles
|
|
124
|
+
} = StyleSheet.create({
|
|
125
|
+
col: {
|
|
126
|
+
flexGrow: 1,
|
|
127
|
+
flexShrink: 0,
|
|
128
|
+
flexBasis: 'auto',
|
|
129
|
+
maxWidth: '100%',
|
|
130
|
+
paddingLeft: gutter ? 16 : 0,
|
|
131
|
+
paddingRight: gutter ? 16 : 0,
|
|
132
|
+
...mediaQueryStyles
|
|
133
|
+
}
|
|
134
|
+
});
|
|
142
135
|
return /*#__PURE__*/_jsx(BaseView, {
|
|
143
136
|
ref: ref,
|
|
144
137
|
...viewProps,
|
|
145
|
-
style: [styles.col,
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
style: [styles.col],
|
|
139
|
+
dataSet: {
|
|
140
|
+
media: ids.col
|
|
141
|
+
},
|
|
148
142
|
children: children
|
|
149
143
|
});
|
|
150
144
|
});
|
|
151
145
|
Col.displayName = 'Col';
|
|
152
|
-
const styles = StyleSheet.create({
|
|
153
|
-
col: {
|
|
154
|
-
flexGrow: 1,
|
|
155
|
-
flexShrink: 0,
|
|
156
|
-
flexBasis: 'auto',
|
|
157
|
-
maxWidth: '100%'
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
146
|
|
|
161
147
|
/*
|
|
162
148
|
* We're disabling default props since passing undefined props to
|