@telus-uds/components-base 1.74.0 → 1.76.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +26 -2
  2. package/lib/Carousel/CarouselThumbnail.js +10 -4
  3. package/lib/Carousel/CarouselThumbnailNavigation.js +3 -3
  4. package/lib/Footnote/Footnote.js +9 -13
  5. package/lib/Link/ChevronLink.js +2 -0
  6. package/lib/Link/InlinePressable.js +15 -2
  7. package/lib/Link/LinkBase.js +1 -0
  8. package/lib/Notification/Notification.js +213 -35
  9. package/lib/OrderedList/OrderedList.js +21 -20
  10. package/lib/PriceLockup/PriceLockup.js +220 -0
  11. package/lib/PriceLockup/index.js +10 -0
  12. package/lib/PriceLockup/utils/renderFootnoteContent.js +93 -0
  13. package/lib/PriceLockup/utils/renderFootnoteLinks.js +36 -0
  14. package/lib/PriceLockup/utils/renderPrice.js +147 -0
  15. package/lib/PriceLockup/utils/renderTypography.js +31 -0
  16. package/lib/index.js +8 -0
  17. package/lib/utils/ssr-media-query/create-stylesheet/index.js +1 -2
  18. package/lib-module/Carousel/CarouselThumbnail.js +10 -4
  19. package/lib-module/Carousel/CarouselThumbnailNavigation.js +3 -3
  20. package/lib-module/Footnote/Footnote.js +9 -13
  21. package/lib-module/Link/ChevronLink.js +2 -0
  22. package/lib-module/Link/InlinePressable.js +16 -2
  23. package/lib-module/Link/LinkBase.js +1 -0
  24. package/lib-module/Notification/Notification.js +216 -38
  25. package/lib-module/OrderedList/OrderedList.js +21 -20
  26. package/lib-module/PriceLockup/PriceLockup.js +214 -0
  27. package/lib-module/PriceLockup/index.js +2 -0
  28. package/lib-module/PriceLockup/utils/renderFootnoteContent.js +87 -0
  29. package/lib-module/PriceLockup/utils/renderFootnoteLinks.js +28 -0
  30. package/lib-module/PriceLockup/utils/renderPrice.js +141 -0
  31. package/lib-module/PriceLockup/utils/renderTypography.js +23 -0
  32. package/lib-module/index.js +1 -0
  33. package/lib-module/utils/ssr-media-query/create-stylesheet/index.js +1 -2
  34. package/package.json +2 -2
  35. package/src/Carousel/CarouselThumbnail.jsx +8 -6
  36. package/src/Carousel/CarouselThumbnailNavigation.jsx +3 -4
  37. package/src/Footnote/Footnote.jsx +3 -6
  38. package/src/Link/ChevronLink.jsx +5 -1
  39. package/src/Link/InlinePressable.jsx +36 -15
  40. package/src/Link/LinkBase.jsx +1 -0
  41. package/src/Notification/Notification.jsx +213 -34
  42. package/src/OrderedList/OrderedList.jsx +17 -20
  43. package/src/PriceLockup/PriceLockup.jsx +218 -0
  44. package/src/PriceLockup/index.js +3 -0
  45. package/src/PriceLockup/utils/renderFootnoteContent.jsx +77 -0
  46. package/src/PriceLockup/utils/renderFootnoteLinks.jsx +38 -0
  47. package/src/PriceLockup/utils/renderPrice.jsx +201 -0
  48. package/src/PriceLockup/utils/renderTypography.jsx +13 -0
  49. package/src/index.js +1 -0
  50. package/src/utils/ssr-media-query/create-stylesheet/index.js +3 -2
@@ -0,0 +1,201 @@
1
+ import React from 'react'
2
+ import { StyleSheet, View, Text, Platform } from 'react-native'
3
+ import A11yText from '../../A11yText'
4
+ import renderTypography from './renderTypography'
5
+ import renderFootnoteLinks from './renderFootnoteLinks'
6
+
7
+ const selectStrikeThroughStyles = ({ strikeThroughColor }) => ({
8
+ textDecorationColor: strikeThroughColor
9
+ })
10
+
11
+ const selectFootnoteLinksStyles = ({ bottomLinksMarginLeft }) => ({
12
+ marginLeft: bottomLinksMarginLeft
13
+ })
14
+
15
+ const renderCurrencySymbol = (
16
+ currencySymbol,
17
+ currencySymbolTypographyTokens,
18
+ ratePosition,
19
+ fontColor
20
+ ) => renderTypography(`${currencySymbol}`, currencySymbolTypographyTokens, ratePosition, fontColor)
21
+
22
+ const renderAmount = (
23
+ amount,
24
+ amountTypographyTokens,
25
+ strikeThrough,
26
+ a11yText,
27
+ fontColor,
28
+ themeTokens
29
+ ) => {
30
+ const amountText = renderTypography(amount, amountTypographyTokens, undefined, fontColor) // undefined is ratePosition
31
+ if (strikeThrough) {
32
+ return (
33
+ <>
34
+ <A11yText text={a11yText} />
35
+ <Text style={[staticStyles.strikeThroughContainer, selectStrikeThroughStyles(themeTokens)]}>
36
+ {amountText}
37
+ </Text>
38
+ </>
39
+ )
40
+ }
41
+
42
+ return amountText
43
+ }
44
+
45
+ const renderPrice = (
46
+ price,
47
+ rateText,
48
+ ratePosition,
49
+ signDirection,
50
+ currencySymbol,
51
+ currencySymbolTypographyTokens,
52
+ amountTypographyTokens,
53
+ centsTypographyTokens,
54
+ rateTypographyTokens,
55
+ fontColor,
56
+ strikeThrough,
57
+ a11yText,
58
+ bottomText,
59
+ bottomLinksMarginLeft,
60
+ footnoteLinks,
61
+ onClickFootnote,
62
+ themeTokens
63
+ ) => {
64
+ const priceString = price
65
+ const lastDotPosition = priceString.lastIndexOf('.')
66
+ const lastCommaPosition = priceString.lastIndexOf(',')
67
+ const [separator, separatorPosition] =
68
+ lastDotPosition > lastCommaPosition ? ['.', lastDotPosition] : [',', lastCommaPosition]
69
+
70
+ // If the separator is at the fourth character from the end of the string or more, it's most probably
71
+ // a part of the amount, and the cents are not included in the price string
72
+ const EXCLUDE_CENTS = 3
73
+ const hasCents =
74
+ separatorPosition !== -1 && separatorPosition >= priceString.length - EXCLUDE_CENTS
75
+ const amount = hasCents ? priceString.substring(0, separatorPosition) : priceString
76
+ const cents = hasCents ? priceString.substring(separatorPosition + 1) : null
77
+
78
+ const footnoteLinkPositionStyles = rateText
79
+ ? staticStyles.footnoteLinksWithoutBottomText
80
+ : staticStyles.footnoteLinksWithoutBottomTextAndRateText
81
+
82
+ const MAX_FOOTNOTE_LINKS_ALLOWED = 3
83
+ return (
84
+ <>
85
+ <View
86
+ style={
87
+ ratePosition === 'bottom'
88
+ ? staticStyles.priceContainerColumn
89
+ : staticStyles.priceContainerRow
90
+ }
91
+ >
92
+ <View style={staticStyles.priceContainer}>
93
+ {signDirection === 'left' ? (
94
+ <Text>
95
+ {renderCurrencySymbol(
96
+ currencySymbol,
97
+ currencySymbolTypographyTokens,
98
+ ratePosition,
99
+ fontColor
100
+ )}
101
+ </Text>
102
+ ) : null}
103
+ {renderAmount(
104
+ amount,
105
+ amountTypographyTokens,
106
+ strikeThrough,
107
+ a11yText,
108
+ fontColor,
109
+ themeTokens
110
+ )}
111
+ {cents
112
+ ? renderTypography(`${separator}${cents}`, centsTypographyTokens, undefined, fontColor)
113
+ : null}
114
+ {signDirection === 'right' ? (
115
+ <Text style={staticStyles.currencySymbol}>
116
+ {renderCurrencySymbol(
117
+ currencySymbol,
118
+ currencySymbolTypographyTokens,
119
+ ratePosition,
120
+ fontColor
121
+ )}
122
+ </Text>
123
+ ) : null}
124
+ </View>
125
+ {rateText ? (
126
+ <Text
127
+ style={
128
+ ratePosition === 'bottom'
129
+ ? staticStyles.rateTextVerticalPosition
130
+ : [staticStyles.rateTextPosition, staticStyles.rateTextVerticalPosition]
131
+ }
132
+ >
133
+ {renderTypography(rateText, rateTypographyTokens, ratePosition, fontColor)}
134
+ </Text>
135
+ ) : null}
136
+ {!bottomText && footnoteLinks.length <= MAX_FOOTNOTE_LINKS_ALLOWED ? (
137
+ <Text
138
+ style={[
139
+ footnoteLinkPositionStyles,
140
+ selectFootnoteLinksStyles({ bottomLinksMarginLeft })
141
+ ]}
142
+ >
143
+ {renderFootnoteLinks(footnoteLinks, themeTokens, onClickFootnote)}
144
+ </Text>
145
+ ) : null}
146
+ </View>
147
+ {!bottomText && footnoteLinks.length > MAX_FOOTNOTE_LINKS_ALLOWED ? (
148
+ <View style={staticStyles.verticalFootnoteLinkContainer}>
149
+ {renderFootnoteLinks(footnoteLinks, themeTokens, onClickFootnote)}
150
+ </View>
151
+ ) : null}
152
+ </>
153
+ )
154
+ }
155
+
156
+ export default renderPrice
157
+
158
+ const staticStyles = StyleSheet.create({
159
+ priceContainerRow: {
160
+ flexDirection: 'row'
161
+ },
162
+ priceContainerColumn: {
163
+ flexDirection: 'column'
164
+ },
165
+ priceContainer: {
166
+ flexDirection: 'row',
167
+ alignSelf: 'flex-start',
168
+ marginTop: 4
169
+ },
170
+ currencySymbol: {
171
+ paddingLeft: 4
172
+ },
173
+ verticalFootnoteLinkContainer: {
174
+ ...Platform.select({
175
+ ios: { top: 10 },
176
+ android: { top: -2 }
177
+ })
178
+ },
179
+ footnoteLinksWithoutBottomText: {
180
+ ...Platform.select({
181
+ ios: { alignSelf: 'flex-end', top: -10 },
182
+ android: { alignSelf: 'center', top: -14 }
183
+ })
184
+ },
185
+ footnoteLinksWithoutBottomTextAndRateText: {
186
+ ...Platform.select({
187
+ ios: { alignSelf: 'center' },
188
+ android: { alignSelf: 'flex-start' }
189
+ })
190
+ },
191
+ strikeThroughContainer: {
192
+ textDecorationLine: 'line-through',
193
+ textDecorationThickness: '1px'
194
+ },
195
+ rateTextPosition: {
196
+ alignSelf: 'flex-end'
197
+ },
198
+ rateTextVerticalPosition: {
199
+ top: -8
200
+ }
201
+ })
@@ -0,0 +1,13 @@
1
+ import React from 'react'
2
+ import Typography from '../../Typography'
3
+
4
+ const renderTypography = (value, themeTokens, ratePosition, fontColor) => {
5
+ const customProps =
6
+ ratePosition === 'bottom'
7
+ ? { variant: { size: 'micro' }, tokens: { color: fontColor } }
8
+ : { tokens: { ...themeTokens, color: fontColor } }
9
+
10
+ return <Typography {...customProps}>{value}</Typography>
11
+ }
12
+
13
+ export default renderTypography
package/src/index.js CHANGED
@@ -32,6 +32,7 @@ export { default as MultiSelectFilter } from './MultiSelectFilter'
32
32
  export { default as Notification } from './Notification'
33
33
  export { default as OrderedList } from './OrderedList'
34
34
  export { default as Pagination } from './Pagination'
35
+ export { default as PriceLockup } from './PriceLockup'
35
36
  export { default as Progress } from './Progress'
36
37
  export { default as QuickLinks } from './QuickLinks'
37
38
  export { default as QuickLinksFeature } from './QuickLinksFeature'
@@ -5,13 +5,14 @@ import { isMediaOrPseudo, deepClone, createCssRule } from '../utils/common'
5
5
 
6
6
  const createStyleSheet = (stylesWithQuery) => {
7
7
  if (!stylesWithQuery) return { ids: {}, styles: {}, fullStyles: {} }
8
- let cleanStyles
8
+
9
9
  let ids = {}
10
+ const cleanStyles = deepClone(stylesWithQuery)
11
+
10
12
  Object.keys(stylesWithQuery).forEach((key) => {
11
13
  if (!stylesWithQuery?.[key]) return
12
14
 
13
15
  const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(isMediaOrPseudo)
14
- cleanStyles = deepClone(stylesWithQuery)
15
16
  mediaQueriesAndPseudoClasses.forEach((query) => {
16
17
  const css = createDeclarationBlock(stylesWithQuery[key][query])
17
18
  const stringHash = `rnmq-${hash(`${key}${query}${css}`)}`