@transferwise/components 0.0.0-experimental-0df72a3 → 0.0.0-experimental-fe160ab

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 (158) hide show
  1. package/build/Calendar/Calendar.constants.js +10 -0
  2. package/build/Calendar/Calendar.constants.js.map +1 -0
  3. package/build/Calendar/Calendar.constants.mjs +8 -0
  4. package/build/Calendar/Calendar.constants.mjs.map +1 -0
  5. package/build/Calendar/Calendar.js +116 -16
  6. package/build/Calendar/Calendar.js.map +1 -1
  7. package/build/Calendar/Calendar.messages.js +12 -0
  8. package/build/Calendar/Calendar.messages.js.map +1 -1
  9. package/build/Calendar/Calendar.messages.mjs +12 -0
  10. package/build/Calendar/Calendar.messages.mjs.map +1 -1
  11. package/build/Calendar/Calendar.mjs +117 -17
  12. package/build/Calendar/Calendar.mjs.map +1 -1
  13. package/build/Calendar/DateHeader/DateHeader.js +5 -1
  14. package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
  15. package/build/Calendar/DateHeader/DateHeader.mjs +5 -1
  16. package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
  17. package/build/Calendar/DayCalendar/DayCalendar.js +20 -2
  18. package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
  19. package/build/Calendar/DayCalendar/DayCalendar.mjs +20 -2
  20. package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
  21. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +60 -19
  22. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
  23. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +60 -19
  24. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
  25. package/build/Calendar/MonthCalendar/MonthCalendar.js +6 -0
  26. package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
  27. package/build/Calendar/MonthCalendar/MonthCalendar.mjs +6 -0
  28. package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
  29. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +8 -3
  30. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
  31. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +8 -3
  32. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
  33. package/build/Calendar/TableLink/TableLink.js +91 -0
  34. package/build/Calendar/TableLink/TableLink.js.map +1 -0
  35. package/build/Calendar/TableLink/TableLink.mjs +87 -0
  36. package/build/Calendar/TableLink/TableLink.mjs.map +1 -0
  37. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +8 -3
  38. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
  39. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +8 -3
  40. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
  41. package/build/Calendar/YearCalendar/YearCalendar.js +7 -0
  42. package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
  43. package/build/Calendar/YearCalendar/YearCalendar.mjs +7 -0
  44. package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
  45. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +33 -0
  46. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +1 -0
  47. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +31 -0
  48. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +1 -0
  49. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js +40 -0
  50. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js.map +1 -0
  51. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs +38 -0
  52. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs.map +1 -0
  53. package/build/DateLookup/DateLookup.js +20 -9
  54. package/build/DateLookup/DateLookup.js.map +1 -1
  55. package/build/DateLookup/DateLookup.mjs +20 -9
  56. package/build/DateLookup/DateLookup.mjs.map +1 -1
  57. package/build/i18n/en.json +4 -0
  58. package/build/i18n/en.json.js +4 -0
  59. package/build/i18n/en.json.js.map +1 -1
  60. package/build/i18n/en.json.mjs +4 -0
  61. package/build/i18n/en.json.mjs.map +1 -1
  62. package/build/i18n/hu.json +1 -1
  63. package/build/i18n/hu.json.js +1 -1
  64. package/build/i18n/hu.json.mjs +1 -1
  65. package/build/index.js +2 -2
  66. package/build/index.mjs +1 -1
  67. package/build/main.css +123 -43
  68. package/build/styles/Calendar/Calendar.css +112 -37
  69. package/build/styles/Calendar/TableLink/TableLink.css +115 -0
  70. package/build/styles/main.css +123 -43
  71. package/build/types/Calendar/Calendar.constants.d.ts +2 -0
  72. package/build/types/Calendar/Calendar.constants.d.ts.map +1 -0
  73. package/build/types/Calendar/Calendar.d.ts +16 -3
  74. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  75. package/build/types/Calendar/Calendar.messages.d.ts +20 -0
  76. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  77. package/build/types/Calendar/Calendar.types.d.ts +32 -0
  78. package/build/types/Calendar/Calendar.types.d.ts.map +1 -0
  79. package/build/types/Calendar/DateHeader/DateHeader.d.ts +2 -0
  80. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  81. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +7 -1
  82. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  83. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +6 -0
  84. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  85. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +1 -0
  86. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  87. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +2 -1
  88. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  89. package/build/types/Calendar/{tableLink → TableLink}/TableLink.d.ts +5 -1
  90. package/build/types/Calendar/TableLink/TableLink.d.ts.map +1 -0
  91. package/build/types/Calendar/TableLink/index.d.ts.map +1 -0
  92. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +2 -1
  93. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  94. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +1 -0
  95. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  96. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +3 -0
  97. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +1 -0
  98. package/build/types/Calendar/_helpers/index.d.ts +3 -0
  99. package/build/types/Calendar/_helpers/index.d.ts.map +1 -0
  100. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts +3 -0
  101. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts.map +1 -0
  102. package/build/types/Calendar/index.d.ts +1 -0
  103. package/build/types/Calendar/index.d.ts.map +1 -1
  104. package/build/types/DateLookup/DateLookup.d.ts +24 -5
  105. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  106. package/build/types/DateLookup/index.d.ts +1 -0
  107. package/build/types/DateLookup/index.d.ts.map +1 -1
  108. package/build/types/index.d.ts +3 -2
  109. package/build/types/index.d.ts.map +1 -1
  110. package/build/types/test-utils/index.d.ts +8 -0
  111. package/build/types/test-utils/index.d.ts.map +1 -1
  112. package/package.json +1 -1
  113. package/src/Calendar/Calendar.constants.ts +5 -0
  114. package/src/Calendar/Calendar.css +112 -37
  115. package/src/Calendar/Calendar.disabledDates.test.tsx +593 -0
  116. package/src/Calendar/Calendar.less +5 -35
  117. package/src/Calendar/Calendar.messages.ts +21 -0
  118. package/src/Calendar/Calendar.test.tsx +310 -28
  119. package/src/Calendar/Calendar.tsx +159 -18
  120. package/src/Calendar/Calendar.types.ts +35 -0
  121. package/src/Calendar/DateHeader/DateHeader.tsx +6 -0
  122. package/src/Calendar/DayCalendar/DayCalendar.tsx +39 -1
  123. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +67 -27
  124. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +8 -0
  125. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +15 -3
  126. package/src/Calendar/TableLink/TableLink.css +115 -0
  127. package/src/Calendar/TableLink/TableLink.less +68 -0
  128. package/src/Calendar/TableLink/TableLink.tsx +112 -0
  129. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +15 -3
  130. package/src/Calendar/YearCalendar/YearCalendar.tsx +9 -0
  131. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +98 -0
  132. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +45 -0
  133. package/src/Calendar/_helpers/index.ts +2 -0
  134. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.test.ts +169 -0
  135. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.ts +59 -0
  136. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +118 -0
  137. package/src/Calendar/_stories/Calendar.story.tsx +138 -4
  138. package/src/Calendar/_stories/Calendar.test.story.tsx +114 -0
  139. package/src/Calendar/index.ts +7 -0
  140. package/src/DateLookup/DateLookup.disabledDates.test.tsx +293 -0
  141. package/src/DateLookup/DateLookup.test.tsx +34 -37
  142. package/src/DateLookup/DateLookup.tsx +37 -13
  143. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +108 -0
  144. package/src/DateLookup/_stories/DateLookup.story.tsx +124 -2
  145. package/src/DateLookup/index.ts +6 -0
  146. package/src/i18n/en.json +4 -0
  147. package/src/i18n/hu.json +1 -1
  148. package/src/index.ts +3 -2
  149. package/src/main.css +123 -43
  150. package/build/Calendar/tableLink/TableLink.js +0 -61
  151. package/build/Calendar/tableLink/TableLink.js.map +0 -1
  152. package/build/Calendar/tableLink/TableLink.mjs +0 -57
  153. package/build/Calendar/tableLink/TableLink.mjs.map +0 -1
  154. package/build/types/Calendar/tableLink/TableLink.d.ts.map +0 -1
  155. package/build/types/Calendar/tableLink/index.d.ts.map +0 -1
  156. package/src/Calendar/tableLink/TableLink.tsx +0 -77
  157. /package/build/types/Calendar/{tableLink → TableLink}/index.d.ts +0 -0
  158. /package/src/Calendar/{tableLink → TableLink}/index.ts +0 -0
@@ -2,10 +2,11 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import { useIntl } from 'react-intl';
3
3
 
4
4
  import { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';
5
- import TableLink from '../../tableLink';
5
+ import TableLink from '../../TableLink';
6
6
 
7
7
  interface MonthCalendarTableProps {
8
8
  selectedDate: Date | null;
9
+ focusedDate?: Date | null;
9
10
  min: Date | null;
10
11
  max: Date | null;
11
12
  viewYear: number;
@@ -19,6 +20,7 @@ const MONTH_ONLY_FORMAT: Intl.DateTimeFormatOptions = { month: 'short' };
19
20
 
20
21
  const MonthCalendarTable = ({
21
22
  selectedDate,
23
+ focusedDate,
22
24
  min,
23
25
  max,
24
26
  viewYear,
@@ -34,7 +36,8 @@ const MonthCalendarTable = ({
34
36
  type="month"
35
37
  title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT)}
36
38
  active={isActive(month)}
37
- disabled={isDisabled(month)}
39
+ outOfRange={isDisabled(month)}
40
+ disabled={false}
38
41
  today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
39
42
  autofocus={autofocusMonth === month}
40
43
  onClick={onSelect}
@@ -46,6 +49,10 @@ const MonthCalendarTable = ({
46
49
  return !!(month === selectedDate?.getMonth() && viewYear === selectedDate?.getFullYear());
47
50
  };
48
51
 
52
+ const isFocused = (month: number) => {
53
+ return !!(month === focusedDate?.getMonth() && viewYear === focusedDate?.getFullYear());
54
+ };
55
+
49
56
  const isThisMonth = (month: number) => {
50
57
  return viewYear === new Date().getFullYear() && month === new Date().getMonth();
51
58
  };
@@ -60,7 +67,12 @@ const MonthCalendarTable = ({
60
67
 
61
68
  const autofocusMonth = (() => {
62
69
  const months = Array.from({ length: ROWS * COLS }, (_, index) => index);
63
- return getFocusableTime({ isActive, isNow: isThisMonth, isDisabled, timeSpan: months });
70
+ return getFocusableTime({
71
+ isActive: isFocused,
72
+ isNow: isThisMonth,
73
+ isDisabled,
74
+ timeSpan: months,
75
+ });
64
76
  })();
65
77
 
66
78
  return (
@@ -0,0 +1,115 @@
1
+ .wds-Calendar__option--day,
2
+ .wds-Calendar__option--month,
3
+ .wds-Calendar__option--year {
4
+ width: 100%;
5
+ padding: 4px 0;
6
+ padding: var(--size-4) 0;
7
+ border: transparent;
8
+ border-radius: 10px;
9
+ border-radius: var(--radius-small);
10
+ background-color: transparent;
11
+ font-weight: 600;
12
+ font-weight: var(--font-weight-semi-bold);
13
+ color: #37517e;
14
+ color: var(--color-content-primary);
15
+ }
16
+ @media (max-width: 320px) {
17
+ .wds-Calendar__option--day,
18
+ .wds-Calendar__option--month,
19
+ .wds-Calendar__option--year {
20
+ padding: 0;
21
+ }
22
+ }
23
+ .wds-Calendar__option--day:focus,
24
+ .wds-Calendar__option--month:focus,
25
+ .wds-Calendar__option--year:focus {
26
+ background-color: var(--color-background-screen-hover);
27
+ }
28
+ .wds-Calendar__option--day.disabled,
29
+ .wds-Calendar__option--month.disabled,
30
+ .wds-Calendar__option--year.disabled,
31
+ .wds-Calendar__option--day[aria-disabled="true"],
32
+ .wds-Calendar__option--month[aria-disabled="true"],
33
+ .wds-Calendar__option--year[aria-disabled="true"] {
34
+ --ring-outline-color: var(--color-sentiment-content-primary);
35
+ color: #768e9c;
36
+ color: var(--color-content-tertiary);
37
+ cursor: not-allowed;
38
+ }
39
+ .wds-Calendar__option--day.disabled:hover,
40
+ .wds-Calendar__option--month.disabled:hover,
41
+ .wds-Calendar__option--year.disabled:hover,
42
+ .wds-Calendar__option--day[aria-disabled="true"]:hover,
43
+ .wds-Calendar__option--month[aria-disabled="true"]:hover,
44
+ .wds-Calendar__option--year[aria-disabled="true"]:hover,
45
+ .wds-Calendar__option--day.disabled:focus,
46
+ .wds-Calendar__option--month.disabled:focus,
47
+ .wds-Calendar__option--year.disabled:focus,
48
+ .wds-Calendar__option--day[aria-disabled="true"]:focus,
49
+ .wds-Calendar__option--month[aria-disabled="true"]:focus,
50
+ .wds-Calendar__option--year[aria-disabled="true"]:focus {
51
+ filter: initial;
52
+ opacity: 1;
53
+ opacity: initial;
54
+ background-color: var(--color-sentiment-background-surface);
55
+ color: var(--color-sentiment-content-primary);
56
+ }
57
+ .wds-Calendar__option--day.disabled.active,
58
+ .wds-Calendar__option--month.disabled.active,
59
+ .wds-Calendar__option--year.disabled.active,
60
+ .wds-Calendar__option--day[aria-disabled="true"].active,
61
+ .wds-Calendar__option--month[aria-disabled="true"].active,
62
+ .wds-Calendar__option--year[aria-disabled="true"].active,
63
+ .wds-Calendar__option--day.disabled.active:hover,
64
+ .wds-Calendar__option--month.disabled.active:hover,
65
+ .wds-Calendar__option--year.disabled.active:hover,
66
+ .wds-Calendar__option--day[aria-disabled="true"].active:hover,
67
+ .wds-Calendar__option--month[aria-disabled="true"].active:hover,
68
+ .wds-Calendar__option--year[aria-disabled="true"].active:hover,
69
+ .wds-Calendar__option--day.disabled.active:active,
70
+ .wds-Calendar__option--month.disabled.active:active,
71
+ .wds-Calendar__option--year.disabled.active:active,
72
+ .wds-Calendar__option--day[aria-disabled="true"].active:active,
73
+ .wds-Calendar__option--month[aria-disabled="true"].active:active,
74
+ .wds-Calendar__option--year[aria-disabled="true"].active:active,
75
+ .wds-Calendar__option--day.disabled.active:focus,
76
+ .wds-Calendar__option--month.disabled.active:focus,
77
+ .wds-Calendar__option--year.disabled.active:focus,
78
+ .wds-Calendar__option--day[aria-disabled="true"].active:focus,
79
+ .wds-Calendar__option--month[aria-disabled="true"].active:focus,
80
+ .wds-Calendar__option--year[aria-disabled="true"].active:focus {
81
+ filter: initial;
82
+ opacity: 1;
83
+ opacity: initial;
84
+ background-color: var(--color-sentiment-interactive-primary);
85
+ color: var(--color-sentiment-interactive-secondary);
86
+ }
87
+ .wds-Calendar__option--day.disabled.today,
88
+ .wds-Calendar__option--month.disabled.today,
89
+ .wds-Calendar__option--year.disabled.today,
90
+ .wds-Calendar__option--day[aria-disabled="true"].today,
91
+ .wds-Calendar__option--month[aria-disabled="true"].today,
92
+ .wds-Calendar__option--year[aria-disabled="true"].today {
93
+ text-decoration-color: #768e9c;
94
+ text-decoration-color: var(--color-content-tertiary);
95
+ }
96
+ .wds-Calendar__option--day {
97
+ height: 40px;
98
+ height: var(--size-40);
99
+ border-radius: 9999px;
100
+ border-radius: var(--radius-full);
101
+ line-height: 40px;
102
+ line-height: var(--size-40);
103
+ width: 40px;
104
+ width: var(--size-40);
105
+ padding: 0;
106
+ display: inline-flex;
107
+ align-items: center;
108
+ justify-content: center;
109
+ }
110
+ .wds-Calendar__option--day.today {
111
+ -webkit-text-decoration: underline;
112
+ text-decoration: underline;
113
+ text-decoration-thickness: 2px;
114
+ text-underline-offset: 4px;
115
+ }
@@ -0,0 +1,68 @@
1
+ @import (reference) "./../../styles/variables/neptune-tokens.less";
2
+
3
+ .wds-Calendar__option--day,
4
+ .wds-Calendar__option--month,
5
+ .wds-Calendar__option--year {
6
+ width: 100%;
7
+ padding: var(--size-4) 0;
8
+ @media (--screen-400-zoom) {
9
+ padding: 0;
10
+ }
11
+ border: transparent;
12
+ border-radius: var(--radius-small);
13
+ background-color: transparent;
14
+ font-weight: var(--font-weight-semi-bold);
15
+ color: var(--color-content-primary);
16
+
17
+ &:focus {
18
+ background-color: var(--color-background-screen-hover);
19
+ }
20
+
21
+ &.disabled,
22
+ &[aria-disabled="true"] {
23
+ --ring-outline-color: var(--color-sentiment-content-primary);
24
+ color: var(--color-content-tertiary);
25
+ cursor: not-allowed;
26
+
27
+ &:hover,
28
+ &:focus {
29
+ filter: unset;
30
+ opacity: unset;
31
+ background-color: var(--color-sentiment-background-surface);
32
+ color: var(--color-sentiment-content-primary);
33
+ }
34
+
35
+ &.active {
36
+ &,
37
+ &:hover,
38
+ &:active,
39
+ &:focus {
40
+ filter: unset;
41
+ opacity: unset;
42
+ background-color: var(--color-sentiment-interactive-primary);
43
+ color: var(--color-sentiment-interactive-secondary);
44
+ }
45
+ }
46
+
47
+ &.today {
48
+ text-decoration-color: var(--color-content-tertiary);
49
+ }
50
+ }
51
+ }
52
+
53
+ .wds-Calendar__option--day {
54
+ height: var(--size-40);
55
+ border-radius: var(--radius-full);
56
+ line-height: var(--size-40);
57
+ width: var(--size-40);
58
+ padding: 0;
59
+ display: inline-flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+
63
+ &.today {
64
+ text-decoration: underline;
65
+ text-decoration-thickness: 2px;
66
+ text-underline-offset: 4px;
67
+ }
68
+ }
@@ -0,0 +1,112 @@
1
+ import { clsx } from 'clsx';
2
+ import { useEffect, useRef } from 'react';
3
+ import { useIntl } from 'react-intl';
4
+
5
+ import messages from '../Calendar.messages';
6
+ import SentimentSurface from '../../SentimentSurface';
7
+
8
+ interface TableLinkProps {
9
+ item: number;
10
+ type: 'day' | 'month' | 'year';
11
+ title?: string;
12
+ longTitle?: string;
13
+ active: boolean;
14
+ outOfRange: boolean;
15
+ disabled: boolean;
16
+ today: boolean;
17
+ autofocus?: boolean;
18
+ disabledReasonId?: string;
19
+ announceReasonOnFocus?: boolean;
20
+ onClick: (item: number) => void;
21
+ onFocus?: (item: number) => void;
22
+ }
23
+
24
+ const TableLink = ({
25
+ item,
26
+ type,
27
+ title,
28
+ longTitle,
29
+ active,
30
+ outOfRange,
31
+ disabled,
32
+ today,
33
+ autofocus,
34
+ disabledReasonId,
35
+ announceReasonOnFocus,
36
+ onClick,
37
+ onFocus,
38
+ }: TableLinkProps) => {
39
+ const buttonRef = useRef<HTMLButtonElement>(null);
40
+ // Distinguishes keyboard-driven .focus() (arrow keys) from screen-reader-initiated focus (VoiceOver cursor).
41
+ // Without this, the onFocus callback would re-trigger state updates that conflict with the already-committed focusedDate.
42
+ const isProgrammaticFocus = useRef(false);
43
+ const intl = useIntl();
44
+
45
+ useEffect(() => {
46
+ if (autofocus) {
47
+ setTimeout(() => {
48
+ isProgrammaticFocus.current = true;
49
+ buttonRef.current?.focus();
50
+ isProgrammaticFocus.current = false;
51
+ }, 0);
52
+ }
53
+ }, [autofocus]);
54
+
55
+ const isUnavailable = outOfRange || disabled;
56
+
57
+ const onCalendarClick = (event: React.MouseEvent) => {
58
+ event.preventDefault();
59
+ if (!isUnavailable) {
60
+ onClick(item);
61
+ }
62
+ };
63
+
64
+ const onCalendarFocus = () => {
65
+ if (!isProgrammaticFocus.current) {
66
+ onFocus?.(item);
67
+ }
68
+ };
69
+
70
+ const calculateAriaLabel = () => {
71
+ let label = longTitle || title || '';
72
+ if (active) {
73
+ label += `, ${intl.formatMessage(messages.selected)} ${intl.formatMessage(messages[type])}`;
74
+ }
75
+ if (isUnavailable) {
76
+ label += `, ${intl.formatMessage(messages.notAvailable)}`;
77
+ }
78
+ return label;
79
+ };
80
+
81
+ return (
82
+ <SentimentSurface
83
+ // @ts-expect-error - Generic forwardRef limitation in SentimentSurface
84
+ ref={buttonRef}
85
+ as="button"
86
+ data-calendar-cell
87
+ aria-describedby={
88
+ isUnavailable || (autofocus && announceReasonOnFocus) ? disabledReasonId : undefined
89
+ }
90
+ aria-disabled={isUnavailable || undefined}
91
+ aria-label={calculateAriaLabel()}
92
+ aria-pressed={active}
93
+ className={clsx(
94
+ `wds-Calendar__option--${type}`,
95
+ `tw-date-lookup-${type}-option np-text-body-default-bold`,
96
+ { active: !!active },
97
+ { today: !!today },
98
+ { disabled: !!isUnavailable },
99
+ )}
100
+ hasBaseStyles={false}
101
+ sentiment={isUnavailable ? 'negative' : 'neutral'}
102
+ tabIndex={autofocus ? 0 : -1}
103
+ type="button"
104
+ onClick={onCalendarClick}
105
+ onFocus={onCalendarFocus}
106
+ >
107
+ {title || item}
108
+ </SentimentSurface>
109
+ );
110
+ };
111
+
112
+ export default TableLink;
@@ -2,10 +2,11 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import { useIntl } from 'react-intl';
3
3
 
4
4
  import { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';
5
- import TableLink from '../../tableLink';
5
+ import TableLink from '../../TableLink';
6
6
 
7
7
  interface YearCalendarTableProps {
8
8
  selectedDate: Date | null;
9
+ focusedDate?: Date | null;
9
10
  min: Date | null;
10
11
  max: Date | null;
11
12
  viewYear: number;
@@ -19,6 +20,7 @@ const YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };
19
20
 
20
21
  const YearCalendarTable = ({
21
22
  selectedDate,
23
+ focusedDate,
22
24
  min,
23
25
  max,
24
26
  viewYear,
@@ -34,7 +36,8 @@ const YearCalendarTable = ({
34
36
  type="year"
35
37
  title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
36
38
  active={isActive(year)}
37
- disabled={isDisabled(year)}
39
+ outOfRange={isDisabled(year)}
40
+ disabled={false}
38
41
  today={isThisYear(year)}
39
42
  autofocus={autofocusYear === year}
40
43
  onClick={onSelect}
@@ -46,6 +49,10 @@ const YearCalendarTable = ({
46
49
  return !!(year === selectedDate?.getFullYear());
47
50
  };
48
51
 
52
+ const isFocused = (year: number) => {
53
+ return !!(year === focusedDate?.getFullYear());
54
+ };
55
+
49
56
  const isThisYear = (year: number) => {
50
57
  return year === new Date().getFullYear();
51
58
  };
@@ -56,7 +63,12 @@ const YearCalendarTable = ({
56
63
 
57
64
  const autofocusYear = (() => {
58
65
  const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);
59
- return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });
66
+ return getFocusableTime({
67
+ isActive: isFocused,
68
+ isNow: isThisYear,
69
+ isDisabled,
70
+ timeSpan: years,
71
+ });
60
72
  })();
61
73
 
62
74
  return (
@@ -8,6 +8,7 @@ import YearCalendarTable from './Table';
8
8
 
9
9
  interface YearCalendarProps extends WrappedComponentProps {
10
10
  selectedDate: Date | null;
11
+ focusedDate?: Date | null;
11
12
  min: Date | null;
12
13
  max: Date | null;
13
14
  viewYear: number;
@@ -33,21 +34,29 @@ class YearCalendar extends PureComponent<YearCalendarProps> {
33
34
  render() {
34
35
  const {
35
36
  selectedDate,
37
+ focusedDate,
36
38
  min,
37
39
  max,
38
40
  viewYear,
39
41
  placeholder,
40
42
  intl: { formatMessage },
41
43
  } = this.props;
44
+ const startYear = viewYear - (viewYear % 20);
45
+ const isPreviousDisabled = !!(min && startYear - 1 < min.getFullYear());
46
+ const isNextDisabled = !!(max && startYear + 20 > max.getFullYear());
47
+
42
48
  return (
43
49
  <>
44
50
  <DateHeader
45
51
  dateMode={formatMessage(messages.twentyYears)}
52
+ isPreviousDisabled={isPreviousDisabled}
53
+ isNextDisabled={isNextDisabled}
46
54
  onPreviousClick={this.selectPreviousYears}
47
55
  onNextClick={this.selectNextYears}
48
56
  />
49
57
  <YearCalendarTable
50
58
  selectedDate={selectedDate}
59
+ focusedDate={focusedDate}
51
60
  min={min}
52
61
  max={max}
53
62
  viewYear={viewYear}
@@ -0,0 +1,98 @@
1
+ import { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth';
2
+ import type { DisabledRules } from '../../Calendar.types';
3
+
4
+ describe('hasDisabledDatesInMonth', () => {
5
+ describe('weekdays', () => {
6
+ it('returns true when weekday rules exist (every month has all weekdays)', () => {
7
+ const rules: DisabledRules = { weekdays: ['sat', 'sun'], reason: 'Closed' };
8
+ expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true);
9
+ });
10
+
11
+ it('returns true for any month when weekday rules exist', () => {
12
+ const rules: DisabledRules = { weekdays: ['mon'], reason: 'Closed' };
13
+ expect(hasDisabledDatesInMonth(0, 2024, rules)).toBe(true);
14
+ expect(hasDisabledDatesInMonth(11, 2024, rules)).toBe(true);
15
+ });
16
+
17
+ it('returns false when weekdays array is empty', () => {
18
+ const rules: DisabledRules = { weekdays: [], reason: 'None' };
19
+ expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false);
20
+ });
21
+ });
22
+
23
+ describe('specific dates', () => {
24
+ const rules: DisabledRules = {
25
+ dates: [new Date(2024, 6, 11), new Date(2024, 6, 25), new Date(2025, 0, 1)],
26
+ reason: 'Bank holidays',
27
+ };
28
+
29
+ it('returns true when month contains a disabled date', () => {
30
+ expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true);
31
+ });
32
+
33
+ it('returns false when month has no disabled dates', () => {
34
+ expect(hasDisabledDatesInMonth(5, 2024, rules)).toBe(false);
35
+ });
36
+
37
+ it('returns true for another year with disabled date', () => {
38
+ expect(hasDisabledDatesInMonth(0, 2025, rules)).toBe(true);
39
+ });
40
+ });
41
+
42
+ describe('ranges', () => {
43
+ const rules: DisabledRules = {
44
+ ranges: [{ start: new Date(2024, 2, 29), end: new Date(2024, 3, 3) }],
45
+ reason: 'Maintenance',
46
+ };
47
+
48
+ it('returns true when range starts in the month', () => {
49
+ expect(hasDisabledDatesInMonth(2, 2024, rules)).toBe(true);
50
+ });
51
+
52
+ it('returns true when range ends in the month', () => {
53
+ expect(hasDisabledDatesInMonth(3, 2024, rules)).toBe(true);
54
+ });
55
+
56
+ it('returns true when range spans the entire month', () => {
57
+ const spanRules: DisabledRules = {
58
+ ranges: [{ start: new Date(2024, 0, 1), end: new Date(2024, 11, 31) }],
59
+ reason: 'Year-long',
60
+ };
61
+ expect(hasDisabledDatesInMonth(6, 2024, spanRules)).toBe(true);
62
+ });
63
+
64
+ it('returns false when range does not overlap the month', () => {
65
+ expect(hasDisabledDatesInMonth(4, 2024, rules)).toBe(false);
66
+ });
67
+ });
68
+
69
+ describe('min/max constraints', () => {
70
+ it('returns false when all disabled dates in month are outside min/max', () => {
71
+ const rules: DisabledRules = {
72
+ dates: [new Date(2024, 6, 1), new Date(2024, 6, 2)],
73
+ reason: 'Early',
74
+ };
75
+ const min = new Date(2024, 6, 10);
76
+ const max = new Date(2024, 6, 31);
77
+ expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(false);
78
+ });
79
+
80
+ it('returns true when weekdays exist regardless of min/max', () => {
81
+ const rules: DisabledRules = { weekdays: ['sat'], reason: 'Closed' };
82
+ const min = new Date(2024, 6, 10);
83
+ const max = new Date(2024, 6, 20);
84
+ expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(true);
85
+ });
86
+ });
87
+
88
+ describe('no rules', () => {
89
+ it('returns false when disabledRules is undefined', () => {
90
+ expect(hasDisabledDatesInMonth(6, 2024, undefined)).toBe(false);
91
+ });
92
+
93
+ it('returns false when only reason is provided', () => {
94
+ const rules: DisabledRules = { reason: 'Reason only' };
95
+ expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false);
96
+ });
97
+ });
98
+ });
@@ -0,0 +1,45 @@
1
+ import type { DisabledRules } from '../../Calendar.types';
2
+
3
+ export function hasDisabledDatesInMonth(
4
+ month: number,
5
+ year: number,
6
+ disabledRules?: DisabledRules,
7
+ min?: Date | null,
8
+ max?: Date | null,
9
+ ): boolean {
10
+ if (!disabledRules) return false;
11
+
12
+ if (disabledRules.weekdays?.length) {
13
+ return true;
14
+ }
15
+
16
+ const monthStart = new Date(year, month, 1);
17
+ const monthEnd = new Date(year, month + 1, 0);
18
+
19
+ if (disabledRules.dates?.length) {
20
+ const hasDateInMonth = disabledRules.dates.some((date) => {
21
+ if (date.getFullYear() !== year || date.getMonth() !== month) return false;
22
+ if (min && date < min) return false;
23
+ if (max && date > max) return false;
24
+ return true;
25
+ });
26
+ if (hasDateInMonth) return true;
27
+ }
28
+
29
+ if (disabledRules.ranges?.length) {
30
+ const hasOverlap = disabledRules.ranges.some((range) => {
31
+ const rangeStart = new Date(
32
+ range.start.getFullYear(),
33
+ range.start.getMonth(),
34
+ range.start.getDate(),
35
+ );
36
+ const rangeEnd = new Date(range.end.getFullYear(), range.end.getMonth(), range.end.getDate());
37
+ if (max && rangeStart > max) return false;
38
+ if (min && rangeEnd < min) return false;
39
+ return rangeStart <= monthEnd && rangeEnd >= monthStart;
40
+ });
41
+ if (hasOverlap) return true;
42
+ }
43
+
44
+ return false;
45
+ }
@@ -0,0 +1,2 @@
1
+ export { isDateDisabled } from './isDateDisabled/isDateDisabled';
2
+ export { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth/hasDisabledDatesInMonth';