@transferwise/components 46.13.0 → 46.15.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 (168) hide show
  1. package/build/index.esm.js +246 -525
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +222 -501
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +6 -82
  6. package/build/styles/decision/Decision.css +6 -82
  7. package/build/styles/main.css +6 -82
  8. package/build/types/actionButton/ActionButton.d.ts +1 -1
  9. package/build/types/body/Body.d.ts +1 -1
  10. package/build/types/common/Option/Option.d.ts.map +1 -1
  11. package/build/types/common/RadioButton/RadioButton.d.ts +10 -34
  12. package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
  13. package/build/types/common/RadioButton/index.d.ts +1 -1
  14. package/build/types/common/RadioButton/index.d.ts.map +1 -1
  15. package/build/types/common/commonProps.d.ts +1 -1
  16. package/build/types/common/commonProps.d.ts.map +1 -1
  17. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts +1 -1
  18. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts.map +1 -1
  19. package/build/types/common/dateUtils/getDayNames/index.d.ts +1 -1
  20. package/build/types/common/dateUtils/getDayNames/index.d.ts.map +1 -1
  21. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts +1 -1
  22. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts.map +1 -1
  23. package/build/types/common/dateUtils/getMonthNames/index.d.ts +1 -1
  24. package/build/types/common/dateUtils/getMonthNames/index.d.ts.map +1 -1
  25. package/build/types/common/dateUtils/index.d.ts +6 -6
  26. package/build/types/common/dateUtils/index.d.ts.map +1 -1
  27. package/build/types/common/dateUtils/isDateValid/index.d.ts +1 -1
  28. package/build/types/common/dateUtils/isDateValid/index.d.ts.map +1 -1
  29. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts +2 -2
  30. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts.map +1 -1
  31. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts +1 -1
  32. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts.map +1 -1
  33. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts +1 -1
  34. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts.map +1 -1
  35. package/build/types/common/dateUtils/isWithinRange/index.d.ts +1 -1
  36. package/build/types/common/dateUtils/isWithinRange/index.d.ts.map +1 -1
  37. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
  38. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
  39. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts +1 -1
  40. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts.map +1 -1
  41. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
  42. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
  43. package/build/types/common/panel/Panel.d.ts +1 -1
  44. package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
  45. package/build/types/dateInput/DateInput.d.ts +30 -41
  46. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  47. package/build/types/dateInput/DateInput.messages.d.ts +24 -33
  48. package/build/types/dateInput/DateInput.messages.d.ts.map +1 -1
  49. package/build/types/dateInput/index.d.ts +2 -2
  50. package/build/types/dateInput/index.d.ts.map +1 -1
  51. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts +1 -1
  52. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts.map +1 -1
  53. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts +1 -1
  54. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts.map +1 -1
  55. package/build/types/dateInput/utils/index.d.ts +1 -2
  56. package/build/types/dateInput/utils/index.d.ts.map +1 -1
  57. package/build/types/dateLookup/DateLookup.d.ts +1 -0
  58. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  59. package/build/types/decision/Decision.d.ts +39 -52
  60. package/build/types/decision/Decision.d.ts.map +1 -1
  61. package/build/types/decision/index.d.ts +1 -2
  62. package/build/types/decision/index.d.ts.map +1 -1
  63. package/build/types/dimmer/Dimmer.d.ts +1 -1
  64. package/build/types/index.d.ts +5 -0
  65. package/build/types/index.d.ts.map +1 -1
  66. package/build/types/promoCard/PromoCard.d.ts +1 -2
  67. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  68. package/build/types/radio/Radio.d.ts +10 -21
  69. package/build/types/radio/Radio.d.ts.map +1 -1
  70. package/build/types/radio/index.d.ts +2 -2
  71. package/build/types/radio/index.d.ts.map +1 -1
  72. package/build/types/radioGroup/RadioGroup.d.ts +10 -26
  73. package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
  74. package/build/types/radioGroup/index.d.ts +2 -1
  75. package/build/types/radioGroup/index.d.ts.map +1 -1
  76. package/build/types/radioOption/RadioOption.d.ts +15 -23
  77. package/build/types/radioOption/RadioOption.d.ts.map +1 -1
  78. package/build/types/radioOption/index.d.ts +2 -1
  79. package/build/types/radioOption/index.d.ts.map +1 -1
  80. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  81. package/package.json +1 -1
  82. package/src/common/Option/Option.tsx +0 -1
  83. package/src/common/RadioButton/RadioButton.tsx +43 -0
  84. package/src/common/commonProps.ts +1 -1
  85. package/src/common/dateUtils/getDayNames/getDayNames.spec.js +2 -2
  86. package/src/common/dateUtils/getDayNames/{getDayNames.js → getDayNames.ts} +5 -2
  87. package/src/common/dateUtils/getMonthNames/getMonthNames.spec.js +9 -8
  88. package/src/common/dateUtils/getMonthNames/{getMonthNames.js → getMonthNames.ts} +5 -3
  89. package/src/common/dateUtils/isDateValid/{isDateValid.spec.js → isDateValid.spec.ts} +1 -1
  90. package/src/common/dateUtils/isDateValid/isDateValid.ts +13 -0
  91. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.spec.js +3 -7
  92. package/src/common/dateUtils/isMonthAndYearFormat/{isMonthAndYearFormat.js → isMonthAndYearFormat.ts} +1 -1
  93. package/src/common/dateUtils/isWithinRange/{isWithinRange.spec.js → isWithinRange.spec.ts} +0 -10
  94. package/src/common/dateUtils/isWithinRange/{isWithinRange.js → isWithinRange.ts} +1 -1
  95. package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.js → moveToWithinRange.ts} +2 -2
  96. package/src/dateInput/DateInput.spec.js +7 -56
  97. package/src/dateInput/DateInput.story.tsx +11 -8
  98. package/src/dateInput/{DateInput.js → DateInput.tsx} +116 -123
  99. package/src/dateInput/index.ts +2 -0
  100. package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.js → convertToLocalMidnight.ts} +1 -1
  101. package/src/dateInput/utils/{index.js → index.ts} +0 -1
  102. package/src/dateLookup/DateLookup.js +12 -1
  103. package/src/dateLookup/DateLookup.testingLibrary.spec.js +12 -1
  104. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -0
  105. package/src/decision/Decision.css +6 -82
  106. package/src/decision/Decision.less +3 -41
  107. package/src/decision/Decision.spec.js +56 -61
  108. package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
  109. package/src/decision/Decision.tsx +133 -0
  110. package/src/decision/index.ts +1 -0
  111. package/src/index.ts +5 -0
  112. package/src/main.css +6 -82
  113. package/src/promoCard/PromoCard.tsx +1 -2
  114. package/src/radio/{Radio.story.js → Radio.story.tsx} +0 -3
  115. package/src/radio/{Radio.js → Radio.tsx} +18 -28
  116. package/src/radio/index.ts +2 -0
  117. package/src/radioGroup/RadioGroup.spec.js +24 -26
  118. package/src/radioGroup/{RadioGroup.story.js → RadioGroup.story.tsx} +0 -3
  119. package/src/radioGroup/RadioGroup.tsx +39 -0
  120. package/src/radioGroup/index.ts +2 -0
  121. package/src/radioOption/RadioOption.spec.js +4 -4
  122. package/src/radioOption/{RadioOption.story.js → RadioOption.story.tsx} +4 -4
  123. package/src/radioOption/RadioOption.tsx +60 -0
  124. package/src/radioOption/index.ts +2 -0
  125. package/src/tile/Tile.js +1 -1
  126. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts +0 -6
  127. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts.map +0 -1
  128. package/build/types/dateInput/utils/explodeDate/index.d.ts +0 -2
  129. package/build/types/dateInput/utils/explodeDate/index.d.ts.map +0 -1
  130. package/build/types/decision/decisionEnums.d.ts +0 -9
  131. package/build/types/decision/decisionEnums.d.ts.map +0 -1
  132. package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
  133. package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
  134. package/build/types/sizeSwapper/index.d.ts +0 -2
  135. package/build/types/sizeSwapper/index.d.ts.map +0 -1
  136. package/src/common/RadioButton/RadioButton.js +0 -41
  137. package/src/common/dateUtils/isDateValid/isDateValid.js +0 -6
  138. package/src/dateInput/index.js +0 -3
  139. package/src/dateInput/utils/explodeDate/explodeDate.js +0 -7
  140. package/src/dateInput/utils/explodeDate/explodeDate.spec.js +0 -11
  141. package/src/dateInput/utils/explodeDate/index.js +0 -1
  142. package/src/decision/Decision.js +0 -148
  143. package/src/decision/decisionEnums.ts +0 -11
  144. package/src/decision/index.js +0 -2
  145. package/src/radio/index.js +0 -3
  146. package/src/radioGroup/RadioGroup.js +0 -66
  147. package/src/radioGroup/index.js +0 -1
  148. package/src/radioOption/RadioOption.js +0 -81
  149. package/src/radioOption/index.js +0 -1
  150. package/src/sizeSwapper/SizeSwapper.js +0 -69
  151. package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
  152. package/src/sizeSwapper/SizeSwapper.story.js +0 -34
  153. package/src/sizeSwapper/index.js +0 -1
  154. /package/src/common/RadioButton/{RadioButton.spec.js → RadioButton.spec.tsx} +0 -0
  155. /package/src/common/RadioButton/__snapshots__/{RadioButton.spec.js.snap → RadioButton.spec.tsx.snap} +0 -0
  156. /package/src/common/RadioButton/{index.js → index.ts} +0 -0
  157. /package/src/common/dateUtils/getDayNames/{index.js → index.ts} +0 -0
  158. /package/src/common/dateUtils/getMonthNames/{index.js → index.ts} +0 -0
  159. /package/src/common/dateUtils/{index.js → index.ts} +0 -0
  160. /package/src/common/dateUtils/isDateValid/{index.js → index.ts} +0 -0
  161. /package/src/common/dateUtils/isMonthAndYearFormat/{index.js → index.ts} +0 -0
  162. /package/src/common/dateUtils/isWithinRange/{index.js → index.ts} +0 -0
  163. /package/src/common/dateUtils/moveToWithinRange/{index.js → index.ts} +0 -0
  164. /package/src/dateInput/{DateInput.messages.js → DateInput.messages.ts} +0 -0
  165. /package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.spec.js → convertToLocalMidnight.spec.ts} +0 -0
  166. /package/src/dateInput/utils/convertToLocalMidnight/{index.js → index.ts} +0 -0
  167. /package/src/radio/{Radio.rtl.spec.js → Radio.rtl.spec.tsx} +0 -0
  168. /package/src/radio/__snapshots__/{Radio.rtl.spec.js.snap → Radio.rtl.spec.tsx.snap} +0 -0
@@ -31,14 +31,12 @@ export const Basic = () => {
31
31
  value: 'radio-1',
32
32
  label: 'Radio1',
33
33
  secondary: 'Secondary line 1',
34
- name: 'name',
35
34
  disabled: false,
36
35
  avatar,
37
36
  },
38
37
  {
39
38
  value: 'radio-2',
40
39
  label: 'Radio2',
41
- name: 'name',
42
40
  disabled: false,
43
41
  avatar,
44
42
  },
@@ -46,7 +44,6 @@ export const Basic = () => {
46
44
  value: 'radio-3',
47
45
  label: 'Radio3',
48
46
  secondary: 'Secondary line 3',
49
- name: 'name',
50
47
  disabled: true,
51
48
  avatar,
52
49
  },
@@ -0,0 +1,39 @@
1
+ import { useState } from 'react';
2
+
3
+ import Radio from '../radio';
4
+ import { RadioProps } from '../radio/Radio';
5
+
6
+ export interface RadioGroupProps<T extends string | number = string> {
7
+ name: string;
8
+ radios: Omit<RadioProps<T>, 'name' | 'checked' | 'onChange' | 'className'>[];
9
+ selectedValue?: T | '';
10
+ onChange: NonNullable<RadioProps<T>['onChange']>;
11
+ }
12
+
13
+ export default function RadioGroup<T extends string | number = string>({
14
+ name,
15
+ radios,
16
+ selectedValue: controlledValue,
17
+ onChange,
18
+ }: RadioGroupProps<T>) {
19
+ const [uncontrolledValue, setUncontrolledValue] = useState(controlledValue);
20
+
21
+ return radios.length > 0 ? (
22
+ <div role="radiogroup">
23
+ {radios.map(({ value = '', ...restProps }, index) => (
24
+ <Radio
25
+ // eslint-disable-next-line react/no-array-index-key
26
+ key={index}
27
+ {...restProps}
28
+ name={name}
29
+ value={value}
30
+ checked={value === uncontrolledValue}
31
+ onChange={(nextValue) => {
32
+ setUncontrolledValue(nextValue);
33
+ onChange(nextValue);
34
+ }}
35
+ />
36
+ ))}
37
+ </div>
38
+ ) : null;
39
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './RadioGroup';
2
+ export type { RadioGroupProps } from './RadioGroup';
@@ -38,9 +38,9 @@ describe('Radio option', () => {
38
38
  });
39
39
 
40
40
  it('passes checked to radio button passed as button', () => {
41
- expect(buttonProperty('checked')).toBe(false);
41
+ expect(buttonProperty('checked')).toBeFalsy();
42
42
  component.setProps({ checked: true });
43
- expect(buttonProperty('checked')).toBe(true);
43
+ expect(buttonProperty('checked')).toBeTruthy();
44
44
  });
45
45
 
46
46
  it('passes change handler to radio button passed as button', () => {
@@ -50,9 +50,9 @@ describe('Radio option', () => {
50
50
  });
51
51
 
52
52
  it('passes disabled to radio button passed as button', () => {
53
- expect(buttonProperty('disabled')).toBe(false);
53
+ expect(buttonProperty('disabled')).toBeFalsy();
54
54
  component.setProps({ disabled: true });
55
- expect(buttonProperty('disabled')).toBe(true);
55
+ expect(buttonProperty('disabled')).toBeTruthy();
56
56
  });
57
57
 
58
58
  it('renders aligned with container content', () => {
@@ -5,14 +5,14 @@ import { useState } from 'react';
5
5
 
6
6
  import { Nudge } from '..';
7
7
 
8
- import RadioOption from './RadioOption';
8
+ import RadioOption, { RadioOptionProps } from './RadioOption';
9
9
 
10
10
  export default {
11
11
  component: RadioOption,
12
12
  title: 'Option/RadioOption',
13
13
  };
14
14
 
15
- const Template = (props) => {
15
+ const Template = (props: Partial<RadioOptionProps>) => {
16
16
  const showMediaAtAllSizes = boolean('showMediaAtAllSizes', false);
17
17
  const title = text('title', 'title');
18
18
  const disabled = boolean('disabled', false);
@@ -32,9 +32,9 @@ const Template = (props) => {
32
32
  value="value"
33
33
  showMediaAtAllSizes={showMediaAtAllSizes}
34
34
  isContainerAligned={isContainerAligned}
35
- onChange={() => {
35
+ onChange={(value) => {
36
36
  action('checked');
37
- props.onChange();
37
+ props.onChange?.(value);
38
38
  }}
39
39
  />
40
40
  );
@@ -0,0 +1,60 @@
1
+ import Option from '../common/Option';
2
+ import RadioButton from '../common/RadioButton';
3
+ import { RadioButtonProps } from '../common/RadioButton/RadioButton';
4
+
5
+ export interface RadioOptionProps<T extends string | number = string>
6
+ extends Required<Pick<RadioButtonProps<T>, 'id' | 'name' | 'onChange'>>,
7
+ Omit<RadioButtonProps<T>, 'readOnly' | 'id' | 'name' | 'onChange'> {
8
+ 'aria-label'?: string;
9
+ media?: React.ReactNode;
10
+ title: React.ReactNode;
11
+ content?: React.ReactNode;
12
+ complex?: boolean;
13
+ showMediaCircle?: boolean;
14
+ showMediaAtAllSizes?: boolean;
15
+ isContainerAligned?: boolean;
16
+ }
17
+
18
+ function RadioOption<T extends string | number = string>({
19
+ 'aria-label': ariaLabel,
20
+ media,
21
+ title,
22
+ content,
23
+ id,
24
+ name,
25
+ checked,
26
+ onChange,
27
+ complex,
28
+ disabled,
29
+ value,
30
+ showMediaCircle,
31
+ showMediaAtAllSizes,
32
+ isContainerAligned,
33
+ }: RadioOptionProps<T>) {
34
+ return (
35
+ <Option
36
+ aria-label={ariaLabel}
37
+ media={media}
38
+ title={title}
39
+ content={content}
40
+ name={name}
41
+ complex={complex}
42
+ disabled={disabled}
43
+ showMediaCircle={showMediaCircle}
44
+ showMediaAtAllSizes={showMediaAtAllSizes}
45
+ isContainerAligned={isContainerAligned}
46
+ button={
47
+ <RadioButton
48
+ id={id}
49
+ name={name}
50
+ checked={checked}
51
+ disabled={disabled}
52
+ value={value}
53
+ onChange={onChange}
54
+ />
55
+ }
56
+ />
57
+ );
58
+ }
59
+
60
+ export default RadioOption;
@@ -0,0 +1,2 @@
1
+ export { default } from './RadioOption';
2
+ export type { RadioOptionProps } from './RadioOption';
package/src/tile/Tile.js CHANGED
@@ -65,7 +65,7 @@ Tile.propTypes = {
65
65
  className: PropTypes.string,
66
66
  description: PropTypes.node,
67
67
  disabled: PropTypes.bool,
68
- href: PropTypes.string.isRequired,
68
+ href: PropTypes.string,
69
69
  target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
70
70
  /** Accepts only Avatar and images */
71
71
  media: PropTypes.node.isRequired,
@@ -1,6 +0,0 @@
1
- export function explodeDate(date: any): {
2
- year: any;
3
- month: any;
4
- day: any;
5
- };
6
- //# sourceMappingURL=explodeDate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"explodeDate.d.ts","sourceRoot":"","sources":["../../../../../src/dateInput/utils/explodeDate/explodeDate.js"],"names":[],"mappings":"AAAO;;;;EAMN"}
@@ -1,2 +0,0 @@
1
- export { explodeDate } from "./explodeDate";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/dateInput/utils/explodeDate/index.js"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- export declare enum Presentation {
2
- LIST = "LIST",
3
- LIST_BLOCK = "LIST_BLOCK",
4
- LIST_BLOCK_GRID = "LIST_BLOCK_GRID"
5
- }
6
- export declare enum Type {
7
- NAVIGATION = "NAVIGATION"
8
- }
9
- //# sourceMappingURL=decisionEnums.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decisionEnums.d.ts","sourceRoot":"","sources":["../../../src/decision/decisionEnums.ts"],"names":[],"mappings":"AACA,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,eAAe,oBAAoB;CACpC;AAGD,oBAAY,IAAI;IACd,UAAU,eAAe;CAC1B"}
@@ -1,3 +0,0 @@
1
- export default SizeSwapper;
2
- declare const SizeSwapper: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
3
- //# sourceMappingURL=SizeSwapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SizeSwapper.d.ts","sourceRoot":"","sources":["../../../src/sizeSwapper/SizeSwapper.js"],"names":[],"mappings":";AASA,yGAqCG"}
@@ -1,2 +0,0 @@
1
- export { default } from "./SizeSwapper";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sizeSwapper/index.js"],"names":[],"mappings":""}
@@ -1,41 +0,0 @@
1
- import classNames from 'classnames';
2
- import PropTypes from 'prop-types';
3
-
4
- const RadioButton = ({ id, value, name, checked, onChange, disabled, readOnly }) => (
5
- <>
6
- <input
7
- type="radio"
8
- className="sr-only"
9
- id={id}
10
- value={value}
11
- name={name}
12
- checked={checked}
13
- disabled={disabled || readOnly}
14
- onChange={() => (!checked ? onChange(value) : null)}
15
- />
16
- <span className={classNames('tw-radio-button', { checked, disabled: disabled || readOnly })}>
17
- <span className="tw-radio-check" />
18
- </span>
19
- </>
20
- );
21
-
22
- RadioButton.propTypes = {
23
- id: PropTypes.string,
24
- name: PropTypes.string.isRequired,
25
- checked: PropTypes.bool,
26
- onChange: PropTypes.func,
27
- disabled: PropTypes.bool,
28
- value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
29
- readOnly: PropTypes.bool,
30
- };
31
-
32
- RadioButton.defaultProps = {
33
- checked: false,
34
- onChange: () => {},
35
- disabled: false,
36
- id: null,
37
- value: '',
38
- readOnly: false,
39
- };
40
-
41
- export default RadioButton;
@@ -1,6 +0,0 @@
1
- export const isDateValid = (date) => validDateObject(date) || validDateString(date);
2
-
3
- export const validDateString = (dateString) =>
4
- typeof dateString === 'string' && validDateObject(new Date(dateString));
5
-
6
- const validDateObject = (dateObject) => dateObject instanceof Date && !isNaN(dateObject); // eslint-disable-line no-restricted-globals
@@ -1,3 +0,0 @@
1
- import DateInput from './DateInput';
2
-
3
- export default DateInput;
@@ -1,7 +0,0 @@
1
- export const explodeDate = (date) => {
2
- const year = date.getFullYear();
3
- const month = date.getMonth();
4
- const day = date.getDate();
5
-
6
- return { year, month, day };
7
- };
@@ -1,11 +0,0 @@
1
- import { explodeDate } from '.';
2
-
3
- describe('explodeDate', () => {
4
- it('returns exploded model for valid format', () => {
5
- expect(explodeDate(new Date('1995-12-17T03:24:00'))).toStrictEqual({
6
- day: 17,
7
- month: 11,
8
- year: 1995,
9
- });
10
- });
11
- });
@@ -1 +0,0 @@
1
- export { explodeDate } from './explodeDate';
@@ -1,148 +0,0 @@
1
- import classNames from 'classnames';
2
- import PropTypes from 'prop-types';
3
-
4
- import { Size, Breakpoint } from '../common';
5
- import NavigationOption from '../navigationOption';
6
- import SizeSwapper from '../sizeSwapper';
7
- import Tile from '../tile';
8
-
9
- import { Presentation, Type } from './decisionEnums';
10
-
11
- const Decision = ({
12
- options,
13
- presentation,
14
- type,
15
- showMediaCircleInList,
16
- isContainerAligned,
17
- size,
18
- }) => {
19
- if (type === Type.NAVIGATION) {
20
- const { LIST_BLOCK, LIST_BLOCK_GRID } = Presentation;
21
- if (presentation === LIST_BLOCK || presentation === LIST_BLOCK_GRID) {
22
- const isSmall = size === Size.SMALL;
23
- const isGrid = presentation === LIST_BLOCK_GRID;
24
- const items = [
25
- {
26
- items: [],
27
- layout: SizeSwapper.Layout.COLUMN,
28
- },
29
- {
30
- items: [],
31
- breakpoint: isSmall ? Breakpoint.EXTRA_SMALL : Breakpoint.SMALL,
32
- wrap: isGrid,
33
- },
34
- ];
35
-
36
- options.forEach(
37
- ({ description, disabled, href, target, media: { block, list }, onClick, title }, key) => {
38
- items[0].items.push(
39
- <NavigationOption
40
- // eslint-disable-next-line react/no-array-index-key
41
- key={`nav-${key}`}
42
- complex={false}
43
- content={description}
44
- disabled={disabled}
45
- href={href}
46
- target={target}
47
- media={list}
48
- showMediaAtAllSizes
49
- showMediaCircle={showMediaCircleInList}
50
- isContainerAligned={isContainerAligned}
51
- title={title}
52
- onClick={onClick}
53
- />,
54
- );
55
- items[1].items.push(
56
- <Tile
57
- // eslint-disable-next-line react/no-array-index-key
58
- key={`tile-${key}`}
59
- className={classNames(`np-decision__tile${isSmall ? '--small' : ''}`, {
60
- 'np-decision__tile--fixed-width': isGrid,
61
- })}
62
- description={description}
63
- disabled={disabled}
64
- href={href}
65
- target={target}
66
- media={block}
67
- size={isSmall ? Size.SMALL : Size.MEDIUM}
68
- title={title}
69
- onClick={onClick}
70
- />,
71
- );
72
- },
73
- );
74
-
75
- return (
76
- <div
77
- className={classNames('np-decision', {
78
- 'np-decision--small': isSmall,
79
- 'np-decision--grid': isGrid,
80
- })}
81
- >
82
- <SizeSwapper items={items} />
83
- </div>
84
- );
85
- }
86
- // LIST
87
- return options.map(
88
- ({ title, description, disabled, href, target, media: { list }, onClick }, key) => (
89
- <NavigationOption
90
- // eslint-disable-next-line react/no-array-index-key
91
- key={`nav-${key}`}
92
- complex={false}
93
- content={description}
94
- disabled={disabled}
95
- href={href}
96
- target={target}
97
- media={list}
98
- showMediaAtAllSizes
99
- showMediaCircle={showMediaCircleInList}
100
- isContainerAligned={isContainerAligned}
101
- title={title}
102
- onClick={onClick}
103
- />
104
- ),
105
- );
106
- }
107
- return <></>;
108
- };
109
-
110
- Decision.propTypes = {
111
- /** A list of elements to be rendered */
112
- options: PropTypes.arrayOf(
113
- PropTypes.shape({
114
- description: PropTypes.node,
115
- disabled: PropTypes.bool,
116
- href: PropTypes.string,
117
- target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
118
- media: PropTypes.shape({
119
- block: PropTypes.node.isRequired,
120
- list: PropTypes.node.isRequired,
121
- }),
122
- onClick: PropTypes.func,
123
- title: PropTypes.node.isRequired,
124
- }),
125
- ).isRequired,
126
- /** Handles the display mode of the component */
127
- presentation: PropTypes.oneOf(['LIST', 'LIST_BLOCK', 'LIST_BLOCK_GRID']),
128
- /** Size currently affects only Tile dimension */
129
- size: PropTypes.oneOf(['sm', 'md']),
130
- /** Decide which kind of element type needs to be rendered ex: Navigation Options or in the future Radio or Checkbox Options */
131
- type: PropTypes.oneOf(['NAVIGATION']),
132
-
133
- /** Display media in a circle in list presentation */
134
- showMediaCircleInList: PropTypes.bool,
135
-
136
- /** Sets navigation options to be aligned with the parent container */
137
- isContainerAligned: PropTypes.bool,
138
- };
139
-
140
- Decision.defaultProps = {
141
- presentation: Presentation.LIST,
142
- size: Size.MEDIUM,
143
- type: Type.NAVIGATION,
144
- showMediaCircleInList: true,
145
- isContainerAligned: false,
146
- };
147
-
148
- export default Decision;
@@ -1,11 +0,0 @@
1
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
2
- export enum Presentation {
3
- LIST = 'LIST',
4
- LIST_BLOCK = 'LIST_BLOCK',
5
- LIST_BLOCK_GRID = 'LIST_BLOCK_GRID',
6
- }
7
-
8
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
9
- export enum Type {
10
- NAVIGATION = 'NAVIGATION',
11
- }
@@ -1,2 +0,0 @@
1
- export { Presentation as DecisionPresentation, Type as DecisionType } from './decisionEnums';
2
- export { default } from './Decision';
@@ -1,3 +0,0 @@
1
- import Radio from './Radio';
2
-
3
- export default Radio;
@@ -1,66 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { Component } from 'react';
3
-
4
- import Radio from '../radio';
5
-
6
- class RadioGroup extends Component {
7
- constructor(props) {
8
- super(props);
9
- this.state = {
10
- selectedValue: props.selectedValue,
11
- };
12
- }
13
-
14
- handleOnChange = (selectedValue) => {
15
- const { onChange } = this.props;
16
- this.setState({ selectedValue }, onChange && onChange(selectedValue));
17
- };
18
-
19
- render() {
20
- const { radios, name } = this.props;
21
- const { selectedValue } = this.state;
22
- return radios && radios.length > 0 ? (
23
- <div role="radiogroup">
24
- {radios.map(({ id, avatar, value, label, disabled, secondary, readOnly }, index) => (
25
- <Radio
26
- // eslint-disable-next-line react/no-array-index-key
27
- key={index}
28
- id={id}
29
- value={value}
30
- label={label}
31
- name={name}
32
- disabled={disabled}
33
- checked={selectedValue === value}
34
- secondary={secondary}
35
- readOnly={readOnly}
36
- avatar={avatar}
37
- onChange={(value_) => this.handleOnChange(value_)}
38
- />
39
- ))}
40
- </div>
41
- ) : null;
42
- }
43
- }
44
-
45
- RadioGroup.propTypes = {
46
- radios: PropTypes.arrayOf(
47
- PropTypes.shape({
48
- id: PropTypes.string,
49
- avatar: PropTypes.element,
50
- value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
51
- secondary: PropTypes.string,
52
- label: PropTypes.string.isRequired,
53
- disabled: PropTypes.bool,
54
- readOnly: PropTypes.bool,
55
- }),
56
- ).isRequired,
57
- onChange: PropTypes.func.isRequired,
58
- selectedValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
59
- name: PropTypes.string.isRequired,
60
- };
61
-
62
- RadioGroup.defaultProps = {
63
- selectedValue: null,
64
- };
65
-
66
- export default RadioGroup;
@@ -1 +0,0 @@
1
- export { default } from './RadioGroup';
@@ -1,81 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- import Option from '../common/Option';
4
- import RadioButton from '../common/RadioButton';
5
-
6
- const RadioOption = ({
7
- 'aria-label': ariaLabel,
8
- media,
9
- title,
10
- content,
11
- id,
12
- name,
13
- checked,
14
- onChange,
15
- complex,
16
- disabled,
17
- value,
18
- showMediaCircle,
19
- showMediaAtAllSizes,
20
- isContainerAligned,
21
- }) => {
22
- const sharedProps = {
23
- 'aria-label': ariaLabel,
24
- media,
25
- title,
26
- content,
27
- name,
28
- complex,
29
- disabled,
30
- showMediaCircle,
31
- showMediaAtAllSizes,
32
- isContainerAligned,
33
- };
34
- return (
35
- <Option
36
- {...sharedProps}
37
- button={
38
- <RadioButton
39
- id={id}
40
- name={name}
41
- checked={checked}
42
- disabled={disabled}
43
- value={value}
44
- onChange={onChange}
45
- />
46
- }
47
- />
48
- );
49
- };
50
-
51
- RadioOption.propTypes = {
52
- 'aria-label': PropTypes.string,
53
- media: PropTypes.node,
54
- id: PropTypes.string.isRequired,
55
- name: PropTypes.string.isRequired,
56
- title: PropTypes.node.isRequired,
57
- content: PropTypes.node,
58
- checked: PropTypes.bool,
59
- onChange: PropTypes.func.isRequired,
60
- complex: PropTypes.bool,
61
- disabled: PropTypes.bool,
62
- value: PropTypes.string,
63
- showMediaCircle: PropTypes.bool,
64
- showMediaAtAllSizes: PropTypes.bool,
65
- isContainerAligned: PropTypes.bool,
66
- };
67
-
68
- RadioOption.defaultProps = {
69
- 'aria-label': undefined,
70
- media: null,
71
- content: null,
72
- checked: false,
73
- complex: false,
74
- disabled: false,
75
- showMediaCircle: true,
76
- showMediaAtAllSizes: false,
77
- isContainerAligned: false,
78
- value: '',
79
- };
80
-
81
- export default RadioOption;
@@ -1 +0,0 @@
1
- export { default } from './RadioOption';