@transferwise/components 46.156.0 → 46.157.1

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 (215) 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 +121 -17
  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 +122 -18
  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 +95 -0
  34. package/build/Calendar/TableLink/TableLink.js.map +1 -0
  35. package/build/Calendar/TableLink/TableLink.mjs +91 -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/clampToDayViewBoundary/clampToDayViewBoundary.js +24 -0
  46. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js.map +1 -0
  47. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs +22 -0
  48. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs.map +1 -0
  49. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +33 -0
  50. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +1 -0
  51. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +31 -0
  52. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +1 -0
  53. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js +40 -0
  54. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js.map +1 -0
  55. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs +38 -0
  56. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs.map +1 -0
  57. package/build/DateLookup/DateLookup.js +20 -9
  58. package/build/DateLookup/DateLookup.js.map +1 -1
  59. package/build/DateLookup/DateLookup.mjs +20 -9
  60. package/build/DateLookup/DateLookup.mjs.map +1 -1
  61. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.js +3 -5
  62. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.js.map +1 -1
  63. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.mjs +3 -5
  64. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.mjs.map +1 -1
  65. package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -1
  66. package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -1
  67. package/build/Typeahead/Typeahead.js +53 -27
  68. package/build/Typeahead/Typeahead.js.map +1 -1
  69. package/build/Typeahead/Typeahead.messages.js +3 -0
  70. package/build/Typeahead/Typeahead.messages.js.map +1 -1
  71. package/build/Typeahead/Typeahead.messages.mjs +3 -0
  72. package/build/Typeahead/Typeahead.messages.mjs.map +1 -1
  73. package/build/Typeahead/Typeahead.mjs +53 -27
  74. package/build/Typeahead/Typeahead.mjs.map +1 -1
  75. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js +2 -2
  76. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js.map +1 -1
  77. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs +2 -2
  78. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs.map +1 -1
  79. package/build/Typeahead/TypeaheadOption/TypeaheadOption.js +3 -1
  80. package/build/Typeahead/TypeaheadOption/TypeaheadOption.js.map +1 -1
  81. package/build/Typeahead/TypeaheadOption/TypeaheadOption.mjs +3 -1
  82. package/build/Typeahead/TypeaheadOption/TypeaheadOption.mjs.map +1 -1
  83. package/build/i18n/en.json +5 -0
  84. package/build/i18n/en.json.js +5 -0
  85. package/build/i18n/en.json.js.map +1 -1
  86. package/build/i18n/en.json.mjs +5 -0
  87. package/build/i18n/en.json.mjs.map +1 -1
  88. package/build/index.js +2 -2
  89. package/build/index.mjs +1 -1
  90. package/build/main.css +147 -43
  91. package/build/styles/Calendar/Calendar.css +112 -37
  92. package/build/styles/Calendar/TableLink/TableLink.css +115 -0
  93. package/build/styles/Typeahead/Typeahead.css +14 -0
  94. package/build/styles/Typeahead/TypeaheadOption/TypeaheadOption.css +5 -0
  95. package/build/styles/main.css +147 -43
  96. package/build/types/Body/Body.d.ts +2 -2
  97. package/build/types/Calendar/Calendar.constants.d.ts +2 -0
  98. package/build/types/Calendar/Calendar.constants.d.ts.map +1 -0
  99. package/build/types/Calendar/Calendar.d.ts +16 -3
  100. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  101. package/build/types/Calendar/Calendar.messages.d.ts +20 -0
  102. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  103. package/build/types/Calendar/Calendar.types.d.ts +32 -0
  104. package/build/types/Calendar/Calendar.types.d.ts.map +1 -0
  105. package/build/types/Calendar/DateHeader/DateHeader.d.ts +2 -0
  106. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  107. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +7 -1
  108. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  109. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +6 -0
  110. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  111. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +1 -0
  112. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  113. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +2 -1
  114. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  115. package/build/types/Calendar/{tableLink → TableLink}/TableLink.d.ts +5 -1
  116. package/build/types/Calendar/TableLink/TableLink.d.ts.map +1 -0
  117. package/build/types/Calendar/TableLink/index.d.ts.map +1 -0
  118. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +2 -1
  119. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  120. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +1 -0
  121. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  122. package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts +8 -0
  123. package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts.map +1 -0
  124. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +3 -0
  125. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +1 -0
  126. package/build/types/Calendar/_helpers/index.d.ts +4 -0
  127. package/build/types/Calendar/_helpers/index.d.ts.map +1 -0
  128. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts +3 -0
  129. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts.map +1 -0
  130. package/build/types/Calendar/index.d.ts +1 -0
  131. package/build/types/Calendar/index.d.ts.map +1 -1
  132. package/build/types/DateLookup/DateLookup.d.ts +24 -5
  133. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  134. package/build/types/DateLookup/index.d.ts +1 -0
  135. package/build/types/DateLookup/index.d.ts.map +1 -1
  136. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts +6 -4
  137. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts.map +1 -1
  138. package/build/types/IconButton/IconButton.d.ts +1 -1
  139. package/build/types/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts +1 -1
  140. package/build/types/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +1 -1
  141. package/build/types/MoneyInput/MoneyInput.d.ts +1 -1
  142. package/build/types/MoneyInput/MoneyInput.d.ts.map +1 -1
  143. package/build/types/Title/Title.d.ts +2 -2
  144. package/build/types/Typeahead/Typeahead.d.ts.map +1 -1
  145. package/build/types/Typeahead/Typeahead.messages.d.ts +5 -0
  146. package/build/types/Typeahead/Typeahead.messages.d.ts.map +1 -1
  147. package/build/types/Typeahead/TypeaheadInput/TypeaheadInput.d.ts.map +1 -1
  148. package/build/types/Typeahead/TypeaheadOption/TypeaheadOption.d.ts +1 -0
  149. package/build/types/Typeahead/TypeaheadOption/TypeaheadOption.d.ts.map +1 -1
  150. package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
  151. package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
  152. package/build/types/index.d.ts +3 -2
  153. package/build/types/index.d.ts.map +1 -1
  154. package/build/types/test-utils/index.d.ts +10 -0
  155. package/build/types/test-utils/index.d.ts.map +1 -1
  156. package/package.json +3 -3
  157. package/src/Calendar/Calendar.constants.ts +5 -0
  158. package/src/Calendar/Calendar.css +112 -37
  159. package/src/Calendar/Calendar.disabledDates.test.tsx +610 -0
  160. package/src/Calendar/Calendar.less +5 -35
  161. package/src/Calendar/Calendar.messages.ts +21 -0
  162. package/src/Calendar/Calendar.test.tsx +342 -32
  163. package/src/Calendar/Calendar.tsx +169 -19
  164. package/src/Calendar/Calendar.types.ts +35 -0
  165. package/src/Calendar/DateHeader/DateHeader.tsx +6 -0
  166. package/src/Calendar/DayCalendar/DayCalendar.tsx +39 -1
  167. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +67 -27
  168. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +8 -0
  169. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +15 -3
  170. package/src/Calendar/TableLink/TableLink.css +115 -0
  171. package/src/Calendar/TableLink/TableLink.less +68 -0
  172. package/src/Calendar/TableLink/TableLink.tsx +117 -0
  173. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +15 -3
  174. package/src/Calendar/YearCalendar/YearCalendar.tsx +9 -0
  175. package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.test.ts +90 -0
  176. package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.ts +25 -0
  177. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +98 -0
  178. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +45 -0
  179. package/src/Calendar/_helpers/index.ts +3 -0
  180. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.test.ts +169 -0
  181. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.ts +59 -0
  182. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +118 -0
  183. package/src/Calendar/_stories/Calendar.story.tsx +144 -4
  184. package/src/Calendar/_stories/Calendar.test.story.tsx +114 -0
  185. package/src/Calendar/index.ts +7 -0
  186. package/src/DateLookup/DateLookup.disabledDates.test.tsx +312 -0
  187. package/src/DateLookup/DateLookup.test.tsx +34 -37
  188. package/src/DateLookup/DateLookup.tsx +37 -13
  189. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +108 -0
  190. package/src/DateLookup/_stories/DateLookup.story.tsx +126 -2
  191. package/src/DateLookup/index.ts +6 -0
  192. package/src/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.tsx +12 -13
  193. package/src/Inputs/SelectInput/SelectInput.test.tsx +37 -0
  194. package/src/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +1 -1
  195. package/src/Typeahead/Typeahead.css +14 -0
  196. package/src/Typeahead/Typeahead.less +8 -0
  197. package/src/Typeahead/Typeahead.messages.ts +5 -0
  198. package/src/Typeahead/Typeahead.test.tsx +80 -3
  199. package/src/Typeahead/Typeahead.tsx +50 -27
  200. package/src/Typeahead/TypeaheadInput/TypeaheadInput.tsx +2 -6
  201. package/src/Typeahead/TypeaheadOption/TypeaheadOption.css +5 -0
  202. package/src/Typeahead/TypeaheadOption/TypeaheadOption.less +9 -0
  203. package/src/Typeahead/TypeaheadOption/TypeaheadOption.tsx +4 -2
  204. package/src/i18n/en.json +4 -0
  205. package/src/index.ts +3 -2
  206. package/src/main.css +147 -43
  207. package/build/Calendar/tableLink/TableLink.js +0 -61
  208. package/build/Calendar/tableLink/TableLink.js.map +0 -1
  209. package/build/Calendar/tableLink/TableLink.mjs +0 -57
  210. package/build/Calendar/tableLink/TableLink.mjs.map +0 -1
  211. package/build/types/Calendar/tableLink/TableLink.d.ts.map +0 -1
  212. package/build/types/Calendar/tableLink/index.d.ts.map +0 -1
  213. package/src/Calendar/tableLink/TableLink.tsx +0 -77
  214. /package/build/types/Calendar/{tableLink → TableLink}/index.d.ts +0 -0
  215. /package/src/Calendar/{tableLink → TableLink}/index.ts +0 -0
@@ -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,3 @@
1
+ export { clampToDayViewBoundary } from './clampToDayViewBoundary/clampToDayViewBoundary';
2
+ export { isDateDisabled } from './isDateDisabled/isDateDisabled';
3
+ export { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth/hasDisabledDatesInMonth';
@@ -0,0 +1,169 @@
1
+ import { isDateDisabled } from './isDateDisabled';
2
+ import type { DisabledRules } from '../../Calendar.types';
3
+
4
+ describe('isDateDisabled', () => {
5
+ describe('when no rules provided', () => {
6
+ it('returns false when disabledRules is undefined', () => {
7
+ expect(isDateDisabled(new Date('2024-07-15'), undefined)).toBe(false);
8
+ });
9
+
10
+ it('returns false when disabledRules has only reason', () => {
11
+ const rules: DisabledRules = { reason: 'some reason' };
12
+ expect(isDateDisabled(new Date('2024-07-15'), rules)).toBe(false);
13
+ });
14
+ });
15
+
16
+ describe('weekdays', () => {
17
+ const rules: DisabledRules = {
18
+ weekdays: ['sat', 'sun'],
19
+ reason: 'Closed on weekends',
20
+ };
21
+
22
+ it('returns true for a Saturday', () => {
23
+ // 2024-07-13 is a Saturday
24
+ expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(true);
25
+ });
26
+
27
+ it('returns true for a Sunday', () => {
28
+ // 2024-07-14 is a Sunday
29
+ expect(isDateDisabled(new Date(2024, 6, 14), rules)).toBe(true);
30
+ });
31
+
32
+ it('returns false for a Monday', () => {
33
+ // 2024-07-15 is a Monday
34
+ expect(isDateDisabled(new Date(2024, 6, 15), rules)).toBe(false);
35
+ });
36
+
37
+ it('returns false for a Friday', () => {
38
+ // 2024-07-12 is a Friday
39
+ expect(isDateDisabled(new Date(2024, 6, 12), rules)).toBe(false);
40
+ });
41
+
42
+ it('handles single weekday rule', () => {
43
+ const singleDay: DisabledRules = { weekdays: ['wed'], reason: 'Closed' };
44
+ // 2024-07-17 is a Wednesday
45
+ expect(isDateDisabled(new Date(2024, 6, 17), singleDay)).toBe(true);
46
+ // 2024-07-18 is a Thursday
47
+ expect(isDateDisabled(new Date(2024, 6, 18), singleDay)).toBe(false);
48
+ });
49
+ });
50
+
51
+ describe('specific dates', () => {
52
+ const rules: DisabledRules = {
53
+ dates: [new Date(2024, 6, 11), new Date(2025, 1, 12), new Date(2025, 4, 1)],
54
+ reason: 'Bank holidays',
55
+ };
56
+
57
+ it('returns true for a disabled date', () => {
58
+ expect(isDateDisabled(new Date(2024, 6, 11), rules)).toBe(true);
59
+ });
60
+
61
+ it('returns false for a non-disabled date', () => {
62
+ expect(isDateDisabled(new Date(2024, 6, 12), rules)).toBe(false);
63
+ });
64
+
65
+ it('compares date-only, ignoring time', () => {
66
+ const dateWithTime = new Date(2024, 6, 11, 14, 30, 0);
67
+ expect(isDateDisabled(dateWithTime, rules)).toBe(true);
68
+ });
69
+
70
+ it('handles disabled dates that have non-zero time components', () => {
71
+ const rulesWithTime: DisabledRules = {
72
+ dates: [new Date(2024, 6, 11, 23, 59, 59)],
73
+ reason: 'Holiday',
74
+ };
75
+ expect(isDateDisabled(new Date(2024, 6, 11), rulesWithTime)).toBe(true);
76
+ });
77
+ });
78
+
79
+ describe('ranges', () => {
80
+ const rules: DisabledRules = {
81
+ ranges: [
82
+ { start: new Date(2024, 2, 29), end: new Date(2024, 3, 3) },
83
+ { start: new Date(2024, 11, 24), end: new Date(2024, 11, 26) },
84
+ ],
85
+ reason: 'Scheduled maintenance',
86
+ };
87
+
88
+ it('returns true for start of range (inclusive)', () => {
89
+ expect(isDateDisabled(new Date(2024, 2, 29), rules)).toBe(true);
90
+ });
91
+
92
+ it('returns true for end of range (inclusive)', () => {
93
+ expect(isDateDisabled(new Date(2024, 3, 3), rules)).toBe(true);
94
+ });
95
+
96
+ it('returns true for date within range', () => {
97
+ expect(isDateDisabled(new Date(2024, 2, 31), rules)).toBe(true);
98
+ });
99
+
100
+ it('returns false for date before range', () => {
101
+ expect(isDateDisabled(new Date(2024, 2, 28), rules)).toBe(false);
102
+ });
103
+
104
+ it('returns false for date after range', () => {
105
+ expect(isDateDisabled(new Date(2024, 3, 4), rules)).toBe(false);
106
+ });
107
+
108
+ it('handles second range', () => {
109
+ expect(isDateDisabled(new Date(2024, 11, 25), rules)).toBe(true);
110
+ expect(isDateDisabled(new Date(2024, 11, 27), rules)).toBe(false);
111
+ });
112
+
113
+ it('correctly checks a date with non-midnight time against a range', () => {
114
+ const dateWithTime = new Date(2024, 2, 31, 14, 30, 0);
115
+ expect(isDateDisabled(dateWithTime, rules)).toBe(true);
116
+ });
117
+
118
+ it('correctly excludes a date with non-midnight time outside a range', () => {
119
+ const dateWithTime = new Date(2024, 2, 28, 23, 59, 59);
120
+ expect(isDateDisabled(dateWithTime, rules)).toBe(false);
121
+ });
122
+ });
123
+
124
+ describe('combined rules (additive)', () => {
125
+ const rules: DisabledRules = {
126
+ weekdays: ['sat', 'sun'],
127
+ dates: [new Date(2024, 6, 15)], // Monday
128
+ ranges: [{ start: new Date(2024, 6, 22), end: new Date(2024, 6, 24) }],
129
+ reason: 'Multiple rules',
130
+ };
131
+
132
+ it('disables by weekday', () => {
133
+ // 2024-07-13 is Saturday
134
+ expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(true);
135
+ });
136
+
137
+ it('disables by specific date', () => {
138
+ // 2024-07-15 is Monday but explicitly disabled
139
+ expect(isDateDisabled(new Date(2024, 6, 15), rules)).toBe(true);
140
+ });
141
+
142
+ it('disables by range', () => {
143
+ // 2024-07-23 is Tuesday but in range
144
+ expect(isDateDisabled(new Date(2024, 6, 23), rules)).toBe(true);
145
+ });
146
+
147
+ it('allows date not matching any rule', () => {
148
+ // 2024-07-16 is Tuesday, not in dates or ranges
149
+ expect(isDateDisabled(new Date(2024, 6, 16), rules)).toBe(false);
150
+ });
151
+ });
152
+
153
+ describe('edge cases', () => {
154
+ it('handles empty weekdays array', () => {
155
+ const rules: DisabledRules = { weekdays: [], reason: 'Empty' };
156
+ expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
157
+ });
158
+
159
+ it('handles empty dates array', () => {
160
+ const rules: DisabledRules = { dates: [], reason: 'Empty' };
161
+ expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
162
+ });
163
+
164
+ it('handles empty ranges array', () => {
165
+ const rules: DisabledRules = { ranges: [], reason: 'Empty' };
166
+ expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
167
+ });
168
+ });
169
+ });
@@ -0,0 +1,59 @@
1
+ import type { DisabledRules, WeekDayType } from '../../Calendar.types';
2
+
3
+ const DAY_INDEX_TO_WEEKDAY: Record<number, WeekDayType> = {
4
+ 0: 'sun',
5
+ 1: 'mon',
6
+ 2: 'tue',
7
+ 3: 'wed',
8
+ 4: 'thu',
9
+ 5: 'fri',
10
+ 6: 'sat',
11
+ };
12
+
13
+ export function isDateDisabled(date: Date, disabledRules?: DisabledRules): boolean {
14
+ if (!disabledRules) return false;
15
+
16
+ if (disabledRules.weekdays?.length) {
17
+ const weekday = DAY_INDEX_TO_WEEKDAY[date.getDay()];
18
+ if (disabledRules.weekdays.includes(weekday)) return true;
19
+ }
20
+
21
+ if (disabledRules.dates?.length) {
22
+ const year = date.getFullYear();
23
+ const month = date.getMonth();
24
+ const day = date.getDate();
25
+ if (
26
+ disabledRules.dates.some(
27
+ (disabledDate) =>
28
+ disabledDate.getFullYear() === year &&
29
+ disabledDate.getMonth() === month &&
30
+ disabledDate.getDate() === day,
31
+ )
32
+ ) {
33
+ return true;
34
+ }
35
+ }
36
+
37
+ if (disabledRules.ranges?.length) {
38
+ const dateStart = date.getTime();
39
+ if (
40
+ disabledRules.ranges.some((range) => {
41
+ const rangeStart = new Date(
42
+ range.start.getFullYear(),
43
+ range.start.getMonth(),
44
+ range.start.getDate(),
45
+ ).getTime();
46
+ const rangeEnd = new Date(
47
+ range.end.getFullYear(),
48
+ range.end.getMonth(),
49
+ range.end.getDate(),
50
+ ).getTime();
51
+ return dateStart >= rangeStart && dateStart <= rangeEnd;
52
+ })
53
+ ) {
54
+ return true;
55
+ }
56
+ }
57
+
58
+ return false;
59
+ }
@@ -0,0 +1,118 @@
1
+ import { Meta } from '@storybook/addon-docs/blocks';
2
+
3
+ <Meta title="Forms/Calendar/Accessibility" />
4
+
5
+ # Accessibility
6
+
7
+ Calendar is a fully keyboard-accessible date picker grid. All dates — including disabled ones — are reachable via keyboard so that screen reader users can discover which dates are unavailable and why.
8
+
9
+ ## Keyboard Support
10
+
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <th>Key</th>
15
+ <th>Action</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr>
20
+ <td>
21
+ <code>ArrowLeft</code>
22
+ </td>
23
+ <td>Move focus to previous day / month / year</td>
24
+ </tr>
25
+ <tr>
26
+ <td>
27
+ <code>ArrowRight</code>
28
+ </td>
29
+ <td>Move focus to next day / month / year</td>
30
+ </tr>
31
+ <tr>
32
+ <td>
33
+ <code>ArrowUp</code>
34
+ </td>
35
+ <td>Move focus up by one week (7 days) / 4 months / 4 years</td>
36
+ </tr>
37
+ <tr>
38
+ <td>
39
+ <code>ArrowDown</code>
40
+ </td>
41
+ <td>Move focus down by one week (7 days) / 4 months / 4 years</td>
42
+ </tr>
43
+ <tr>
44
+ <td>
45
+ <code>Enter</code> / <code>Space</code>
46
+ </td>
47
+ <td>Select the focused date (if enabled)</td>
48
+ </tr>
49
+ </tbody>
50
+ </table>
51
+
52
+ <br /> Navigation **does not skip** disabled dates. Users can arrow through every date in the grid
53
+ regardless of its enabled state.
54
+
55
+ ## Screen Reader Announcements
56
+
57
+ Each date cell is a `<button>` with an `aria-label` in a human-readable long format (e.g. "6 July 2024") constructed via `Intl.DateTimeFormat` for full locale support.
58
+
59
+ ### Active (Selected) Date
60
+
61
+ The currently selected date includes "selected day" in its aria-label:
62
+
63
+ > "6 July 2024, selected day"
64
+
65
+ ### Disabled Dates (via `disabledRules`)
66
+
67
+ Dates disabled via `disabledRules` remain focusable and keyboard-navigable. They are announced with additional context:
68
+
69
+ - `aria-disabled="true"` signals the date is not selectable
70
+ - The aria-label appends "not available" (e.g. "6 July 2024, not available")
71
+ - `aria-describedby` links to the InlinePrompt element containing the reason text
72
+
73
+ This means a screen reader will announce something like:
74
+
75
+ > "6 July 2024, not available — We are closed on weekends. button, dimmed."
76
+
77
+ ### Disabled + Selected
78
+
79
+ If the focused date is both active and disabled:
80
+
81
+ > "6 July 2024, selected day, not available"
82
+
83
+ ### Out-of-Range Dates (via `min`/`max`)
84
+
85
+ Dates outside `min`/`max` boundaries use `aria-disabled="true"` (not the native HTML `disabled` attribute). They are rendered as interactive buttons in the grid: they can be clicked and the `aria-label` appends "not available". Arrow key navigation clamps at the boundary, so keyboard users cannot navigate into out-of-range cells — but they remain visible and clickable for pointer users.
86
+
87
+ This distinction is intentional: `min`/`max` defines a hard boundary (the calendar simply doesn't extend beyond it), while `disabledRules` marks dates that exist but are unavailable (users should be able to discover them and understand why).
88
+
89
+ ## InlinePrompt Behaviour
90
+
91
+ An `InlinePrompt` renders below the day grid when the current month contains disabled dates. It displays the `disabledRules.reason` text.
92
+
93
+ ### When It Appears
94
+
95
+ The prompt is visible when **all** of the following are true:
96
+
97
+ 1. The Calendar is in day view
98
+ 2. `disabledRules.reason` is provided
99
+ 3. The currently displayed month contains at least one disabled date
100
+
101
+ ### How It's Announced
102
+
103
+ The prompt is linked to disabled date cells via `aria-describedby`. This means the reason text is read as a description when a disabled cell receives focus — screen readers announce it after the label and role.
104
+
105
+ The prompt element has an `id` that matches the `aria-describedby` on each disabled cell. It is **not** a live region (`role="alert"` or `role="status"`) because:
106
+
107
+ - It does not change dynamically while focus is on a disabled cell
108
+ - Announcing it on every arrow key press would be disruptive
109
+ - The `aria-describedby` relationship already ensures it's read on focus
110
+
111
+ ### Sentiment
112
+
113
+ The prompt's visual sentiment changes based on the currently focused date:
114
+
115
+ - **Negative** (red) — when the focused date is disabled
116
+ - **Neutral** — when the focused date is enabled
117
+
118
+ This is a visual-only change and does not affect screen reader output.
@@ -1,22 +1,47 @@
1
1
  import { useState } from 'react';
2
2
  import { StoryObj } from '@storybook/react-webpack5';
3
- import { userEvent, within } from 'storybook/test';
3
+ import { fn, userEvent, within } from 'storybook/test';
4
4
  import {
5
5
  createSandboxStory,
6
6
  globalScope,
7
7
  } from '../../../.storybook/components/sandbox/SandboxEditor';
8
+ import { storySourceWithoutNoise } from '../../../.storybook/helpers';
8
9
  import Calendar, { type CalendarProps } from '../Calendar';
9
10
  import Modal from '../../Modal';
10
11
  import Button from '../../Button';
12
+ import { action } from 'storybook/actions';
11
13
 
12
- /** Inline calendar for selecting a single date, with optional min/max bounds. */
13
14
  export default {
14
15
  component: Calendar,
15
16
  title: 'Forms/Calendar',
17
+ args: {
18
+ value: undefined,
19
+ min: undefined,
20
+ max: undefined,
21
+ monthFormat: undefined,
22
+ placeholder: undefined,
23
+ disabledRules: undefined,
24
+ onChange: fn(),
25
+ onDateFocus: fn(),
26
+ },
16
27
  argTypes: {
17
28
  monthFormat: { control: 'select', options: ['long', 'short'] },
18
29
  min: { control: 'date' },
19
30
  max: { control: 'date' },
31
+ disabledRules: {
32
+ control: false,
33
+ table: {
34
+ type: {
35
+ summary: 'DisabledRules',
36
+ detail: `{
37
+ weekdays?: ('mon'|'tue'|'wed'|'thu'|'fri'|'sat'|'sun')[]
38
+ dates?: Date[]
39
+ ranges?: { start: Date; end: Date }[]
40
+ reason: string // required — shown in prompt, linked via aria-describedby
41
+ }`,
42
+ },
43
+ },
44
+ },
20
45
  },
21
46
  };
22
47
 
@@ -30,12 +55,17 @@ thePast.setUTCDate(epoch.getUTCDate() - 10);
30
55
 
31
56
  export const Sandbox = createSandboxStory({
32
57
  code: `const App = () => {
33
- const [value, setValue] = React.useState(new Date('2024-06-15'));
58
+ const [value, setValue] = React.useState(new Date(2024, 5, 18));
34
59
 
35
60
  return (
36
61
  <Calendar
37
62
  monthFormat="long"
38
63
  value={value}
64
+ disabledRules={{
65
+ weekdays: ['sat', 'sun'],
66
+ dates: [new Date(2024, 5, 19)],
67
+ reason: 'Weekends and holidays are unavailable.',
68
+ }}
39
69
  onChange={(date) => setValue(date)}
40
70
  />
41
71
  );
@@ -52,7 +82,13 @@ export const Basic: Story = {
52
82
  min={args.min ? new Date(args.min) : thePast}
53
83
  max={args.max ? new Date(args.max) : theFuture}
54
84
  value={value}
55
- onChange={(v) => setValue(v)}
85
+ onDateFocus={(date, options) => {
86
+ action('onDateFocus')(date, options);
87
+ }}
88
+ onChange={(date) => {
89
+ action('onChange')(date);
90
+ setValue(date);
91
+ }}
56
92
  />
57
93
  );
58
94
  },
@@ -102,3 +138,107 @@ export const InsideModal: Story = {
102
138
  await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
103
139
  },
104
140
  };
141
+
142
+ /**
143
+ * Use `disabledRules` to disable specific weekdays, individual dates, or date ranges.
144
+ * Disabled dates remain focusable and keyboard-navigable — clicking or focusing one
145
+ * fires `onDateFocus` with `isEnabled: false` and shows a negative inline prompt with
146
+ * the `reason` text. `min`/`max` out-of-range dates show a built-in boundary prompt
147
+ * (e.g. "Please select a date between 4 December 2024 and 18 January 2025.").
148
+ *
149
+ * The `reason` field is **required for accessibility**: it renders as an InlinePrompt
150
+ * below the grid and is linked to every disabled cell via `aria-describedby`, so screen
151
+ * reader users understand why a date is unavailable. For per-date reason customisation
152
+ * see [DisabledDatesWithDynamicReason](#disabled-dates-with-dynamic-reason).
153
+ */
154
+ export const DisabledDates: Story = storySourceWithoutNoise<CalendarProps>({
155
+ args: {
156
+ min: new Date(2024, 11, 4),
157
+ max: new Date(2025, 0, 18),
158
+ },
159
+ render: function Render(args) {
160
+ const [value, setValue] = useState<Date | null>(new Date(2024, 11, 13));
161
+
162
+ return (
163
+ <Calendar
164
+ value={value}
165
+ min={args.min ? new Date(args.min) : undefined}
166
+ max={args.max ? new Date(args.max) : undefined}
167
+ disabledRules={{
168
+ weekdays: ['sat', 'sun'],
169
+ dates: [new Date(2024, 11, 10), new Date(2025, 0, 15)],
170
+ ranges: [{ start: new Date(2024, 11, 23), end: new Date(2024, 11, 27) }],
171
+ reason: 'Some dates are unavailable for this service.',
172
+ }}
173
+ onDateFocus={(date, { isEnabled }) => {
174
+ action('onDateFocus')(date, { isEnabled });
175
+ }}
176
+ onChange={(date) => {
177
+ action('onChange')(date);
178
+ setValue(date);
179
+ }}
180
+ />
181
+ );
182
+ },
183
+ });
184
+
185
+ /**
186
+ * When different disabled dates warrant different explanations, drive the `reason`
187
+ * dynamically from `onDateFocus`. The `isEnabled` flag tells you whether the focused
188
+ * date is selectable; from there you can look up the specific reason and update state.
189
+ *
190
+ * `min`/`max` out-of-range dates are handled automatically — the component shows a
191
+ * built-in prompt with the boundary dates, so `determineReason` only needs to cover
192
+ * rule-disabled dates.
193
+ */
194
+ export const DisabledDatesWithDynamicReason: Story = storySourceWithoutNoise<CalendarProps>({
195
+ args: {
196
+ min: new Date(2024, 11, 4),
197
+ max: new Date(2025, 0, 18),
198
+ },
199
+ render: function Render(args) {
200
+ const DEFAULT_REASON = 'Some dates are unavailable for this service.';
201
+ const maintenanceDays = [new Date(2024, 11, 10), new Date(2025, 0, 15)];
202
+ const [value, setValue] = useState<Date | null>(new Date(2024, 11, 13));
203
+ const [reason, setReason] = useState(DEFAULT_REASON);
204
+
205
+ function determineReason(date: Date, isEnabled: boolean): string {
206
+ if (isEnabled) return DEFAULT_REASON;
207
+ if (
208
+ maintenanceDays.some(
209
+ (maintenanceDay) => maintenanceDay.toDateString() === date.toDateString(),
210
+ )
211
+ ) {
212
+ return 'This date is a maintenance day.';
213
+ }
214
+ if (date.getDay() === 0 || date.getDay() === 6) {
215
+ return 'We do not operate on weekends.';
216
+ }
217
+ return 'This date is unavailable.';
218
+ }
219
+
220
+ return (
221
+ <Calendar
222
+ value={value}
223
+ min={args.min ? new Date(args.min) : undefined}
224
+ max={args.max ? new Date(args.max) : undefined}
225
+ disabledRules={{
226
+ weekdays: ['sat', 'sun'],
227
+ dates: maintenanceDays,
228
+ ranges: [{ start: new Date(2024, 11, 23), end: new Date(2024, 11, 27) }],
229
+ reason,
230
+ }}
231
+ onDateFocus={(date, { isEnabled }) => {
232
+ action('onDateFocus')(date, { isEnabled });
233
+ if (date) {
234
+ setReason(determineReason(date, isEnabled));
235
+ }
236
+ }}
237
+ onChange={(date) => {
238
+ action('onChange')(date);
239
+ setValue(date);
240
+ }}
241
+ />
242
+ );
243
+ },
244
+ });