@transferwise/components 46.27.0 → 46.29.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 (206) hide show
  1. package/build/i18n/th.json +2 -2
  2. package/build/index.js +344 -1147
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs +346 -1147
  5. package/build/index.mjs.map +1 -1
  6. package/build/main.css +16 -5
  7. package/build/styles/logo/Logo.css +16 -0
  8. package/build/styles/main.css +16 -5
  9. package/build/types/alert/Alert.d.ts +47 -58
  10. package/build/types/alert/Alert.d.ts.map +1 -1
  11. package/build/types/alert/index.d.ts +2 -1
  12. package/build/types/alert/index.d.ts.map +1 -1
  13. package/build/types/button/Button.d.ts +7 -9
  14. package/build/types/button/Button.d.ts.map +1 -1
  15. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
  16. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
  17. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
  18. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
  19. package/build/types/common/propsValues/sentiment.d.ts +0 -1
  20. package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
  21. package/build/types/dateLookup/DateLookup.d.ts +75 -28
  22. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  23. package/build/types/dateLookup/DateLookup.messages.d.ts +42 -63
  24. package/build/types/dateLookup/DateLookup.messages.d.ts.map +1 -1
  25. package/build/types/dateLookup/dateHeader/DateHeader.d.ts +9 -22
  26. package/build/types/dateLookup/dateHeader/DateHeader.d.ts.map +1 -1
  27. package/build/types/dateLookup/dateHeader/index.d.ts +1 -1
  28. package/build/types/dateLookup/dateHeader/index.d.ts.map +1 -1
  29. package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts +13 -31
  30. package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
  31. package/build/types/dateLookup/dateTrigger/index.d.ts +1 -1
  32. package/build/types/dateLookup/dateTrigger/index.d.ts.map +1 -1
  33. package/build/types/dateLookup/dayCalendar/DayCalendar.d.ts +19 -2
  34. package/build/types/dateLookup/dayCalendar/DayCalendar.d.ts.map +1 -1
  35. package/build/types/dateLookup/dayCalendar/index.d.ts +1 -1
  36. package/build/types/dateLookup/dayCalendar/index.d.ts.map +1 -1
  37. package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts +12 -2
  38. package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts.map +1 -1
  39. package/build/types/dateLookup/dayCalendar/table/index.d.ts +1 -1
  40. package/build/types/dateLookup/dayCalendar/table/index.d.ts.map +1 -1
  41. package/build/types/dateLookup/getStartOfDay/getStartOfDay.d.ts +1 -1
  42. package/build/types/dateLookup/getStartOfDay/getStartOfDay.d.ts.map +1 -1
  43. package/build/types/dateLookup/getStartOfDay/index.d.ts +1 -1
  44. package/build/types/dateLookup/getStartOfDay/index.d.ts.map +1 -1
  45. package/build/types/dateLookup/index.d.ts +2 -1
  46. package/build/types/dateLookup/index.d.ts.map +1 -1
  47. package/build/types/dateLookup/monthCalendar/MonthCalendar.d.ts +17 -2
  48. package/build/types/dateLookup/monthCalendar/MonthCalendar.d.ts.map +1 -1
  49. package/build/types/dateLookup/monthCalendar/index.d.ts +1 -1
  50. package/build/types/dateLookup/monthCalendar/index.d.ts.map +1 -1
  51. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +10 -26
  52. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  53. package/build/types/dateLookup/monthCalendar/table/index.d.ts +1 -1
  54. package/build/types/dateLookup/monthCalendar/table/index.d.ts.map +1 -1
  55. package/build/types/dateLookup/yearCalendar/YearCalendar.d.ts +15 -2
  56. package/build/types/dateLookup/yearCalendar/YearCalendar.d.ts.map +1 -1
  57. package/build/types/dateLookup/yearCalendar/index.d.ts +1 -1
  58. package/build/types/dateLookup/yearCalendar/index.d.ts.map +1 -1
  59. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts +10 -26
  60. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
  61. package/build/types/dateLookup/yearCalendar/table/index.d.ts +1 -1
  62. package/build/types/dateLookup/yearCalendar/table/index.d.ts.map +1 -1
  63. package/build/types/dimmer/Dimmer.d.ts.map +1 -1
  64. package/build/types/index.d.ts +2 -2
  65. package/build/types/index.d.ts.map +1 -1
  66. package/build/types/inlineAlert/InlineAlert.d.ts +2 -4
  67. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  68. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  69. package/build/types/inputs/_BottomSheet.d.ts.map +1 -1
  70. package/build/types/loader/Loader.d.ts.map +1 -1
  71. package/build/types/logo/Logo.d.ts.map +1 -1
  72. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  73. package/build/types/popover/Popover.d.ts.map +1 -1
  74. package/build/types/segmentedControl/SegmentedControl.d.ts +2 -2
  75. package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -1
  76. package/build/types/select/Select.d.ts.map +1 -1
  77. package/build/types/statusIcon/StatusIcon.d.ts +1 -1
  78. package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
  79. package/build/types/stepper/deviceDetection.d.ts.map +1 -1
  80. package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
  81. package/package.json +3 -3
  82. package/src/accordion/Accordion.story.tsx +1 -1
  83. package/src/alert/{Alert.spec.js → Alert.spec.tsx} +43 -40
  84. package/src/alert/Alert.story.tsx +1 -2
  85. package/src/alert/Alert.tsx +219 -0
  86. package/src/alert/index.ts +2 -0
  87. package/src/avatar/colors/colors.ts +1 -1
  88. package/src/body/Body.spec.tsx +1 -1
  89. package/src/body/Body.story.tsx +8 -8
  90. package/src/button/Button.tsx +6 -10
  91. package/src/checkbox/Checkbox.js +1 -1
  92. package/src/checkboxButton/CheckboxButton.spec.tsx +0 -1
  93. package/src/common/Option/Option.tsx +1 -1
  94. package/src/common/dateUtils/isWithinRange/isWithinRange.spec.ts +21 -0
  95. package/src/common/dateUtils/isWithinRange/isWithinRange.ts +2 -2
  96. package/src/common/dateUtils/moveToWithinRange/moveToWithinRange.ts +8 -4
  97. package/src/common/deviceDetection/deviceDetection.js +1 -1
  98. package/src/common/deviceDetection/deviceDetection.spec.js +4 -2
  99. package/src/common/propsValues/sentiment.ts +0 -10
  100. package/src/common/responsivePanel/ResponsivePanel.spec.js +11 -15
  101. package/src/dateLookup/DateLookup.state.spec.js +7 -0
  102. package/src/dateLookup/{DateLookup.story.js → DateLookup.story.tsx} +13 -14
  103. package/src/dateLookup/DateLookup.tests.story.tsx +70 -0
  104. package/src/dateLookup/{DateLookup.js → DateLookup.tsx} +115 -81
  105. package/src/dateLookup/dateHeader/{DateHeader.js → DateHeader.tsx} +15 -15
  106. package/src/dateLookup/dateTrigger/DateTrigger.spec.js +0 -22
  107. package/src/dateLookup/dateTrigger/{DateTrigger.js → DateTrigger.tsx} +15 -32
  108. package/src/dateLookup/dayCalendar/{DayCalendar.js → DayCalendar.tsx} +14 -21
  109. package/src/dateLookup/dayCalendar/table/{DayCalendarTable.js → DayCalendarTable.tsx} +26 -37
  110. package/src/dateLookup/getStartOfDay/{getStartOfDay.js → getStartOfDay.tsx} +1 -1
  111. package/src/dateLookup/index.ts +2 -0
  112. package/src/dateLookup/monthCalendar/{MonthCalendar.js → MonthCalendar.tsx} +19 -22
  113. package/src/dateLookup/monthCalendar/table/{MonthCalendarTable.js → MonthCalendarTable.tsx} +31 -30
  114. package/src/dateLookup/yearCalendar/{YearCalendar.js → YearCalendar.tsx} +18 -21
  115. package/src/dateLookup/yearCalendar/table/{YearCalendarTable.js → YearCalendarTable.tsx} +26 -28
  116. package/src/decision/Decision.spec.js +0 -1
  117. package/src/dimmer/Dimmer.tsx +6 -2
  118. package/src/i18n/th.json +2 -2
  119. package/src/index.ts +2 -2
  120. package/src/inlineAlert/InlineAlert.spec.tsx +0 -7
  121. package/src/inlineAlert/InlineAlert.story.tsx +8 -7
  122. package/src/inlineAlert/InlineAlert.tsx +19 -47
  123. package/src/inputs/InputGroup.tsx +3 -3
  124. package/src/inputs/SelectInput.tsx +2 -0
  125. package/src/inputs/_BottomSheet.tsx +21 -26
  126. package/src/inputs/_Popover.tsx +4 -4
  127. package/src/link/Link.story.tsx +16 -16
  128. package/src/loader/Loader.tsx +0 -1
  129. package/src/logo/Logo.css +16 -0
  130. package/src/logo/Logo.js +4 -9
  131. package/src/logo/Logo.less +16 -0
  132. package/src/logo/__snapshots__/Logo.spec.js.snap +104 -8
  133. package/src/main.css +16 -5
  134. package/src/main.less +0 -1
  135. package/src/moneyInput/MoneyInput.story.tsx +3 -3
  136. package/src/nudge/Nudge.spec.tsx +5 -5
  137. package/src/phoneNumberInput/PhoneNumberInput.tsx +2 -1
  138. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +1 -1
  139. package/src/popover/Popover.tsx +2 -1
  140. package/src/promoCard/PromoCard.tsx +1 -1
  141. package/src/radioGroup/RadioGroup.spec.js +1 -1
  142. package/src/section/Section.story.tsx +2 -1
  143. package/src/segmentedControl/SegmentedControl.spec.tsx +88 -2
  144. package/src/segmentedControl/SegmentedControl.story.tsx +54 -16
  145. package/src/segmentedControl/SegmentedControl.tsx +21 -33
  146. package/src/select/Select.js +2 -3
  147. package/src/statusIcon/StatusIcon.tsx +14 -14
  148. package/src/stepper/deviceDetection.js +1 -2
  149. package/src/stepper/deviceDetection.spec.js +8 -3
  150. package/src/test-utils/index.js +1 -1
  151. package/src/test-utils/story-config.ts +1 -1
  152. package/src/title/Title.spec.tsx +1 -1
  153. package/src/typeahead/Typeahead.spec.js +4 -2
  154. package/src/upload/Upload.spec.js +8 -4
  155. package/src/uploadInput/uploadButton/UploadButton.tsx +1 -0
  156. package/build/styles/dynamicFieldDefinitionList/FormattedValue/FormattedValue.css +0 -5
  157. package/build/types/alert/withArrow/alertArrowPositions.d.ts +0 -9
  158. package/build/types/alert/withArrow/alertArrowPositions.d.ts.map +0 -1
  159. package/build/types/alert/withArrow/index.d.ts +0 -3
  160. package/build/types/alert/withArrow/index.d.ts.map +0 -1
  161. package/build/types/alert/withArrow/withArrow.d.ts +0 -11
  162. package/build/types/alert/withArrow/withArrow.d.ts.map +0 -1
  163. package/build/types/common/requirements.d.ts +0 -3
  164. package/build/types/common/requirements.d.ts.map +0 -1
  165. package/build/types/dynamicFieldDefinitionList/DynamicFieldDefinitionList.d.ts +0 -21
  166. package/build/types/dynamicFieldDefinitionList/DynamicFieldDefinitionList.d.ts.map +0 -1
  167. package/build/types/dynamicFieldDefinitionList/FormattedValue/FormattedValue.d.ts +0 -12
  168. package/build/types/dynamicFieldDefinitionList/FormattedValue/FormattedValue.d.ts.map +0 -1
  169. package/build/types/dynamicFieldDefinitionList/FormattedValue/index.d.ts +0 -2
  170. package/build/types/dynamicFieldDefinitionList/FormattedValue/index.d.ts.map +0 -1
  171. package/build/types/dynamicFieldDefinitionList/index.d.ts +0 -2
  172. package/build/types/dynamicFieldDefinitionList/index.d.ts.map +0 -1
  173. package/build/types/dynamicFieldDefinitionList/utils/createDefinitions.d.ts +0 -2
  174. package/build/types/dynamicFieldDefinitionList/utils/createDefinitions.d.ts.map +0 -1
  175. package/build/types/dynamicFieldDefinitionList/utils/text-format.d.ts +0 -2
  176. package/build/types/dynamicFieldDefinitionList/utils/text-format.d.ts.map +0 -1
  177. package/src/alert/Alert.js +0 -196
  178. package/src/alert/index.js +0 -1
  179. package/src/alert/withArrow/alertArrowPositions.ts +0 -9
  180. package/src/alert/withArrow/index.js +0 -2
  181. package/src/alert/withArrow/withArrow.js +0 -50
  182. package/src/alert/withArrow/withArrow.spec.js +0 -51
  183. package/src/dateLookup/index.js +0 -1
  184. package/src/dynamicFieldDefinitionList/DynamicFieldDefinitionList.js +0 -41
  185. package/src/dynamicFieldDefinitionList/DynamicFieldDefinitionList.spec.js +0 -21
  186. package/src/dynamicFieldDefinitionList/DynamicFieldDefinitionList.story.js +0 -134
  187. package/src/dynamicFieldDefinitionList/FormattedValue/FormattedValue.css +0 -5
  188. package/src/dynamicFieldDefinitionList/FormattedValue/FormattedValue.js +0 -73
  189. package/src/dynamicFieldDefinitionList/FormattedValue/FormattedValue.less +0 -4
  190. package/src/dynamicFieldDefinitionList/FormattedValue/FormattedValue.spec.js +0 -200
  191. package/src/dynamicFieldDefinitionList/FormattedValue/index.js +0 -1
  192. package/src/dynamicFieldDefinitionList/index.js +0 -1
  193. package/src/dynamicFieldDefinitionList/utils/createDefinitions.js +0 -33
  194. package/src/dynamicFieldDefinitionList/utils/createDefinitions.spec.js +0 -83
  195. package/src/dynamicFieldDefinitionList/utils/text-format.js +0 -46
  196. package/src/dynamicFieldDefinitionList/utils/text-format.spec.js +0 -43
  197. /package/src/dateLookup/{DateLookup.messages.js → DateLookup.messages.ts} +0 -0
  198. /package/src/dateLookup/dateHeader/{index.js → index.ts} +0 -0
  199. /package/src/dateLookup/dateTrigger/{index.js → index.ts} +0 -0
  200. /package/src/dateLookup/dayCalendar/{index.js → index.ts} +0 -0
  201. /package/src/dateLookup/dayCalendar/table/{index.js → index.ts} +0 -0
  202. /package/src/dateLookup/getStartOfDay/{index.js → index.ts} +0 -0
  203. /package/src/dateLookup/monthCalendar/{index.js → index.ts} +0 -0
  204. /package/src/dateLookup/monthCalendar/table/{index.js → index.ts} +0 -0
  205. /package/src/dateLookup/yearCalendar/{index.js → index.ts} +0 -0
  206. /package/src/dateLookup/yearCalendar/table/{index.js → index.ts} +0 -0
@@ -1,17 +1,26 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import { isKey } from '@transferwise/neptune-validation';
3
- import PropTypes from 'prop-types';
4
2
  import { useIntl } from 'react-intl';
5
3
 
6
4
  import Chevron from '../../chevron';
7
- import { Size, Position } from '../../common';
5
+ import { Size, Position, SizeSmall, SizeMedium, SizeLarge } from '../../common';
8
6
  import { CloseButton } from '../../common/closeButton/CloseButton';
9
7
 
10
8
  import messages from './DateTrigger.messages';
11
9
 
12
- const DateTrigger = ({
10
+ interface DateTriggerProps {
11
+ selectedDate: Date | null;
12
+ size: SizeSmall | SizeMedium | SizeLarge;
13
+ placeholder: string;
14
+ label: string;
15
+ monthFormat: 'short' | 'long';
16
+ disabled: boolean;
17
+ onClick: () => void;
18
+ onClear?: () => void;
19
+ }
20
+
21
+ const DateTrigger: React.FC<DateTriggerProps> = ({
13
22
  selectedDate,
14
- size,
23
+ size = Size.MEDIUM,
15
24
  placeholder,
16
25
  label,
17
26
  monthFormat,
@@ -21,14 +30,6 @@ const DateTrigger = ({
21
30
  }) => {
22
31
  const { locale, formatMessage } = useIntl();
23
32
 
24
- const handleKeyDown = (event) => {
25
- if (isKey({ keyType: 'Space', event: event }) || isKey({ keyType: 'Enter', event: event })) {
26
- event.stopPropagation();
27
- event.preventDefault();
28
- onClear();
29
- }
30
- };
31
-
32
33
  return (
33
34
  <>
34
35
  <button
@@ -64,12 +65,11 @@ const DateTrigger = ({
64
65
  className={`clear-btn clear-btn--${size}`}
65
66
  aria-label={`${formatMessage(messages.ariaLabel)} ${label}`}
66
67
  size={Size.SMALL}
67
- onClick={(event) => {
68
+ onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
68
69
  event.stopPropagation();
69
70
  event.preventDefault();
70
71
  onClear();
71
72
  }}
72
- onKeyPress={handleKeyDown}
73
73
  />
74
74
  </span>
75
75
  </>
@@ -78,21 +78,4 @@ const DateTrigger = ({
78
78
  );
79
79
  };
80
80
 
81
- DateTrigger.propTypes = {
82
- selectedDate: PropTypes.instanceOf(Date),
83
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
84
- placeholder: PropTypes.string.isRequired,
85
- label: PropTypes.string.isRequired,
86
- monthFormat: PropTypes.oneOf(['short', 'long']).isRequired,
87
- disabled: PropTypes.bool.isRequired,
88
- onClick: PropTypes.func,
89
- onClear: PropTypes.func,
90
- };
91
-
92
- DateTrigger.defaultProps = {
93
- selectedDate: null,
94
- size: Size.MEDIUM,
95
- onClear: undefined,
96
- };
97
-
98
81
  export default DateTrigger;
@@ -1,7 +1,6 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import PropTypes from 'prop-types';
3
2
  import { PureComponent } from 'react';
4
- import { injectIntl } from 'react-intl';
3
+ import { injectIntl, WrappedComponentProps } from 'react-intl';
5
4
 
6
5
  import { MonthFormat } from '../../common';
7
6
  import messages from '../DateLookup.messages';
@@ -9,7 +8,19 @@ import DateHeader from '../dateHeader';
9
8
 
10
9
  import DayCalendarTable from './table';
11
10
 
12
- class DayCalendar extends PureComponent {
11
+ interface DayCalendarProps extends WrappedComponentProps {
12
+ selectedDate: Date | null;
13
+ min: Date | null;
14
+ max: Date | null;
15
+ viewMonth: number;
16
+ viewYear: number;
17
+ monthFormat: `${MonthFormat}`;
18
+ onSelect: (date: Date) => void;
19
+ onLabelClick: () => void;
20
+ onViewDateUpdate: (date: { month: number; year: number }) => void;
21
+ }
22
+
23
+ class DayCalendar extends PureComponent<DayCalendarProps> {
13
24
  selectPreviousMonth = () => {
14
25
  const { viewMonth, viewYear } = this.props;
15
26
  this.props.onViewDateUpdate({
@@ -56,22 +67,4 @@ class DayCalendar extends PureComponent {
56
67
  }
57
68
  }
58
69
 
59
- DayCalendar.propTypes = {
60
- selectedDate: PropTypes.instanceOf(Date),
61
- min: PropTypes.instanceOf(Date),
62
- max: PropTypes.instanceOf(Date),
63
- viewMonth: PropTypes.number.isRequired,
64
- viewYear: PropTypes.number.isRequired,
65
- monthFormat: PropTypes.oneOf([MonthFormat.LONG, MonthFormat.SHORT]).isRequired,
66
- onSelect: PropTypes.func.isRequired,
67
- onLabelClick: PropTypes.func.isRequired,
68
- onViewDateUpdate: PropTypes.func.isRequired,
69
- };
70
-
71
- DayCalendar.defaultProps = {
72
- selectedDate: null,
73
- min: null,
74
- max: null,
75
- };
76
-
77
70
  export default injectIntl(DayCalendar);
@@ -1,16 +1,24 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import PropTypes from 'prop-types';
3
2
  import { PureComponent } from 'react';
4
- import { injectIntl } from 'react-intl';
3
+ import { injectIntl, WrappedComponentProps } from 'react-intl';
5
4
 
6
5
  import { getDayNames, isWithinRange } from '../../../common/dateUtils';
7
6
  import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
8
7
  import { getStartOfDay } from '../../getStartOfDay';
9
8
  import TableLink from '../../tableLink';
10
9
 
11
- const SHORT_DAY_FORMAT = { day: 'numeric' };
10
+ const SHORT_DAY_FORMAT: Intl.DateTimeFormatOptions = { day: 'numeric' };
12
11
 
13
- class DayCalendarTable extends PureComponent {
12
+ interface DayCalendarTableProps extends WrappedComponentProps {
13
+ selectedDate: Date | null;
14
+ min: Date | null;
15
+ max: Date | null;
16
+ viewMonth: number;
17
+ viewYear: number;
18
+ onSelect: (date: Date) => void;
19
+ }
20
+
21
+ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
14
22
  getTableStructure = () => {
15
23
  const { viewMonth, viewYear } = this.props;
16
24
  let firstDayOfMonth = new Date(viewYear, viewMonth, 1).getDay();
@@ -20,13 +28,13 @@ class DayCalendarTable extends PureComponent {
20
28
  }
21
29
  const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
22
30
 
23
- let week = [];
24
- const weeks = [];
31
+ let week: number[] = [];
32
+ const weeks: number[][] = [];
25
33
  let i;
26
34
 
27
35
  // Pad first week
28
36
  for (i = 1; i < firstDayOfMonth; i += 1) {
29
- week.push(false);
37
+ week.push(-1);
30
38
  }
31
39
  // Fill in days
32
40
  for (i = 1; i <= daysInMonth; i += 1) {
@@ -39,7 +47,7 @@ class DayCalendarTable extends PureComponent {
39
47
  if (week.length > 0) {
40
48
  // Pad last week
41
49
  for (i = week.length; i < 7; i += 1) {
42
- week.push(false);
50
+ week.push(-1);
43
51
  }
44
52
  weeks.push(week);
45
53
  }
@@ -50,29 +58,29 @@ class DayCalendarTable extends PureComponent {
50
58
  daysShort = getDayNames(this.props.intl.locale, 'narrow');
51
59
  daysLong = getDayNames(this.props.intl.locale, 'long');
52
60
 
53
- selectDay = (day) => {
61
+ selectDay = (day: number) => {
54
62
  const { viewMonth, viewYear, onSelect } = this.props;
55
63
  onSelect(new Date(viewYear, viewMonth, day));
56
64
  };
57
65
 
58
- isDisabled = (day) => {
66
+ isDisabled = (day: number) => {
59
67
  const { min, max, viewMonth, viewYear } = this.props;
60
68
  const date = new Date(viewYear, viewMonth, day);
61
69
 
62
70
  return !isWithinRange(date, min, max);
63
71
  };
64
72
 
65
- isActive = (day) => {
73
+ isActive = (day: number) => {
66
74
  const { selectedDate, viewMonth, viewYear } = this.props;
67
75
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
68
76
  };
69
77
 
70
- isToday = (day) => {
78
+ isToday = (day: number) => {
71
79
  const { viewMonth, viewYear } = this.props;
72
80
  return Number(getStartOfDay(new Date())) === Number(new Date(viewYear, viewMonth, day));
73
81
  };
74
82
 
75
- getAutofocusDay = (weeks) => {
83
+ getAutofocusDay = (weeks: number[][]) => {
76
84
  const days = weeks.flatMap((week) => week);
77
85
  return getFocusableTime({
78
86
  isActive: this.isActive,
@@ -83,13 +91,9 @@ class DayCalendarTable extends PureComponent {
83
91
  };
84
92
 
85
93
  render() {
86
- const {
87
- viewMonth,
88
- viewYear,
89
- intl: { locale },
90
- } = this.props;
94
+ const { viewMonth, viewYear, intl } = this.props;
91
95
  const weeks = this.getTableStructure();
92
- let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
96
+ const autoFocusDay = this.getAutofocusDay(weeks);
93
97
  return (
94
98
  <table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
95
99
  <thead>
@@ -119,17 +123,17 @@ class DayCalendarTable extends PureComponent {
119
123
  <tr key={weekIndex}>
120
124
  {week.map((day, dayIndex) => (
121
125
  <td key={dayIndex} className={dayIndex > 4 ? 'weekend' : ''}>
122
- {day && (
126
+ {day !== -1 && (
123
127
  <TableLink
124
128
  item={day}
125
129
  type="day"
126
130
  title={formatDate(
127
131
  new Date(viewYear, viewMonth, day),
128
- locale,
132
+ intl.locale,
129
133
  SHORT_DAY_FORMAT,
130
134
  )}
131
135
  autofocus={day === autoFocusDay}
132
- longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
136
+ longTitle={formatDate(new Date(viewYear, viewMonth, day), intl.locale)}
133
137
  active={this.isActive(day)}
134
138
  disabled={this.isDisabled(day)}
135
139
  today={this.isToday(day)}
@@ -147,19 +151,4 @@ class DayCalendarTable extends PureComponent {
147
151
  }
148
152
  }
149
153
 
150
- DayCalendarTable.propTypes = {
151
- selectedDate: PropTypes.instanceOf(Date),
152
- min: PropTypes.instanceOf(Date),
153
- max: PropTypes.instanceOf(Date),
154
- viewMonth: PropTypes.number.isRequired,
155
- viewYear: PropTypes.number.isRequired,
156
- onSelect: PropTypes.func.isRequired,
157
- };
158
-
159
- DayCalendarTable.defaultProps = {
160
- selectedDate: null,
161
- min: null,
162
- max: null,
163
- };
164
-
165
154
  export default injectIntl(DayCalendarTable);
@@ -2,7 +2,7 @@
2
2
  // getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
3
3
  // in Singapore it is 1 Jan 1995.
4
4
  // You might want to use/implement `getUTCStartOfDay` if you want it to be 1995 in any timezone
5
- export function getStartOfDay(date) {
5
+ export function getStartOfDay(date: Date | null) {
6
6
  if (!date) {
7
7
  return null;
8
8
  }
@@ -0,0 +1,2 @@
1
+ export { default } from './DateLookup';
2
+ export type { DateLookupProps } from './DateLookup';
@@ -1,15 +1,25 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import PropTypes from 'prop-types';
3
2
  import { PureComponent } from 'react';
4
- import { injectIntl } from 'react-intl';
3
+ import { injectIntl, WrappedComponentProps } from 'react-intl';
5
4
 
6
5
  import messages from '../DateLookup.messages';
7
6
  import DateHeader from '../dateHeader';
8
7
 
9
8
  import MonthCalendarTable from './table';
10
9
 
11
- class MonthCalendar extends PureComponent {
12
- onMonthSelect = (month) => {
10
+ interface MonthCalendarProps extends WrappedComponentProps {
11
+ selectedDate: Date | null;
12
+ min: Date | null;
13
+ max: Date | null;
14
+ viewYear: number;
15
+ placeholder: string;
16
+ onSelect: () => void;
17
+ onLabelClick: () => void;
18
+ onViewDateUpdate: (date: { year?: number; month?: number }) => void;
19
+ }
20
+
21
+ class MonthCalendar extends PureComponent<MonthCalendarProps> {
22
+ onMonthSelect = (month: number) => {
13
23
  this.props.onViewDateUpdate({ month });
14
24
  this.props.onSelect();
15
25
  };
@@ -42,7 +52,11 @@ class MonthCalendar extends PureComponent {
42
52
  onNextClick={this.selectNextYear}
43
53
  />
44
54
  <MonthCalendarTable
45
- {...{ selectedDate, min, max, viewYear, placeholder }}
55
+ selectedDate={selectedDate}
56
+ min={min}
57
+ max={max}
58
+ viewYear={viewYear}
59
+ placeholder={placeholder}
46
60
  onSelect={this.onMonthSelect}
47
61
  />
48
62
  </>
@@ -50,21 +64,4 @@ class MonthCalendar extends PureComponent {
50
64
  }
51
65
  }
52
66
 
53
- MonthCalendar.propTypes = {
54
- selectedDate: PropTypes.instanceOf(Date),
55
- min: PropTypes.instanceOf(Date),
56
- max: PropTypes.instanceOf(Date),
57
- viewYear: PropTypes.number.isRequired,
58
- placeholder: PropTypes.string.isRequired,
59
- onSelect: PropTypes.func.isRequired,
60
- onLabelClick: PropTypes.func.isRequired,
61
- onViewDateUpdate: PropTypes.func.isRequired,
62
- };
63
-
64
- MonthCalendar.defaultProps = {
65
- selectedDate: null,
66
- min: null,
67
- max: null,
68
- };
69
-
70
67
  export default injectIntl(MonthCalendar);
@@ -1,17 +1,33 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import PropTypes from 'prop-types';
3
2
  import { useIntl } from 'react-intl';
4
3
 
5
4
  import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
6
5
  import TableLink from '../../tableLink';
7
6
 
7
+ interface MonthCalendarTableProps {
8
+ selectedDate: Date | null;
9
+ min: Date | null;
10
+ max: Date | null;
11
+ viewYear: number;
12
+ placeholder: string;
13
+ onSelect: (date: number) => void;
14
+ }
15
+
8
16
  const ROWS = 3;
9
17
  const COLS = 4;
10
- const MONTH_ONLY_FORMAT = { month: 'short' };
18
+ const MONTH_ONLY_FORMAT: Intl.DateTimeFormatOptions = { month: 'short' };
11
19
 
12
- const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSelect }) => {
20
+ const MonthCalendarTable = ({
21
+ selectedDate,
22
+ min,
23
+ max,
24
+ viewYear,
25
+ placeholder,
26
+ onSelect,
27
+ }: MonthCalendarTableProps) => {
13
28
  const { locale } = useIntl();
14
- const getLink = (month) => {
29
+
30
+ const getLink = (month: number) => {
15
31
  return (
16
32
  <TableLink
17
33
  item={month}
@@ -26,17 +42,19 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
26
42
  );
27
43
  };
28
44
 
29
- const isActive = (month) => {
30
- return (
31
- selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear()
45
+ const isActive = (month: number) => {
46
+ return !!(
47
+ selectedDate &&
48
+ month === selectedDate.getMonth() &&
49
+ viewYear === selectedDate.getFullYear()
32
50
  );
33
51
  };
34
52
 
35
- const isThisMonth = (month) => {
53
+ const isThisMonth = (month: number) => {
36
54
  return viewYear === new Date().getFullYear() && month === new Date().getMonth();
37
55
  };
38
56
 
39
- const isDisabled = (month) => {
57
+ const isDisabled = (month: number) => {
40
58
  const date = new Date(viewYear, month);
41
59
  return !!(
42
60
  (min && date < new Date(min.getFullYear(), min.getMonth())) ||
@@ -45,7 +63,7 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
45
63
  };
46
64
 
47
65
  const autofocusMonth = (() => {
48
- const months = [...new Array(ROWS * COLS)].map((_, index) => index);
66
+ const months = Array.from({ length: ROWS * COLS }, (_, index) => index);
49
67
  return getFocusableTime({ isActive, isNow: isThisMonth, isDisabled, timeSpan: months });
50
68
  })();
51
69
 
@@ -53,37 +71,20 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
53
71
  <table className="table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0">
54
72
  <thead className="sr-only">
55
73
  <tr>
56
- <th colSpan="3">{placeholder}</th>
74
+ <th colSpan={COLS}>{placeholder}</th>
57
75
  </tr>
58
76
  </thead>
59
77
  <tbody>
60
- {/* eslint-disable react/no-array-index-key */}
61
- {[...new Array(ROWS)].map((row, rowIndex) => (
78
+ {Array.from({ length: ROWS }, (_, rowIndex) => (
62
79
  <tr key={rowIndex}>
63
- {[...new Array(COLS)].map((col, colIndex) => (
80
+ {Array.from({ length: COLS }, (_, colIndex) => (
64
81
  <td key={colIndex}>{getLink(rowIndex * COLS + colIndex)}</td>
65
82
  ))}
66
83
  </tr>
67
84
  ))}
68
- {/* eslint-enable react/no-array-index-key */}
69
85
  </tbody>
70
86
  </table>
71
87
  );
72
88
  };
73
89
 
74
- MonthCalendarTable.propTypes = {
75
- selectedDate: PropTypes.instanceOf(Date),
76
- min: PropTypes.instanceOf(Date),
77
- max: PropTypes.instanceOf(Date),
78
- viewYear: PropTypes.number.isRequired,
79
- placeholder: PropTypes.string.isRequired,
80
- onSelect: PropTypes.func.isRequired,
81
- };
82
-
83
- MonthCalendarTable.defaultProps = {
84
- selectedDate: null,
85
- min: null,
86
- max: null,
87
- };
88
-
89
90
  export default MonthCalendarTable;
@@ -1,14 +1,23 @@
1
- import PropTypes from 'prop-types';
2
1
  import { PureComponent } from 'react';
3
- import { injectIntl } from 'react-intl';
2
+ import { injectIntl, WrappedComponentProps } from 'react-intl';
4
3
 
5
4
  import messages from '../DateLookup.messages';
6
5
  import DateHeader from '../dateHeader';
7
6
 
8
7
  import YearCalendarTable from './table';
9
8
 
10
- class YearCalendar extends PureComponent {
11
- onYearSelect = (year) => {
9
+ interface YearCalendarProps extends WrappedComponentProps {
10
+ selectedDate: Date | null;
11
+ min: Date | null;
12
+ max: Date | null;
13
+ viewYear: number;
14
+ placeholder: string;
15
+ onSelect: () => void;
16
+ onViewDateUpdate: (date: { year: number }) => void;
17
+ }
18
+
19
+ class YearCalendar extends PureComponent<YearCalendarProps> {
20
+ onYearSelect = (year: number) => {
12
21
  this.props.onViewDateUpdate({ year });
13
22
  this.props.onSelect();
14
23
  };
@@ -38,7 +47,11 @@ class YearCalendar extends PureComponent {
38
47
  onNextClick={this.selectNextYears}
39
48
  />
40
49
  <YearCalendarTable
41
- {...{ selectedDate, min, max, viewYear, placeholder }}
50
+ selectedDate={selectedDate}
51
+ min={min}
52
+ max={max}
53
+ viewYear={viewYear}
54
+ placeholder={placeholder}
42
55
  onSelect={this.onYearSelect}
43
56
  />
44
57
  </>
@@ -46,20 +59,4 @@ class YearCalendar extends PureComponent {
46
59
  }
47
60
  }
48
61
 
49
- YearCalendar.propTypes = {
50
- selectedDate: PropTypes.instanceOf(Date),
51
- min: PropTypes.instanceOf(Date),
52
- max: PropTypes.instanceOf(Date),
53
- viewYear: PropTypes.number.isRequired,
54
- placeholder: PropTypes.string.isRequired,
55
- onSelect: PropTypes.func.isRequired,
56
- onViewDateUpdate: PropTypes.func.isRequired,
57
- };
58
-
59
- YearCalendar.defaultProps = {
60
- selectedDate: null,
61
- min: null,
62
- max: null,
63
- };
64
-
65
62
  export default injectIntl(YearCalendar);
@@ -1,18 +1,33 @@
1
1
  import { formatDate } from '@transferwise/formatting';
2
- import PropTypes from 'prop-types';
3
2
  import { useIntl } from 'react-intl';
4
3
 
5
4
  import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
6
5
  import TableLink from '../../tableLink';
7
6
 
7
+ interface YearCalendarTableProps {
8
+ selectedDate: Date | null;
9
+ min: Date | null;
10
+ max: Date | null;
11
+ viewYear: number;
12
+ placeholder: string;
13
+ onSelect: (year: number) => void;
14
+ }
15
+
8
16
  const ROWS = 5;
9
17
  const COLS = 4;
10
- const YEAR_ONLY_FORMAT = { year: 'numeric' };
18
+ const YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };
11
19
 
12
- const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSelect }) => {
20
+ const YearCalendarTable = ({
21
+ selectedDate,
22
+ min,
23
+ max,
24
+ viewYear,
25
+ placeholder,
26
+ onSelect,
27
+ }: YearCalendarTableProps) => {
13
28
  const { locale } = useIntl();
14
29
  const startYear = viewYear - (viewYear % 20);
15
- const getLink = (year) => {
30
+ const getLink = (year: number) => {
16
31
  return (
17
32
  <TableLink
18
33
  item={year}
@@ -27,20 +42,20 @@ const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSe
27
42
  );
28
43
  };
29
44
 
30
- const isActive = (year) => {
45
+ const isActive = (year: number) => {
31
46
  return !!(selectedDate && year === selectedDate.getFullYear());
32
47
  };
33
48
 
34
- const isThisYear = (year) => {
49
+ const isThisYear = (year: number) => {
35
50
  return year === new Date().getFullYear();
36
51
  };
37
52
 
38
- const isDisabled = (year) => {
53
+ const isDisabled = (year: number) => {
39
54
  return !!((min && year < min.getFullYear()) || (max && year > max.getFullYear()));
40
55
  };
41
56
 
42
57
  const autofocusYear = (() => {
43
- const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
58
+ const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);
44
59
  return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });
45
60
  })();
46
61
 
@@ -48,37 +63,20 @@ const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSe
48
63
  <table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
49
64
  <thead className="sr-only">
50
65
  <tr>
51
- <th colSpan="4">{placeholder}</th>
66
+ <th colSpan={COLS}>{placeholder}</th>
52
67
  </tr>
53
68
  </thead>
54
69
  <tbody>
55
- {/* eslint-disable react/no-array-index-key */}
56
- {[...new Array(ROWS)].map((row, rowIndex) => (
70
+ {Array.from({ length: ROWS }, (_, rowIndex) => (
57
71
  <tr key={rowIndex}>
58
- {[...new Array(COLS)].map((col, colIndex) => (
72
+ {Array.from({ length: COLS }, (_, colIndex) => (
59
73
  <td key={colIndex}>{getLink(startYear + rowIndex * COLS + colIndex)}</td>
60
74
  ))}
61
75
  </tr>
62
76
  ))}
63
- {/* eslint-enable react/no-array-index-key */}
64
77
  </tbody>
65
78
  </table>
66
79
  );
67
80
  };
68
81
 
69
- YearCalendarTable.propTypes = {
70
- selectedDate: PropTypes.instanceOf(Date),
71
- min: PropTypes.instanceOf(Date),
72
- max: PropTypes.instanceOf(Date),
73
- viewYear: PropTypes.number.isRequired,
74
- placeholder: PropTypes.string.isRequired,
75
- onSelect: PropTypes.func.isRequired,
76
- };
77
-
78
- YearCalendarTable.defaultProps = {
79
- selectedDate: null,
80
- min: null,
81
- max: null,
82
- };
83
-
84
82
  export default YearCalendarTable;
@@ -1,4 +1,3 @@
1
- /* eslint-disable testing-library/no-render-in-setup */
2
1
  import '@testing-library/jest-dom';
3
2
 
4
3
  import Avatar from '../avatar';
@@ -99,12 +99,16 @@ const Dimmer = ({
99
99
  const onEnter = () => {
100
100
  setHasNotExited(true);
101
101
 
102
- dimmerReference.current && dimmerManager.add(dimmerReference.current);
102
+ if (dimmerReference.current) {
103
+ dimmerManager.add(dimmerReference.current);
104
+ }
103
105
  };
104
106
  const onExited = () => {
105
107
  setHasNotExited(false);
106
108
 
107
- dimmerReference.current && dimmerManager.remove(dimmerReference.current);
109
+ if (dimmerReference.current) {
110
+ dimmerManager.remove(dimmerReference.current);
111
+ }
108
112
  };
109
113
 
110
114
  useEffect(() => {
package/src/i18n/th.json CHANGED
@@ -4,10 +4,10 @@
4
4
  "neptune.ClearButton.ariaLabel": "ล้าง",
5
5
  "neptune.CloseButton.ariaLabel": "ปิด",
6
6
  "neptune.DateInput.day.label": "วัน",
7
- "neptune.DateInput.day.placeholder": "DD",
7
+ "neptune.DateInput.day.placeholder": "วัน",
8
8
  "neptune.DateInput.month.label": "เดือน",
9
9
  "neptune.DateInput.year.label": "ปี",
10
- "neptune.DateInput.year.placeholder": "YYYY",
10
+ "neptune.DateInput.year.placeholder": "ปี",
11
11
  "neptune.DateLookup.day": "วัน",
12
12
  "neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
13
13
  "neptune.DateLookup.month": "เดือน",