@cloudscape-design/components 3.0.681 → 3.0.682

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 (192) hide show
  1. package/button/index.d.ts.map +1 -1
  2. package/button/index.js +2 -2
  3. package/button/index.js.map +1 -1
  4. package/button/interfaces.d.ts +6 -0
  5. package/button/interfaces.d.ts.map +1 -1
  6. package/button/interfaces.js.map +1 -1
  7. package/button/internal.d.ts.map +1 -1
  8. package/button/internal.js +15 -4
  9. package/button/internal.js.map +1 -1
  10. package/button/styles.css.js +20 -19
  11. package/button/styles.scoped.css +161 -167
  12. package/button/styles.selectors.js +20 -19
  13. package/button/test-classes/styles.css.js +6 -0
  14. package/button/test-classes/styles.scoped.css +7 -0
  15. package/button/test-classes/styles.selectors.js +7 -0
  16. package/button-dropdown/category-elements/expandable-category-element.js +1 -1
  17. package/button-dropdown/category-elements/expandable-category-element.js.map +1 -1
  18. package/button-dropdown/category-elements/mobile-expandable-category-element.js +1 -1
  19. package/button-dropdown/category-elements/mobile-expandable-category-element.js.map +1 -1
  20. package/button-dropdown/index.d.ts.map +1 -1
  21. package/button-dropdown/index.js +2 -2
  22. package/button-dropdown/index.js.map +1 -1
  23. package/button-dropdown/interfaces.d.ts +7 -0
  24. package/button-dropdown/interfaces.d.ts.map +1 -1
  25. package/button-dropdown/interfaces.js.map +1 -1
  26. package/button-dropdown/internal.d.ts.map +1 -1
  27. package/button-dropdown/internal.js +4 -2
  28. package/button-dropdown/internal.js.map +1 -1
  29. package/button-dropdown/item-element/index.js +1 -1
  30. package/button-dropdown/item-element/index.js.map +1 -1
  31. package/calendar/grid/index.d.ts +3 -1
  32. package/calendar/grid/index.d.ts.map +1 -1
  33. package/calendar/grid/index.js +26 -6
  34. package/calendar/grid/index.js.map +1 -1
  35. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts +2 -1
  36. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts.map +1 -1
  37. package/calendar/grid/use-calendar-grid-keyboard-navigation.js +8 -5
  38. package/calendar/grid/use-calendar-grid-keyboard-navigation.js.map +1 -1
  39. package/calendar/interfaces.d.ts +9 -0
  40. package/calendar/interfaces.d.ts.map +1 -1
  41. package/calendar/interfaces.js.map +1 -1
  42. package/calendar/internal.d.ts +1 -1
  43. package/calendar/internal.d.ts.map +1 -1
  44. package/calendar/internal.js +7 -5
  45. package/calendar/internal.js.map +1 -1
  46. package/calendar/styles.css.js +21 -20
  47. package/calendar/styles.scoped.css +46 -42
  48. package/calendar/styles.selectors.js +21 -20
  49. package/calendar/utils/navigation.d.ts +10 -10
  50. package/calendar/utils/navigation.d.ts.map +1 -1
  51. package/calendar/utils/navigation.js +29 -29
  52. package/calendar/utils/navigation.js.map +1 -1
  53. package/date-picker/index.d.ts.map +1 -1
  54. package/date-picker/index.js +2 -2
  55. package/date-picker/index.js.map +1 -1
  56. package/date-range-picker/calendar/grids/grid.d.ts +2 -1
  57. package/date-range-picker/calendar/grids/grid.d.ts.map +1 -1
  58. package/date-range-picker/calendar/grids/grid.js +55 -7
  59. package/date-range-picker/calendar/grids/grid.js.map +1 -1
  60. package/date-range-picker/calendar/grids/index.d.ts +2 -1
  61. package/date-range-picker/calendar/grids/index.d.ts.map +1 -1
  62. package/date-range-picker/calendar/grids/index.js +20 -12
  63. package/date-range-picker/calendar/grids/index.js.map +1 -1
  64. package/date-range-picker/calendar/grids/styles.css.js +28 -27
  65. package/date-range-picker/calendar/grids/styles.scoped.css +46 -42
  66. package/date-range-picker/calendar/grids/styles.selectors.js +28 -27
  67. package/date-range-picker/calendar/index.d.ts +2 -1
  68. package/date-range-picker/calendar/index.d.ts.map +1 -1
  69. package/date-range-picker/calendar/index.js +2 -2
  70. package/date-range-picker/calendar/index.js.map +1 -1
  71. package/date-range-picker/dropdown.d.ts +2 -2
  72. package/date-range-picker/dropdown.d.ts.map +1 -1
  73. package/date-range-picker/dropdown.js +2 -2
  74. package/date-range-picker/dropdown.js.map +1 -1
  75. package/date-range-picker/index.d.ts.map +1 -1
  76. package/date-range-picker/index.js +2 -2
  77. package/date-range-picker/index.js.map +1 -1
  78. package/date-range-picker/interfaces.d.ts +9 -0
  79. package/date-range-picker/interfaces.d.ts.map +1 -1
  80. package/date-range-picker/interfaces.js.map +1 -1
  81. package/internal/base-component/styles.scoped.css +12 -10
  82. package/internal/components/option/interfaces.d.ts +2 -0
  83. package/internal/components/option/interfaces.d.ts.map +1 -1
  84. package/internal/components/option/interfaces.js.map +1 -1
  85. package/internal/components/selectable-item/index.d.ts +1 -0
  86. package/internal/components/selectable-item/index.d.ts.map +1 -1
  87. package/internal/components/selectable-item/index.js +3 -0
  88. package/internal/components/selectable-item/index.js.map +1 -1
  89. package/internal/components/tooltip/index.d.ts +3 -1
  90. package/internal/components/tooltip/index.d.ts.map +1 -1
  91. package/internal/components/tooltip/index.js +3 -3
  92. package/internal/components/tooltip/index.js.map +1 -1
  93. package/internal/environment.js +1 -1
  94. package/internal/environment.json +1 -1
  95. package/internal/generated/styles/tokens.d.ts +2 -0
  96. package/internal/generated/styles/tokens.js +4 -2
  97. package/internal/generated/theming/index.cjs +78 -12
  98. package/internal/generated/theming/index.cjs.d.ts +16 -0
  99. package/internal/generated/theming/index.d.ts +16 -0
  100. package/internal/generated/theming/index.js +78 -12
  101. package/{button-dropdown/utils/use-hidden-description.d.ts → internal/hooks/use-hidden-description/index.d.ts} +2 -1
  102. package/internal/hooks/use-hidden-description/index.d.ts.map +1 -0
  103. package/{button-dropdown/utils/use-hidden-description.js → internal/hooks/use-hidden-description/index.js} +3 -2
  104. package/internal/hooks/use-hidden-description/index.js.map +1 -0
  105. package/internal/manifest.json +1 -1
  106. package/package.json +1 -1
  107. package/segmented-control/interfaces.d.ts +2 -0
  108. package/segmented-control/interfaces.d.ts.map +1 -1
  109. package/segmented-control/interfaces.js.map +1 -1
  110. package/segmented-control/internal-segmented-control.d.ts.map +1 -1
  111. package/segmented-control/internal-segmented-control.js +11 -8
  112. package/segmented-control/internal-segmented-control.js.map +1 -1
  113. package/segmented-control/segment.d.ts.map +1 -1
  114. package/segmented-control/segment.js +14 -4
  115. package/segmented-control/segment.js.map +1 -1
  116. package/segmented-control/styles.css.js +15 -14
  117. package/segmented-control/styles.scoped.css +37 -33
  118. package/segmented-control/styles.selectors.js +15 -14
  119. package/select/interfaces.d.ts +1 -0
  120. package/select/interfaces.d.ts.map +1 -1
  121. package/select/interfaces.js.map +1 -1
  122. package/select/parts/filter.d.ts +1 -1
  123. package/select/parts/item.d.ts.map +1 -1
  124. package/select/parts/item.js +13 -3
  125. package/select/parts/item.js.map +1 -1
  126. package/select/parts/multiselect-item.d.ts.map +1 -1
  127. package/select/parts/multiselect-item.js +15 -3
  128. package/select/parts/multiselect-item.js.map +1 -1
  129. package/select/parts/styles.css.js +17 -16
  130. package/select/parts/styles.scoped.css +21 -17
  131. package/select/parts/styles.selectors.js +17 -16
  132. package/split-panel/icons/styles.css.js +22 -22
  133. package/split-panel/icons/styles.scoped.css +25 -25
  134. package/split-panel/icons/styles.selectors.js +22 -22
  135. package/table/body-cell/disabled-inline-editor.js +1 -1
  136. package/table/body-cell/disabled-inline-editor.js.map +1 -1
  137. package/tabs/interfaces.d.ts +5 -0
  138. package/tabs/interfaces.d.ts.map +1 -1
  139. package/tabs/interfaces.js.map +1 -1
  140. package/tabs/styles.css.js +28 -25
  141. package/tabs/styles.scoped.css +60 -49
  142. package/tabs/styles.selectors.js +28 -25
  143. package/tabs/tab-header-bar.d.ts.map +1 -1
  144. package/tabs/tab-header-bar.js +38 -14
  145. package/tabs/tab-header-bar.js.map +1 -1
  146. package/test-utils/dom/button/index.d.ts +1 -0
  147. package/test-utils/dom/button/index.js +6 -2
  148. package/test-utils/dom/button/index.js.map +1 -1
  149. package/test-utils/dom/button-dropdown/index.d.ts +2 -1
  150. package/test-utils/dom/button-dropdown/index.js +5 -1
  151. package/test-utils/dom/button-dropdown/index.js.map +1 -1
  152. package/test-utils/dom/calendar/index.d.ts +4 -1
  153. package/test-utils/dom/calendar/index.js +8 -1
  154. package/test-utils/dom/calendar/index.js.map +1 -1
  155. package/test-utils/dom/date-range-picker/index.d.ts +4 -1
  156. package/test-utils/dom/date-range-picker/index.js +8 -2
  157. package/test-utils/dom/date-range-picker/index.js.map +1 -1
  158. package/test-utils/dom/internal/dropdown-host.js.map +1 -1
  159. package/test-utils/dom/internal/option.d.ts +1 -0
  160. package/test-utils/dom/internal/option.js +4 -0
  161. package/test-utils/dom/internal/option.js.map +1 -1
  162. package/test-utils/dom/segmented-control/index.d.ts +9 -0
  163. package/test-utils/dom/segmented-control/index.js +15 -0
  164. package/test-utils/dom/segmented-control/index.js.map +1 -1
  165. package/test-utils/dom/tabs/index.d.ts +9 -2
  166. package/test-utils/dom/tabs/index.js +15 -2
  167. package/test-utils/dom/tabs/index.js.map +1 -1
  168. package/test-utils/selectors/button/index.d.ts +1 -0
  169. package/test-utils/selectors/button/index.js +6 -2
  170. package/test-utils/selectors/button/index.js.map +1 -1
  171. package/test-utils/selectors/button-dropdown/index.d.ts +2 -1
  172. package/test-utils/selectors/button-dropdown/index.js +5 -1
  173. package/test-utils/selectors/button-dropdown/index.js.map +1 -1
  174. package/test-utils/selectors/calendar/index.d.ts +4 -1
  175. package/test-utils/selectors/calendar/index.js +8 -1
  176. package/test-utils/selectors/calendar/index.js.map +1 -1
  177. package/test-utils/selectors/date-range-picker/index.d.ts +4 -1
  178. package/test-utils/selectors/date-range-picker/index.js +8 -2
  179. package/test-utils/selectors/date-range-picker/index.js.map +1 -1
  180. package/test-utils/selectors/internal/dropdown-host.js.map +1 -1
  181. package/test-utils/selectors/internal/option.d.ts +1 -0
  182. package/test-utils/selectors/internal/option.js +4 -0
  183. package/test-utils/selectors/internal/option.js.map +1 -1
  184. package/test-utils/selectors/segmented-control/index.d.ts +9 -0
  185. package/test-utils/selectors/segmented-control/index.js +15 -0
  186. package/test-utils/selectors/segmented-control/index.js.map +1 -1
  187. package/test-utils/selectors/tabs/index.d.ts +9 -2
  188. package/test-utils/selectors/tabs/index.js +15 -2
  189. package/test-utils/selectors/tabs/index.js.map +1 -1
  190. package/test-utils/tsconfig.tsbuildinfo +1 -1
  191. package/button-dropdown/utils/use-hidden-description.d.ts.map +0 -1
  192. package/button-dropdown/utils/use-hidden-description.js.map +0 -1
@@ -1,11 +1,29 @@
1
+ import { __rest } from "tslib";
1
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
3
  // SPDX-License-Identifier: Apache-2.0
3
- import React, { useRef } from 'react';
4
+ import React, { useRef, forwardRef, useState } from 'react';
4
5
  import styles from '../styles.css.js';
5
6
  import clsx from 'clsx';
6
7
  import { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';
7
8
  import ScreenreaderOnly from '../../internal/components/screenreader-only/index.js';
8
- export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSelectDate, selectedDate, ariaLabelledby, header, rows, isCurrentPage, renderDate, renderDateAnnouncement, isSameDate, onGridKeyDownHandler, }) {
9
+ import { applyDisplayName } from '../../internal/utils/apply-display-name';
10
+ import useHiddenDescription from '../../internal/hooks/use-hidden-description';
11
+ import Tooltip from '../../internal/components/tooltip';
12
+ import { useMergeRefs } from '../../internal/hooks/use-merge-refs';
13
+ const GridCell = forwardRef((props, focusedDateRef) => {
14
+ const { disabledReason } = props, rest = __rest(props, ["disabledReason"]);
15
+ const isDisabledWithReason = !!disabledReason;
16
+ const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);
17
+ const ref = useRef(null);
18
+ const [showTooltip, setShowTooltip] = useState(false);
19
+ return (React.createElement("td", Object.assign({ ref: useMergeRefs(focusedDateRef, ref) }, (isDisabledWithReason ? targetProps : {}), rest, { onFocus: () => (isDisabledWithReason ? setShowTooltip(true) : undefined), onBlur: () => (isDisabledWithReason ? setShowTooltip(false) : undefined), onMouseEnter: () => (isDisabledWithReason ? setShowTooltip(true) : undefined), onMouseLeave: () => (isDisabledWithReason ? setShowTooltip(false) : undefined) }),
20
+ props.children,
21
+ isDisabledWithReason && (React.createElement(React.Fragment, null,
22
+ descriptionEl,
23
+ showTooltip && (React.createElement(Tooltip, { className: styles['disabled-reason-tooltip'], trackRef: ref, value: disabledReason }))))));
24
+ });
25
+ applyDisplayName(GridCell, 'GridCell');
26
+ export default function Grid({ isDateEnabled, dateDisabledReason, focusedDate, focusableDate, onSelectDate, selectedDate, ariaLabelledby, header, rows, isCurrentPage, renderDate, renderDateAnnouncement, isSameDate, onGridKeyDownHandler, }) {
9
27
  const focusedDateRef = useRef(null);
10
28
  // The focused date changes as a feedback to keyboard navigation in the grid.
11
29
  // Once changed, the corresponding date button needs to receive the actual focus.
@@ -22,18 +40,20 @@ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSele
22
40
  const isFocusable = !!focusableDate && isSameDate(date, focusableDate);
23
41
  const isSelected = !!selectedDate && isSameDate(date, selectedDate);
24
42
  const isEnabled = !isDateEnabled || isDateEnabled(date);
43
+ const disabledReason = dateDisabledReason(date);
44
+ const isDisabledWithReason = !isEnabled && !!disabledReason;
25
45
  const isCurrentDate = isSameDate(date, new Date());
26
46
  // Can't be focused.
27
47
  let tabIndex = undefined;
28
- if (isFocusable && isEnabled) {
48
+ if (isFocusable && (isEnabled || isDisabledWithReason)) {
29
49
  // Next focus target.
30
50
  tabIndex = 0;
31
51
  }
32
- else if (isEnabled) {
52
+ else if (isEnabled || isDisabledWithReason) {
33
53
  // Can be focused programmatically.
34
54
  tabIndex = -1;
35
55
  }
36
- return (React.createElement("td", { key: `${rowIndex}:${dateIndex}`, ref: tabIndex === 0 ? focusedDateRef : undefined, tabIndex: tabIndex, "aria-current": isCurrentDate ? 'date' : undefined, "aria-selected": isEnabled ? isSelected : undefined, "aria-disabled": !isEnabled,
56
+ return (React.createElement(GridCell, { key: `${rowIndex}:${dateIndex}`, ref: tabIndex === 0 ? focusedDateRef : undefined, tabIndex: tabIndex, "aria-current": isCurrentDate ? 'date' : undefined, "aria-selected": isEnabled ? isSelected : undefined, "aria-disabled": !isEnabled,
37
57
  // Do not attach click event when the date is disabled, otherwise VO+safari announces clickable
38
58
  onClick: isEnabled ? () => onSelectDate(date) : undefined, className: clsx(styles['calendar-grid-cell'], styles['calendar-date'], {
39
59
  [styles['calendar-date-current-page']]: isCurrentPage(date),
@@ -41,7 +61,7 @@ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSele
41
61
  [styles['calendar-date-selected']]: isSelected,
42
62
  [styles['calendar-date-current']]: isCurrentDate,
43
63
  [styles['calendar-date-dense']]: denseGrid,
44
- }) },
64
+ }), disabledReason: isDisabledWithReason ? disabledReason : undefined },
45
65
  React.createElement("span", { className: styles['date-inner'], "aria-hidden": "true" }, renderDate(date)),
46
66
  React.createElement(ScreenreaderOnly, null, renderDateAnnouncement(date, isCurrentDate))));
47
67
  })))))));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/calendar/grid/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,gBAAgB,MAAM,sDAAsD,CAAC;AAmCpF,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,MAAM,EACN,IAAI,EACJ,aAAa,EACb,UAAU,EACV,sBAAsB,EACtB,UAAU,EACV,oBAAoB,GACV;IACV,MAAM,cAAc,GAAG,MAAM,CAAuB,IAAI,CAAC,CAAC;IAE1D,6EAA6E;IAC7E,iFAAiF;IACjF,iBAAiB,CAAC,GAAG,EAAE;QACrB,IAAI,WAAW,IAAI,cAAc,CAAC,OAAO,EAAE;YACxC,cAAc,CAAC,OAA0B,CAAC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EAC/B,GAAG,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,EAChD,QAAQ,EAAE,QAAQ,kBACJ,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,mBACjC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,mBAClC,CAAC,SAAS;gBACzB,+FAA+F;gBAC/F,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,EACzD,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,EAAE;oBACrE,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC;oBAC3D,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,EAAE,SAAS;oBAC5C,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,UAAU;oBAC9C,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,EAAE,aAAa;oBAChD,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,EAAE,SAAS;iBAC3C,CAAC;gBAEF,8BAAM,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC,iBAAc,MAAM,IACtD,UAAU,CAAC,IAAI,CAAC,CACZ;gBAEP,oBAAC,gBAAgB,QAAE,sBAAsB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAoB,CAC/E,CACN,CAAC;QACJ,CAAC,CAAC,CACC,CACN,CAAC,CACI,CACF,CACT,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useRef } from 'react';\nimport styles from '../styles.css.js';\nimport { DatePickerProps } from '../../date-picker/interfaces';\nimport clsx from 'clsx';\nimport { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';\nimport ScreenreaderOnly from '../../internal/components/screenreader-only/index.js';\n\n/**\n * Calendar grid supports two mechanisms of keyboard navigation:\n * - Native screen-reader table navigation (semantic table markup);\n * - Keyboard arrow-keys navigation (a custom key-down handler).\n *\n * The implementation largely follows the w3 example (https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/datepicker-dialog) and shares the following issues:\n * - (table navigation) Chrome+VO - weekday is announced twice when navigating to the calendar's header;\n * - (table navigation) Safari+VO - \"dimmed\" state is announced twice;\n * - (table navigation) Firefox/Chrome+NVDA - cannot use table navigation if any cell has a focus;\n * - (keyboard navigation) Firefox+NVDA - every date is announced as \"not selected\";\n * - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;\n * - (keyboard navigation) Safari/Chrome+VO - dates are not announced as interactive (clickable or selectable);\n * - (keyboard navigation) Safari/Chrome+VO - date announcements are not interruptive and can be missed if navigating fast.\n */\n\nexport interface GridProps {\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n focusedDate: Date | null;\n focusableDate: Date | null;\n onSelectDate: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onChangePage: (date: Date) => void;\n selectedDate: Date | null;\n ariaLabelledby: string;\n header?: React.ReactNode;\n rows: ReadonlyArray<ReadonlyArray<Date>>;\n isCurrentPage: (date: Date) => boolean;\n renderDate: (date: Date) => string;\n renderDateAnnouncement: (date: Date, isOnCurrentDate: boolean) => string;\n isSameDate: (date: Date, baseDate: Date) => boolean;\n onGridKeyDownHandler: (event: React.KeyboardEvent<HTMLElement>) => void;\n}\n\nexport default function Grid({\n isDateEnabled,\n focusedDate,\n focusableDate,\n onSelectDate,\n selectedDate,\n ariaLabelledby,\n header,\n rows,\n isCurrentPage,\n renderDate,\n renderDateAnnouncement,\n isSameDate,\n onGridKeyDownHandler,\n}: GridProps) {\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n // The focused date changes as a feedback to keyboard navigation in the grid.\n // Once changed, the corresponding date button needs to receive the actual focus.\n useEffectOnUpdate(() => {\n if (focusedDate && focusedDateRef.current) {\n (focusedDateRef.current as HTMLDivElement).focus();\n }\n }, [focusedDate]);\n\n const rowLength = rows[0].length;\n\n const denseGrid = rowLength > 3;\n\n return (\n <table\n role=\"grid\"\n className={clsx(styles['calendar-grid'], denseGrid && styles['calendar-grid-dense'])}\n aria-labelledby={ariaLabelledby}\n >\n {header}\n <tbody onKeyDown={onGridKeyDownHandler}>\n {rows.map((row, rowIndex) => (\n <tr key={rowIndex} className={styles['calendar-row']}>\n {row.map((date, dateIndex) => {\n const isFocusable = !!focusableDate && isSameDate(date, focusableDate);\n const isSelected = !!selectedDate && isSameDate(date, selectedDate);\n const isEnabled = !isDateEnabled || isDateEnabled(date);\n const isCurrentDate = isSameDate(date, new Date());\n\n // Can't be focused.\n let tabIndex = undefined;\n if (isFocusable && isEnabled) {\n // Next focus target.\n tabIndex = 0;\n } else if (isEnabled) {\n // Can be focused programmatically.\n tabIndex = -1;\n }\n\n return (\n <td\n key={`${rowIndex}:${dateIndex}`}\n ref={tabIndex === 0 ? focusedDateRef : undefined}\n tabIndex={tabIndex}\n aria-current={isCurrentDate ? 'date' : undefined}\n aria-selected={isEnabled ? isSelected : undefined}\n aria-disabled={!isEnabled}\n // Do not attach click event when the date is disabled, otherwise VO+safari announces clickable\n onClick={isEnabled ? () => onSelectDate(date) : undefined}\n className={clsx(styles['calendar-grid-cell'], styles['calendar-date'], {\n [styles['calendar-date-current-page']]: isCurrentPage(date),\n [styles['calendar-date-enabled']]: isEnabled,\n [styles['calendar-date-selected']]: isSelected,\n [styles['calendar-date-current']]: isCurrentDate,\n [styles['calendar-date-dense']]: denseGrid,\n })}\n >\n <span className={styles['date-inner']} aria-hidden=\"true\">\n {renderDate(date)}\n </span>\n {/* Screen-reader announcement for the focused date. */}\n <ScreenreaderOnly>{renderDateAnnouncement(date, isCurrentDate)}</ScreenreaderOnly>\n </td>\n );\n })}\n </tr>\n ))}\n </tb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// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { TdHTMLAttributes, useRef, forwardRef, useState } from 'react';\nimport styles from '../styles.css.js';\nimport { DatePickerProps } from '../../date-picker/interfaces';\nimport { CalendarProps } from '../interfaces';\nimport clsx from 'clsx';\nimport { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';\nimport ScreenreaderOnly from '../../internal/components/screenreader-only/index.js';\nimport { applyDisplayName } from '../../internal/utils/apply-display-name';\nimport useHiddenDescription from '../../internal/hooks/use-hidden-description';\nimport Tooltip from '../../internal/components/tooltip';\nimport { useMergeRefs } from '../../internal/hooks/use-merge-refs';\n\n/**\n * Calendar grid supports two mechanisms of keyboard navigation:\n * - Native screen-reader table navigation (semantic table markup);\n * - Keyboard arrow-keys navigation (a custom key-down handler).\n *\n * The implementation largely follows the w3 example (https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/datepicker-dialog) and shares the following issues:\n * - (table navigation) Chrome+VO - weekday is announced twice when navigating to the calendar's header;\n * - (table navigation) Safari+VO - \"dimmed\" state is announced twice;\n * - (table navigation) Firefox/Chrome+NVDA - cannot use table navigation if any cell has a focus;\n * - (keyboard navigation) Firefox+NVDA - every date is announced as \"not selected\";\n * - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;\n * - (keyboard navigation) Safari/Chrome+VO - dates are not announced as interactive (clickable or selectable);\n * - (keyboard navigation) Safari/Chrome+VO - date announcements are not interruptive and can be missed if navigating fast.\n */\n\nexport interface GridProps {\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n dateDisabledReason: CalendarProps.DateDisabledReasonFunction;\n focusedDate: Date | null;\n focusableDate: Date | null;\n onSelectDate: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onChangePage: (date: Date) => void;\n selectedDate: Date | null;\n ariaLabelledby: string;\n header?: React.ReactNode;\n rows: ReadonlyArray<ReadonlyArray<Date>>;\n isCurrentPage: (date: Date) => boolean;\n renderDate: (date: Date) => string;\n renderDateAnnouncement: (date: Date, isOnCurrentDate: boolean) => string;\n isSameDate: (date: Date, baseDate: Date) => boolean;\n onGridKeyDownHandler: (event: React.KeyboardEvent<HTMLElement>) => void;\n}\n\ninterface GridCellProps extends TdHTMLAttributes<HTMLTableCellElement> {\n disabledReason?: string;\n}\n\nconst GridCell = forwardRef((props: GridCellProps, focusedDateRef: React.Ref<HTMLTableCellElement>) => {\n const { disabledReason, ...rest } = props;\n const isDisabledWithReason = !!disabledReason;\n const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);\n const ref = useRef<HTMLTableCellElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n return (\n <td\n ref={useMergeRefs(focusedDateRef, ref)}\n {...(isDisabledWithReason ? targetProps : {})}\n {...rest}\n onFocus={() => (isDisabledWithReason ? setShowTooltip(true) : undefined)}\n onBlur={() => (isDisabledWithReason ? setShowTooltip(false) : undefined)}\n onMouseEnter={() => (isDisabledWithReason ? setShowTooltip(true) : undefined)}\n onMouseLeave={() => (isDisabledWithReason ? setShowTooltip(false) : undefined)}\n >\n {props.children}\n {isDisabledWithReason && (\n <>\n {descriptionEl}\n {showTooltip && (\n <Tooltip className={styles['disabled-reason-tooltip']} trackRef={ref} value={disabledReason!} />\n )}\n </>\n )}\n </td>\n );\n});\n\napplyDisplayName(GridCell, 'GridCell');\n\nexport default function Grid({\n isDateEnabled,\n dateDisabledReason,\n focusedDate,\n focusableDate,\n onSelectDate,\n selectedDate,\n ariaLabelledby,\n header,\n rows,\n isCurrentPage,\n renderDate,\n renderDateAnnouncement,\n isSameDate,\n onGridKeyDownHandler,\n}: GridProps) {\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n // The focused date changes as a feedback to keyboard navigation in the grid.\n // Once changed, the corresponding date button needs to receive the actual focus.\n useEffectOnUpdate(() => {\n if (focusedDate && focusedDateRef.current) {\n (focusedDateRef.current as HTMLDivElement).focus();\n }\n }, [focusedDate]);\n\n const rowLength = rows[0].length;\n\n const denseGrid = rowLength > 3;\n\n return (\n <table\n role=\"grid\"\n className={clsx(styles['calendar-grid'], denseGrid && styles['calendar-grid-dense'])}\n aria-labelledby={ariaLabelledby}\n >\n {header}\n <tbody onKeyDown={onGridKeyDownHandler}>\n {rows.map((row, rowIndex) => (\n <tr key={rowIndex} className={styles['calendar-row']}>\n {row.map((date, dateIndex) => {\n const isFocusable = !!focusableDate && isSameDate(date, focusableDate);\n const isSelected = !!selectedDate && isSameDate(date, selectedDate);\n const isEnabled = !isDateEnabled || isDateEnabled(date);\n const disabledReason = dateDisabledReason(date);\n const isDisabledWithReason = !isEnabled && !!disabledReason;\n const isCurrentDate = isSameDate(date, new Date());\n\n // Can't be focused.\n let tabIndex = undefined;\n if (isFocusable && (isEnabled || isDisabledWithReason)) {\n // Next focus target.\n tabIndex = 0;\n } else if (isEnabled || isDisabledWithReason) {\n // Can be focused programmatically.\n tabIndex = -1;\n }\n\n return (\n <GridCell\n key={`${rowIndex}:${dateIndex}`}\n ref={tabIndex === 0 ? focusedDateRef : undefined}\n tabIndex={tabIndex}\n aria-current={isCurrentDate ? 'date' : undefined}\n aria-selected={isEnabled ? isSelected : undefined}\n aria-disabled={!isEnabled}\n // Do not attach click event when the date is disabled, otherwise VO+safari announces clickable\n onClick={isEnabled ? () => onSelectDate(date) : undefined}\n className={clsx(styles['calendar-grid-cell'], styles['calendar-date'], {\n [styles['calendar-date-current-page']]: isCurrentPage(date),\n [styles['calendar-date-enabled']]: isEnabled,\n [styles['calendar-date-selected']]: isSelected,\n [styles['calendar-date-current']]: isCurrentDate,\n [styles['calendar-date-dense']]: denseGrid,\n })}\n disabledReason={isDisabledWithReason ? disabledReason : undefined}\n >\n <span className={styles['date-inner']} aria-hidden=\"true\">\n {renderDate(date)}\n </span>\n {/* Screen-reader announcement for the focused date. */}\n <ScreenreaderOnly>{renderDateAnnouncement(date, isCurrentDate)}</ScreenreaderOnly>\n </GridCell>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n );\n}\n"]}
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import { CalendarProps } from '../interfaces';
3
- export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }: {
3
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, isDateFocusable, onChangePage, onFocusDate, onSelectDate, }: {
4
4
  baseDate: Date;
5
5
  focusableDate: Date | null;
6
6
  granularity: CalendarProps.Granularity;
7
7
  isDateEnabled: CalendarProps.IsDateEnabledFunction;
8
+ isDateFocusable: CalendarProps.IsDateEnabledFunction;
8
9
  onChangePage: (date: Date) => void;
9
10
  onFocusDate: (date: null | Date) => void;
10
11
  onSelectDate: (date: Date) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-keyboard-navigation.d.ts","sourceRoot":"","sources":["../../../../src/calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAc9C,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC;IACf,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC,qBAAqB,CAAC;IACnD,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACpC,WAUsC,mBAAmB,CAAC,WAAW,CAAC,UAiCtE"}
1
+ {"version":3,"file":"use-calendar-grid-keyboard-navigation.d.ts","sourceRoot":"","sources":["../../../../src/calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAc9C,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC;IACf,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC;IAEvC,aAAa,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAEnD,eAAe,EAAE,aAAa,CAAC,qBAAqB,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACpC,WAUsC,mBAAmB,CAAC,WAAW,CAAC,UAqCtE"}
@@ -4,7 +4,7 @@ import { isSameMonth, isSameYear } from 'date-fns';
4
4
  import { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek, moveNextMonth, movePrevMonth, moveMonthDown, moveMonthUp, } from '../utils/navigation';
5
5
  import { KeyCode } from '../../internal/keycode';
6
6
  import handleKey from '../../internal/utils/handle-key';
7
- export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }) {
7
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, isDateFocusable, onChangePage, onFocusDate, onSelectDate, }) {
8
8
  const isMonthPicker = granularity === 'month';
9
9
  const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;
10
10
  const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;
@@ -20,13 +20,16 @@ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableD
20
20
  event.preventDefault();
21
21
  handleKey(event, {
22
22
  onActivate: () => {
23
+ if (!isDateEnabled(focusableDate)) {
24
+ return;
25
+ }
23
26
  onFocusDate(null);
24
27
  onSelectDate(focusableDate);
25
28
  },
26
- onBlockEnd: () => (updatedFocusDate = moveDown(focusableDate, isDateEnabled)),
27
- onBlockStart: () => (updatedFocusDate = moveUp(focusableDate, isDateEnabled)),
28
- onInlineStart: () => (updatedFocusDate = moveLeft(focusableDate, isDateEnabled)),
29
- onInlineEnd: () => (updatedFocusDate = moveRight(focusableDate, isDateEnabled)),
29
+ onBlockEnd: () => (updatedFocusDate = moveDown(focusableDate, isDateFocusable)),
30
+ onBlockStart: () => (updatedFocusDate = moveUp(focusableDate, isDateFocusable)),
31
+ onInlineStart: () => (updatedFocusDate = moveLeft(focusableDate, isDateFocusable)),
32
+ onInlineEnd: () => (updatedFocusDate = moveRight(focusableDate, isDateFocusable)),
30
33
  });
31
34
  if (!updatedFocusDate) {
32
35
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-keyboard-navigation.js","sourceRoot":"","sources":["../../../../src/calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,SAAS,MAAM,iCAAiC,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,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Y,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;YAC7E,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;YAChF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;SAChF,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO;SACR;QAED,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE;YAC3C,YAAY,CAAC,gBAAgB,CAAC,CAAC;SAChC;QACD,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,oBAAoB,CAAC;AAC9B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React from 'react';\nimport { isSameMonth, isSameYear } from 'date-fns';\nimport { CalendarProps } from '../interfaces';\nimport {\n moveNextDay,\n movePrevDay,\n moveNextWeek,\n movePrevWeek,\n moveNextMonth,\n movePrevMonth,\n moveMonthDown,\n moveMonthUp,\n} from '../utils/navigation';\nimport { KeyCode } from '../../internal/keycode';\nimport handleKey from '../../internal/utils/handle-key';\n\nexport default function useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n onChangePage,\n onFocusDate,\n onSelectDate,\n}: {\n baseDate: Date;\n focusableDate: Date | null;\n granularity: CalendarProps.Granularity;\n isDateEnabled: CalendarProps.IsDateEnabledFunction;\n onChangePage: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onSelectDate: (date: Date) => void;\n}) {\n const isMonthPicker = granularity === 'month';\n\n const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;\n const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;\n const moveRight = isMonthPicker ? moveNextMonth : moveNextDay;\n const moveUp = isMonthPicker ? moveMonthUp : movePrevWeek;\n\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n\n const onGridKeyDownHandler = (event: React.KeyboardEvent<HTMLElement>) => {\n let updatedFocusDate;\n\n const keys = [KeyCode.up, KeyCode.down, KeyCode.left, KeyCode.right, KeyCode.space, KeyCode.enter];\n\n if (focusableDate === null || keys.indexOf(event.keyCode) === -1) {\n return;\n }\n\n event.preventDefault();\n\n handleKey(event, {\n onActivate: () => {\n onFocusDate(null);\n onSelectDate(focusableDate);\n },\n onBlockEnd: () => (updatedFocusDate = moveDown(focusableDate, isDateEnabled)),\n onBlockStart: () => (updatedFocusDate = moveUp(focusableDate, isDateEnabled)),\n onInlineStart: () => (updatedFocusDate = moveLeft(focusableDate, isDateEnabled)),\n onInlineEnd: () => (updatedFocusDate = moveRight(focusableDate, isDateEnabled)),\n });\n\n if (!updatedFocusDate) {\n return;\n }\n\n if (!isSamePage(updatedFocusDate, baseDate)) {\n onChangePage(updatedFocusDate);\n }\n onFocusDate(updatedFocusDate);\n };\n\n return onGridKeyDownHandler;\n}\n"]}
1
+ {"version":3,"file":"use-calendar-grid-keyboard-navigation.js","sourceRoot":"","sources":["../../../../src/calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,SAAS,MAAM,iCAAiC,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,WAAW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AQ,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;YAC/E,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;YAC/E,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;YAClF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,GAAG,SAAS,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;SAClF,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO;SACR;QAED,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE;YAC3C,YAAY,CAAC,gBAAgB,CAAC,CAAC;SAChC;QACD,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,oBAAoB,CAAC;AAC9B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React from 'react';\nimport { isSameMonth, isSameYear } from 'date-fns';\nimport { CalendarProps } from '../interfaces';\nimport {\n moveNextDay,\n movePrevDay,\n moveNextWeek,\n movePrevWeek,\n moveNextMonth,\n movePrevMonth,\n moveMonthDown,\n moveMonthUp,\n} from '../utils/navigation';\nimport { KeyCode } from '../../internal/keycode';\nimport handleKey from '../../internal/utils/handle-key';\n\nexport default function useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n isDateFocusable,\n onChangePage,\n onFocusDate,\n onSelectDate,\n}: {\n baseDate: Date;\n focusableDate: Date | null;\n granularity: CalendarProps.Granularity;\n // determines if a date could be selected by user actions\n isDateEnabled: CalendarProps.IsDateEnabledFunction;\n // a date could be not enabled (isDateEnabled returns false), but focusable if it's disabled with reason\n isDateFocusable: CalendarProps.IsDateEnabledFunction;\n onChangePage: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onSelectDate: (date: Date) => void;\n}) {\n const isMonthPicker = granularity === 'month';\n\n const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;\n const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;\n const moveRight = isMonthPicker ? moveNextMonth : moveNextDay;\n const moveUp = isMonthPicker ? moveMonthUp : movePrevWeek;\n\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n\n const onGridKeyDownHandler = (event: React.KeyboardEvent<HTMLElement>) => {\n let updatedFocusDate;\n\n const keys = [KeyCode.up, KeyCode.down, KeyCode.left, KeyCode.right, KeyCode.space, KeyCode.enter];\n\n if (focusableDate === null || keys.indexOf(event.keyCode) === -1) {\n return;\n }\n\n event.preventDefault();\n\n handleKey(event, {\n onActivate: () => {\n if (!isDateEnabled(focusableDate)) {\n return;\n }\n\n onFocusDate(null);\n onSelectDate(focusableDate);\n },\n onBlockEnd: () => (updatedFocusDate = moveDown(focusableDate, isDateFocusable)),\n onBlockStart: () => (updatedFocusDate = moveUp(focusableDate, isDateFocusable)),\n onInlineStart: () => (updatedFocusDate = moveLeft(focusableDate, isDateFocusable)),\n onInlineEnd: () => (updatedFocusDate = moveRight(focusableDate, isDateFocusable)),\n });\n\n if (!updatedFocusDate) {\n return;\n }\n\n if (!isSamePage(updatedFocusDate, baseDate)) {\n onChangePage(updatedFocusDate);\n }\n onFocusDate(updatedFocusDate);\n };\n\n return onGridKeyDownHandler;\n}\n"]}
@@ -13,6 +13,12 @@ export interface CalendarProps extends BaseComponentProps {
13
13
  * @param date
14
14
  */
15
15
  isDateEnabled?: CalendarProps.IsDateEnabledFunction;
16
+ /**
17
+ * Provides a reason why a particular date in the calendar is not enabled (only when `isDateEnabled` returns `false`).
18
+ * If provided, the date becomes focusable.
19
+ * @param date
20
+ */
21
+ dateDisabledReason?: CalendarProps.DateDisabledReasonFunction;
16
22
  /**
17
23
  * Specifies the locale to use to render month names and determine the starting day of the week.
18
24
  * If you don't provide this, the locale is determined by the page and browser locales.
@@ -79,6 +85,9 @@ export declare namespace CalendarProps {
79
85
  interface IsDateEnabledFunction {
80
86
  (date: Date): boolean;
81
87
  }
88
+ interface DateDisabledReasonFunction {
89
+ (date: Date): string;
90
+ }
82
91
  type Granularity = 'day' | 'month';
83
92
  interface I18nStrings {
84
93
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACvD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAEpD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,EAAE,yBAAyB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;IAExC;;;QAGI;IACJ,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;CACzC;AAED,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,YA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GG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,EAAE,yBAAyB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;IAExC;;;QAGI;IACJ,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;CACzC;AAED,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,YAAY;QAC3B;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf;IAED,UAAiB,qBAAqB;QACpC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;KACvB;IAED,UAAiB,0BAA0B;QACzC,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;KACtB;IAED,KAAY,WAAW,GAAG,KAAK,GAAG,OAAO,CAAC;IAE1C,UAAiB,WAAW;QAC1B;;WAEG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QAExB;;WAEG;QACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAE5B;;WAEG;QACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAEhC;;;WAGG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAE/B;;;WAGG;QACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAE3B;;;WAGG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BaseComponentProps } from '../internal/base-component';\nimport { NonCancelableEventHandler } from '../internal/events';\n\nexport interface CalendarProps extends BaseComponentProps {\n /**\n * The current input value, in YYYY-MM-DD format.\n */\n value: string;\n\n /**\n * Defines whether a particular date is enabled in the calendar or not.\n * If you disable a date in the calendar, users can still enter this date using a keyboard.\n * We recommend that you also validate these constraints on the client-side and server-side\n * as you would for other form elements.\n * @param date\n */\n isDateEnabled?: CalendarProps.IsDateEnabledFunction;\n\n /**\n * Specifies the locale to use to render month names and determine the starting day of the week.\n * If you don't provide this, the locale is determined by the page and browser locales.\n * Supported values and formats are listed in the\n * [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Determines the starting day of the week. The values 0-6 map to Sunday-Saturday.\n * By default the starting day of the week is defined by the locale, but you can use this property to override it.\n */\n startOfWeek?: number;\n\n /**\n * Adds an `aria-label` to the calendar.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the calendar.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the calendar.\n */\n ariaDescribedby?: string;\n\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n * @deprecated Use `i18nString.todayAriaLabel` instead.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n * @deprecated Use `i18nStrings.nextMonthAriaLabel` instead.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n * @deprecated Use `i18nStrings.previousMonthAriaLabel` instead.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Called whenever a user changes the input value (by typing, pasting, or selecting a value).\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<CalendarProps.ChangeDetail>;\n\n /**\n * An object containing all the necessary localized strings required by\n * the component.\n * @i18n\n */\n i18nStrings?: CalendarProps.I18nStrings;\n\n /**\n * Specifies the granularity at which users will be able to select a date.\n * Defaults to `day`.\n **/\n granularity?: CalendarProps.Granularity;\n}\n\nexport namespace CalendarProps {\n export interface ChangeDetail {\n /**\n * The new value of this component.\n */\n value: string;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export type Granularity = 'day' | 'month';\n\n export interface I18nStrings {\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Used as part of the `aria-label` for the current month in the calendar.\n * @i18n\n */\n currentMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next year' button.\n * @i18n\n */\n nextYearAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous year' button.\n * @i18n\n */\n previousYearAriaLabel?: string;\n }\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BaseComponentProps } from '../internal/base-component';\nimport { NonCancelableEventHandler } from '../internal/events';\n\nexport interface CalendarProps extends BaseComponentProps {\n /**\n * The current input value, in YYYY-MM-DD format.\n */\n value: string;\n\n /**\n * Defines whether a particular date is enabled in the calendar or not.\n * If you disable a date in the calendar, users can still enter this date using a keyboard.\n * We recommend that you also validate these constraints on the client-side and server-side\n * as you would for other form elements.\n * @param date\n */\n isDateEnabled?: CalendarProps.IsDateEnabledFunction;\n\n /**\n * Provides a reason why a particular date in the calendar is not enabled (only when `isDateEnabled` returns `false`).\n * If provided, the date becomes focusable.\n * @param date\n */\n dateDisabledReason?: CalendarProps.DateDisabledReasonFunction;\n\n /**\n * Specifies the locale to use to render month names and determine the starting day of the week.\n * If you don't provide this, the locale is determined by the page and browser locales.\n * Supported values and formats are listed in the\n * [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Determines the starting day of the week. The values 0-6 map to Sunday-Saturday.\n * By default the starting day of the week is defined by the locale, but you can use this property to override it.\n */\n startOfWeek?: number;\n\n /**\n * Adds an `aria-label` to the calendar.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the calendar.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the calendar.\n */\n ariaDescribedby?: string;\n\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n * @deprecated Use `i18nString.todayAriaLabel` instead.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n * @deprecated Use `i18nStrings.nextMonthAriaLabel` instead.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n * @deprecated Use `i18nStrings.previousMonthAriaLabel` instead.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Called whenever a user changes the input value (by typing, pasting, or selecting a value).\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<CalendarProps.ChangeDetail>;\n\n /**\n * An object containing all the necessary localized strings required by\n * the component.\n * @i18n\n */\n i18nStrings?: CalendarProps.I18nStrings;\n\n /**\n * Specifies the granularity at which users will be able to select a date.\n * Defaults to `day`.\n **/\n granularity?: CalendarProps.Granularity;\n}\n\nexport namespace CalendarProps {\n export interface ChangeDetail {\n /**\n * The new value of this component.\n */\n value: string;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface DateDisabledReasonFunction {\n (date: Date): string;\n }\n\n export type Granularity = 'day' | 'month';\n\n export interface I18nStrings {\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Used as part of the `aria-label` for the current month in the calendar.\n * @i18n\n */\n currentMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next year' button.\n * @i18n\n */\n nextYearAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous year' button.\n * @i18n\n */\n previousYearAriaLabel?: string;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { CalendarProps } from './interfaces.js';
3
3
  import { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';
4
- export default function Calendar({ value, locale, startOfWeek, isDateEnabled, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, granularity, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel, ...rest }: CalendarProps & InternalBaseComponentProps): JSX.Element;
4
+ export default function Calendar({ value, locale, startOfWeek, isDateEnabled, dateDisabledReason, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, granularity, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel, ...rest }: CalendarProps & InternalBaseComponentProps): JSX.Element;
5
5
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAS3F,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAK,EACL,MAAW,EACX,WAAW,EACX,aAA0B,EAC1B,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,WAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,GAAG,IAAI,EACR,EAAE,aAAa,GAAG,0BAA0B,eAgJ5C"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAS3F,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAK,EACL,MAAW,EACX,WAAW,EACX,aAA0B,EAC1B,kBAA6B,EAC7B,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,WAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,GAAG,IAAI,EACR,EAAE,aAAa,GAAG,0BAA0B,eAoJ5C"}
@@ -20,7 +20,7 @@ import useCalendarGridRows from './grid/use-calendar-grid-rows';
20
20
  import useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';
21
21
  import CalendarGridHeader from './grid/calendar-grid-header';
22
22
  export default function Calendar(_a) {
23
- var { value, locale = '', startOfWeek, isDateEnabled = () => true, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, granularity = 'day', previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel } = _a, rest = __rest(_a, ["value", "locale", "startOfWeek", "isDateEnabled", "ariaLabel", "ariaLabelledby", "ariaDescribedby", "onChange", "__internalRootRef", "i18nStrings", "granularity", "previousMonthAriaLabel", "nextMonthAriaLabel", "todayAriaLabel"]);
23
+ var { value, locale = '', startOfWeek, isDateEnabled = () => true, dateDisabledReason = () => '', ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, granularity = 'day', previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel } = _a, rest = __rest(_a, ["value", "locale", "startOfWeek", "isDateEnabled", "dateDisabledReason", "ariaLabel", "ariaLabelledby", "ariaDescribedby", "onChange", "__internalRootRef", "i18nStrings", "granularity", "previousMonthAriaLabel", "nextMonthAriaLabel", "todayAriaLabel"]);
24
24
  checkControlled('Calendar', 'value', value, 'onChange', onChange);
25
25
  const baseProps = getBaseProps(rest);
26
26
  const normalizedLocale = normalizeLocale('Calendar', locale);
@@ -35,6 +35,7 @@ export default function Calendar(_a) {
35
35
  const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);
36
36
  const headingId = useUniqueId('calendar-heading');
37
37
  const isMonthPicker = granularity === 'month';
38
+ const isDateFocusable = (date) => isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));
38
39
  const baseDate = isMonthPicker
39
40
  ? getBaseMonth(displayedDate, isDateEnabled)
40
41
  : getBaseDay(displayedDate, isDateEnabled);
@@ -55,14 +56,14 @@ export default function Calendar(_a) {
55
56
  memoizedValue && setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));
56
57
  }, [memoizedValue]);
57
58
  const selectFocusedDate = (selected, baseDate) => {
58
- if (selected && isDateEnabled(selected) && isSamePage(selected, baseDate)) {
59
+ if (selected && isDateFocusable(selected) && isSamePage(selected, baseDate)) {
59
60
  return selected;
60
61
  }
61
62
  const today = new Date();
62
- if (isDateEnabled(today) && isSamePage(today, baseDate)) {
63
+ if (isDateFocusable(today) && isSamePage(today, baseDate)) {
63
64
  return today;
64
65
  }
65
- if (isDateEnabled(baseDate)) {
66
+ if (isDateFocusable(baseDate)) {
66
67
  return baseDate;
67
68
  }
68
69
  return null;
@@ -98,6 +99,7 @@ export default function Calendar(_a) {
98
99
  focusableDate,
99
100
  granularity,
100
101
  isDateEnabled,
102
+ isDateFocusable,
101
103
  onChangePage: onChangePageHandler,
102
104
  onFocusDate: onGridFocusDateHandler,
103
105
  onSelectDate: onGridSelectDateHandler,
@@ -107,6 +109,6 @@ export default function Calendar(_a) {
107
109
  React.createElement("div", { className: styles['calendar-inner'] },
108
110
  React.createElement(CalendarHeader, { formattedDate: headerText, onChange: onHeaderChangePageHandler, previousLabel: previousButtonLabel, nextLabel: nextButtonLabel, headingId: headingId }),
109
111
  React.createElement("div", { onBlur: onGridBlur, ref: gridWrapperRef },
110
- React.createElement(Grid, { isDateEnabled: isDateEnabled, focusedDate: focusedDate, focusableDate: focusableDate, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangePage: onChangePageHandler, selectedDate: memoizedValue, ariaLabelledby: headingId, header: isMonthPicker ? null : React.createElement(CalendarGridHeader, { locale: normalizedLocale, rows: gridRows }), rows: gridRows, isCurrentPage: isCurrentPage, renderDate: renderDate, renderDateAnnouncement: renderDateAnnouncement, isSameDate: isSameDate, onGridKeyDownHandler: onGridKeyDownHandler })))));
112
+ React.createElement(Grid, { isDateEnabled: isDateEnabled, dateDisabledReason: dateDisabledReason, focusedDate: focusedDate, focusableDate: focusableDate, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangePage: onChangePageHandler, selectedDate: memoizedValue, ariaLabelledby: headingId, header: isMonthPicker ? null : React.createElement(CalendarGridHeader, { locale: normalizedLocale, rows: gridRows }), rows: gridRows, isCurrentPage: isCurrentPage, renderDate: renderDate, renderDateAnnouncement: renderDateAnnouncement, isSameDate: isSameDate, onGridKeyDownHandler: onGridKeyDownHandler })))));
111
113
  }
112
114
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,cAAc,MAAM,UAAU,CAAC;AACtC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0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e,EACjC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC;QAElE,6BAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC;YACtC,oBAAC,cAAc,IACb,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,yBAAyB,EACnC,aAAa,EAAE,mBAAmB,EAClC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,SAAS,GACpB;YACF,6BAAK,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,cAAc;gBAC1C,oBAAC,IAAI,IACH,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,uBAAuB,EACrC,WAAW,EAAE,sBAAsB,EACnC,YAAY,EAAE,mBAAmB,EACjC,YAAY,EAAE,aAAa,EAC3B,cAAc,EAAE,SAAS,EACzB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAC,kBAAkB,IAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAI,EAC/F,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,GAC1C,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';\nimport styles from './styles.css.js';\nimport CalendarHeader from './header';\nimport Grid from './grid';\nimport { normalizeLocale } from '../internal/utils/locale';\nimport { formatDate, parseDate } from '../internal/utils/date-time';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport checkControlled from '../internal/hooks/check-controlled/index.js';\nimport clsx from 'clsx';\nimport { CalendarProps } from './interfaces.js';\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { getBaseDay, getBaseMonth } from './utils/navigation';\nimport { useDateCache } from '../internal/hooks/use-date-cache/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id/index.js';\nimport useCalendarLabels from './use-calendar-labels';\nimport useCalendarGridRows from './grid/use-calendar-grid-rows';\nimport useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';\nimport CalendarGridHeader from './grid/calendar-grid-header';\n\nexport default function Calendar({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n onChange,\n __internalRootRef,\n i18nStrings,\n granularity = 'day',\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n ...rest\n}: CalendarProps & InternalBaseComponentProps) {\n checkControlled('Calendar', 'value', value, 'onChange', onChange);\n\n const baseProps = getBaseProps(rest);\n const normalizedLocale = normalizeLocale('Calendar', locale);\n\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [focusedDate, setFocusedDate] = useState<Date | null>(null);\n\n const valueDateCache = useDateCache();\n const focusedDateCache = useDateCache();\n\n // Set displayed date to value if defined or to current date otherwise.\n const parsedValue = value && value.length >= 4 ? parseDate(value) : null;\n const memoizedValue = parsedValue ? valueDateCache(parsedValue) : null;\n const defaultDisplayedDate = memoizedValue ?? new Date();\n const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);\n\n const headingId = useUniqueId('calendar-heading');\n\n const isMonthPicker = granularity === 'month';\n\n const baseDate = isMonthPicker\n ? getBaseMonth(displayedDate, isDateEnabled)\n : getBaseDay(displayedDate, isDateEnabled);\n\n const isSameDate = isMonthPicker ? isSameMonth : isSameDay;\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n const isCurrentPage = (date: Date) => isMonthPicker || isSameMonth(date, baseDate);\n\n const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } =\n useCalendarLabels({\n granularity,\n i18nStrings,\n locale: normalizedLocale,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n });\n\n const gridRows = useCalendarGridRows({ baseDate, granularity, startOfWeek, locale: normalizedLocale });\n\n // Update displayed date if value changes.\n useEffect(() => {\n memoizedValue && setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));\n }, [memoizedValue]);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateEnabled(selected) && isSamePage(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSamePage(today, baseDate)) {\n return today;\n }\n if (isDateEnabled(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);\n\n const onHeaderChangePageHandler = (amount: number) => {\n const movePage = isMonthPicker ? addYears : addMonths;\n const newDate = movePage(baseDate, amount);\n onChangePageHandler(newDate);\n };\n\n const onChangePageHandler = (newDate: Date) => {\n setDisplayedDate(newDate);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler = (date: null | Date) => {\n if (date) {\n setFocusedDate(date ? focusedDateCache(date) : null);\n }\n };\n\n const onGridSelectDateHandler = (date: Date) => {\n fireNonCancelableEvent(onChange, { value: formatDate(date, granularity) });\n setFocusedDate(null);\n };\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setFocusedDate(null);\n }\n };\n\n const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n onChangePage: onChangePageHandler,\n onFocusDate: onGridFocusDateHandler,\n onSelectDate: onGridSelectDateHandler,\n });\n\n const headerText = renderHeaderText(baseDate);\n\n return (\n <div\n ref={__internalRootRef}\n {...baseProps}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n className={clsx(styles.root, styles.calendar, baseProps.className)}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n formattedDate={headerText}\n onChange={onHeaderChangePageHandler}\n previousLabel={previousButtonLabel}\n nextLabel={nextButtonLabel}\n headingId={headingId}\n />\n <div onBlur={onGridBlur} ref={gridWrapperRef}>\n <Grid\n isDateEnabled={isDateEnabled}\n focusedDate={focusedDate}\n focusableDate={focusableDate}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangePage={onChangePageHandler}\n selectedDate={memoizedValue}\n ariaLabelledby={headingId}\n header={isMonthPicker ? null : <CalendarGridHeader locale={normalizedLocale} rows={gridRows} />}\n rows={gridRows}\n isCurrentPage={isCurrentPage}\n renderDate={renderDate}\n renderDateAnnouncement={renderDateAnnouncement}\n isSameDate={isSameDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n />\n </div>\n </div>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,cAAc,MAAM,UAAU,CAAC;AACtC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,M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CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAO,CACL,2CACE,GAAG,EAAE,iBAAiB,IAClB,SAAS,IACb,IAAI,EAAC,OAAO,gBACA,SAAS,qBACJ,cAAc,sBACb,eAAe,EACjC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC;QAElE,6BAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC;YACtC,oBAAC,cAAc,IACb,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,yBAAyB,EACnC,aAAa,EAAE,mBAAmB,EAClC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,SAAS,GACpB;YACF,6BAAK,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,cAAc;gBAC1C,oBAAC,IAAI,IACH,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,uBAAuB,EACrC,WAAW,EAAE,sBAAsB,EACnC,YAAY,EAAE,mBAAmB,EACjC,YAAY,EAAE,aAAa,EAC3B,cAAc,EAAE,SAAS,EACzB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAC,kBAAkB,IAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAI,EAC/F,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,GAC1C,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';\nimport styles from './styles.css.js';\nimport CalendarHeader from './header';\nimport Grid from './grid';\nimport { normalizeLocale } from '../internal/utils/locale';\nimport { formatDate, parseDate } from '../internal/utils/date-time';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport checkControlled from '../internal/hooks/check-controlled/index.js';\nimport clsx from 'clsx';\nimport { CalendarProps } from './interfaces.js';\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { getBaseDay, getBaseMonth } from './utils/navigation';\nimport { useDateCache } from '../internal/hooks/use-date-cache/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id/index.js';\nimport useCalendarLabels from './use-calendar-labels';\nimport useCalendarGridRows from './grid/use-calendar-grid-rows';\nimport useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';\nimport CalendarGridHeader from './grid/calendar-grid-header';\n\nexport default function Calendar({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n dateDisabledReason = () => '',\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n onChange,\n __internalRootRef,\n i18nStrings,\n granularity = 'day',\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n ...rest\n}: CalendarProps & InternalBaseComponentProps) {\n checkControlled('Calendar', 'value', value, 'onChange', onChange);\n\n const baseProps = getBaseProps(rest);\n const normalizedLocale = normalizeLocale('Calendar', locale);\n\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [focusedDate, setFocusedDate] = useState<Date | null>(null);\n\n const valueDateCache = useDateCache();\n const focusedDateCache = useDateCache();\n\n // Set displayed date to value if defined or to current date otherwise.\n const parsedValue = value && value.length >= 4 ? parseDate(value) : null;\n const memoizedValue = parsedValue ? valueDateCache(parsedValue) : null;\n const defaultDisplayedDate = memoizedValue ?? new Date();\n const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);\n\n const headingId = useUniqueId('calendar-heading');\n\n const isMonthPicker = granularity === 'month';\n\n const isDateFocusable = (date: Date) => isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));\n\n const baseDate = isMonthPicker\n ? getBaseMonth(displayedDate, isDateEnabled)\n : getBaseDay(displayedDate, isDateEnabled);\n\n const isSameDate = isMonthPicker ? isSameMonth : isSameDay;\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n const isCurrentPage = (date: Date) => isMonthPicker || isSameMonth(date, baseDate);\n\n const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } =\n useCalendarLabels({\n granularity,\n i18nStrings,\n locale: normalizedLocale,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n });\n\n const gridRows = useCalendarGridRows({ baseDate, granularity, startOfWeek, locale: normalizedLocale });\n\n // Update displayed date if value changes.\n useEffect(() => {\n memoizedValue && setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));\n }, [memoizedValue]);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateFocusable(selected) && isSamePage(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateFocusable(today) && isSamePage(today, baseDate)) {\n return today;\n }\n if (isDateFocusable(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);\n\n const onHeaderChangePageHandler = (amount: number) => {\n const movePage = isMonthPicker ? addYears : addMonths;\n const newDate = movePage(baseDate, amount);\n onChangePageHandler(newDate);\n };\n\n const onChangePageHandler = (newDate: Date) => {\n setDisplayedDate(newDate);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler = (date: null | Date) => {\n if (date) {\n setFocusedDate(date ? focusedDateCache(date) : null);\n }\n };\n\n const onGridSelectDateHandler = (date: Date) => {\n fireNonCancelableEvent(onChange, { value: formatDate(date, granularity) });\n setFocusedDate(null);\n };\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setFocusedDate(null);\n }\n };\n\n const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n isDateFocusable,\n onChangePage: onChangePageHandler,\n onFocusDate: onGridFocusDateHandler,\n onSelectDate: onGridSelectDateHandler,\n });\n\n const headerText = renderHeaderText(baseDate);\n\n return (\n <div\n ref={__internalRootRef}\n {...baseProps}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n className={clsx(styles.root, styles.calendar, baseProps.className)}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n formattedDate={headerText}\n onChange={onHeaderChangePageHandler}\n previousLabel={previousButtonLabel}\n nextLabel={nextButtonLabel}\n headingId={headingId}\n />\n <div onBlur={onGridBlur} ref={gridWrapperRef}>\n <Grid\n isDateEnabled={isDateEnabled}\n dateDisabledReason={dateDisabledReason}\n focusedDate={focusedDate}\n focusableDate={focusableDate}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangePage={onChangePageHandler}\n selectedDate={memoizedValue}\n ariaLabelledby={headingId}\n header={isMonthPicker ? null : <CalendarGridHeader locale={normalizedLocale} rows={gridRows} />}\n rows={gridRows}\n isCurrentPage={isCurrentPage}\n renderDate={renderDate}\n renderDateAnnouncement={renderDateAnnouncement}\n isSameDate={isSameDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n />\n </div>\n </div>\n </div>\n );\n}\n"]}
@@ -1,25 +1,26 @@
1
1
 
2
2
  import './styles.scoped.css';
3
3
  export default {
4
- "calendar": "awsui_calendar_1ykar_183yz_97",
5
- "awsui-motion-fade-in-0": "awsui_awsui-motion-fade-in-0_1ykar_183yz_1",
6
- "root": "awsui_root_1ykar_183yz_128",
7
- "calendar-inner": "awsui_calendar-inner_1ykar_183yz_169",
8
- "calendar-header": "awsui_calendar-header_1ykar_183yz_173",
9
- "calendar-header-title": "awsui_calendar-header-title_1ykar_183yz_178",
10
- "calendar-next-btn": "awsui_calendar-next-btn_1ykar_183yz_186",
11
- "calendar-prev-btn": "awsui_calendar-prev-btn_1ykar_183yz_189",
12
- "calendar-grid": "awsui_calendar-grid_1ykar_183yz_192",
13
- "calendar-grid-dense": "awsui_calendar-grid-dense_1ykar_183yz_196",
14
- "calendar-grid-cell": "awsui_calendar-grid-cell_1ykar_183yz_204",
15
- "calendar-date-header": "awsui_calendar-date-header_1ykar_183yz_209",
16
- "calendar-date": "awsui_calendar-date_1ykar_183yz_209",
17
- "calendar-date-enabled": "awsui_calendar-date-enabled_1ykar_183yz_229",
18
- "calendar-date-current-page": "awsui_calendar-date-current-page_1ykar_183yz_239",
19
- "calendar-date-selected": "awsui_calendar-date-selected_1ykar_183yz_250",
20
- "calendar-date-current": "awsui_calendar-date-current_1ykar_183yz_239",
21
- "calendar-date-dense": "awsui_calendar-date-dense_1ykar_183yz_271",
22
- "date-inner": "awsui_date-inner_1ykar_183yz_279",
23
- "calendar-row": "awsui_calendar-row_1ykar_183yz_354"
4
+ "calendar": "awsui_calendar_1ykar_tn512_97",
5
+ "awsui-motion-fade-in-0": "awsui_awsui-motion-fade-in-0_1ykar_tn512_1",
6
+ "root": "awsui_root_1ykar_tn512_128",
7
+ "calendar-inner": "awsui_calendar-inner_1ykar_tn512_169",
8
+ "calendar-header": "awsui_calendar-header_1ykar_tn512_173",
9
+ "calendar-header-title": "awsui_calendar-header-title_1ykar_tn512_178",
10
+ "calendar-next-btn": "awsui_calendar-next-btn_1ykar_tn512_186",
11
+ "calendar-prev-btn": "awsui_calendar-prev-btn_1ykar_tn512_189",
12
+ "calendar-grid": "awsui_calendar-grid_1ykar_tn512_192",
13
+ "calendar-grid-dense": "awsui_calendar-grid-dense_1ykar_tn512_196",
14
+ "calendar-grid-cell": "awsui_calendar-grid-cell_1ykar_tn512_204",
15
+ "calendar-date-header": "awsui_calendar-date-header_1ykar_tn512_209",
16
+ "calendar-date": "awsui_calendar-date_1ykar_tn512_209",
17
+ "calendar-date-enabled": "awsui_calendar-date-enabled_1ykar_tn512_229",
18
+ "calendar-date-current-page": "awsui_calendar-date-current-page_1ykar_tn512_239",
19
+ "calendar-date-selected": "awsui_calendar-date-selected_1ykar_tn512_250",
20
+ "calendar-date-current": "awsui_calendar-date-current_1ykar_tn512_239",
21
+ "calendar-date-dense": "awsui_calendar-date-dense_1ykar_tn512_271",
22
+ "date-inner": "awsui_date-inner_1ykar_tn512_279",
23
+ "calendar-row": "awsui_calendar-row_1ykar_tn512_354",
24
+ "disabled-reason-tooltip": "awsui_disabled-reason-tooltip_1ykar_tn512_358"
24
25
  };
25
26