@telus-uds/components-web 1.3.0 → 1.5.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 (128) hide show
  1. package/CHANGELOG.md +32 -2
  2. package/lib/Breadcrumbs/Breadcrumbs.js +247 -0
  3. package/lib/Breadcrumbs/Item/Item.js +165 -0
  4. package/lib/Breadcrumbs/index.js +15 -0
  5. package/lib/Callout/Callout.js +121 -0
  6. package/lib/Callout/index.js +13 -0
  7. package/lib/DatePicker/CalendarContainer.js +221 -0
  8. package/lib/DatePicker/DatePicker.js +329 -0
  9. package/lib/DatePicker/dictionary.js +134 -0
  10. package/lib/DatePicker/index.js +13 -0
  11. package/lib/DatePicker/reactDatesCss.js +12 -0
  12. package/lib/ExpandCollapseMini/ExpandCollapseMini.js +75 -0
  13. package/lib/ExpandCollapseMini/ExpandCollapseMiniControl.js +95 -0
  14. package/lib/ExpandCollapseMini/index.js +13 -0
  15. package/lib/Footnote/Footnote.js +571 -0
  16. package/lib/Footnote/FootnoteLink.js +149 -0
  17. package/lib/Footnote/dictionary.js +19 -0
  18. package/lib/Footnote/index.js +16 -0
  19. package/lib/Paragraph/Paragraph.js +107 -0
  20. package/lib/Paragraph/index.js +13 -0
  21. package/lib/PreviewCard/AuthorDate.js +64 -0
  22. package/lib/PreviewCard/PreviewCard.js +236 -0
  23. package/lib/PreviewCard/index.js +13 -0
  24. package/lib/PriceLockup/PriceLockup.js +237 -0
  25. package/lib/PriceLockup/index.js +13 -0
  26. package/lib/PriceLockup/tokens.js +131 -0
  27. package/lib/ResponsiveImage/ResponsiveImage.js +115 -0
  28. package/lib/ResponsiveImage/index.js +13 -0
  29. package/lib/Ribbon/Ribbon.js +0 -1
  30. package/lib/Span/Span.js +88 -0
  31. package/lib/Span/index.js +13 -0
  32. package/lib/index.js +91 -1
  33. package/lib/shared/FullBleedContent/FullBleedContent.js +121 -0
  34. package/lib/shared/FullBleedContent/getFullBleedBorderRadius.js +73 -0
  35. package/lib/shared/FullBleedContent/index.js +29 -0
  36. package/lib/shared/FullBleedContent/useFullBleedContentProps.js +73 -0
  37. package/lib/utils/index.js +32 -0
  38. package/lib/utils/logger.js +31 -0
  39. package/lib/utils/media.js +54 -0
  40. package/lib/utils/renderStructuredContent.js +89 -0
  41. package/lib/utils/useTypographyTheme.js +32 -0
  42. package/lib-module/Breadcrumbs/Breadcrumbs.js +228 -0
  43. package/lib-module/Breadcrumbs/Item/Item.js +141 -0
  44. package/lib-module/Breadcrumbs/index.js +1 -0
  45. package/lib-module/Callout/Callout.js +106 -0
  46. package/lib-module/Callout/index.js +2 -0
  47. package/lib-module/DatePicker/CalendarContainer.js +208 -0
  48. package/lib-module/DatePicker/DatePicker.js +302 -0
  49. package/lib-module/DatePicker/dictionary.js +127 -0
  50. package/lib-module/DatePicker/index.js +2 -0
  51. package/lib-module/DatePicker/reactDatesCss.js +3 -0
  52. package/lib-module/ExpandCollapseMini/ExpandCollapseMini.js +56 -0
  53. package/lib-module/ExpandCollapseMini/ExpandCollapseMiniControl.js +80 -0
  54. package/lib-module/ExpandCollapseMini/index.js +2 -0
  55. package/lib-module/Footnote/Footnote.js +541 -0
  56. package/lib-module/Footnote/FootnoteLink.js +130 -0
  57. package/lib-module/Footnote/dictionary.js +12 -0
  58. package/lib-module/Footnote/index.js +4 -0
  59. package/lib-module/Paragraph/Paragraph.js +89 -0
  60. package/lib-module/Paragraph/index.js +2 -0
  61. package/lib-module/PreviewCard/AuthorDate.js +53 -0
  62. package/lib-module/PreviewCard/PreviewCard.js +211 -0
  63. package/lib-module/PreviewCard/index.js +2 -0
  64. package/lib-module/PriceLockup/PriceLockup.js +213 -0
  65. package/lib-module/PriceLockup/index.js +2 -0
  66. package/lib-module/PriceLockup/tokens.js +120 -0
  67. package/lib-module/ResponsiveImage/ResponsiveImage.js +100 -0
  68. package/lib-module/ResponsiveImage/index.js +2 -0
  69. package/lib-module/Ribbon/Ribbon.js +1 -2
  70. package/lib-module/Span/Span.js +70 -0
  71. package/lib-module/Span/index.js +2 -0
  72. package/lib-module/index.js +10 -0
  73. package/lib-module/shared/FullBleedContent/FullBleedContent.js +106 -0
  74. package/lib-module/shared/FullBleedContent/getFullBleedBorderRadius.js +65 -0
  75. package/lib-module/shared/FullBleedContent/index.js +4 -0
  76. package/lib-module/shared/FullBleedContent/useFullBleedContentProps.js +65 -0
  77. package/lib-module/utils/index.js +5 -1
  78. package/lib-module/utils/logger.js +18 -0
  79. package/lib-module/utils/media.js +46 -0
  80. package/lib-module/utils/renderStructuredContent.js +77 -0
  81. package/lib-module/utils/useTypographyTheme.js +24 -0
  82. package/package.json +9 -5
  83. package/src/Breadcrumbs/Breadcrumbs.jsx +222 -0
  84. package/src/Breadcrumbs/Item/Item.jsx +127 -0
  85. package/src/Breadcrumbs/index.js +1 -0
  86. package/src/Callout/Callout.jsx +76 -0
  87. package/src/Callout/index.js +3 -0
  88. package/src/DatePicker/CalendarContainer.jsx +210 -0
  89. package/src/DatePicker/DatePicker.jsx +303 -0
  90. package/src/DatePicker/dictionary.js +92 -0
  91. package/src/DatePicker/index.js +3 -0
  92. package/src/DatePicker/reactDatesCss.js +892 -0
  93. package/src/ExpandCollapseMini/ExpandCollapseMini.jsx +48 -0
  94. package/src/ExpandCollapseMini/ExpandCollapseMiniControl.jsx +67 -0
  95. package/src/ExpandCollapseMini/index.js +3 -0
  96. package/src/Footnote/Footnote.jsx +468 -0
  97. package/src/Footnote/FootnoteLink.jsx +120 -0
  98. package/src/Footnote/dictionary.js +12 -0
  99. package/src/Footnote/index.js +6 -0
  100. package/src/Paragraph/Paragraph.jsx +79 -0
  101. package/src/Paragraph/index.js +3 -0
  102. package/src/PreviewCard/AuthorDate.jsx +31 -0
  103. package/src/PreviewCard/PreviewCard.jsx +201 -0
  104. package/src/PreviewCard/index.js +3 -0
  105. package/src/PriceLockup/PriceLockup.jsx +210 -0
  106. package/src/PriceLockup/index.js +3 -0
  107. package/src/PriceLockup/tokens.js +58 -0
  108. package/src/ResponsiveImage/ResponsiveImage.jsx +77 -0
  109. package/src/ResponsiveImage/index.js +3 -0
  110. package/src/Ribbon/Ribbon.jsx +0 -1
  111. package/src/Span/Span.jsx +66 -0
  112. package/src/Span/index.js +3 -0
  113. package/src/index.js +10 -0
  114. package/src/shared/FullBleedContent/FullBleedContent.jsx +90 -0
  115. package/src/shared/FullBleedContent/getFullBleedBorderRadius.js +55 -0
  116. package/src/shared/FullBleedContent/index.js +6 -0
  117. package/src/shared/FullBleedContent/useFullBleedContentProps.js +63 -0
  118. package/src/utils/index.js +5 -1
  119. package/src/utils/logger.js +20 -0
  120. package/src/utils/media.js +40 -0
  121. package/src/utils/renderStructuredContent.jsx +73 -0
  122. package/src/utils/useTypographyTheme.js +14 -0
  123. package/types/Callout.d.ts +13 -0
  124. package/types/DatePicker.d.ts +21 -0
  125. package/types/Footnote.d.ts +21 -0
  126. package/types/FootnoteLink.d.ts +20 -0
  127. package/types/PriceLockup.d.ts +22 -0
  128. package/types/common.d.ts +14 -0
@@ -0,0 +1,303 @@
1
+ import React, { forwardRef, useState } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import styled from 'styled-components'
4
+ import momentPropTypes from 'react-moment-proptypes'
5
+ import 'react-dates/initialize'
6
+ import SingleDatePicker from 'react-dates/lib/components/SingleDatePicker'
7
+ import DayPickerSingleDateController from 'react-dates/lib/components/DayPickerSingleDateController'
8
+ import {
9
+ Icon,
10
+ InputSupports,
11
+ selectSystemProps,
12
+ useCopy,
13
+ useViewport,
14
+ useThemeTokens,
15
+ applyTextStyles
16
+ } from '@telus-uds/components-base'
17
+ import CalendarContainer from './CalendarContainer'
18
+ import dictionary from './dictionary'
19
+ import { htmlAttrs } from '../utils'
20
+
21
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs])
22
+
23
+ const getResponsiveDaySize = (inline = false, viewport = 'md') => {
24
+ let responsiveDaySize
25
+ if (viewport === 'xs') {
26
+ responsiveDaySize = inline ? undefined : 36
27
+ } else {
28
+ responsiveDaySize = inline ? 60 : 44
29
+ }
30
+
31
+ return responsiveDaySize
32
+ }
33
+
34
+ const getIcon = (icon) => <Icon icon={icon} variant={{ size: 'small' }} />
35
+
36
+ const MonthCenterContainer = styled.div({
37
+ display: 'flex',
38
+ justifyContent: 'center'
39
+ })
40
+
41
+ /**
42
+ * Use DatePicker to select a date on a calendar.
43
+ *
44
+ * ## Usage Criteria
45
+ *
46
+ * - Use DatePicker to select a date on a calendar
47
+ * - Available in 2 formats: Overlay and Inline
48
+ *
49
+ * ### Overlay DatePicker
50
+ * - Use Overlay to display in a modal container
51
+ * - Use Overlay whenever possible as it is the most accessible solution; the input form field is type-accessible and optimized for mobile customers
52
+ * - Includes an input form field to allow manual key-in of dates
53
+ * - Opens the modal when the input form field receives focus
54
+ * - Width expands 100% until max-width of 340px
55
+ *
56
+ * ### Inline DatePicker
57
+ * - Use Inline to display the DatePicker in a larger vieweable area; allows the customer to quickly and easily date availability
58
+ * - Does not include an input form field
59
+ * - Optimized for keyboard interaction and tablet touch
60
+ * - Recommended for viewports greater than or equal to 576px
61
+ */
62
+ const DatePicker = forwardRef(
63
+ (
64
+ {
65
+ copy = 'en',
66
+ id,
67
+ date,
68
+ feedback,
69
+ inline,
70
+ isDayDisabled,
71
+ label,
72
+ onDateChange,
73
+ hint,
74
+ hintPosition = 'inline',
75
+ tooltip,
76
+ tokens,
77
+ variant = {},
78
+ validation,
79
+ ...rest
80
+ },
81
+ ref
82
+ ) => {
83
+ const [inputDate, setInputDate] = useState(date)
84
+ const [isFocused, setIsFocused] = useState(false)
85
+ const getCopy = useCopy({ dictionary, copy })
86
+ const onFocusChange = ({ focused }) => {
87
+ setIsFocused(focused)
88
+ }
89
+ const onChange = (value) => {
90
+ setInputDate(value)
91
+ if (onDateChange) onDateChange(value)
92
+ }
93
+ const viewport = useViewport()
94
+ const daySize = getResponsiveDaySize(inline, viewport)
95
+
96
+ const value = date ?? inputDate
97
+
98
+ const HiddenInputFieldContainer = styled.div`
99
+ height: ${(props) => props.height};
100
+ width: ${(props) => props.width};
101
+ overflow: hidden;
102
+ `
103
+
104
+ const {
105
+ hiddenInputFieldContainerHeight,
106
+ hiddenInputFieldContainerWidth,
107
+ previousIcon,
108
+ nextIcon,
109
+ ...remainingTokens
110
+ } = useThemeTokens('DatePicker', tokens, variant, {
111
+ viewport
112
+ })
113
+
114
+ const defaultFontTokens = applyTextStyles({
115
+ fontName: remainingTokens.calendarDayDefaultFontName,
116
+ fontWeight: remainingTokens.calendarDayDefaultFontWeight
117
+ })
118
+
119
+ const calendarMonthFontTokens = applyTextStyles({
120
+ fontName: remainingTokens.calendarMonthCaptionFontName,
121
+ fontWeight: remainingTokens.calendarMonthCaptionFontWeight
122
+ })
123
+
124
+ const dayPickerNavigationButtonTokens = applyTextStyles({
125
+ fontName: remainingTokens.dayPickerWeekHeaderFontName,
126
+ fontWeight: remainingTokens.dayPickerWeekHeaderFontWeight
127
+ })
128
+
129
+ return (
130
+ <CalendarContainer
131
+ {...selectProps(rest)}
132
+ daySize={daySize}
133
+ validation={validation}
134
+ remainingTokens={remainingTokens}
135
+ calendarMonthFontTokens={calendarMonthFontTokens}
136
+ dayPickerNavigationButtonTokens={dayPickerNavigationButtonTokens}
137
+ defaultFontTokens={defaultFontTokens}
138
+ >
139
+ <InputSupports
140
+ copy={copy}
141
+ feedback={feedback}
142
+ hint={hint}
143
+ hintPosition={hintPosition}
144
+ label={dictionary[copy]?.roleDescription ?? label}
145
+ nativeID={id}
146
+ tooltip={tooltip}
147
+ validation={validation}
148
+ >
149
+ {inline ? (
150
+ <>
151
+ <HiddenInputFieldContainer
152
+ height={hiddenInputFieldContainerHeight}
153
+ width={hiddenInputFieldContainerWidth}
154
+ >
155
+ <input
156
+ ref={ref}
157
+ id={id}
158
+ type="text"
159
+ value={value?.format('YYYY-MM-DD') ?? ''}
160
+ readOnly
161
+ />
162
+ </HiddenInputFieldContainer>
163
+ <DayPickerSingleDateController
164
+ date={value}
165
+ onDateChange={onChange}
166
+ focused={isFocused}
167
+ onFocusChange={onFocusChange}
168
+ numberOfMonths={1}
169
+ hideKeyboardShortcutsPanel={true}
170
+ keepOpenOnDateSelect={false}
171
+ daySize={daySize}
172
+ navPrev={getIcon(previousIcon)}
173
+ navNext={getIcon(nextIcon)}
174
+ isOutsideRange={isDayDisabled}
175
+ phrases={getCopy()}
176
+ renderMonthElement={({ month }) => (
177
+ <MonthCenterContainer>
178
+ <div>
179
+ {dictionary[copy]
180
+ ? dictionary[copy].months[month.month()]
181
+ : month.format('MMMM')}{' '}
182
+ {month.year()}
183
+ </div>
184
+ </MonthCenterContainer>
185
+ )}
186
+ renderWeekHeaderElement={(day) => (
187
+ <div>{dictionary[copy] ? dictionary[copy].weekDays[day] : day}</div>
188
+ )}
189
+ />
190
+ </>
191
+ ) : (
192
+ <SingleDatePicker
193
+ ref={ref}
194
+ id={id}
195
+ date={value}
196
+ onDateChange={onChange}
197
+ focused={isFocused}
198
+ onFocusChange={onFocusChange}
199
+ numberOfMonths={1}
200
+ hideKeyboardShortcutsPanel={true}
201
+ displayFormat="DD / MM / YYYY"
202
+ placeholder="DD / MM / YYYY"
203
+ keepOpenOnDateSelect={false}
204
+ daySize={daySize}
205
+ navPrev={getIcon(previousIcon)}
206
+ navNext={getIcon(nextIcon)}
207
+ isOutsideRange={isDayDisabled}
208
+ phrases={getCopy()}
209
+ renderMonthElement={({ month }) => (
210
+ <MonthCenterContainer>
211
+ <div>
212
+ {dictionary[copy]
213
+ ? dictionary[copy].months[month.month()]
214
+ : month.format('MMMM')}{' '}
215
+ {month.year()}
216
+ </div>
217
+ </MonthCenterContainer>
218
+ )}
219
+ renderWeekHeaderElement={(day) => (
220
+ <div>{dictionary[copy] ? dictionary[copy].weekDays[day] : day}</div>
221
+ )}
222
+ />
223
+ )}
224
+ </InputSupports>
225
+ </CalendarContainer>
226
+ )
227
+ }
228
+ )
229
+
230
+ DatePicker.displayName = 'DatePicker'
231
+
232
+ DatePicker.propTypes = {
233
+ ...selectedSystemPropTypes,
234
+ /**
235
+ * A unique identifier.
236
+ */
237
+ id: PropTypes.string.isRequired,
238
+ /**
239
+ * Whether the English or French copy will be used (e.g. for accessibility labels).
240
+ */
241
+ copy: PropTypes.oneOf(['en', 'fr']),
242
+ /**
243
+ * A Moment instance representing the currently selected date, i.e. `moment()`
244
+ */
245
+ date: momentPropTypes.momentObj,
246
+ /**
247
+ * A detailed description of validation error/success or additional instructions.
248
+ * Visual variant is determined based on the `validation` prop.
249
+ */
250
+ feedback: PropTypes.string,
251
+ /**
252
+ * Event triggered every time a new date is clicked on
253
+ * @param {Moment} date The new date that was selected
254
+ */
255
+ onDateChange: PropTypes.func,
256
+ /**
257
+ * A function determining whether a given date should be disabled
258
+ * @param {Moment} date The date to optionally disable
259
+ * @returns {bool}
260
+ */
261
+ isDayDisabled: PropTypes.func,
262
+ /**
263
+ * The field label to be displayed above the calendar
264
+ */
265
+ label: PropTypes.string,
266
+ /**
267
+ * A flag determining if the calendar picker is standalone or an input with overlay
268
+ */
269
+ inline: PropTypes.bool,
270
+ /**
271
+ * A short description of the expected input.
272
+ */
273
+ hint: PropTypes.string,
274
+ /**
275
+ * Position of the hint relative to label. Use `below` to display a larger hint below the label.
276
+ */
277
+ hintPosition: PropTypes.oneOf(['inline', 'below']),
278
+
279
+ /**
280
+ * Content of an optional `Tooltip`. If set, a tooltip button will be shown next to the label.
281
+ */
282
+ tooltip: PropTypes.string,
283
+ /**
284
+ * Use to visually mark an input as valid or invalid.
285
+ */
286
+ validation: PropTypes.oneOf(['error', 'success'])
287
+ }
288
+
289
+ DatePicker.defaultProps = {
290
+ copy: 'en',
291
+ date: undefined,
292
+ feedback: undefined,
293
+ inline: false,
294
+ isDayDisabled: undefined,
295
+ label: undefined,
296
+ hint: undefined,
297
+ hintPosition: 'inline',
298
+ tooltip: undefined,
299
+ onDateChange: () => {},
300
+ validation: undefined
301
+ }
302
+
303
+ export default DatePicker
@@ -0,0 +1,92 @@
1
+ // from https://github.com/airbnb/react-dates/blob/master/src/defaultPhrases.js
2
+ const calendarLabel = 'Calendrier'
3
+ const roleDescription = 'Sélecteur de date'
4
+ const closeDatePicker = 'Fermer '
5
+ const clearDate = 'Supprimer la date'
6
+ const jumpToPrevMonth = 'Reculer pour passer au mois précédent.'
7
+ const jumpToNextMonth = 'Avancer pour passer au mois suivant.'
8
+ const keyboardShortcuts = 'Raccourcis clavier '
9
+ const showKeyboardShortcutsPanel = 'Ouvrir le panneau de raccourcis clavier.'
10
+ const hideKeyboardShortcutsPanel = 'Fermez le panneau de raccourcis.'
11
+ const openThisPanel = 'Ouvrir le panneau. '
12
+ const enterKey = 'Touche Entrée '
13
+ const leftArrowRightArrow = 'Touches de direction droite et gauche'
14
+ const upArrowDownArrow = 'Touches de direction haut et bas'
15
+ const pageUpPageDown = 'Touches Page précédente et Page suivante'
16
+ const homeEnd = 'Touches Accueil et Fin'
17
+ const escape = 'Touche Échap.'
18
+ const questionMark = `Point d'interrogation`
19
+ const selectFocusedDate = 'Sélectionner la date mise au point.'
20
+ const moveFocusByOneDay = `Reculer (à gauche) et avancer (à droite) d'un jour.`
21
+ const moveFocusByOneWeek = `Reculer (vers le haut) et avancer (vers le bas) d'une semaine.`
22
+ const moveFocusByOneMonth = 'Changer de mois.'
23
+ const moveFocustoStartAndEndOfWeek = 'Aller au premier ou au dernier jour de la semaine.'
24
+ const returnFocusToInput = 'Revenir au champ de saisie de la date.'
25
+ const keyboardForwardNavigationInstructions = `Naviguer vers l'avant pour interagir avec le calendrier et sélectionner une date. Appuyer sur la touche Point d'interrogation pour obtenir les raccourcis clavier permettant de modifier les dates.`
26
+ const keyboardBackwardNavigationInstructions = `Naviguer en arrière pour interagir avec le calendrier et sélectionner une date. Appuyer sur la touche Point d'interrogation pour obtenir les raccourcis clavier permettant de modifier les dates.`
27
+ const months = [
28
+ 'Janvier',
29
+ 'Février',
30
+ 'Mars',
31
+ 'Avril',
32
+ 'Mai',
33
+ 'Juin',
34
+ 'Julliet',
35
+ 'Août',
36
+ 'Septembre',
37
+ 'Octobre',
38
+ 'Novembre',
39
+ 'Décembre'
40
+ ]
41
+ const weekDays = { Su: 'Dim', Mo: 'Lun', Tu: 'Mar', We: 'Mer', Th: 'Jeu', Fr: 'Ven', Sa: 'Sam' }
42
+
43
+ const chooseAvailableStartDate = ({ date }) => `Choisir ${date}. Disponible.`
44
+ const chooseAvailableEndDate = ({ date }) => `Non disponible. ${date}`
45
+ const chooseAvailableDate = ({ date }) => date
46
+ const dateIsUnavailable = ({ date }) => `Not available. ${date}`
47
+ const dateIsSelected = ({ date }) => `Choisie. ${date}`
48
+ const dateIsSelectedAsStartDate = ({ date }) => `Choisie comme date de début. ${date}`
49
+ const dateIsSelectedAsEndDate = ({ date }) => `Choisie comme date de fin. ${date}`
50
+
51
+ const dictionary = {
52
+ en: undefined, // uses react-dates defaults
53
+ fr: {
54
+ calendarLabel,
55
+ roleDescription,
56
+ jumpToPrevMonth,
57
+ jumpToNextMonth,
58
+ keyboardShortcuts,
59
+ showKeyboardShortcutsPanel,
60
+ hideKeyboardShortcutsPanel,
61
+ openThisPanel,
62
+ enterKey,
63
+ leftArrowRightArrow,
64
+ upArrowDownArrow,
65
+ pageUpPageDown,
66
+ homeEnd,
67
+ escape,
68
+ questionMark,
69
+ selectFocusedDate,
70
+ moveFocusByOneDay,
71
+ moveFocusByOneWeek,
72
+ moveFocusByOneMonth,
73
+ moveFocustoStartAndEndOfWeek,
74
+ returnFocusToInput,
75
+ months,
76
+ weekDays,
77
+ chooseAvailableStartDate,
78
+ chooseAvailableEndDate,
79
+ chooseAvailableDate,
80
+ dateIsUnavailable,
81
+ dateIsSelected,
82
+ dateIsSelectedAsStartDate,
83
+ dateIsSelectedAsEndDate,
84
+
85
+ closeDatePicker,
86
+ clearDate,
87
+ keyboardForwardNavigationInstructions,
88
+ keyboardBackwardNavigationInstructions
89
+ }
90
+ }
91
+
92
+ export default dictionary
@@ -0,0 +1,3 @@
1
+ import DatePicker from './DatePicker'
2
+
3
+ export default DatePicker