@telus-uds/components-web 2.25.1 → 2.27.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 +33 -3
- package/lib/Card/Card.js +46 -29
- package/lib/DatePicker/DatePicker.js +129 -69
- package/lib/OptimizeImage/OptimizeImage.js +1 -1
- package/lib/OptimizeImage/utils/getFallbackUrl.js +2 -2
- package/lib/baseExports.js +6 -0
- package/lib-module/Card/Card.js +49 -31
- package/lib-module/DatePicker/DatePicker.js +132 -72
- package/lib-module/OptimizeImage/OptimizeImage.js +1 -1
- package/lib-module/OptimizeImage/utils/getFallbackUrl.js +2 -2
- package/lib-module/baseExports.js +1 -1
- package/package.json +3 -3
- package/src/Card/Card.jsx +47 -29
- package/src/DatePicker/DatePicker.jsx +125 -63
- package/src/OptimizeImage/OptimizeImage.jsx +1 -1
- package/src/OptimizeImage/utils/getFallbackUrl.js +2 -2
- package/src/baseExports.js +1 -0
- package/types/MultiSelectFilter.d.ts +2 -1
- package/types/WebVideo.d.ts +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, useEffect, useState } from 'react'
|
|
1
|
+
import React, { forwardRef, useEffect, useState, useRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import styled from 'styled-components'
|
|
4
4
|
import momentPropTypes from 'react-moment-proptypes'
|
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
useViewport,
|
|
14
14
|
useThemeTokens,
|
|
15
15
|
applyTextStyles,
|
|
16
|
-
getTokensPropType
|
|
16
|
+
getTokensPropType,
|
|
17
|
+
Portal,
|
|
18
|
+
useSafeLayoutEffect
|
|
17
19
|
} from '@telus-uds/components-base'
|
|
18
20
|
import moment from 'moment'
|
|
19
|
-
import { isUndefined } from 'lodash'
|
|
21
|
+
import { isUndefined, throttle } from 'lodash'
|
|
20
22
|
import CalendarContainer from './CalendarContainer'
|
|
21
23
|
import dictionary from './dictionary'
|
|
22
24
|
import { htmlAttrs } from '../utils'
|
|
@@ -48,6 +50,12 @@ const DateInputWrapper = styled.div({
|
|
|
48
50
|
flexDirection: 'column'
|
|
49
51
|
})
|
|
50
52
|
|
|
53
|
+
const PortalPositionedContainer = styled.div({
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
left: ({ left }) => `${left}px`,
|
|
56
|
+
top: ({ top }) => `${top}px`
|
|
57
|
+
})
|
|
58
|
+
|
|
51
59
|
/**
|
|
52
60
|
* Use DatePicker to select a date on a calendar.
|
|
53
61
|
*
|
|
@@ -97,6 +105,23 @@ const DatePicker = forwardRef(
|
|
|
97
105
|
const [inputText, setInputText] = useState(
|
|
98
106
|
date instanceof moment ? date.format(dateFormat) : ''
|
|
99
107
|
)
|
|
108
|
+
const textInputRef = useRef()
|
|
109
|
+
const [datePickerPosition, setDatePickerPosition] = useState({ left: 0, top: 0 })
|
|
110
|
+
|
|
111
|
+
useSafeLayoutEffect(() => {
|
|
112
|
+
const updateDimensions = () => {
|
|
113
|
+
if (inline) return
|
|
114
|
+
const { left, top } = textInputRef.current.getBoundingClientRect()
|
|
115
|
+
setDatePickerPosition({
|
|
116
|
+
left,
|
|
117
|
+
top: top + textInputRef.current.offsetHeight
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
const throttledUpdateDimensions = throttle(updateDimensions, 100, { leading: false })
|
|
121
|
+
updateDimensions()
|
|
122
|
+
window.addEventListener('resize', throttledUpdateDimensions)
|
|
123
|
+
return () => window.removeEventListener('resize', throttledUpdateDimensions)
|
|
124
|
+
}, [])
|
|
100
125
|
|
|
101
126
|
const [isFocused, setIsFocused] = useState(false)
|
|
102
127
|
const [isClickedInside, setIsClickedInside] = useState(false)
|
|
@@ -204,19 +229,7 @@ const DatePicker = forwardRef(
|
|
|
204
229
|
/>
|
|
205
230
|
)
|
|
206
231
|
return (
|
|
207
|
-
|
|
208
|
-
{...selectProps(rest)}
|
|
209
|
-
daySize={daySize}
|
|
210
|
-
validation={validation}
|
|
211
|
-
remainingTokens={{
|
|
212
|
-
...remainingTokens
|
|
213
|
-
}}
|
|
214
|
-
calendarDayDefaultHeight={circleSize}
|
|
215
|
-
calendarDayDefaultWidth={circleSize}
|
|
216
|
-
calendarMonthFontTokens={calendarMonthFontTokens}
|
|
217
|
-
calendarWeekFontTokens={calendarWeekFontTokens}
|
|
218
|
-
defaultFontTokens={defaultFontTokens}
|
|
219
|
-
>
|
|
232
|
+
<>
|
|
220
233
|
{inline ? (
|
|
221
234
|
<>
|
|
222
235
|
<HiddenInputFieldContainer
|
|
@@ -225,65 +238,30 @@ const DatePicker = forwardRef(
|
|
|
225
238
|
>
|
|
226
239
|
<input ref={ref} id={id} type="text" value={inputText} readOnly />
|
|
227
240
|
</HiddenInputFieldContainer>
|
|
228
|
-
<
|
|
229
|
-
|
|
230
|
-
onDateChange={onChange}
|
|
231
|
-
focused={isFocused}
|
|
232
|
-
onFocusChange={onFocusChange}
|
|
233
|
-
numberOfMonths={1}
|
|
234
|
-
hideKeyboardShortcutsPanel={true}
|
|
235
|
-
keepOpenOnDateSelect={false}
|
|
241
|
+
<CalendarContainer
|
|
242
|
+
{...selectProps(rest)}
|
|
236
243
|
daySize={daySize}
|
|
237
|
-
renderNavPrevButton={renderPrevButton}
|
|
238
|
-
renderNavNextButton={renderNextButton}
|
|
239
|
-
isOutsideRange={isDayDisabled}
|
|
240
|
-
phrases={getCopy()}
|
|
241
|
-
renderMonthElement={({ month }) => (
|
|
242
|
-
<MonthCenterContainer>
|
|
243
|
-
<div>
|
|
244
|
-
{dictionary[copy]
|
|
245
|
-
? dictionary[copy].months[month.month()]
|
|
246
|
-
: month.format('MMMM')}{' '}
|
|
247
|
-
{month.year()}
|
|
248
|
-
</div>
|
|
249
|
-
</MonthCenterContainer>
|
|
250
|
-
)}
|
|
251
|
-
renderWeekHeaderElement={(day) => (
|
|
252
|
-
<div>{dictionary[copy] ? dictionary[copy].weekDays[day] : day}</div>
|
|
253
|
-
)}
|
|
254
|
-
/>
|
|
255
|
-
</>
|
|
256
|
-
) : (
|
|
257
|
-
<DateInputWrapper onMouseDown={handleMouseDown} onFocus={handleFocus}>
|
|
258
|
-
<TextInput
|
|
259
|
-
copy={copy}
|
|
260
|
-
feedback={feedback}
|
|
261
|
-
hint={hint}
|
|
262
|
-
placeholder="DD / MM / YYYY"
|
|
263
|
-
onChange={onChangeInput}
|
|
264
|
-
tooltip={tooltip}
|
|
265
|
-
hintPosition={hintPosition}
|
|
266
|
-
label={dictionary[copy]?.roleDescription ?? label}
|
|
267
|
-
value={inputText}
|
|
268
244
|
validation={validation}
|
|
269
|
-
|
|
245
|
+
remainingTokens={remainingTokens}
|
|
246
|
+
calendarDayDefaultHeight={circleSize}
|
|
247
|
+
calendarDayDefaultWidth={circleSize}
|
|
248
|
+
calendarMonthFontTokens={calendarMonthFontTokens}
|
|
249
|
+
calendarWeekFontTokens={calendarWeekFontTokens}
|
|
250
|
+
defaultFontTokens={defaultFontTokens}
|
|
270
251
|
>
|
|
271
|
-
<
|
|
252
|
+
<DayPickerSingleDateController
|
|
272
253
|
date={inputDate}
|
|
273
|
-
disabled={disabled}
|
|
274
254
|
onDateChange={onChange}
|
|
275
255
|
focused={isFocused}
|
|
276
256
|
onFocusChange={onFocusChange}
|
|
277
257
|
numberOfMonths={1}
|
|
278
258
|
hideKeyboardShortcutsPanel={true}
|
|
279
|
-
keepOpenOnDateSelect={
|
|
259
|
+
keepOpenOnDateSelect={false}
|
|
280
260
|
daySize={daySize}
|
|
281
|
-
ref={ref}
|
|
282
261
|
renderNavPrevButton={renderPrevButton}
|
|
262
|
+
renderNavNextButton={renderNextButton}
|
|
283
263
|
isOutsideRange={isDayDisabled}
|
|
284
264
|
phrases={getCopy()}
|
|
285
|
-
id={id}
|
|
286
|
-
renderNavNextButton={renderNextButton}
|
|
287
265
|
renderMonthElement={({ month }) => (
|
|
288
266
|
<MonthCenterContainer>
|
|
289
267
|
<div>
|
|
@@ -298,10 +276,94 @@ const DatePicker = forwardRef(
|
|
|
298
276
|
<div>{dictionary[copy] ? dictionary[copy].weekDays[day] : day}</div>
|
|
299
277
|
)}
|
|
300
278
|
/>
|
|
279
|
+
</CalendarContainer>
|
|
280
|
+
</>
|
|
281
|
+
) : (
|
|
282
|
+
<DateInputWrapper onMouseDown={handleMouseDown} onFocus={handleFocus}>
|
|
283
|
+
<TextInput
|
|
284
|
+
copy={copy}
|
|
285
|
+
feedback={feedback}
|
|
286
|
+
hint={hint}
|
|
287
|
+
placeholder="DD / MM / YYYY"
|
|
288
|
+
onChange={onChangeInput}
|
|
289
|
+
tooltip={tooltip}
|
|
290
|
+
hintPosition={hintPosition}
|
|
291
|
+
label={dictionary[copy]?.roleDescription ?? label}
|
|
292
|
+
value={inputText}
|
|
293
|
+
validation={validation}
|
|
294
|
+
inactive={disabled}
|
|
295
|
+
ref={textInputRef}
|
|
296
|
+
>
|
|
297
|
+
<Portal>
|
|
298
|
+
{/* Because `SingleDatePicker` is an absolutely positioned element,
|
|
299
|
+
* putting it in a `Portal` breaks view heirarchy because it doesn't
|
|
300
|
+
* align with `TextInput`, but rather position itself with the nearest
|
|
301
|
+
* positioned ancestor.
|
|
302
|
+
*
|
|
303
|
+
* This means that the `Portal` needs to be positioned absolutely,
|
|
304
|
+
* but the `SingleDatePicker` needs to be positioned relative to the
|
|
305
|
+
* `Portal`.
|
|
306
|
+
*
|
|
307
|
+
* This is accomplished by wrapping the `SingleDatePicker` in a
|
|
308
|
+
* `PortalPositionedContainer` which positions the `SingleDatePicker`
|
|
309
|
+
* relative to the `Portal`. This container is then positioned absolutely
|
|
310
|
+
* relative to the `TextInput`.
|
|
311
|
+
*
|
|
312
|
+
* TODO: Using `floating-ui` or something like that is a more preferred and streamlined way
|
|
313
|
+
* to position popovers and overlays.
|
|
314
|
+
*/}
|
|
315
|
+
<PortalPositionedContainer
|
|
316
|
+
top={datePickerPosition.top}
|
|
317
|
+
left={datePickerPosition.left}
|
|
318
|
+
>
|
|
319
|
+
<CalendarContainer
|
|
320
|
+
{...selectProps(rest)}
|
|
321
|
+
daySize={daySize}
|
|
322
|
+
validation={validation}
|
|
323
|
+
remainingTokens={remainingTokens}
|
|
324
|
+
calendarDayDefaultHeight={circleSize}
|
|
325
|
+
calendarDayDefaultWidth={circleSize}
|
|
326
|
+
calendarMonthFontTokens={calendarMonthFontTokens}
|
|
327
|
+
calendarWeekFontTokens={calendarWeekFontTokens}
|
|
328
|
+
defaultFontTokens={defaultFontTokens}
|
|
329
|
+
>
|
|
330
|
+
<SingleDatePicker
|
|
331
|
+
date={inputDate}
|
|
332
|
+
disabled={disabled}
|
|
333
|
+
onDateChange={onChange}
|
|
334
|
+
focused={isFocused}
|
|
335
|
+
onFocusChange={onFocusChange}
|
|
336
|
+
numberOfMonths={1}
|
|
337
|
+
hideKeyboardShortcutsPanel={true}
|
|
338
|
+
keepOpenOnDateSelect={true}
|
|
339
|
+
daySize={daySize}
|
|
340
|
+
ref={ref}
|
|
341
|
+
renderNavPrevButton={renderPrevButton}
|
|
342
|
+
isOutsideRange={isDayDisabled}
|
|
343
|
+
phrases={getCopy()}
|
|
344
|
+
id={id}
|
|
345
|
+
renderNavNextButton={renderNextButton}
|
|
346
|
+
renderMonthElement={({ month }) => (
|
|
347
|
+
<MonthCenterContainer>
|
|
348
|
+
<div>
|
|
349
|
+
{dictionary[copy]
|
|
350
|
+
? dictionary[copy].months[month.month()]
|
|
351
|
+
: month.format('MMMM')}{' '}
|
|
352
|
+
{month.year()}
|
|
353
|
+
</div>
|
|
354
|
+
</MonthCenterContainer>
|
|
355
|
+
)}
|
|
356
|
+
renderWeekHeaderElement={(day) => (
|
|
357
|
+
<div>{dictionary[copy] ? dictionary[copy].weekDays[day] : day}</div>
|
|
358
|
+
)}
|
|
359
|
+
/>
|
|
360
|
+
</CalendarContainer>
|
|
361
|
+
</PortalPositionedContainer>
|
|
362
|
+
</Portal>
|
|
301
363
|
</TextInput>
|
|
302
364
|
</DateInputWrapper>
|
|
303
365
|
)}
|
|
304
|
-
|
|
366
|
+
</>
|
|
305
367
|
)
|
|
306
368
|
}
|
|
307
369
|
)
|
|
@@ -69,7 +69,7 @@ const OptimizeImage = ({
|
|
|
69
69
|
disableRetina,
|
|
70
70
|
supportsWebp
|
|
71
71
|
),
|
|
72
|
-
fallbackSrc: getFallbackUrl(contentfulAssetUrl, xl, quality)
|
|
72
|
+
fallbackSrc: getFallbackUrl(contentfulAssetUrl, dimension, xl, quality)
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
}, [contentfulAssetUrl, dimension, disableRetina, lg, md, quality, sm, xl, xs])
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import isSvgUrl from './isSvgUrl'
|
|
2
2
|
|
|
3
|
-
export default function getFallbackUrl(url,
|
|
3
|
+
export default function getFallbackUrl(url, dimension, size, quality) {
|
|
4
4
|
if (!isSvgUrl(url)) {
|
|
5
|
-
return `${url}
|
|
5
|
+
return `${url}?${dimension}=${size}&q=${quality}`
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
return url
|
package/src/baseExports.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentType } from 'react'
|
|
2
|
+
import type { Tokens } from './common'
|
|
2
3
|
|
|
3
4
|
interface MultiSelectFilterItem {
|
|
4
5
|
label: string
|
|
@@ -10,7 +11,7 @@ export interface MultiSelectFilterProps {
|
|
|
10
11
|
subtitle?: string
|
|
11
12
|
id?: string
|
|
12
13
|
variant?: string
|
|
13
|
-
tokens?:
|
|
14
|
+
tokens?: Tokens
|
|
14
15
|
items: MultiSelectFilterItem[]
|
|
15
16
|
values?: string[]
|
|
16
17
|
initialValues?: string[]
|
package/types/WebVideo.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentType } from 'react'
|
|
2
|
+
import { YouTubeEvent } from 'react-youtube'
|
|
2
3
|
import type { HTMLAttrs } from './common'
|
|
3
4
|
|
|
4
5
|
export interface WebVideoProps extends HTMLAttrs {
|
|
@@ -10,9 +11,9 @@ export interface WebVideoProps extends HTMLAttrs {
|
|
|
10
11
|
videoLength: number
|
|
11
12
|
copy?: 'en' | 'fr'
|
|
12
13
|
onStart?: () => void
|
|
13
|
-
onPlay?: () => void
|
|
14
|
-
onEnd?: () => void
|
|
15
|
-
onPause?: () => void
|
|
14
|
+
onPlay?: (event: YouTubeEvent<number>) => void
|
|
15
|
+
onEnd?: (event: YouTubeEvent<number>) => void
|
|
16
|
+
onPause?: (event: YouTubeEvent<number>) => void
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
declare const WebVideo: ComponentType<WebVideoProps>
|