@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
@@ -15,8 +15,6 @@ interface DateHeaderProps {
15
15
  onPreviousClick: () => void;
16
16
  onNextClick: () => void;
17
17
  dateMode: string;
18
- isPreviousDisabled?: boolean;
19
- isNextDisabled?: boolean;
20
18
  }
21
19
 
22
20
  const DateHeader: React.FC<DateHeaderProps> = ({
@@ -25,8 +23,6 @@ const DateHeader: React.FC<DateHeaderProps> = ({
25
23
  onPreviousClick,
26
24
  onNextClick,
27
25
  dateMode,
28
- isPreviousDisabled,
29
- isNextDisabled,
30
26
  }) => {
31
27
  const intl = useIntl();
32
28
  const { isMobile } = useLayout();
@@ -38,7 +34,6 @@ const DateHeader: React.FC<DateHeaderProps> = ({
38
34
  priority="minimal"
39
35
  className="d-inline-flex"
40
36
  aria-label={`${intl.formatMessage(messages.previous)} ${dateMode}`}
41
- disabled={isPreviousDisabled}
42
37
  onClick={onPreviousClick}
43
38
  >
44
39
  <ChevronLeft className="left-single-direction" />
@@ -66,7 +61,6 @@ const DateHeader: React.FC<DateHeaderProps> = ({
66
61
  className="d-inline-flex"
67
62
  aria-label={`${intl.formatMessage(messages.next)} ${dateMode}`}
68
63
  priority="minimal"
69
- disabled={isNextDisabled}
70
64
  onClick={onNextClick}
71
65
  >
72
66
  <ChevronRight className="right-single-direction" />
@@ -2,7 +2,6 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import { PureComponent } from 'react';
3
3
 
4
4
  import { MonthFormat } from '../../common';
5
- import type { DisabledRules } from '../Calendar.types';
6
5
  import messages from '../Calendar.messages';
7
6
  import DateHeader from '../DateHeader';
8
7
 
@@ -11,14 +10,11 @@ import { injectIntl, type WrappedComponentProps } from '../../common/injectIntl'
11
10
 
12
11
  interface DayCalendarProps extends WrappedComponentProps {
13
12
  selectedDate: Date | null;
14
- focusedDate?: Date | null;
15
13
  min: Date | null;
16
14
  max: Date | null;
17
15
  viewMonth: number;
18
16
  viewYear: number;
19
17
  monthFormat: `${MonthFormat}`;
20
- disabledRules?: DisabledRules;
21
- disabledReasonId?: string;
22
18
  onSelect: (date: Date) => void;
23
19
  onLabelClick: () => void;
24
20
  onViewDateUpdate: (date: { month: number; year: number }) => void;
@@ -44,29 +40,15 @@ class DayCalendar extends PureComponent<DayCalendarProps> {
44
40
  render() {
45
41
  const {
46
42
  selectedDate,
47
- focusedDate,
48
43
  min,
49
44
  max,
50
45
  viewMonth,
51
46
  viewYear,
52
47
  intl: { locale, formatMessage },
53
48
  monthFormat,
54
- disabledRules,
55
- disabledReasonId,
56
49
  onLabelClick,
57
50
  onSelect,
58
51
  } = this.props;
59
- const prevMonth = viewMonth <= 0 ? 11 : viewMonth - 1;
60
- const prevYear = viewMonth <= 0 ? viewYear - 1 : viewYear;
61
- const nextMonth = viewMonth >= 11 ? 0 : viewMonth + 1;
62
- const nextYear = viewMonth >= 11 ? viewYear + 1 : viewYear;
63
- const isPreviousDisabled = !!(
64
- min && new Date(prevYear, prevMonth) < new Date(min.getFullYear(), min.getMonth())
65
- );
66
- const isNextDisabled = !!(
67
- max && new Date(nextYear, nextMonth) > new Date(max.getFullYear(), max.getMonth())
68
- );
69
-
70
52
  return (
71
53
  <>
72
54
  <DateHeader
@@ -75,25 +57,11 @@ class DayCalendar extends PureComponent<DayCalendarProps> {
75
57
  year: 'numeric',
76
58
  })}
77
59
  dateMode={formatMessage(messages.month)}
78
- isPreviousDisabled={isPreviousDisabled}
79
- isNextDisabled={isNextDisabled}
80
60
  onLabelClick={onLabelClick}
81
61
  onPreviousClick={this.selectPreviousMonth}
82
62
  onNextClick={this.selectNextMonth}
83
63
  />
84
- <DayCalendarTable
85
- {...{
86
- selectedDate,
87
- focusedDate,
88
- min,
89
- max,
90
- viewMonth,
91
- viewYear,
92
- disabledRules,
93
- disabledReasonId,
94
- onSelect,
95
- }}
96
- />
64
+ <DayCalendarTable {...{ selectedDate, min, max, viewMonth, viewYear, onSelect }} />
97
65
  </>
98
66
  );
99
67
  }
@@ -2,28 +2,19 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import { PureComponent } from 'react';
3
3
  import { injectIntl, type WrappedComponentProps } from '../../../common/injectIntl';
4
4
 
5
- import { getDayNames, isWithinRange, isDateDisabled } from '../../../common/DateUtils';
6
- import type { DisabledRules } from '../../Calendar.types';
5
+ import { getDayNames, isWithinRange } from '../../../common/DateUtils';
7
6
  import { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';
8
7
  import { getStartOfDay } from '../../GetStartOfDay';
9
- import TableLink from '../../TableLink';
8
+ import TableLink from '../../tableLink';
10
9
 
11
10
  const SHORT_DAY_FORMAT: Intl.DateTimeFormatOptions = { day: 'numeric' };
12
- const LONG_DAY_FORMAT: Intl.DateTimeFormatOptions = {
13
- day: 'numeric',
14
- month: 'long',
15
- year: 'numeric',
16
- };
17
11
 
18
12
  interface DayCalendarTableProps extends WrappedComponentProps {
19
13
  selectedDate: Date | null;
20
- focusedDate?: Date | null;
21
14
  min: Date | null;
22
15
  max: Date | null;
23
16
  viewMonth: number;
24
17
  viewYear: number;
25
- disabledRules?: DisabledRules;
26
- disabledReasonId?: string;
27
18
  onSelect: (date: Date) => void;
28
19
  }
29
20
 
@@ -72,36 +63,21 @@ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
72
63
  onSelect(new Date(viewYear, viewMonth, day));
73
64
  };
74
65
 
75
- isOutOfRange = (day: number) => {
66
+ isDisabled = (day: number) => {
76
67
  if (day < 0) {
77
68
  return true;
78
69
  }
79
70
  const { min, max, viewMonth, viewYear } = this.props;
80
71
  const date = new Date(viewYear, viewMonth, day);
81
- return !isWithinRange(date, min, max);
82
- };
83
72
 
84
- isDisabled = (day: number) => {
85
- if (day < 0) {
86
- return false;
87
- }
88
- const { viewMonth, viewYear, disabledRules } = this.props;
89
- const date = new Date(viewYear, viewMonth, day);
90
- return isDateDisabled(date, disabledRules);
73
+ return !isWithinRange(date, min, max);
91
74
  };
92
75
 
93
- isUnavailable = (day: number) => this.isOutOfRange(day) || this.isDisabled(day);
94
-
95
76
  isActive = (day: number) => {
96
77
  const { selectedDate, viewMonth, viewYear } = this.props;
97
78
  return !!(selectedDate && Number(new Date(viewYear, viewMonth, day)) === Number(selectedDate));
98
79
  };
99
80
 
100
- isFocused = (day: number) => {
101
- const { focusedDate, viewMonth, viewYear } = this.props;
102
- return !!(focusedDate && Number(new Date(viewYear, viewMonth, day)) === Number(focusedDate));
103
- };
104
-
105
81
  isToday = (day: number) => {
106
82
  const { viewMonth, viewYear } = this.props;
107
83
  return Number(getStartOfDay(new Date())) === Number(new Date(viewYear, viewMonth, day));
@@ -110,15 +86,15 @@ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
110
86
  getAutofocusDay = (weeks: number[][]) => {
111
87
  const days = weeks.flatMap((week) => week);
112
88
  return getFocusableTime({
113
- isActive: this.isFocused,
89
+ isActive: this.isActive,
114
90
  isNow: this.isToday,
115
- isDisabled: this.isUnavailable,
91
+ isDisabled: this.isDisabled,
116
92
  timeSpan: days,
117
93
  });
118
94
  };
119
95
 
120
96
  render() {
121
- const { viewMonth, viewYear, intl, disabledReasonId } = this.props;
97
+ const { viewMonth, viewYear, intl } = this.props;
122
98
  const weeks = this.getTableStructure();
123
99
  const autoFocusDay = this.getAutofocusDay(weeks);
124
100
  return (
@@ -148,37 +124,27 @@ class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
148
124
  {/* eslint-disable react/no-array-index-key */}
149
125
  {weeks.map((week, weekIndex) => (
150
126
  <tr key={weekIndex}>
151
- {week.map((day, dayIndex) => {
152
- const dayOutOfRange = this.isOutOfRange(day);
153
- const dayDisabled = this.isDisabled(day);
154
- return (
155
- <td key={dayIndex} className={dayIndex > 4 ? 'weekend' : ''}>
156
- {day !== -1 && (
157
- <TableLink
158
- item={day}
159
- type="day"
160
- title={formatDate(
161
- new Date(viewYear, viewMonth, day),
162
- intl.locale,
163
- SHORT_DAY_FORMAT,
164
- )}
165
- autofocus={day === autoFocusDay}
166
- longTitle={formatDate(
167
- new Date(viewYear, viewMonth, day),
168
- intl.locale,
169
- LONG_DAY_FORMAT,
170
- )}
171
- active={this.isActive(day)}
172
- outOfRange={dayOutOfRange}
173
- disabled={dayDisabled}
174
- today={this.isToday(day)}
175
- disabledReasonId={disabledReasonId}
176
- onClick={this.selectDay}
177
- />
178
- )}
179
- </td>
180
- );
181
- })}
127
+ {week.map((day, dayIndex) => (
128
+ <td key={dayIndex} className={dayIndex > 4 ? 'weekend' : ''}>
129
+ {day !== -1 && (
130
+ <TableLink
131
+ item={day}
132
+ type="day"
133
+ title={formatDate(
134
+ new Date(viewYear, viewMonth, day),
135
+ intl.locale,
136
+ SHORT_DAY_FORMAT,
137
+ )}
138
+ autofocus={day === autoFocusDay}
139
+ longTitle={formatDate(new Date(viewYear, viewMonth, day), intl.locale)}
140
+ active={this.isActive(day)}
141
+ disabled={this.isDisabled(day)}
142
+ today={this.isToday(day)}
143
+ onClick={this.selectDay}
144
+ />
145
+ )}
146
+ </td>
147
+ ))}
182
148
  </tr>
183
149
  ))}
184
150
  {/* eslint-enable react/no-array-index-key */}
@@ -9,7 +9,6 @@ import MonthCalendarTable from './Table';
9
9
 
10
10
  interface MonthCalendarProps extends WrappedComponentProps {
11
11
  selectedDate: Date | null;
12
- focusedDate?: Date | null;
13
12
  min: Date | null;
14
13
  max: Date | null;
15
14
  viewYear: number;
@@ -36,7 +35,6 @@ class MonthCalendar extends PureComponent<MonthCalendarProps> {
36
35
  render() {
37
36
  const {
38
37
  selectedDate,
39
- focusedDate,
40
38
  min,
41
39
  max,
42
40
  viewYear,
@@ -44,23 +42,17 @@ class MonthCalendar extends PureComponent<MonthCalendarProps> {
44
42
  placeholder,
45
43
  onLabelClick,
46
44
  } = this.props;
47
- const isPreviousDisabled = !!(min && viewYear - 1 < min.getFullYear());
48
- const isNextDisabled = !!(max && viewYear + 1 > max.getFullYear());
49
-
50
45
  return (
51
46
  <>
52
47
  <DateHeader
53
48
  dateMode={formatMessage(messages.year)}
54
49
  label={formatDate(new Date(viewYear, 0), locale, { year: 'numeric' })}
55
- isPreviousDisabled={isPreviousDisabled}
56
- isNextDisabled={isNextDisabled}
57
50
  onLabelClick={onLabelClick}
58
51
  onPreviousClick={this.selectPreviousYear}
59
52
  onNextClick={this.selectNextYear}
60
53
  />
61
54
  <MonthCalendarTable
62
55
  selectedDate={selectedDate}
63
- focusedDate={focusedDate}
64
56
  min={min}
65
57
  max={max}
66
58
  viewYear={viewYear}
@@ -2,11 +2,10 @@ 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;
10
9
  min: Date | null;
11
10
  max: Date | null;
12
11
  viewYear: number;
@@ -20,7 +19,6 @@ const MONTH_ONLY_FORMAT: Intl.DateTimeFormatOptions = { month: 'short' };
20
19
 
21
20
  const MonthCalendarTable = ({
22
21
  selectedDate,
23
- focusedDate,
24
22
  min,
25
23
  max,
26
24
  viewYear,
@@ -36,8 +34,7 @@ const MonthCalendarTable = ({
36
34
  type="month"
37
35
  title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT)}
38
36
  active={isActive(month)}
39
- outOfRange={isDisabled(month)}
40
- disabled={false}
37
+ disabled={isDisabled(month)}
41
38
  today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
42
39
  autofocus={autofocusMonth === month}
43
40
  onClick={onSelect}
@@ -49,10 +46,6 @@ const MonthCalendarTable = ({
49
46
  return !!(month === selectedDate?.getMonth() && viewYear === selectedDate?.getFullYear());
50
47
  };
51
48
 
52
- const isFocused = (month: number) => {
53
- return !!(month === focusedDate?.getMonth() && viewYear === focusedDate?.getFullYear());
54
- };
55
-
56
49
  const isThisMonth = (month: number) => {
57
50
  return viewYear === new Date().getFullYear() && month === new Date().getMonth();
58
51
  };
@@ -67,12 +60,7 @@ const MonthCalendarTable = ({
67
60
 
68
61
  const autofocusMonth = (() => {
69
62
  const months = Array.from({ length: ROWS * COLS }, (_, index) => index);
70
- return getFocusableTime({
71
- isActive: isFocused,
72
- isNow: isThisMonth,
73
- isDisabled,
74
- timeSpan: months,
75
- });
63
+ return getFocusableTime({ isActive, isNow: isThisMonth, isDisabled, timeSpan: months });
76
64
  })();
77
65
 
78
66
  return (
@@ -2,11 +2,10 @@ 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;
10
9
  min: Date | null;
11
10
  max: Date | null;
12
11
  viewYear: number;
@@ -20,7 +19,6 @@ const YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };
20
19
 
21
20
  const YearCalendarTable = ({
22
21
  selectedDate,
23
- focusedDate,
24
22
  min,
25
23
  max,
26
24
  viewYear,
@@ -36,8 +34,7 @@ const YearCalendarTable = ({
36
34
  type="year"
37
35
  title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
38
36
  active={isActive(year)}
39
- outOfRange={isDisabled(year)}
40
- disabled={false}
37
+ disabled={isDisabled(year)}
41
38
  today={isThisYear(year)}
42
39
  autofocus={autofocusYear === year}
43
40
  onClick={onSelect}
@@ -49,10 +46,6 @@ const YearCalendarTable = ({
49
46
  return !!(year === selectedDate?.getFullYear());
50
47
  };
51
48
 
52
- const isFocused = (year: number) => {
53
- return !!(year === focusedDate?.getFullYear());
54
- };
55
-
56
49
  const isThisYear = (year: number) => {
57
50
  return year === new Date().getFullYear();
58
51
  };
@@ -63,12 +56,7 @@ const YearCalendarTable = ({
63
56
 
64
57
  const autofocusYear = (() => {
65
58
  const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);
66
- return getFocusableTime({
67
- isActive: isFocused,
68
- isNow: isThisYear,
69
- isDisabled,
70
- timeSpan: years,
71
- });
59
+ return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });
72
60
  })();
73
61
 
74
62
  return (
@@ -8,7 +8,6 @@ import YearCalendarTable from './Table';
8
8
 
9
9
  interface YearCalendarProps extends WrappedComponentProps {
10
10
  selectedDate: Date | null;
11
- focusedDate?: Date | null;
12
11
  min: Date | null;
13
12
  max: Date | null;
14
13
  viewYear: number;
@@ -34,29 +33,21 @@ class YearCalendar extends PureComponent<YearCalendarProps> {
34
33
  render() {
35
34
  const {
36
35
  selectedDate,
37
- focusedDate,
38
36
  min,
39
37
  max,
40
38
  viewYear,
41
39
  placeholder,
42
40
  intl: { formatMessage },
43
41
  } = 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
-
48
42
  return (
49
43
  <>
50
44
  <DateHeader
51
45
  dateMode={formatMessage(messages.twentyYears)}
52
- isPreviousDisabled={isPreviousDisabled}
53
- isNextDisabled={isNextDisabled}
54
46
  onPreviousClick={this.selectPreviousYears}
55
47
  onNextClick={this.selectNextYears}
56
48
  />
57
49
  <YearCalendarTable
58
50
  selectedDate={selectedDate}
59
- focusedDate={focusedDate}
60
51
  min={min}
61
52
  max={max}
62
53
  viewYear={viewYear}
@@ -1,47 +1,22 @@
1
1
  import { useState } from 'react';
2
2
  import { StoryObj } from '@storybook/react-webpack5';
3
- import { fn, userEvent, within } from 'storybook/test';
3
+ import { 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';
9
8
  import Calendar, { type CalendarProps } from '../Calendar';
10
9
  import Modal from '../../Modal';
11
10
  import Button from '../../Button';
12
- import { action } from 'storybook/actions';
13
11
 
12
+ /** Inline calendar for selecting a single date, with optional min/max bounds. */
14
13
  export default {
15
14
  component: Calendar,
16
15
  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
- },
27
16
  argTypes: {
28
17
  monthFormat: { control: 'select', options: ['long', 'short'] },
29
18
  min: { control: 'date' },
30
19
  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
- },
45
20
  },
46
21
  };
47
22
 
@@ -55,17 +30,12 @@ thePast.setUTCDate(epoch.getUTCDate() - 10);
55
30
 
56
31
  export const Sandbox = createSandboxStory({
57
32
  code: `const App = () => {
58
- const [value, setValue] = React.useState(new Date(2024, 5, 18));
33
+ const [value, setValue] = React.useState(new Date('2024-06-15'));
59
34
 
60
35
  return (
61
36
  <Calendar
62
37
  monthFormat="long"
63
38
  value={value}
64
- disabledRules={{
65
- weekdays: ['sat', 'sun'],
66
- dates: [new Date(2024, 5, 19)],
67
- reason: 'Weekends and holidays are unavailable.',
68
- }}
69
39
  onChange={(date) => setValue(date)}
70
40
  />
71
41
  );
@@ -82,13 +52,7 @@ export const Basic: Story = {
82
52
  min={args.min ? new Date(args.min) : thePast}
83
53
  max={args.max ? new Date(args.max) : theFuture}
84
54
  value={value}
85
- onDateFocus={(date, options) => {
86
- action('onDateFocus')(date, options);
87
- }}
88
- onChange={(date) => {
89
- action('onChange')(date);
90
- setValue(date);
91
- }}
55
+ onChange={(v) => setValue(v)}
92
56
  />
93
57
  );
94
58
  },
@@ -138,101 +102,3 @@ export const InsideModal: Story = {
138
102
  await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
139
103
  },
140
104
  };
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({
155
- render: function Render() {
156
- const [value, setValue] = useState<Date | null>(new Date(2024, 11, 13));
157
-
158
- return (
159
- <Calendar
160
- value={value}
161
- min={new Date(2024, 11, 4)}
162
- max={new Date(2025, 0, 18)}
163
- disabledRules={{
164
- weekdays: ['sat', 'sun'],
165
- dates: [new Date(2024, 11, 10), new Date(2025, 0, 15)],
166
- ranges: [{ start: new Date(2024, 11, 23), end: new Date(2024, 11, 27) }],
167
- reason: 'Some dates are unavailable for this service.',
168
- }}
169
- onDateFocus={(date, { isEnabled }) => {
170
- action('onDateFocus')(date, { isEnabled });
171
- }}
172
- onChange={(date) => {
173
- action('onChange')(date);
174
- setValue(date);
175
- }}
176
- />
177
- );
178
- },
179
- });
180
-
181
- /**
182
- * When different disabled dates warrant different explanations, drive the `reason`
183
- * dynamically from `onDateFocus`. The `isEnabled` flag tells you whether the focused
184
- * date is selectable; from there you can look up the specific reason and update state.
185
- *
186
- * `min`/`max` out-of-range dates are handled automatically — the component shows a
187
- * built-in prompt with the boundary dates, so `determineReason` only needs to cover
188
- * rule-disabled dates.
189
- */
190
- export const DisabledDatesWithDynamicReason: Story = storySourceWithoutNoise({
191
- render: function Render() {
192
- const DEFAULT_REASON = 'Some dates are unavailable for this service.';
193
- const min = new Date(2024, 11, 4);
194
- const max = new Date(2025, 0, 18);
195
- const maintenanceDays = [new Date(2024, 11, 10), new Date(2025, 0, 15)];
196
- const [value, setValue] = useState<Date | null>(new Date(2024, 11, 13));
197
- const [reason, setReason] = useState(DEFAULT_REASON);
198
-
199
- function determineReason(date: Date, isEnabled: boolean): string {
200
- if (isEnabled) return DEFAULT_REASON;
201
- if (
202
- maintenanceDays.some(
203
- (maintenanceDay) => maintenanceDay.toDateString() === date.toDateString(),
204
- )
205
- ) {
206
- return 'This date is a maintenance day.';
207
- }
208
- if (date.getDay() === 0 || date.getDay() === 6) {
209
- return 'We do not operate on weekends.';
210
- }
211
- return 'This date is unavailable.';
212
- }
213
-
214
- return (
215
- <Calendar
216
- value={value}
217
- min={min}
218
- max={max}
219
- disabledRules={{
220
- weekdays: ['sat', 'sun'],
221
- dates: maintenanceDays,
222
- ranges: [{ start: new Date(2024, 11, 23), end: new Date(2024, 11, 27) }],
223
- reason,
224
- }}
225
- onDateFocus={(date, { isEnabled }) => {
226
- action('onDateFocus')(date, { isEnabled });
227
- if (date) {
228
- setReason(determineReason(date, isEnabled));
229
- }
230
- }}
231
- onChange={(date) => {
232
- action('onChange')(date);
233
- setValue(date);
234
- }}
235
- />
236
- );
237
- },
238
- });
@@ -1,9 +1,2 @@
1
1
  export { default } from './Calendar';
2
2
  export type { CalendarProps } from './Calendar';
3
- export type {
4
- DateChangeMeta,
5
- DisabledRules,
6
- DisabledDateRange,
7
- WeekDayType,
8
- OnDateSelectParams,
9
- } from './Calendar.types';