@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
package/src/Card/Card.jsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
+
import { View } from 'react-native'
|
|
3
4
|
|
|
4
|
-
import { useThemeTokens } from '../ThemeProvider'
|
|
5
|
+
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider'
|
|
5
6
|
import { getTokensPropType, variantProp } from '../utils'
|
|
6
7
|
import { useViewport } from '../ViewportProvider'
|
|
7
8
|
import { a11yProps, selectSystemProps, viewProps } from '../utils/props'
|
|
8
9
|
import CardBase from './CardBase'
|
|
10
|
+
import PressableCardBase from './PressableCardBase'
|
|
9
11
|
|
|
10
12
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps])
|
|
11
13
|
|
|
@@ -57,24 +59,84 @@ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, vie
|
|
|
57
59
|
* you automatically make inaccessible its children, which may or may not be appropriate
|
|
58
60
|
* depending on what you are trying to achieve.
|
|
59
61
|
*/
|
|
60
|
-
const Card = forwardRef(
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const Card = forwardRef(
|
|
63
|
+
({ children, tokens, variant, dataSet, onPress, interactiveCard, ...rest }, ref) => {
|
|
64
|
+
const viewport = useViewport()
|
|
65
|
+
const themeTokens = useThemeTokens('Card', tokens, variant, { viewport })
|
|
66
|
+
const getThemeTokens = useThemeTokensCallback('Card', interactiveCard?.tokens, {
|
|
67
|
+
interactive: true,
|
|
68
|
+
...(interactiveCard?.variant || {})
|
|
69
|
+
})
|
|
70
|
+
// When interactive area is present, spacing tokens should only be applied
|
|
71
|
+
// to individual Card sections, not Card as a whole
|
|
72
|
+
const { paddingTop, paddingBottom, paddingLeft, paddingRight, ...restOfTokens } = themeTokens
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<CardBase
|
|
77
|
+
ref={ref}
|
|
78
|
+
tokens={interactiveCard?.body ? restOfTokens : themeTokens}
|
|
79
|
+
dataSet={dataSet}
|
|
80
|
+
{...selectProps(rest)}
|
|
81
|
+
>
|
|
82
|
+
{interactiveCard?.body ? (
|
|
83
|
+
<>
|
|
84
|
+
<PressableCardBase
|
|
85
|
+
ref={ref}
|
|
86
|
+
tokens={getThemeTokens}
|
|
87
|
+
dataSet={dataSet}
|
|
88
|
+
onPress={onPress}
|
|
89
|
+
{...selectProps(rest)}
|
|
90
|
+
>
|
|
91
|
+
{interactiveCard?.body}
|
|
92
|
+
</PressableCardBase>
|
|
93
|
+
{children ? (
|
|
94
|
+
<View style={{ paddingTop, paddingBottom, paddingLeft, paddingRight }}>
|
|
95
|
+
{children}
|
|
96
|
+
</View>
|
|
97
|
+
) : null}
|
|
98
|
+
</>
|
|
99
|
+
) : (
|
|
100
|
+
children
|
|
101
|
+
)}
|
|
102
|
+
</CardBase>
|
|
103
|
+
</>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
)
|
|
70
107
|
|
|
71
108
|
Card.displayName = 'Card'
|
|
72
109
|
|
|
73
110
|
Card.propTypes = {
|
|
74
111
|
...selectedSystemPropTypes,
|
|
112
|
+
/**
|
|
113
|
+
* Card content.
|
|
114
|
+
*/
|
|
75
115
|
children: PropTypes.node,
|
|
116
|
+
/**
|
|
117
|
+
* Card tokens.
|
|
118
|
+
*/
|
|
76
119
|
tokens: getTokensPropType('Card'),
|
|
77
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Card variant.
|
|
122
|
+
*/
|
|
123
|
+
variant: variantProp.propType,
|
|
124
|
+
/**
|
|
125
|
+
* Function to call on pressing the card.
|
|
126
|
+
* Note: This is only available when `interactiveCard` prop is used.
|
|
127
|
+
*/
|
|
128
|
+
onPress: PropTypes.func,
|
|
129
|
+
/**
|
|
130
|
+
* Object to set interactive card's properties
|
|
131
|
+
* - body: The body of the interactive card, can be any renderable node
|
|
132
|
+
* - tokens: The tokens to be used for the interactive card
|
|
133
|
+
* - variant: The variant to be used for the interactive card
|
|
134
|
+
*/
|
|
135
|
+
interactiveCard: PropTypes.shape({
|
|
136
|
+
body: PropTypes.node,
|
|
137
|
+
tokens: getTokensPropType('Card'),
|
|
138
|
+
variant: variantProp.propType
|
|
139
|
+
})
|
|
78
140
|
}
|
|
79
141
|
|
|
80
142
|
export default Card
|
|
@@ -54,6 +54,7 @@ const PressableCardBase = forwardRef(
|
|
|
54
54
|
inactive,
|
|
55
55
|
href,
|
|
56
56
|
hrefAttrs,
|
|
57
|
+
dataSet,
|
|
57
58
|
accessibilityRole = href ? 'link' : undefined,
|
|
58
59
|
...rawRest
|
|
59
60
|
},
|
|
@@ -103,6 +104,7 @@ const PressableCardBase = forwardRef(
|
|
|
103
104
|
onKeyDown={handleKeyDown}
|
|
104
105
|
hrefAttrs={hrefAttrs}
|
|
105
106
|
style={getOuterBorderStyle}
|
|
107
|
+
dataSet={dataSet}
|
|
106
108
|
{...selectProps({ ...rest, accessibilityRole })}
|
|
107
109
|
>
|
|
108
110
|
{(pressableState) => (
|
package/src/FlexGrid/Col/Col.jsx
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import React, { forwardRef, useContext } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { Platform
|
|
4
|
-
import { viewports } from '@telus-uds/system-constants'
|
|
3
|
+
import { Platform } from 'react-native'
|
|
5
4
|
|
|
6
5
|
import GutterContext from '../providers/GutterContext'
|
|
7
|
-
import { useViewport } from '../../ViewportProvider'
|
|
8
6
|
import applyInheritance from '../helpers'
|
|
9
|
-
import { responsiveProps, BaseView } from '../../utils'
|
|
7
|
+
import { responsiveProps, BaseView, StyleSheet, createMediaQueryStyles } from '../../utils'
|
|
10
8
|
|
|
11
9
|
const Col = forwardRef(
|
|
12
10
|
(
|
|
@@ -29,8 +27,6 @@ const Col = forwardRef(
|
|
|
29
27
|
ref
|
|
30
28
|
) => {
|
|
31
29
|
const gutter = useContext(GutterContext)
|
|
32
|
-
const viewPort = useViewport()
|
|
33
|
-
|
|
34
30
|
const hiddenLevels = applyInheritance([xs, sm, md, lg, xl])
|
|
35
31
|
|
|
36
32
|
const getHorizontalAlignLevel = () => {
|
|
@@ -84,65 +80,11 @@ const Col = forwardRef(
|
|
|
84
80
|
return {}
|
|
85
81
|
}
|
|
86
82
|
|
|
87
|
-
const sizeStyles = (sizes) => {
|
|
88
|
-
const currViewport = Object.keys(sizes).find((key) => key.startsWith(viewPort))
|
|
89
|
-
const currSize = sizes[currViewport]
|
|
90
|
-
return {
|
|
91
|
-
...calculateWidth(currSize)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const offsetStyles = (offsets) => {
|
|
96
|
-
const currViewport = Object.keys(offsets).find((key) => key.startsWith(viewPort))
|
|
97
|
-
const currOffset = offsets[currViewport]
|
|
98
|
-
return {
|
|
99
|
-
...calculateOffset(currOffset)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const gutterPadding = {
|
|
104
|
-
paddingLeft: gutter ? 16 : 0,
|
|
105
|
-
paddingRight: gutter ? 16 : 0
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let hidingStyles = {}
|
|
109
|
-
|
|
110
83
|
// TODO: consider setting this to always 'flex' in a major release.
|
|
111
84
|
// `display: block` is invalid in native apps.
|
|
112
85
|
// See https://telusdigital.atlassian.net/browse/UDS1-92
|
|
113
86
|
const shown = !flex && Platform.OS === 'web' ? 'block' : 'flex'
|
|
114
87
|
|
|
115
|
-
if (viewPort === viewports.xs) {
|
|
116
|
-
hidingStyles = {
|
|
117
|
-
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
118
|
-
textAlign: horizontalAlignLevel[0]
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (viewPort === viewports.sm) {
|
|
122
|
-
hidingStyles = {
|
|
123
|
-
display: hiddenLevels[1] === 0 ? 'none' : shown,
|
|
124
|
-
textAlign: horizontalAlignLevel[1]
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (viewPort === viewports.md) {
|
|
128
|
-
hidingStyles = {
|
|
129
|
-
display: hiddenLevels[2] === 0 ? 'none' : shown,
|
|
130
|
-
textAlign: horizontalAlignLevel[2]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (viewPort === viewports.lg) {
|
|
134
|
-
hidingStyles = {
|
|
135
|
-
display: hiddenLevels[3] === 0 ? 'none' : shown,
|
|
136
|
-
textAlign: horizontalAlignLevel[3]
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (viewPort === viewports.xl) {
|
|
140
|
-
hidingStyles = {
|
|
141
|
-
display: hiddenLevels[4] === 0 ? 'none' : shown,
|
|
142
|
-
textAlign: horizontalAlignLevel[4]
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
88
|
const sizesArray = [xs, sm, md, lg, xl]
|
|
147
89
|
const offSetsArray = [xsOffset, smOffset, mdOffset, lgOffset, xlOffset]
|
|
148
90
|
const sizesWithIheritance = applyInheritance(sizesArray)
|
|
@@ -161,18 +103,53 @@ const Col = forwardRef(
|
|
|
161
103
|
lg: offsetsWithIheritance[3],
|
|
162
104
|
xl: offsetsWithIheritance[4]
|
|
163
105
|
}
|
|
106
|
+
|
|
107
|
+
const mediaQueryStyles = createMediaQueryStyles({
|
|
108
|
+
xs: {
|
|
109
|
+
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
110
|
+
textAlign: horizontalAlignLevel[0],
|
|
111
|
+
...calculateWidth(sizes.xs),
|
|
112
|
+
...calculateOffset(offsets.xs)
|
|
113
|
+
},
|
|
114
|
+
sm: {
|
|
115
|
+
display: hiddenLevels[1] === 0 ? 'none' : shown,
|
|
116
|
+
textAlign: horizontalAlignLevel[1],
|
|
117
|
+
...calculateWidth(sizes.sm),
|
|
118
|
+
...calculateOffset(offsets.sm)
|
|
119
|
+
},
|
|
120
|
+
md: {
|
|
121
|
+
display: hiddenLevels[2] === 0 ? 'none' : shown,
|
|
122
|
+
textAlign: horizontalAlignLevel[2],
|
|
123
|
+
...calculateWidth(sizes.md),
|
|
124
|
+
...calculateOffset(offsets.md)
|
|
125
|
+
},
|
|
126
|
+
lg: {
|
|
127
|
+
display: hiddenLevels[3] === 0 ? 'none' : shown,
|
|
128
|
+
textAlign: horizontalAlignLevel[3],
|
|
129
|
+
...calculateWidth(sizes.lg),
|
|
130
|
+
...calculateOffset(offsets.lg)
|
|
131
|
+
},
|
|
132
|
+
xl: {
|
|
133
|
+
display: hiddenLevels[4] === 0 ? 'none' : shown,
|
|
134
|
+
textAlign: horizontalAlignLevel[4],
|
|
135
|
+
...calculateWidth(sizes.xl),
|
|
136
|
+
...calculateOffset(offsets.xl)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const { ids, styles } = StyleSheet.create({
|
|
141
|
+
col: {
|
|
142
|
+
flexGrow: 1,
|
|
143
|
+
flexShrink: 0,
|
|
144
|
+
flexBasis: 'auto',
|
|
145
|
+
maxWidth: '100%',
|
|
146
|
+
paddingLeft: gutter ? 16 : 0,
|
|
147
|
+
paddingRight: gutter ? 16 : 0,
|
|
148
|
+
...mediaQueryStyles
|
|
149
|
+
}
|
|
150
|
+
})
|
|
164
151
|
return (
|
|
165
|
-
<BaseView
|
|
166
|
-
ref={ref}
|
|
167
|
-
{...viewProps}
|
|
168
|
-
style={[
|
|
169
|
-
styles.col,
|
|
170
|
-
gutterPadding,
|
|
171
|
-
offsetStyles(offsets),
|
|
172
|
-
sizeStyles(sizes),
|
|
173
|
-
{ ...hidingStyles }
|
|
174
|
-
]}
|
|
175
|
-
>
|
|
152
|
+
<BaseView ref={ref} {...viewProps} style={[styles.col]} dataSet={{ media: ids.col }}>
|
|
176
153
|
{children}
|
|
177
154
|
</BaseView>
|
|
178
155
|
)
|
|
@@ -180,15 +157,6 @@ const Col = forwardRef(
|
|
|
180
157
|
)
|
|
181
158
|
Col.displayName = 'Col'
|
|
182
159
|
|
|
183
|
-
const styles = StyleSheet.create({
|
|
184
|
-
col: {
|
|
185
|
-
flexGrow: 1,
|
|
186
|
-
flexShrink: 0,
|
|
187
|
-
flexBasis: 'auto',
|
|
188
|
-
maxWidth: '100%'
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
|
|
192
160
|
/*
|
|
193
161
|
* We're disabling default props since passing undefined props to
|
|
194
162
|
* the react-flexbox-grid component sets up blank classes that may cause
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { viewports } from '@telus-uds/system-constants'
|
|
5
5
|
import {
|
|
6
6
|
a11yProps,
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
getA11yPropsFromHtmlTag,
|
|
9
9
|
layoutTags,
|
|
10
10
|
selectSystemProps,
|
|
11
|
-
BaseView
|
|
11
|
+
BaseView,
|
|
12
|
+
StyleSheet,
|
|
13
|
+
createMediaQueryStyles
|
|
12
14
|
} from '../utils'
|
|
13
|
-
|
|
14
15
|
import Row from './Row'
|
|
15
16
|
import Col from './Col'
|
|
16
|
-
import { useViewport } from '../ViewportProvider'
|
|
17
17
|
import GutterContext from './providers/GutterContext'
|
|
18
18
|
import applyInheritance from './helpers'
|
|
19
19
|
|
|
@@ -41,33 +41,38 @@ const FlexGrid = forwardRef(
|
|
|
41
41
|
},
|
|
42
42
|
ref
|
|
43
43
|
) => {
|
|
44
|
-
const viewPort = useViewport()
|
|
45
44
|
const reverseLevel = applyInheritance([xsReverse, smReverse, mdReverse, lgReverse, xlReverse])
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
const mediaQueryStyles = createMediaQueryStyles({
|
|
46
|
+
xs: {
|
|
47
|
+
flexDirection: reverseLevel[0] ? 'column-reverse' : 'column'
|
|
48
|
+
},
|
|
49
|
+
sm: {
|
|
50
|
+
maxWidth: limitWidth && viewports.map.get('sm'),
|
|
51
|
+
flexDirection: reverseLevel[1] ? 'column-reverse' : 'column'
|
|
52
|
+
},
|
|
53
|
+
md: {
|
|
54
|
+
maxWidth: limitWidth && viewports.map.get('md'),
|
|
55
|
+
flexDirection: reverseLevel[2] ? 'column-reverse' : 'column'
|
|
56
|
+
},
|
|
57
|
+
lg: {
|
|
58
|
+
maxWidth: limitWidth && viewports.map.get('lg'),
|
|
59
|
+
flexDirection: reverseLevel[3] ? 'column-reverse' : 'column'
|
|
60
|
+
},
|
|
61
|
+
xl: {
|
|
62
|
+
maxWidth: limitWidth && viewports.map.get('xl'),
|
|
63
|
+
flexDirection: reverseLevel[4] ? 'column-reverse' : 'column'
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const { ids, styles } = StyleSheet.create({
|
|
68
|
+
flexgrid: {
|
|
69
|
+
flexWrap: 'wrap',
|
|
70
|
+
width: outsideGutter ? '100%' : 'auto',
|
|
71
|
+
marginVertical: 0,
|
|
72
|
+
marginHorizontal: outsideGutter ? 'auto' : -16,
|
|
73
|
+
...mediaQueryStyles
|
|
74
|
+
}
|
|
75
|
+
})
|
|
71
76
|
|
|
72
77
|
const props = {
|
|
73
78
|
accessibilityRole,
|
|
@@ -77,14 +82,7 @@ const FlexGrid = forwardRef(
|
|
|
77
82
|
|
|
78
83
|
return (
|
|
79
84
|
<GutterContext.Provider value={gutter}>
|
|
80
|
-
<BaseView
|
|
81
|
-
ref={ref}
|
|
82
|
-
{...props}
|
|
83
|
-
style={[
|
|
84
|
-
styles.grid,
|
|
85
|
-
{ marginHorizontal, marginVertical, width, flexDirection, maxWidth }
|
|
86
|
-
]}
|
|
87
|
-
>
|
|
85
|
+
<BaseView ref={ref} {...props} style={[styles.flexgrid]} dataSet={{ media: ids.flexgrid }}>
|
|
88
86
|
{children}
|
|
89
87
|
</BaseView>
|
|
90
88
|
</GutterContext.Provider>
|
|
@@ -93,12 +91,6 @@ const FlexGrid = forwardRef(
|
|
|
93
91
|
)
|
|
94
92
|
FlexGrid.displayName = 'FlexGrid'
|
|
95
93
|
|
|
96
|
-
const styles = StyleSheet.create({
|
|
97
|
-
grid: {
|
|
98
|
-
flexWrap: 'wrap'
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
94
|
FlexGrid.propTypes = {
|
|
103
95
|
...selectedSystemPropTypes,
|
|
104
96
|
/**
|
package/src/FlexGrid/Row/Row.jsx
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { StyleSheet } from 'react-native'
|
|
4
|
-
import { viewports } from '@telus-uds/system-constants'
|
|
5
3
|
|
|
6
|
-
import { useViewport } from '../../ViewportProvider'
|
|
7
4
|
import applyInheritance from '../helpers'
|
|
8
|
-
import { BaseView } from '../../utils'
|
|
5
|
+
import { BaseView, StyleSheet, createMediaQueryStyles } from '../../utils'
|
|
9
6
|
|
|
10
7
|
const horizontalAlignStyles = (horizontalAlign) => {
|
|
11
8
|
switch (horizontalAlign) {
|
|
@@ -69,48 +66,45 @@ const Row = forwardRef(
|
|
|
69
66
|
},
|
|
70
67
|
ref
|
|
71
68
|
) => {
|
|
72
|
-
const viewPort = useViewport()
|
|
73
69
|
const reverseLevel = applyInheritance([xsReverse, smReverse, mdReverse, lgReverse, xlReverse])
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
const mediaQueryStyles = createMediaQueryStyles({
|
|
71
|
+
xs: {
|
|
72
|
+
flexDirection: reverseLevel[0] ? 'row-reverse' : 'row',
|
|
73
|
+
flexWrap: reverseLevel[0] ? 'wrap-reverse' : 'wrap'
|
|
74
|
+
},
|
|
75
|
+
sm: {
|
|
76
|
+
flexDirection: reverseLevel[1] ? 'row-reverse' : 'row',
|
|
77
|
+
flexWrap: reverseLevel[1] ? 'wrap-reverse' : 'wrap'
|
|
78
|
+
},
|
|
79
|
+
md: {
|
|
80
|
+
flexDirection: reverseLevel[2] ? 'row-reverse' : 'row',
|
|
81
|
+
flexWrap: reverseLevel[2] ? 'wrap-reverse' : 'wrap'
|
|
82
|
+
},
|
|
83
|
+
lg: {
|
|
84
|
+
flexDirection: reverseLevel[3] ? 'row-reverse' : 'row',
|
|
85
|
+
flexWrap: reverseLevel[3] ? 'wrap-reverse' : 'wrap'
|
|
86
|
+
},
|
|
87
|
+
xl: {
|
|
88
|
+
flexDirection: reverseLevel[4] ? 'row-reverse' : 'row',
|
|
89
|
+
flexWrap: reverseLevel[4] ? 'wrap-reverse' : 'wrap'
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
const { ids, styles } = StyleSheet.create({
|
|
93
|
+
row: {
|
|
94
|
+
width: '100%',
|
|
95
|
+
marginVertical: 0,
|
|
96
|
+
marginHorizontal: 'auto',
|
|
97
|
+
flexGrow: 0,
|
|
98
|
+
flexShrink: 1,
|
|
99
|
+
flexBasis: 'auto',
|
|
100
|
+
...horizontalAlignStyles(horizontalAlign),
|
|
101
|
+
...verticalAlignStyles(verticalAlign),
|
|
102
|
+
...distributeStyles(distribute),
|
|
103
|
+
...mediaQueryStyles
|
|
104
|
+
}
|
|
105
|
+
})
|
|
99
106
|
return (
|
|
100
|
-
<BaseView
|
|
101
|
-
ref={ref}
|
|
102
|
-
{...rest}
|
|
103
|
-
style={[
|
|
104
|
-
styles.row,
|
|
105
|
-
{
|
|
106
|
-
flexDirection,
|
|
107
|
-
flexWrap,
|
|
108
|
-
...horizontalAlignStyles(horizontalAlign),
|
|
109
|
-
...verticalAlignStyles(verticalAlign),
|
|
110
|
-
...distributeStyles(distribute)
|
|
111
|
-
}
|
|
112
|
-
]}
|
|
113
|
-
>
|
|
107
|
+
<BaseView ref={ref} {...rest} style={[styles.row]} dataSet={{ media: ids.row }}>
|
|
114
108
|
{children}
|
|
115
109
|
</BaseView>
|
|
116
110
|
)
|
|
@@ -118,18 +112,6 @@ const Row = forwardRef(
|
|
|
118
112
|
)
|
|
119
113
|
Row.displayName = 'Row'
|
|
120
114
|
|
|
121
|
-
const styles = StyleSheet.create({
|
|
122
|
-
row: {
|
|
123
|
-
width: '100%',
|
|
124
|
-
marginVertical: 0,
|
|
125
|
-
marginHorizontal: 'auto',
|
|
126
|
-
flexGrow: 0,
|
|
127
|
-
flexShrink: 1,
|
|
128
|
-
flexBasis: 'auto',
|
|
129
|
-
flexDirection: 'row'
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
|
|
133
115
|
Row.propTypes = {
|
|
134
116
|
/**
|
|
135
117
|
* Align columns horizontally within their row.
|
package/src/Icon/IconText.jsx
CHANGED
|
@@ -23,12 +23,22 @@ const IconText = forwardRef(
|
|
|
23
23
|
// Inline images on Android are always baseline-aligned which makes them look misaligned - offset it.
|
|
24
24
|
// See abandoned issue https://github.com/facebook/react-native/issues/6529
|
|
25
25
|
const size = iconProps?.tokens?.size ?? 0
|
|
26
|
+
const valueTranslateY = iconProps?.tokens?.translateY
|
|
27
|
+
/**
|
|
28
|
+
* These calculations were carried out using a set of linear equations to calculate that the
|
|
29
|
+
* position of the icon "->"" is aligned to the first line of the tooltip text on IOS and Android.
|
|
30
|
+
* The issue was mainly on IOS, the translateY style didn't match with the old calculations.
|
|
31
|
+
*/
|
|
32
|
+
const resultY = valueTranslateY ? Math.floor(-1 * (valueTranslateY - 4)) : 0
|
|
33
|
+
|
|
26
34
|
const iconAdjustedAndriod = (
|
|
27
35
|
<View style={{ transform: [{ translateY: size * 0.2 }] }}>{iconContent}</View>
|
|
28
36
|
)
|
|
29
37
|
|
|
30
38
|
const iconAdjustedIOS = (
|
|
31
|
-
<View style={{ transform: [{ translateY: size * 0.01 }] }}>
|
|
39
|
+
<View style={{ transform: [{ translateY: valueTranslateY ? resultY : size * 0.01 }] }}>
|
|
40
|
+
{iconContent}
|
|
41
|
+
</View>
|
|
32
42
|
)
|
|
33
43
|
|
|
34
44
|
const mobile = Platform.OS === 'android' ? iconAdjustedAndriod : iconAdjustedIOS
|
package/src/Link/ChevronLink.jsx
CHANGED
package/src/Link/LinkBase.jsx
CHANGED
|
@@ -72,6 +72,7 @@ const selectDecorationStyles = ({ color, textLine, textLineStyle, alignSelf }) =
|
|
|
72
72
|
textDecorationLine: textLine,
|
|
73
73
|
textDecorationStyle: textLineStyle,
|
|
74
74
|
alignSelf,
|
|
75
|
+
|
|
75
76
|
...Platform.select({
|
|
76
77
|
web: {
|
|
77
78
|
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
@@ -80,12 +81,21 @@ const selectDecorationStyles = ({ color, textLine, textLineStyle, alignSelf }) =
|
|
|
80
81
|
})
|
|
81
82
|
})
|
|
82
83
|
|
|
83
|
-
const selectIconTokens = ({ color, iconSize,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const selectIconTokens = ({ color, iconSize, blockFontSize, iconTranslateX }) => {
|
|
85
|
+
/**
|
|
86
|
+
* These calculations were carried out using a set of linear equations to calculate that the
|
|
87
|
+
* position of the icon "->"" is aligned to the first line of the tooltip text.
|
|
88
|
+
* The base equation is: X/4 + Y/4 - 4 - |X - Y| = Z
|
|
89
|
+
* where X = blockFontSize, Y = iconSize and Z = translateY
|
|
90
|
+
*/
|
|
91
|
+
const translateY = blockFontSize / 4 + iconSize / 4 - 4 - Math.abs(iconSize - blockFontSize)
|
|
92
|
+
return {
|
|
93
|
+
color,
|
|
94
|
+
translateX: iconTranslateX,
|
|
95
|
+
translateY: translateY < 0 ? 0 : translateY,
|
|
96
|
+
size: iconSize
|
|
97
|
+
}
|
|
98
|
+
}
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
101
|
* Renders a pressable text link, with optional icon. This is rendered as a block element
|
package/src/utils/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export * from './children'
|
|
|
4
4
|
export * from './input'
|
|
5
5
|
export * from './pressability'
|
|
6
6
|
export * from './props'
|
|
7
|
-
|
|
7
|
+
export * from './ssr-media-query'
|
|
8
8
|
export { default as info } from './info'
|
|
9
9
|
export { default as useCopy } from './useCopy'
|
|
10
10
|
export { default as useHash } from './useHash'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import mediaQuery from 'css-mediaquery'
|
|
2
|
+
import { Dimensions, Platform } from 'react-native'
|
|
3
|
+
import { addCss } from './utils/inject'
|
|
4
|
+
import createDeclarationBlock from './utils/create-declaration-block'
|
|
5
|
+
import hash from './hash'
|
|
6
|
+
import { isMediaOrPseudo, isMedia, deepClone, createCssRule } from './utils/common'
|
|
7
|
+
|
|
8
|
+
const createStyleSheet = (stylesWithQuery) => {
|
|
9
|
+
if (!stylesWithQuery) return { ids: {}, styles: {}, fullStyles: {} }
|
|
10
|
+
let cleanStyles
|
|
11
|
+
let ids = {}
|
|
12
|
+
Object.keys(stylesWithQuery).forEach((key) => {
|
|
13
|
+
if (!stylesWithQuery?.[key]) return
|
|
14
|
+
|
|
15
|
+
const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(isMediaOrPseudo)
|
|
16
|
+
if (Platform.OS === 'web') {
|
|
17
|
+
cleanStyles = deepClone(stylesWithQuery)
|
|
18
|
+
mediaQueriesAndPseudoClasses.forEach((query) => {
|
|
19
|
+
const css = createDeclarationBlock(stylesWithQuery[key][query])
|
|
20
|
+
const stringHash = `rnmq-${hash(`${key}${query}${css}`)}`
|
|
21
|
+
const rule = createCssRule(query, stringHash, css)
|
|
22
|
+
|
|
23
|
+
addCss(`${stringHash}`, rule)
|
|
24
|
+
delete cleanStyles[key][query]
|
|
25
|
+
|
|
26
|
+
ids = {
|
|
27
|
+
...ids,
|
|
28
|
+
[key]: `${ids?.[key] ? `${ids[key]} ` : ''}${stringHash}`
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
} else {
|
|
32
|
+
cleanStyles = JSON.parse(JSON.stringify(stylesWithQuery))
|
|
33
|
+
mediaQueriesAndPseudoClasses.forEach((str) => {
|
|
34
|
+
if (isMedia(str)) {
|
|
35
|
+
const mqStr = str.replace('@media', '')
|
|
36
|
+
const { width, height } = Dimensions.get('window')
|
|
37
|
+
|
|
38
|
+
const isMatchingMediaQuery = mediaQuery.match(mqStr, {
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
orientation: width > height ? 'landscape' : 'portrait',
|
|
42
|
+
'aspect-ratio': width / height
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
if (isMatchingMediaQuery) {
|
|
46
|
+
cleanStyles = {
|
|
47
|
+
...cleanStyles,
|
|
48
|
+
[key]: { ...cleanStyles[key], ...stylesWithQuery[key][str] }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
delete cleanStyles[key][str]
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return { ids, styles: cleanStyles, fullStyles: stylesWithQuery }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default createStyleSheet
|