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

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 (154) hide show
  1. package/build/Calendar/Calendar.js +94 -16
  2. package/build/Calendar/Calendar.js.map +1 -1
  3. package/build/Calendar/Calendar.messages.js +12 -0
  4. package/build/Calendar/Calendar.messages.js.map +1 -1
  5. package/build/Calendar/Calendar.messages.mjs +12 -0
  6. package/build/Calendar/Calendar.messages.mjs.map +1 -1
  7. package/build/Calendar/Calendar.mjs +95 -17
  8. package/build/Calendar/Calendar.mjs.map +1 -1
  9. package/build/Calendar/DateHeader/DateHeader.js +5 -1
  10. package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
  11. package/build/Calendar/DateHeader/DateHeader.mjs +5 -1
  12. package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
  13. package/build/Calendar/DayCalendar/DayCalendar.js +14 -0
  14. package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
  15. package/build/Calendar/DayCalendar/DayCalendar.mjs +14 -0
  16. package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
  17. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +53 -19
  18. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
  19. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +53 -19
  20. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
  21. package/build/Calendar/MonthCalendar/MonthCalendar.js +6 -0
  22. package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
  23. package/build/Calendar/MonthCalendar/MonthCalendar.mjs +6 -0
  24. package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
  25. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +8 -3
  26. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
  27. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +8 -3
  28. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
  29. package/build/Calendar/{tableLink → TableLink}/TableLink.js +26 -11
  30. package/build/Calendar/TableLink/TableLink.js.map +1 -0
  31. package/build/Calendar/{tableLink → TableLink}/TableLink.mjs +26 -11
  32. package/build/Calendar/TableLink/TableLink.mjs.map +1 -0
  33. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +8 -3
  34. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
  35. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +8 -3
  36. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
  37. package/build/Calendar/YearCalendar/YearCalendar.js +7 -0
  38. package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
  39. package/build/Calendar/YearCalendar/YearCalendar.mjs +7 -0
  40. package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
  41. package/build/DateLookup/DateLookup.js +20 -9
  42. package/build/DateLookup/DateLookup.js.map +1 -1
  43. package/build/DateLookup/DateLookup.mjs +20 -9
  44. package/build/DateLookup/DateLookup.mjs.map +1 -1
  45. package/build/DefinitionList/DefinitionList.js +1 -2
  46. package/build/DefinitionList/DefinitionList.js.map +1 -1
  47. package/build/DefinitionList/DefinitionList.mjs +1 -2
  48. package/build/DefinitionList/DefinitionList.mjs.map +1 -1
  49. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +33 -0
  50. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +1 -0
  51. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +31 -0
  52. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +1 -0
  53. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +40 -0
  54. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +1 -0
  55. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +38 -0
  56. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +1 -0
  57. package/build/i18n/en.json +4 -0
  58. package/build/i18n/en.json.js +4 -0
  59. package/build/i18n/en.json.js.map +1 -1
  60. package/build/i18n/en.json.mjs +4 -0
  61. package/build/i18n/en.json.mjs.map +1 -1
  62. package/build/index.js +2 -2
  63. package/build/index.mjs +1 -1
  64. package/build/main.css +123 -73
  65. package/build/styles/Calendar/Calendar.css +112 -37
  66. package/build/styles/Calendar/TableLink/TableLink.css +115 -0
  67. package/build/styles/DefinitionList/DefinitionList.css +0 -30
  68. package/build/styles/main.css +123 -73
  69. package/build/types/Calendar/Calendar.d.ts +16 -3
  70. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  71. package/build/types/Calendar/Calendar.messages.d.ts +20 -0
  72. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  73. package/build/types/Calendar/Calendar.types.d.ts +32 -0
  74. package/build/types/Calendar/Calendar.types.d.ts.map +1 -0
  75. package/build/types/Calendar/DateHeader/DateHeader.d.ts +2 -0
  76. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  77. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +5 -1
  78. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  79. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +4 -0
  80. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  81. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +1 -0
  82. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  83. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +2 -1
  84. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  85. package/build/types/Calendar/{tableLink → TableLink}/TableLink.d.ts +3 -1
  86. package/build/types/Calendar/TableLink/TableLink.d.ts.map +1 -0
  87. package/build/types/Calendar/TableLink/index.d.ts.map +1 -0
  88. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +2 -1
  89. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  90. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +1 -0
  91. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  92. package/build/types/Calendar/index.d.ts +1 -0
  93. package/build/types/Calendar/index.d.ts.map +1 -1
  94. package/build/types/DateLookup/DateLookup.d.ts +24 -5
  95. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  96. package/build/types/DateLookup/index.d.ts +1 -0
  97. package/build/types/DateLookup/index.d.ts.map +1 -1
  98. package/build/types/DefinitionList/DefinitionList.d.ts.map +1 -1
  99. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +3 -0
  100. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +1 -0
  101. package/build/types/common/DateUtils/index.d.ts +2 -0
  102. package/build/types/common/DateUtils/index.d.ts.map +1 -1
  103. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +3 -0
  104. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +1 -0
  105. package/build/types/index.d.ts +3 -2
  106. package/build/types/index.d.ts.map +1 -1
  107. package/build/types/test-utils/index.d.ts +8 -0
  108. package/build/types/test-utils/index.d.ts.map +1 -1
  109. package/package.json +1 -1
  110. package/src/Calendar/Calendar.css +112 -37
  111. package/src/Calendar/Calendar.disabledDates.test.tsx +518 -0
  112. package/src/Calendar/Calendar.less +5 -35
  113. package/src/Calendar/Calendar.messages.ts +21 -0
  114. package/src/Calendar/Calendar.test.tsx +288 -27
  115. package/src/Calendar/Calendar.tsx +136 -19
  116. package/src/Calendar/Calendar.types.ts +35 -0
  117. package/src/Calendar/DateHeader/DateHeader.tsx +6 -0
  118. package/src/Calendar/DayCalendar/DayCalendar.tsx +33 -1
  119. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +62 -28
  120. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +8 -0
  121. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +15 -3
  122. package/src/Calendar/TableLink/TableLink.css +115 -0
  123. package/src/Calendar/TableLink/TableLink.less +68 -0
  124. package/src/Calendar/{tableLink → TableLink}/TableLink.tsx +29 -14
  125. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +15 -3
  126. package/src/Calendar/YearCalendar/YearCalendar.tsx +9 -0
  127. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +118 -0
  128. package/src/Calendar/_stories/Calendar.story.tsx +138 -4
  129. package/src/Calendar/_stories/Calendar.test.story.tsx +74 -0
  130. package/src/Calendar/index.ts +7 -0
  131. package/src/DateLookup/DateLookup.disabledDates.test.tsx +293 -0
  132. package/src/DateLookup/DateLookup.test.tsx +34 -37
  133. package/src/DateLookup/DateLookup.tsx +37 -13
  134. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +108 -0
  135. package/src/DateLookup/_stories/DateLookup.story.tsx +124 -2
  136. package/src/DateLookup/index.ts +6 -0
  137. package/src/DefinitionList/DefinitionList.css +0 -30
  138. package/src/DefinitionList/DefinitionList.less +0 -24
  139. package/src/DefinitionList/DefinitionList.tsx +0 -1
  140. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +98 -0
  141. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +45 -0
  142. package/src/common/DateUtils/index.ts +2 -0
  143. package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +169 -0
  144. package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +59 -0
  145. package/src/i18n/en.json +4 -0
  146. package/src/index.ts +3 -2
  147. package/src/main.css +123 -73
  148. package/build/Calendar/tableLink/TableLink.js.map +0 -1
  149. package/build/Calendar/tableLink/TableLink.mjs.map +0 -1
  150. package/build/types/Calendar/tableLink/TableLink.d.ts.map +0 -1
  151. package/build/types/Calendar/tableLink/index.d.ts.map +0 -1
  152. package/src/DefinitionList/_stories/DefinitionList.test.story.tsx +0 -168
  153. /package/build/types/Calendar/{tableLink → TableLink}/index.d.ts +0 -0
  154. /package/src/Calendar/{tableLink → TableLink}/index.ts +0 -0
@@ -2,10 +2,11 @@ import { formatDate } from '@transferwise/formatting';
2
2
  import { useIntl } from 'react-intl';
3
3
 
4
4
  import { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';
5
- import TableLink from '../../tableLink';
5
+ import TableLink from '../../TableLink';
6
6
 
7
7
  interface YearCalendarTableProps {
8
8
  selectedDate: Date | null;
9
+ focusedDate?: Date | null;
9
10
  min: Date | null;
10
11
  max: Date | null;
11
12
  viewYear: number;
@@ -19,6 +20,7 @@ const YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };
19
20
 
20
21
  const YearCalendarTable = ({
21
22
  selectedDate,
23
+ focusedDate,
22
24
  min,
23
25
  max,
24
26
  viewYear,
@@ -34,7 +36,8 @@ const YearCalendarTable = ({
34
36
  type="year"
35
37
  title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
36
38
  active={isActive(year)}
37
- disabled={isDisabled(year)}
39
+ outOfRange={isDisabled(year)}
40
+ disabled={false}
38
41
  today={isThisYear(year)}
39
42
  autofocus={autofocusYear === year}
40
43
  onClick={onSelect}
@@ -46,6 +49,10 @@ const YearCalendarTable = ({
46
49
  return !!(year === selectedDate?.getFullYear());
47
50
  };
48
51
 
52
+ const isFocused = (year: number) => {
53
+ return !!(year === focusedDate?.getFullYear());
54
+ };
55
+
49
56
  const isThisYear = (year: number) => {
50
57
  return year === new Date().getFullYear();
51
58
  };
@@ -56,7 +63,12 @@ const YearCalendarTable = ({
56
63
 
57
64
  const autofocusYear = (() => {
58
65
  const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);
59
- return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });
66
+ return getFocusableTime({
67
+ isActive: isFocused,
68
+ isNow: isThisYear,
69
+ isDisabled,
70
+ timeSpan: years,
71
+ });
60
72
  })();
61
73
 
62
74
  return (
@@ -8,6 +8,7 @@ import YearCalendarTable from './Table';
8
8
 
9
9
  interface YearCalendarProps extends WrappedComponentProps {
10
10
  selectedDate: Date | null;
11
+ focusedDate?: Date | null;
11
12
  min: Date | null;
12
13
  max: Date | null;
13
14
  viewYear: number;
@@ -33,21 +34,29 @@ class YearCalendar extends PureComponent<YearCalendarProps> {
33
34
  render() {
34
35
  const {
35
36
  selectedDate,
37
+ focusedDate,
36
38
  min,
37
39
  max,
38
40
  viewYear,
39
41
  placeholder,
40
42
  intl: { formatMessage },
41
43
  } = this.props;
44
+ const startYear = viewYear - (viewYear % 20);
45
+ const isPreviousDisabled = !!(min && startYear - 1 < min.getFullYear());
46
+ const isNextDisabled = !!(max && startYear + 20 > max.getFullYear());
47
+
42
48
  return (
43
49
  <>
44
50
  <DateHeader
45
51
  dateMode={formatMessage(messages.twentyYears)}
52
+ isPreviousDisabled={isPreviousDisabled}
53
+ isNextDisabled={isNextDisabled}
46
54
  onPreviousClick={this.selectPreviousYears}
47
55
  onNextClick={this.selectNextYears}
48
56
  />
49
57
  <YearCalendarTable
50
58
  selectedDate={selectedDate}
59
+ focusedDate={focusedDate}
51
60
  min={min}
52
61
  max={max}
53
62
  viewYear={viewYear}
@@ -0,0 +1,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,101 @@ 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({
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
+ });
@@ -0,0 +1,74 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-webpack5';
2
+ import { expect, within , userEvent } from 'storybook/test';
3
+
4
+ import Calendar from '../Calendar';
5
+
6
+ export default {
7
+ component: Calendar,
8
+ title: 'Forms/Calendar/Tests',
9
+ tags: ['!autodocs', '!manifest'],
10
+ } satisfies Meta<typeof Calendar>;
11
+
12
+ type Story = StoryObj<typeof Calendar>;
13
+
14
+ // min: March 2024, max: October 2024
15
+ const min = new Date(2024, 2, 1);
16
+ const max = new Date(2024, 9, 31);
17
+
18
+ /**
19
+ * Year view: years within min/max are enabled, years outside are disabled (aria-disabled),
20
+ * and both navigation arrows are disabled because min and max fall within the same 2020–2039 block.
21
+ */
22
+ export const YearViewBoundaries: Story = {
23
+ render: () => <Calendar value={new Date(2024, 5, 15)} min={min} max={max} />,
24
+ play: async ({ canvasElement }) => {
25
+ const canvas = within(canvasElement);
26
+
27
+ await userEvent.click(canvas.getByRole('button', { name: /year view/iu }));
28
+
29
+ // Selected year (within range) is enabled
30
+ await expect(canvas.getByRole('button', { name: /2024.*selected year/iu })).not.toBeDisabled();
31
+
32
+ // Adjacent years outside range are disabled
33
+ await expect(canvas.getByRole('button', { name: /^2023.*not available/iu })).toBeDisabled();
34
+ await expect(canvas.getByRole('button', { name: /^2025.*not available/iu })).toBeDisabled();
35
+
36
+ // Both nav arrows disabled — min and max are both in the 2020–2039 block
37
+ await expect(canvas.getByRole('button', { name: /previous 20 years/iu })).toBeDisabled();
38
+ await expect(canvas.getByRole('button', { name: /next 20 years/iu })).toBeDisabled();
39
+ },
40
+ };
41
+
42
+ /**
43
+ * Month view: months within min/max are enabled, months outside are disabled (aria-disabled),
44
+ * and both navigation arrows are disabled because min and max are both in 2024.
45
+ */
46
+ export const MonthViewBoundaries: Story = {
47
+ render: () => <Calendar value={new Date(2024, 5, 15)} min={min} max={max} />,
48
+ play: async ({ canvasElement }) => {
49
+ const canvas = within(canvasElement);
50
+
51
+ // Navigate: year view → click 2024 → month view
52
+ await userEvent.click(canvas.getByRole('button', { name: /year view/iu }));
53
+ await userEvent.click(canvas.getByRole('button', { name: /2024.*selected year/iu }));
54
+
55
+ // Selected month (within range) is enabled
56
+ await expect(canvas.getByRole('button', { name: /^Jun.*selected month/iu })).not.toBeDisabled();
57
+
58
+ // Boundary months (min=Mar, max=Oct) are enabled
59
+ await expect(
60
+ canvas.getByRole('button', { name: /^Mar(?!.*not available)/iu }),
61
+ ).not.toBeDisabled();
62
+ await expect(
63
+ canvas.getByRole('button', { name: /^Oct(?!.*not available)/iu }),
64
+ ).not.toBeDisabled();
65
+
66
+ // Months outside range are disabled
67
+ await expect(canvas.getByRole('button', { name: /^Feb.*not available/iu })).toBeDisabled();
68
+ await expect(canvas.getByRole('button', { name: /^Nov.*not available/iu })).toBeDisabled();
69
+
70
+ // Both nav arrows disabled — min and max are both in 2024
71
+ await expect(canvas.getByRole('button', { name: /previous year/iu })).toBeDisabled();
72
+ await expect(canvas.getByRole('button', { name: /next year/iu })).toBeDisabled();
73
+ },
74
+ };
@@ -1,2 +1,9 @@
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';