@telus-uds/components-base 1.71.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 +37 -2
- package/lib/Box/Box.js +17 -6
- package/lib/ColourToggle/ColourBubble.js +135 -0
- package/lib/ColourToggle/ColourToggle.js +101 -0
- package/lib/ColourToggle/index.js +10 -0
- 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/Modal/ModalContent.js +4 -6
- package/lib/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib/Notification/Notification.js +13 -5
- package/lib/OrderedList/Item.js +180 -0
- package/lib/OrderedList/ItemBase.js +54 -0
- package/lib/OrderedList/OrderedList.js +71 -0
- package/lib/OrderedList/OrderedListBase.js +47 -0
- package/lib/OrderedList/index.js +10 -0
- 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/index.js +16 -0
- package/lib/server.js +40 -0
- package/lib/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +56 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.android.js +10 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.ios.js +10 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.js +44 -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/ColourToggle/ColourBubble.js +125 -0
- package/lib-module/ColourToggle/ColourToggle.js +92 -0
- package/lib-module/ColourToggle/index.js +2 -0
- 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/Modal/ModalContent.js +4 -6
- package/lib-module/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib-module/Notification/Notification.js +13 -5
- package/lib-module/OrderedList/Item.js +171 -0
- package/lib-module/OrderedList/ItemBase.js +43 -0
- package/lib-module/OrderedList/OrderedList.js +61 -0
- package/lib-module/OrderedList/OrderedListBase.js +36 -0
- package/lib-module/OrderedList/index.js +2 -0
- 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/index.js +2 -0
- package/lib-module/server.js +4 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +48 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.android.js +2 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.ios.js +2 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.js +36 -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/ColourToggle/ColourBubble.jsx +111 -0
- package/src/ColourToggle/ColourToggle.jsx +83 -0
- package/src/ColourToggle/index.js +3 -0
- 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/Modal/ModalContent.jsx +4 -6
- package/src/MultiSelectFilter/MultiSelectFilter.jsx +2 -0
- package/src/Notification/Notification.jsx +15 -3
- package/src/OrderedList/Item.jsx +152 -0
- package/src/OrderedList/ItemBase.jsx +43 -0
- package/src/OrderedList/OrderedList.jsx +61 -0
- package/src/OrderedList/OrderedListBase.jsx +33 -0
- package/src/OrderedList/index.js +3 -0
- 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/index.js +2 -0
- package/src/server.js +4 -0
- package/src/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +41 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.android.js +3 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.ios.js +3 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.js +33 -0
- package/src/utils/ssr-media-query/utils/create-media-query-styles.js +21 -6
- package/types/Badge.d.ts +28 -0
- package/types/Box.d.ts +52 -0
- package/types/ChevronLink.d.ts +47 -0
- package/types/Common.d.ts +106 -0
- package/types/Divider.d.ts +19 -0
- package/types/ExpandCollapse.d.ts +65 -0
- package/types/HorizontalScrollButton.d.ts +16 -0
- package/types/Icon.d.ts +21 -0
- package/types/Link.d.ts +48 -0
- package/types/List.d.ts +48 -0
- package/types/Search.d.ts +38 -0
- package/types/Select.d.ts +57 -0
- package/types/Spacer.d.ts +5 -0
- package/types/StackView.d.ts +28 -0
- package/types/Tabs.d.ts +46 -0
- package/types/TextButton.d.ts +11 -0
- package/types/ToggleSwitch.d.ts +54 -0
- package/types/ToolTip.d.ts +40 -0
- package/types/Typography.d.ts +39 -0
- package/types/index.d.ts +62 -0
- package/lib/utils/ssr-media-query/create-stylesheet.js +0 -76
- package/lib-module/utils/ssr-media-query/create-stylesheet.js +0 -68
- package/src/utils/ssr-media-query/create-stylesheet.js +0 -61
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import View from "react-native-web/dist/exports/View";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import { getTokensPropType, htmlAttrs, selectSystemProps, variantProp, viewProps, wrapStringsInText } from '../utils';
|
|
6
|
+
import { applyTextStyles, useTheme, useThemeTokens } from '../ThemeProvider';
|
|
7
|
+
import StackView from '../StackView';
|
|
8
|
+
import Typography from '../Typography';
|
|
9
|
+
import ItemBase from './ItemBase';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs, viewProps]);
|
|
13
|
+
const selectItemTextStyles = (_ref, themeOptions) => {
|
|
14
|
+
let {
|
|
15
|
+
itemFontHeight,
|
|
16
|
+
itemFontSize,
|
|
17
|
+
itemLineHeight,
|
|
18
|
+
itemFontName,
|
|
19
|
+
itemColor
|
|
20
|
+
} = _ref;
|
|
21
|
+
return applyTextStyles({
|
|
22
|
+
fontWeight: itemFontHeight,
|
|
23
|
+
fontSize: itemFontSize,
|
|
24
|
+
fontName: itemFontName,
|
|
25
|
+
color: itemColor,
|
|
26
|
+
themeOptions,
|
|
27
|
+
lineHeight: itemLineHeight
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const selectItemCounterStyles = _ref2 => {
|
|
31
|
+
let {
|
|
32
|
+
itemBulletContainerWidth,
|
|
33
|
+
itemBulletContainerAlign,
|
|
34
|
+
itemFontWeight,
|
|
35
|
+
itemFontSize,
|
|
36
|
+
itemFontName,
|
|
37
|
+
itemLineHeight,
|
|
38
|
+
themeOptions,
|
|
39
|
+
listGutter,
|
|
40
|
+
itemColor
|
|
41
|
+
} = _ref2;
|
|
42
|
+
return {
|
|
43
|
+
color: itemColor,
|
|
44
|
+
width: itemBulletContainerWidth,
|
|
45
|
+
paddingRight: listGutter,
|
|
46
|
+
textAlign: itemBulletContainerAlign,
|
|
47
|
+
...applyTextStyles({
|
|
48
|
+
fontWeight: itemFontWeight,
|
|
49
|
+
fontSize: itemFontSize,
|
|
50
|
+
fontName: itemFontName,
|
|
51
|
+
themeOptions
|
|
52
|
+
}),
|
|
53
|
+
lineHeight: itemLineHeight * itemFontSize
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const selectItemContentStyles = (_ref3, isLastChild) => {
|
|
57
|
+
let {
|
|
58
|
+
interItemMargin,
|
|
59
|
+
...themeTokens
|
|
60
|
+
} = _ref3;
|
|
61
|
+
return {
|
|
62
|
+
...themeTokens,
|
|
63
|
+
marginBottom: !isLastChild ? interItemMargin : 0
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const Item = /*#__PURE__*/forwardRef((_ref4, ref) => {
|
|
67
|
+
let {
|
|
68
|
+
children,
|
|
69
|
+
index,
|
|
70
|
+
isLastChild,
|
|
71
|
+
title,
|
|
72
|
+
tokens,
|
|
73
|
+
variant,
|
|
74
|
+
...rest
|
|
75
|
+
} = _ref4;
|
|
76
|
+
const themeTokens = useThemeTokens('OrderedList', tokens, variant);
|
|
77
|
+
const headingTokens = title && {
|
|
78
|
+
lineHeight: themeTokens.itemLineHeight,
|
|
79
|
+
fontSize: themeTokens.itemFontSize,
|
|
80
|
+
color: themeTokens.itemColor,
|
|
81
|
+
fontName: themeTokens.headerFontName,
|
|
82
|
+
fontWeight: themeTokens.headerFontWeight
|
|
83
|
+
};
|
|
84
|
+
const {
|
|
85
|
+
themeOptions
|
|
86
|
+
} = useTheme();
|
|
87
|
+
const itemContent = wrapStringsInText(children, {
|
|
88
|
+
style: selectItemTextStyles(themeTokens, themeOptions)
|
|
89
|
+
});
|
|
90
|
+
const itemCounter = wrapStringsInText(`${index}.`, {
|
|
91
|
+
style: selectItemTextStyles(themeTokens, themeOptions)
|
|
92
|
+
});
|
|
93
|
+
return /*#__PURE__*/_jsxs(ItemBase, {
|
|
94
|
+
ref: ref,
|
|
95
|
+
style: {
|
|
96
|
+
...staticStyles.container,
|
|
97
|
+
...themeTokens
|
|
98
|
+
},
|
|
99
|
+
...selectProps(rest),
|
|
100
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
101
|
+
style: [staticStyles.itemCounter, selectItemCounterStyles(themeTokens)],
|
|
102
|
+
children: itemCounter
|
|
103
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
104
|
+
style: staticStyles.itemContent,
|
|
105
|
+
children: title ? /*#__PURE__*/_jsxs(StackView, {
|
|
106
|
+
tokens: {
|
|
107
|
+
flexShrink: 1
|
|
108
|
+
},
|
|
109
|
+
space: 0,
|
|
110
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
111
|
+
variant: {
|
|
112
|
+
size: 'h4'
|
|
113
|
+
},
|
|
114
|
+
tokens: headingTokens,
|
|
115
|
+
children: title
|
|
116
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
117
|
+
style: selectItemContentStyles(themeTokens, isLastChild),
|
|
118
|
+
children: itemContent
|
|
119
|
+
})]
|
|
120
|
+
}) : /*#__PURE__*/_jsx(View, {
|
|
121
|
+
style: selectItemContentStyles(themeTokens, isLastChild),
|
|
122
|
+
children: itemContent
|
|
123
|
+
})
|
|
124
|
+
})]
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
Item.propTypes = {
|
|
128
|
+
...selectedSystemPropTypes,
|
|
129
|
+
/**
|
|
130
|
+
* Item content
|
|
131
|
+
*/
|
|
132
|
+
children: PropTypes.node.isRequired,
|
|
133
|
+
/**
|
|
134
|
+
* Item index
|
|
135
|
+
*/
|
|
136
|
+
index: PropTypes.number,
|
|
137
|
+
/**
|
|
138
|
+
* If true, the item is the last one on the list
|
|
139
|
+
*/
|
|
140
|
+
isLastChild: PropTypes.bool,
|
|
141
|
+
/**
|
|
142
|
+
* Defines the title of the `OrderedList.Item`
|
|
143
|
+
*/
|
|
144
|
+
title: PropTypes.string,
|
|
145
|
+
/**
|
|
146
|
+
* Item tokens
|
|
147
|
+
*/
|
|
148
|
+
tokens: getTokensPropType('List'),
|
|
149
|
+
/**
|
|
150
|
+
* Item variant
|
|
151
|
+
*/
|
|
152
|
+
variant: variantProp.propType
|
|
153
|
+
};
|
|
154
|
+
Item.displayName = 'OrderedListItem';
|
|
155
|
+
Item.defaultProps = {
|
|
156
|
+
title: undefined,
|
|
157
|
+
tokens: {}
|
|
158
|
+
};
|
|
159
|
+
export default Item;
|
|
160
|
+
const staticStyles = StyleSheet.create({
|
|
161
|
+
container: {
|
|
162
|
+
flexDirection: 'row'
|
|
163
|
+
},
|
|
164
|
+
itemCounter: {
|
|
165
|
+
flexWrap: 'wrap'
|
|
166
|
+
},
|
|
167
|
+
itemContent: {
|
|
168
|
+
flexDirection: 'column',
|
|
169
|
+
marginLeft: 8
|
|
170
|
+
}
|
|
171
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import View from "react-native-web/dist/exports/View";
|
|
5
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
6
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const getAccessibilityRole = () => Platform.select({
|
|
9
|
+
ios: 'listitem',
|
|
10
|
+
android: 'none',
|
|
11
|
+
web: 'listitem'
|
|
12
|
+
});
|
|
13
|
+
const Item = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
14
|
+
let {
|
|
15
|
+
children,
|
|
16
|
+
style,
|
|
17
|
+
...rest
|
|
18
|
+
} = _ref;
|
|
19
|
+
return /*#__PURE__*/_jsx(View, {
|
|
20
|
+
accessibilityRole: getAccessibilityRole(),
|
|
21
|
+
ref: ref,
|
|
22
|
+
style: [staticStyles.container, style],
|
|
23
|
+
...rest,
|
|
24
|
+
children: children
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
Item.propTypes = {
|
|
28
|
+
/**
|
|
29
|
+
* Item content
|
|
30
|
+
*/
|
|
31
|
+
children: PropTypes.node.isRequired,
|
|
32
|
+
/**
|
|
33
|
+
* Item custom styles
|
|
34
|
+
*/
|
|
35
|
+
style: PropTypes.object
|
|
36
|
+
};
|
|
37
|
+
Item.displayName = 'OrderedListItem';
|
|
38
|
+
export default Item;
|
|
39
|
+
const staticStyles = StyleSheet.create({
|
|
40
|
+
container: {
|
|
41
|
+
display: 'flex'
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { getTokensPropType, htmlAttrs, selectSystemProps, variantProp, viewProps } from '../utils';
|
|
4
|
+
import OrderedListBase from './OrderedListBase';
|
|
5
|
+
import Item from './Item';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const [selectProps, selectedSystemPropsTypes] = selectSystemProps([htmlAttrs, viewProps]);
|
|
8
|
+
const getChildrenWithParentVariants = (variant, children, start) => {
|
|
9
|
+
if (variant) return children.map((child, i) => {
|
|
10
|
+
var _child$props;
|
|
11
|
+
const existingChildVariants = ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.variant) ?? {};
|
|
12
|
+
return {
|
|
13
|
+
...child,
|
|
14
|
+
props: {
|
|
15
|
+
...child.props,
|
|
16
|
+
index: start + i,
|
|
17
|
+
isLastChild: i === children.length - 1,
|
|
18
|
+
variant: {
|
|
19
|
+
...existingChildVariants,
|
|
20
|
+
...variant
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return children;
|
|
26
|
+
};
|
|
27
|
+
const OrderedList = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
28
|
+
let {
|
|
29
|
+
children,
|
|
30
|
+
start,
|
|
31
|
+
variant,
|
|
32
|
+
...rest
|
|
33
|
+
} = _ref;
|
|
34
|
+
const childrenWithParentVariants = useMemo(() => getChildrenWithParentVariants(variant, children, start), [children, variant, start]);
|
|
35
|
+
return /*#__PURE__*/_jsx(OrderedListBase, {
|
|
36
|
+
ref: ref,
|
|
37
|
+
...selectProps(rest),
|
|
38
|
+
children: childrenWithParentVariants
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
OrderedList.propTypes = {
|
|
42
|
+
...selectedSystemPropsTypes,
|
|
43
|
+
tokens: getTokensPropType('OrderedList'),
|
|
44
|
+
/**
|
|
45
|
+
* A list of ordered items wrapped in `OrderedList.Item`.
|
|
46
|
+
*/
|
|
47
|
+
children: PropTypes.node.isRequired,
|
|
48
|
+
/**
|
|
49
|
+
* The position to start the list with.
|
|
50
|
+
*/
|
|
51
|
+
start: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
52
|
+
variant: variantProp.propType
|
|
53
|
+
};
|
|
54
|
+
OrderedList.defaultProps = {
|
|
55
|
+
start: 1,
|
|
56
|
+
tokens: {},
|
|
57
|
+
variant: {}
|
|
58
|
+
};
|
|
59
|
+
OrderedList.displayName = 'OrderedList';
|
|
60
|
+
OrderedList.Item = Item;
|
|
61
|
+
export default OrderedList;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import View from "react-native-web/dist/exports/View";
|
|
5
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
6
|
+
import ItemBase from './ItemBase';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const OrderedListBase = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
...rest
|
|
12
|
+
} = _ref;
|
|
13
|
+
return /*#__PURE__*/_jsx(View, {
|
|
14
|
+
accessibilityRole: "list",
|
|
15
|
+
ref: ref,
|
|
16
|
+
style: staticStyles.container,
|
|
17
|
+
...rest,
|
|
18
|
+
children: children
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
OrderedListBase.propTypes = {
|
|
22
|
+
/**
|
|
23
|
+
* A list of ordered items wrapped in `OrderedListBase.Item`.
|
|
24
|
+
*/
|
|
25
|
+
children: PropTypes.node.isRequired
|
|
26
|
+
};
|
|
27
|
+
OrderedListBase.displayName = 'OrderedList';
|
|
28
|
+
OrderedListBase.Item = ItemBase;
|
|
29
|
+
export default OrderedListBase;
|
|
30
|
+
const staticStyles = StyleSheet.create({
|
|
31
|
+
container: {
|
|
32
|
+
flexDirection: 'column',
|
|
33
|
+
margin: 0,
|
|
34
|
+
padding: 0
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { useTheme } from '../ThemeProvider';
|
|
4
|
+
import ResponsiveProp from './ResponsiveProp';
|
|
5
|
+
import ResponsiveWithMediaQueryStyleSheet from './ResponsiveWithMediaQueryStyleSheet';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Responsive conditionally renders children based on whether the viewport matches the provided
|
|
8
9
|
* min and max viewports.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* If enableMediaQueryStyleSheet themeOption is set to false in ThemeProvider, then in SSR,
|
|
12
|
+
* like other viewport utilities, it treats the viewport as `xs` both in SSR itself and
|
|
11
13
|
* during first hydration on the client side; then if the viewport is not `xs`, it re-renders
|
|
12
14
|
* after hydration. This may cause a layout shift on devices other than the narrowest.
|
|
15
|
+
*
|
|
16
|
+
* If enableMediaQueryStyleSheet themeOption is set to true in ThemeProvider, then media query stylesheet
|
|
17
|
+
* is used to hide and show children of `Responsive` within a View.
|
|
13
18
|
*/
|
|
14
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
15
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
20
|
const Responsive = _ref => {
|
|
17
21
|
let {
|
|
@@ -19,20 +23,25 @@ const Responsive = _ref => {
|
|
|
19
23
|
max,
|
|
20
24
|
children
|
|
21
25
|
} = _ref;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const {
|
|
27
|
+
themeOptions: {
|
|
28
|
+
enableMediaQueryStyleSheet
|
|
29
|
+
}
|
|
30
|
+
} = useTheme();
|
|
31
|
+
if (enableMediaQueryStyleSheet) {
|
|
32
|
+
return /*#__PURE__*/_jsx(ResponsiveWithMediaQueryStyleSheet, {
|
|
33
|
+
min: min,
|
|
34
|
+
max: max,
|
|
35
|
+
children: children
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
|
-
return /*#__PURE__*/_jsx(
|
|
33
|
-
|
|
38
|
+
return /*#__PURE__*/_jsx(ResponsiveProp, {
|
|
39
|
+
min: min,
|
|
40
|
+
max: max,
|
|
41
|
+
children: children
|
|
34
42
|
});
|
|
35
43
|
};
|
|
44
|
+
Responsive.displayName = 'Responsive';
|
|
36
45
|
Responsive.propTypes = {
|
|
37
46
|
/**
|
|
38
47
|
* To hide children of `Responsive` if the current viewport is smaller than `min`
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { viewports } from '@telus-uds/system-constants';
|
|
4
|
+
import { useResponsiveProp } from '../utils';
|
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const ResponsiveProp = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
min = 'xs',
|
|
10
|
+
max,
|
|
11
|
+
children
|
|
12
|
+
} = _ref;
|
|
13
|
+
const byViewports = {
|
|
14
|
+
[min]: children
|
|
15
|
+
};
|
|
16
|
+
if (max && max !== 'xl') {
|
|
17
|
+
// Stop returning children at the viewport one above 'max' or greater
|
|
18
|
+
const maxIndex = viewports.keys.indexOf(max);
|
|
19
|
+
const maxPlusOne = maxIndex >= 0 ? viewports.keys[maxIndex + 1] : null;
|
|
20
|
+
if (maxPlusOne) byViewports[maxPlusOne] = null;
|
|
21
|
+
}
|
|
22
|
+
const responsiveProp = useResponsiveProp(byViewports, null);
|
|
23
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
24
|
+
children: responsiveProp
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
ResponsiveProp.displayName = 'Responsive';
|
|
28
|
+
ResponsiveProp.propTypes = {
|
|
29
|
+
/**
|
|
30
|
+
* To hide children of `Responsive` if the current viewport is smaller than `min`
|
|
31
|
+
*/
|
|
32
|
+
min: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
|
|
33
|
+
/**
|
|
34
|
+
* To hide children of `Responsive` if the current viewport is larger than `max`
|
|
35
|
+
*/
|
|
36
|
+
max: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']),
|
|
37
|
+
children: PropTypes.node.isRequired
|
|
38
|
+
};
|
|
39
|
+
export default ResponsiveProp;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { viewports } from '@telus-uds/system-constants';
|
|
4
|
+
import { BaseView, StyleSheet, createMediaQueryStyles } from '../utils';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function generateResponsiveStyles(min, max) {
|
|
7
|
+
const viewportsArray = viewports.keys;
|
|
8
|
+
const minIndex = viewportsArray.indexOf(min);
|
|
9
|
+
const maxIndex = viewportsArray.indexOf(max);
|
|
10
|
+
let hiddenViewports = [];
|
|
11
|
+
if (minIndex !== -1) {
|
|
12
|
+
hiddenViewports = viewportsArray.slice(0, minIndex);
|
|
13
|
+
}
|
|
14
|
+
if (maxIndex !== -1) {
|
|
15
|
+
hiddenViewports = hiddenViewports.concat(viewportsArray.slice(maxIndex + 1));
|
|
16
|
+
}
|
|
17
|
+
const styles = {};
|
|
18
|
+
viewportsArray.forEach(viewport => {
|
|
19
|
+
if (hiddenViewports.includes(viewport)) {
|
|
20
|
+
styles[viewport] = {
|
|
21
|
+
display: 'none'
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return createMediaQueryStyles(styles, false);
|
|
26
|
+
}
|
|
27
|
+
const ResponsiveWithMediaQueryStyleSheet = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
min,
|
|
30
|
+
max,
|
|
31
|
+
children
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
ids,
|
|
35
|
+
styles
|
|
36
|
+
} = StyleSheet.create({
|
|
37
|
+
responsive: {
|
|
38
|
+
flexDirection: 'inherit',
|
|
39
|
+
alignItems: 'inherit',
|
|
40
|
+
justifyContent: 'inherit',
|
|
41
|
+
...generateResponsiveStyles(min, max)
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return /*#__PURE__*/_jsx(BaseView, {
|
|
45
|
+
style: styles.responsive,
|
|
46
|
+
dataSet: ids.responsive && {
|
|
47
|
+
media: ids.responsive
|
|
48
|
+
},
|
|
49
|
+
children: children
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
ResponsiveWithMediaQueryStyleSheet.displayName = 'Responsive';
|
|
53
|
+
ResponsiveWithMediaQueryStyleSheet.propTypes = {
|
|
54
|
+
/**
|
|
55
|
+
* To hide children of `Responsive` if the current viewport is smaller than `min`
|
|
56
|
+
*/
|
|
57
|
+
min: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
|
|
58
|
+
/**
|
|
59
|
+
* To hide children of `Responsive` if the current viewport is larger than `max`
|
|
60
|
+
*/
|
|
61
|
+
max: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']),
|
|
62
|
+
children: PropTypes.node.isRequired
|
|
63
|
+
};
|
|
64
|
+
export default ResponsiveWithMediaQueryStyleSheet;
|
|
@@ -15,7 +15,8 @@ const defaultThemeOptions = {
|
|
|
15
15
|
// TODO: switch `forceZIndex` to be false by default in the next major version
|
|
16
16
|
forceZIndex: true,
|
|
17
17
|
// TODO: switch `enableHelmetSSR` to be false by default in the next major version
|
|
18
|
-
enableHelmetSSR: true
|
|
18
|
+
enableHelmetSSR: true,
|
|
19
|
+
enableMediaQueryStyleSheet: false
|
|
19
20
|
};
|
|
20
21
|
const ThemeProvider = _ref => {
|
|
21
22
|
let {
|
|
@@ -70,12 +71,14 @@ ThemeProvider.propTypes = {
|
|
|
70
71
|
* - `enableHelmetSSR`: on Web SSR, allows React Helmet to run during server-side rendering. This should be
|
|
71
72
|
* disabled unless a web app has been specifically configured to stop React Helmet accumulating
|
|
72
73
|
* instances (which may cause a memory leak). See React Helmet's docs: https://github.com/nfl/react-helmet
|
|
74
|
+
* - `enableMediaQueryStyleSheet`: enables the use of Media Query StyleSheet.
|
|
73
75
|
*/
|
|
74
76
|
themeOptions: PropTypes.shape({
|
|
75
77
|
forceAbsoluteFontSizing: PropTypes.bool,
|
|
76
78
|
forceZIndex: PropTypes.bool,
|
|
77
79
|
enableHelmetSSR: PropTypes.bool,
|
|
78
|
-
contentMaxWidth: responsiveProps.getTypeOptionallyByViewport(PropTypes.number)
|
|
80
|
+
contentMaxWidth: responsiveProps.getTypeOptionallyByViewport(PropTypes.number),
|
|
81
|
+
enableMediaQueryStyleSheet: PropTypes.bool
|
|
79
82
|
})
|
|
80
83
|
};
|
|
81
84
|
export default ThemeProvider;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ThemeProvider from './ThemeProvider';
|
|
2
2
|
export { default as useTheme } from './useTheme';
|
|
3
3
|
export { default as useSetTheme } from './useSetTheme';
|
|
4
|
+
export { default as useResponsiveThemeTokens } from './useResponsiveThemeTokens';
|
|
4
5
|
export * from './useThemeTokens';
|
|
5
6
|
export * from './utils';
|
|
6
7
|
export default ThemeProvider;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { viewports } from '@telus-uds/system-constants';
|
|
2
|
+
import useTheme from './useTheme';
|
|
3
|
+
import { getComponentTheme, mergeAppearances, resolveThemeTokens } from './utils';
|
|
4
|
+
const getResponsiveThemeTokens = function (_ref, tokensProp) {
|
|
5
|
+
let {
|
|
6
|
+
rules = [],
|
|
7
|
+
tokens: defaultThemeTokens = {}
|
|
8
|
+
} = _ref;
|
|
9
|
+
let variants = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10
|
+
let states = arguments.length > 3 ? arguments[3] : undefined;
|
|
11
|
+
const appearances = mergeAppearances(variants, states);
|
|
12
|
+
const tokensByViewport = Object.fromEntries(viewports.keys.map(viewport => [viewport, {
|
|
13
|
+
...defaultThemeTokens
|
|
14
|
+
}]));
|
|
15
|
+
|
|
16
|
+
// Go through each rule and collect them for the corresponding viewport if they apply
|
|
17
|
+
rules.forEach(rule => {
|
|
18
|
+
if (doesRuleApply(rule, appearances)) {
|
|
19
|
+
// If the rule does not have a viewport specified, we collect it in all viewports
|
|
20
|
+
let targetViewports = rule.if.viewport || viewports.keys;
|
|
21
|
+
if (!Array.isArray(targetViewports)) {
|
|
22
|
+
targetViewports = [targetViewports];
|
|
23
|
+
}
|
|
24
|
+
targetViewports.forEach(viewport => {
|
|
25
|
+
tokensByViewport[viewport] = {
|
|
26
|
+
...tokensByViewport[viewport],
|
|
27
|
+
...rule.tokens
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.keys(tokensByViewport).forEach(viewport => {
|
|
33
|
+
tokensByViewport[viewport] = resolveThemeTokens(tokensByViewport[viewport], appearances, tokensProp);
|
|
34
|
+
});
|
|
35
|
+
return tokensByViewport;
|
|
36
|
+
};
|
|
37
|
+
const doesRuleApply = (rule, appearances) => Object.entries(rule.if).every(condition => doesConditionApply(condition, appearances));
|
|
38
|
+
const doesConditionApply = (_ref2, appearances) => {
|
|
39
|
+
let [key, value] = _ref2;
|
|
40
|
+
if (key === 'viewport') {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// use null rather than undefined so we can serialise the value in themes
|
|
44
|
+
const appearanceValue = appearances[key] ?? null;
|
|
45
|
+
return Array.isArray(value) ? value.includes(appearanceValue) : value === appearanceValue;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {import('../utils/props/tokens.js').TokensSet} TokensSet
|
|
50
|
+
* @typedef {import('../utils/props/tokens.js').TokensProp} TokensProp
|
|
51
|
+
* @typedef {import('../utils/props/variantProp').AppearanceSet} AppearanceSet
|
|
52
|
+
*
|
|
53
|
+
* Returns a complete set of tokens for a component for each viewport based on which of the
|
|
54
|
+
* component's theme rules apply to the current set of theme appearances.
|
|
55
|
+
* Pass the returned output to createMediaQueryStyles to generate media query styles for use inside
|
|
56
|
+
* the media query stylesheet from './utils/ssr-media-query'.
|
|
57
|
+
*
|
|
58
|
+
* @typedef {Object} ResponsiveObject
|
|
59
|
+
* @property {TokensSet} xs
|
|
60
|
+
* @property {TokensSet} sm
|
|
61
|
+
* @property {TokensSet} md
|
|
62
|
+
* @property {TokensSet} lg
|
|
63
|
+
* @property {TokensSet} xl
|
|
64
|
+
*
|
|
65
|
+
* @param { string } componentName
|
|
66
|
+
* @param { TokensProp } tokens
|
|
67
|
+
* @param { AppearanceSet } variants
|
|
68
|
+
* @param { AppearanceSet } states
|
|
69
|
+
* @returns { ResponsiveObject }
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
const useResponsiveThemeTokens = function (componentName) {
|
|
73
|
+
let tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
74
|
+
let variants = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
75
|
+
let states = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
76
|
+
const theme = useTheme();
|
|
77
|
+
const componentTheme = getComponentTheme(theme, componentName);
|
|
78
|
+
const themeTokens = getResponsiveThemeTokens(componentTheme, tokens, variants, states);
|
|
79
|
+
return themeTokens;
|
|
80
|
+
};
|
|
81
|
+
export default useResponsiveThemeTokens;
|