@telus-uds/components-web 2.32.1 → 2.32.2

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 CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @telus-uds/components-web
2
2
 
3
- This log was last generated on Tue, 19 Mar 2024 18:37:02 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 27 Mar 2024 21:09:55 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 2.32.2
8
+
9
+ Wed, 27 Mar 2024 21:09:55 GMT
10
+
11
+ ### Patches
12
+
13
+ - validation added to the datepicker input and input cleaned after the content is deleted (35577399+JoshHC@users.noreply.github.com)
14
+ - Bump @telus-uds/components-base to v1.81.0
15
+
7
16
  ## 2.32.1
8
17
 
9
- Tue, 19 Mar 2024 18:37:02 GMT
18
+ Tue, 19 Mar 2024 18:39:50 GMT
10
19
 
11
20
  ### Patches
12
21
 
@@ -11,7 +11,7 @@ var _componentsBase = require("@telus-uds/components-base");
11
11
  var _utils = require("../utils");
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- const [, selectedSystemPropTypes] = (0, _componentsBase.selectSystemProps)([_utils.htmlAttrs]);
14
+ const [selectProps, selectedSystemPropTypes] = (0, _componentsBase.selectSystemProps)([_utils.htmlAttrs]);
15
15
  const BadgeContainer = /*#__PURE__*/_styledComponents.default.div.withConfig({
16
16
  displayName: "Badge__BadgeContainer",
17
17
  componentId: "components-web__sc-tsiuo2-0"
@@ -48,6 +48,11 @@ const BadgeContainer = /*#__PURE__*/_styledComponents.default.div.withConfig({
48
48
  ${gradient && '-webkit-text-fill-color: transparent;'}
49
49
  }`;
50
50
  });
51
+ const fontSizeMapping = {
52
+ 12: 'micro',
53
+ 14: 'small',
54
+ 16: 'h6'
55
+ };
51
56
  const Badge = _ref6 => {
52
57
  let {
53
58
  children,
@@ -61,10 +66,14 @@ const Badge = _ref6 => {
61
66
  borderColor,
62
67
  borderRadius,
63
68
  borderWidth,
69
+ color,
64
70
  paddingLeft,
65
71
  paddingRight,
66
72
  paddingTop,
67
- paddingBottom
73
+ paddingBottom,
74
+ fontName,
75
+ fontWeight,
76
+ fontSize
68
77
  } = (0, _componentsBase.useThemeTokens)('Badge', tokens, variant);
69
78
  const semanticGradient = gradient && (0, _utils.transformGradient)(gradient);
70
79
  const {
@@ -85,12 +94,20 @@ const Badge = _ref6 => {
85
94
  padding: `${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`,
86
95
  radius: `${borderRadius}px`,
87
96
  background: background,
97
+ fontName: fontName,
98
+ fontWeight: fontWeight,
88
99
  gradient: semanticGradient,
89
100
  border: `${borderWidth}px solid ${borderColor}`,
90
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Badge, {
91
- tokens: tokens,
92
- variant: variant,
93
- ...rest,
101
+ ...selectProps(rest),
102
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
103
+ tokens: {
104
+ fontName,
105
+ fontWeight,
106
+ color
107
+ },
108
+ variant: {
109
+ size: fontSizeMapping[fontSize]
110
+ },
94
111
  children: children
95
112
  })
96
113
  });
@@ -72,6 +72,7 @@ const PortalPositionedContainer = /*#__PURE__*/_styledComponents.default.div.wit
72
72
  return `${top}px`;
73
73
  }
74
74
  });
75
+ const validDatePattern = /^([0-2][0-9]|3[0-1])(\/)(0[1-9]|1[0-2])\2(\d{4})$/;
75
76
 
76
77
  /**
77
78
  * Use DatePicker to select a date on a calendar.
@@ -193,14 +194,34 @@ const DatePicker = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
193
194
  if (onDateChange) onDateChange(value);
194
195
  };
195
196
  const onChangeInput = value => {
196
- if ((0, _moment.default)(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()) {
197
- setInputDate((0, _moment.default)(value, dateFormat));
198
- if (onDateChange) onDateChange((0, _moment.default)(value, dateFormat));
199
- setInputText((0, _moment.default)(value, dateFormatWithoutSpaces).format(dateFormat));
197
+ if (value === '' || (0, _moment.default)(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()) {
198
+ if (value === '') {
199
+ setInputDate(undefined); // Set inputDate to undefined if input is empty
200
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(undefined);
201
+ } else {
202
+ setInputDate((0, _moment.default)(value, dateFormat));
203
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange((0, _moment.default)(value, dateFormat));
204
+ }
205
+ setInputText(value === '' ? '' : (0, _moment.default)(value, dateFormatWithoutSpaces).format(dateFormat));
200
206
  } else {
201
207
  setInputText(value);
202
208
  }
203
209
  };
210
+ const handleOnKeyPress = event => {
211
+ if (event.key === 'Backspace' && inputText === '') {
212
+ setInputDate(undefined);
213
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(undefined);
214
+ }
215
+ };
216
+ const handleValidation = inputValidation => {
217
+ if (validDatePattern.test(inputText.replace(/\s+/g, '')) === false && inputText !== '') {
218
+ return 'error';
219
+ }
220
+ if (inputValidation === 'error' || inputValidation === 'success') {
221
+ return inputValidation;
222
+ }
223
+ return inputValidation;
224
+ };
204
225
  const viewport = (0, _componentsBase.useViewport)();
205
226
  const daySize = getResponsiveDaySize(inline, viewport);
206
227
  const circleSize = getResponsiveCircleSize(inline, viewport);
@@ -321,11 +342,12 @@ const DatePicker = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
321
342
  hint: hint,
322
343
  placeholder: "DD / MM / YYYY",
323
344
  onChange: onChangeInput,
345
+ onKeyPress: handleOnKeyPress,
324
346
  tooltip: tooltip,
325
347
  hintPosition: hintPosition,
326
348
  label: label ?? ((_dictionary$copy = _dictionary.default[copy]) === null || _dictionary$copy === void 0 ? void 0 : _dictionary$copy.roleDescription),
327
349
  value: inputText,
328
- validation: validation,
350
+ validation: handleValidation(validation),
329
351
  inactive: disabled,
330
352
  ref: textInputRef,
331
353
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Portal, {
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
  import PropTypes from 'prop-types';
4
- import { selectSystemProps, getTokensPropType, useThemeTokens, Badge as BaseBadge } from '@telus-uds/components-base';
4
+ import { selectSystemProps, Typography, getTokensPropType, useThemeTokens } from '@telus-uds/components-base';
5
5
  import { htmlAttrs, transformGradient } from '../utils';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
- const [, selectedSystemPropTypes] = selectSystemProps([htmlAttrs]);
7
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs]);
8
8
  const BadgeContainer = /*#__PURE__*/styled.div.withConfig({
9
9
  displayName: "Badge__BadgeContainer",
10
10
  componentId: "components-web__sc-tsiuo2-0"
@@ -41,6 +41,11 @@ const BadgeContainer = /*#__PURE__*/styled.div.withConfig({
41
41
  ${gradient && '-webkit-text-fill-color: transparent;'}
42
42
  }`;
43
43
  });
44
+ const fontSizeMapping = {
45
+ 12: 'micro',
46
+ 14: 'small',
47
+ 16: 'h6'
48
+ };
44
49
  const Badge = _ref6 => {
45
50
  let {
46
51
  children,
@@ -54,10 +59,14 @@ const Badge = _ref6 => {
54
59
  borderColor,
55
60
  borderRadius,
56
61
  borderWidth,
62
+ color,
57
63
  paddingLeft,
58
64
  paddingRight,
59
65
  paddingTop,
60
- paddingBottom
66
+ paddingBottom,
67
+ fontName,
68
+ fontWeight,
69
+ fontSize
61
70
  } = useThemeTokens('Badge', tokens, variant);
62
71
  const semanticGradient = gradient && transformGradient(gradient);
63
72
  const {
@@ -78,12 +87,20 @@ const Badge = _ref6 => {
78
87
  padding: `${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`,
79
88
  radius: `${borderRadius}px`,
80
89
  background: background,
90
+ fontName: fontName,
91
+ fontWeight: fontWeight,
81
92
  gradient: semanticGradient,
82
93
  border: `${borderWidth}px solid ${borderColor}`,
83
- children: /*#__PURE__*/_jsx(BaseBadge, {
84
- tokens: tokens,
85
- variant: variant,
86
- ...rest,
94
+ ...selectProps(rest),
95
+ children: /*#__PURE__*/_jsx(Typography, {
96
+ tokens: {
97
+ fontName,
98
+ fontWeight,
99
+ color
100
+ },
101
+ variant: {
102
+ size: fontSizeMapping[fontSize]
103
+ },
87
104
  children: children
88
105
  })
89
106
  });
@@ -65,6 +65,7 @@ const PortalPositionedContainer = /*#__PURE__*/styled.div.withConfig({
65
65
  return `${top}px`;
66
66
  }
67
67
  });
68
+ const validDatePattern = /^([0-2][0-9]|3[0-1])(\/)(0[1-9]|1[0-2])\2(\d{4})$/;
68
69
 
69
70
  /**
70
71
  * Use DatePicker to select a date on a calendar.
@@ -186,14 +187,34 @@ const DatePicker = /*#__PURE__*/forwardRef((_ref3, ref) => {
186
187
  if (onDateChange) onDateChange(value);
187
188
  };
188
189
  const onChangeInput = value => {
189
- if (moment(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()) {
190
- setInputDate(moment(value, dateFormat));
191
- if (onDateChange) onDateChange(moment(value, dateFormat));
192
- setInputText(moment(value, dateFormatWithoutSpaces).format(dateFormat));
190
+ if (value === '' || moment(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()) {
191
+ if (value === '') {
192
+ setInputDate(undefined); // Set inputDate to undefined if input is empty
193
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(undefined);
194
+ } else {
195
+ setInputDate(moment(value, dateFormat));
196
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(moment(value, dateFormat));
197
+ }
198
+ setInputText(value === '' ? '' : moment(value, dateFormatWithoutSpaces).format(dateFormat));
193
199
  } else {
194
200
  setInputText(value);
195
201
  }
196
202
  };
203
+ const handleOnKeyPress = event => {
204
+ if (event.key === 'Backspace' && inputText === '') {
205
+ setInputDate(undefined);
206
+ onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(undefined);
207
+ }
208
+ };
209
+ const handleValidation = inputValidation => {
210
+ if (validDatePattern.test(inputText.replace(/\s+/g, '')) === false && inputText !== '') {
211
+ return 'error';
212
+ }
213
+ if (inputValidation === 'error' || inputValidation === 'success') {
214
+ return inputValidation;
215
+ }
216
+ return inputValidation;
217
+ };
197
218
  const viewport = useViewport();
198
219
  const daySize = getResponsiveDaySize(inline, viewport);
199
220
  const circleSize = getResponsiveCircleSize(inline, viewport);
@@ -314,11 +335,12 @@ const DatePicker = /*#__PURE__*/forwardRef((_ref3, ref) => {
314
335
  hint: hint,
315
336
  placeholder: "DD / MM / YYYY",
316
337
  onChange: onChangeInput,
338
+ onKeyPress: handleOnKeyPress,
317
339
  tooltip: tooltip,
318
340
  hintPosition: hintPosition,
319
341
  label: label ?? ((_dictionary$copy = dictionary[copy]) === null || _dictionary$copy === void 0 ? void 0 : _dictionary$copy.roleDescription),
320
342
  value: inputText,
321
- validation: validation,
343
+ validation: handleValidation(validation),
322
344
  inactive: disabled,
323
345
  ref: textInputRef,
324
346
  children: /*#__PURE__*/_jsx(Portal, {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  ],
6
6
  "dependencies": {
7
7
  "@gorhom/portal": "^1.0.14",
8
- "@telus-uds/components-base": "1.80.1",
8
+ "@telus-uds/components-base": "1.81.0",
9
9
  "@telus-uds/system-constants": "^1.3.0",
10
10
  "fscreen": "^1.2.0",
11
11
  "lodash.omit": "^4.5.0",
@@ -83,5 +83,5 @@
83
83
  "skip": true
84
84
  },
85
85
  "types": "types/index.d.ts",
86
- "version": "2.32.1"
86
+ "version": "2.32.2"
87
87
  }
@@ -3,13 +3,13 @@ import styled from 'styled-components'
3
3
  import PropTypes from 'prop-types'
4
4
  import {
5
5
  selectSystemProps,
6
+ Typography,
6
7
  getTokensPropType,
7
- useThemeTokens,
8
- Badge as BaseBadge
8
+ useThemeTokens
9
9
  } from '@telus-uds/components-base'
10
10
  import { htmlAttrs, transformGradient } from '../utils'
11
11
 
12
- const [, selectedSystemPropTypes] = selectSystemProps([htmlAttrs])
12
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs])
13
13
 
14
14
  const BadgeContainer = styled.div`
15
15
  background: ${({ background }) => background};
@@ -29,6 +29,12 @@ const BadgeContainer = styled.div`
29
29
  }`}
30
30
  `
31
31
 
32
+ const fontSizeMapping = {
33
+ 12: 'micro',
34
+ 14: 'small',
35
+ 16: 'h6'
36
+ }
37
+
32
38
  const Badge = ({ children, tokens, variant = {}, ...rest }) => {
33
39
  const {
34
40
  backgroundColor,
@@ -36,10 +42,14 @@ const Badge = ({ children, tokens, variant = {}, ...rest }) => {
36
42
  borderColor,
37
43
  borderRadius,
38
44
  borderWidth,
45
+ color,
39
46
  paddingLeft,
40
47
  paddingRight,
41
48
  paddingTop,
42
- paddingBottom
49
+ paddingBottom,
50
+ fontName,
51
+ fontWeight,
52
+ fontSize
43
53
  } = useThemeTokens('Badge', tokens, variant)
44
54
 
45
55
  const semanticGradient = gradient && transformGradient(gradient)
@@ -60,12 +70,18 @@ const Badge = ({ children, tokens, variant = {}, ...rest }) => {
60
70
  padding={`${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`}
61
71
  radius={`${borderRadius}px`}
62
72
  background={background}
73
+ fontName={fontName}
74
+ fontWeight={fontWeight}
63
75
  gradient={semanticGradient}
64
76
  border={`${borderWidth}px solid ${borderColor}`}
77
+ {...selectProps(rest)}
65
78
  >
66
- <BaseBadge tokens={tokens} variant={variant} {...rest}>
79
+ <Typography
80
+ tokens={{ fontName, fontWeight, color }}
81
+ variant={{ size: fontSizeMapping[fontSize] }}
82
+ >
67
83
  {children}
68
- </BaseBadge>
84
+ </Typography>
69
85
  </BadgeContainer>
70
86
  )
71
87
  }
@@ -56,6 +56,8 @@ const PortalPositionedContainer = styled.div({
56
56
  top: ({ top }) => `${top}px`
57
57
  })
58
58
 
59
+ const validDatePattern = /^([0-2][0-9]|3[0-1])(\/)(0[1-9]|1[0-2])\2(\d{4})$/
60
+
59
61
  /**
60
62
  * Use DatePicker to select a date on a calendar.
61
63
  *
@@ -168,14 +170,42 @@ const DatePicker = forwardRef(
168
170
  if (onDateChange) onDateChange(value)
169
171
  }
170
172
  const onChangeInput = (value) => {
171
- if (moment(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()) {
172
- setInputDate(moment(value, dateFormat))
173
- if (onDateChange) onDateChange(moment(value, dateFormat))
174
- setInputText(moment(value, dateFormatWithoutSpaces).format(dateFormat))
173
+ if (
174
+ value === '' ||
175
+ moment(value.replace(/\s/g, ''), dateFormatWithoutSpaces, true).isValid()
176
+ ) {
177
+ if (value === '') {
178
+ setInputDate(undefined) // Set inputDate to undefined if input is empty
179
+ onDateChange?.(undefined)
180
+ } else {
181
+ setInputDate(moment(value, dateFormat))
182
+ onDateChange?.(moment(value, dateFormat))
183
+ }
184
+ setInputText(value === '' ? '' : moment(value, dateFormatWithoutSpaces).format(dateFormat))
175
185
  } else {
176
186
  setInputText(value)
177
187
  }
178
188
  }
189
+
190
+ const handleOnKeyPress = (event) => {
191
+ if (event.key === 'Backspace' && inputText === '') {
192
+ setInputDate(undefined)
193
+ onDateChange?.(undefined)
194
+ }
195
+ }
196
+
197
+ const handleValidation = (inputValidation) => {
198
+ if (validDatePattern.test(inputText.replace(/\s+/g, '')) === false && inputText !== '') {
199
+ return 'error'
200
+ }
201
+
202
+ if (inputValidation === 'error' || inputValidation === 'success') {
203
+ return inputValidation
204
+ }
205
+
206
+ return inputValidation
207
+ }
208
+
179
209
  const viewport = useViewport()
180
210
  const daySize = getResponsiveDaySize(inline, viewport)
181
211
  const circleSize = getResponsiveCircleSize(inline, viewport)
@@ -286,11 +316,12 @@ const DatePicker = forwardRef(
286
316
  hint={hint}
287
317
  placeholder="DD / MM / YYYY"
288
318
  onChange={onChangeInput}
319
+ onKeyPress={handleOnKeyPress}
289
320
  tooltip={tooltip}
290
321
  hintPosition={hintPosition}
291
322
  label={label ?? dictionary[copy]?.roleDescription}
292
323
  value={inputText}
293
- validation={validation}
324
+ validation={handleValidation(validation)}
294
325
  inactive={disabled}
295
326
  ref={textInputRef}
296
327
  >