@transferwise/components 0.0.0-experimental-fa3aa98 → 0.0.0-experimental-f4a328f

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 (201) hide show
  1. package/build/Calendar/Calendar.js +16 -94
  2. package/build/Calendar/Calendar.js.map +1 -1
  3. package/build/Calendar/Calendar.messages.js +0 -12
  4. package/build/Calendar/Calendar.messages.js.map +1 -1
  5. package/build/Calendar/Calendar.messages.mjs +0 -12
  6. package/build/Calendar/Calendar.messages.mjs.map +1 -1
  7. package/build/Calendar/Calendar.mjs +17 -95
  8. package/build/Calendar/Calendar.mjs.map +1 -1
  9. package/build/Calendar/DateHeader/DateHeader.js +1 -5
  10. package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
  11. package/build/Calendar/DateHeader/DateHeader.mjs +1 -5
  12. package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
  13. package/build/Calendar/DayCalendar/DayCalendar.js +0 -14
  14. package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
  15. package/build/Calendar/DayCalendar/DayCalendar.mjs +0 -14
  16. package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
  17. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +19 -53
  18. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
  19. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +19 -53
  20. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
  21. package/build/Calendar/MonthCalendar/MonthCalendar.js +0 -6
  22. package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
  23. package/build/Calendar/MonthCalendar/MonthCalendar.mjs +0 -6
  24. package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
  25. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +3 -8
  26. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
  27. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +3 -8
  28. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
  29. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +3 -8
  30. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
  31. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +3 -8
  32. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
  33. package/build/Calendar/YearCalendar/YearCalendar.js +0 -7
  34. package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
  35. package/build/Calendar/YearCalendar/YearCalendar.mjs +0 -7
  36. package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
  37. package/build/Calendar/{TableLink → tableLink}/TableLink.js +11 -26
  38. package/build/Calendar/tableLink/TableLink.js.map +1 -0
  39. package/build/Calendar/{TableLink → tableLink}/TableLink.mjs +11 -26
  40. package/build/Calendar/tableLink/TableLink.mjs.map +1 -0
  41. package/build/DateLookup/DateLookup.js +9 -20
  42. package/build/DateLookup/DateLookup.js.map +1 -1
  43. package/build/DateLookup/DateLookup.mjs +9 -20
  44. package/build/DateLookup/DateLookup.mjs.map +1 -1
  45. package/build/Markup/Markup.js +137 -0
  46. package/build/Markup/Markup.js.map +1 -0
  47. package/build/Markup/Markup.mjs +132 -0
  48. package/build/Markup/Markup.mjs.map +1 -0
  49. package/build/Markup/constants.js +36 -0
  50. package/build/Markup/constants.js.map +1 -0
  51. package/build/Markup/constants.mjs +29 -0
  52. package/build/Markup/constants.mjs.map +1 -0
  53. package/build/Markup/utils/parseMarkup.js +236 -0
  54. package/build/Markup/utils/parseMarkup.js.map +1 -0
  55. package/build/Markup/utils/parseMarkup.mjs +231 -0
  56. package/build/Markup/utils/parseMarkup.mjs.map +1 -0
  57. package/build/Markup/utils/sanitise.js +114 -0
  58. package/build/Markup/utils/sanitise.js.map +1 -0
  59. package/build/Markup/utils/sanitise.mjs +111 -0
  60. package/build/Markup/utils/sanitise.mjs.map +1 -0
  61. package/build/i18n/en.json +0 -4
  62. package/build/i18n/en.json.js +0 -4
  63. package/build/i18n/en.json.js.map +1 -1
  64. package/build/i18n/en.json.mjs +0 -4
  65. package/build/i18n/en.json.mjs.map +1 -1
  66. package/build/index.js +4 -2
  67. package/build/index.js.map +1 -1
  68. package/build/index.mjs +2 -1
  69. package/build/index.mjs.map +1 -1
  70. package/build/main.css +78 -123
  71. package/build/styles/Calendar/Calendar.css +37 -112
  72. package/build/styles/Markup/Markup.css +28 -0
  73. package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  74. package/build/styles/main.css +78 -123
  75. package/build/types/Body/Body.d.ts +2 -2
  76. package/build/types/Calendar/Calendar.d.ts +3 -16
  77. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  78. package/build/types/Calendar/Calendar.messages.d.ts +0 -20
  79. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  80. package/build/types/Calendar/DateHeader/DateHeader.d.ts +0 -2
  81. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  82. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +1 -5
  83. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  84. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +0 -4
  85. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  86. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +0 -1
  87. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  88. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +1 -2
  89. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  90. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +1 -2
  91. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  92. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +0 -1
  93. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  94. package/build/types/Calendar/index.d.ts +0 -1
  95. package/build/types/Calendar/index.d.ts.map +1 -1
  96. package/build/types/Calendar/{TableLink → tableLink}/TableLink.d.ts +1 -3
  97. package/build/types/Calendar/tableLink/TableLink.d.ts.map +1 -0
  98. package/build/types/Calendar/tableLink/index.d.ts.map +1 -0
  99. package/build/types/DateLookup/DateLookup.d.ts +5 -24
  100. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  101. package/build/types/DateLookup/index.d.ts +0 -1
  102. package/build/types/DateLookup/index.d.ts.map +1 -1
  103. package/build/types/IconButton/IconButton.d.ts +1 -1
  104. package/build/types/Markup/Markup.d.ts +18 -0
  105. package/build/types/Markup/Markup.d.ts.map +1 -0
  106. package/build/types/Markup/Markup.types.d.ts +77 -0
  107. package/build/types/Markup/Markup.types.d.ts.map +1 -0
  108. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
  109. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
  110. package/build/types/Markup/constants.d.ts +20 -0
  111. package/build/types/Markup/constants.d.ts.map +1 -0
  112. package/build/types/Markup/index.d.ts +3 -0
  113. package/build/types/Markup/index.d.ts.map +1 -0
  114. package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
  115. package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
  116. package/build/types/Markup/utils/sanitise.d.ts +4 -0
  117. package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
  118. package/build/types/Title/Title.d.ts +2 -2
  119. package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
  120. package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
  121. package/build/types/common/DateUtils/index.d.ts +0 -2
  122. package/build/types/common/DateUtils/index.d.ts.map +1 -1
  123. package/build/types/index.d.ts +4 -3
  124. package/build/types/index.d.ts.map +1 -1
  125. package/build/types/test-utils/index.d.ts +0 -8
  126. package/build/types/test-utils/index.d.ts.map +1 -1
  127. package/package.json +1 -1
  128. package/src/Calendar/Calendar.css +37 -112
  129. package/src/Calendar/Calendar.less +35 -5
  130. package/src/Calendar/Calendar.messages.ts +0 -21
  131. package/src/Calendar/Calendar.test.tsx +27 -288
  132. package/src/Calendar/Calendar.tsx +19 -136
  133. package/src/Calendar/DateHeader/DateHeader.tsx +0 -6
  134. package/src/Calendar/DayCalendar/DayCalendar.tsx +1 -33
  135. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +28 -62
  136. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +0 -8
  137. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +3 -15
  138. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +3 -15
  139. package/src/Calendar/YearCalendar/YearCalendar.tsx +0 -9
  140. package/src/Calendar/_stories/Calendar.story.tsx +4 -138
  141. package/src/Calendar/index.ts +0 -7
  142. package/src/Calendar/{TableLink → tableLink}/TableLink.tsx +14 -29
  143. package/src/DateLookup/DateLookup.test.tsx +37 -34
  144. package/src/DateLookup/DateLookup.tsx +13 -37
  145. package/src/DateLookup/_stories/DateLookup.story.tsx +2 -124
  146. package/src/DateLookup/index.ts +0 -6
  147. package/src/Markup/Markup.css +28 -0
  148. package/src/Markup/Markup.injection.test.tsx +163 -0
  149. package/src/Markup/Markup.less +29 -0
  150. package/src/Markup/Markup.test.tsx +463 -0
  151. package/src/Markup/Markup.tsx +169 -0
  152. package/src/Markup/Markup.types.ts +62 -0
  153. package/src/Markup/_stories/Markup.docs.mdx +75 -0
  154. package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
  155. package/src/Markup/_stories/Markup.story.tsx +266 -0
  156. package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  157. package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
  158. package/src/Markup/constants.ts +41 -0
  159. package/src/Markup/index.ts +2 -0
  160. package/src/Markup/utils/parseMarkup.test.ts +706 -0
  161. package/src/Markup/utils/parseMarkup.ts +234 -0
  162. package/src/Markup/utils/sanitise.test.ts +497 -0
  163. package/src/Markup/utils/sanitise.ts +133 -0
  164. package/src/common/DateUtils/index.ts +0 -2
  165. package/src/i18n/en.json +0 -4
  166. package/src/index.ts +4 -3
  167. package/src/main.css +78 -123
  168. package/src/main.less +1 -0
  169. package/build/Calendar/TableLink/TableLink.js.map +0 -1
  170. package/build/Calendar/TableLink/TableLink.mjs.map +0 -1
  171. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +0 -33
  172. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +0 -1
  173. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +0 -31
  174. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +0 -1
  175. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +0 -40
  176. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +0 -1
  177. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +0 -38
  178. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +0 -1
  179. package/build/styles/Calendar/TableLink/TableLink.css +0 -115
  180. package/build/types/Calendar/Calendar.types.d.ts +0 -32
  181. package/build/types/Calendar/Calendar.types.d.ts.map +0 -1
  182. package/build/types/Calendar/TableLink/TableLink.d.ts.map +0 -1
  183. package/build/types/Calendar/TableLink/index.d.ts.map +0 -1
  184. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +0 -3
  185. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +0 -1
  186. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +0 -3
  187. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +0 -1
  188. package/src/Calendar/Calendar.disabledDates.test.tsx +0 -518
  189. package/src/Calendar/Calendar.types.ts +0 -35
  190. package/src/Calendar/TableLink/TableLink.css +0 -115
  191. package/src/Calendar/TableLink/TableLink.less +0 -68
  192. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +0 -118
  193. package/src/Calendar/_stories/Calendar.test.story.tsx +0 -74
  194. package/src/DateLookup/DateLookup.disabledDates.test.tsx +0 -293
  195. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +0 -108
  196. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +0 -98
  197. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +0 -45
  198. package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +0 -169
  199. package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +0 -59
  200. /package/build/types/Calendar/{TableLink → tableLink}/index.d.ts +0 -0
  201. /package/src/Calendar/{TableLink → tableLink}/index.ts +0 -0
@@ -1,98 +0,0 @@
1
- import { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth';
2
- import type { DisabledRules } from '../../../Calendar/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
- });
@@ -1,45 +0,0 @@
1
- import type { DisabledRules } from '../../../Calendar/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
- }
@@ -1,169 +0,0 @@
1
- import { isDateDisabled } from './isDateDisabled';
2
- import type { DisabledRules } from '../../../Calendar/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
- });
@@ -1,59 +0,0 @@
1
- import type { DisabledRules, WeekDayType } from '../../../Calendar/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
- }
File without changes