@cloudscape-design/components 3.0.541 → 3.0.543

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 (90) hide show
  1. package/calendar/grid/index.d.ts.map +1 -1
  2. package/calendar/grid/index.js +4 -1
  3. package/calendar/grid/index.js.map +1 -1
  4. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts +2 -1
  5. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts.map +1 -1
  6. package/calendar/grid/use-calendar-grid-keyboard-navigation.js +14 -8
  7. package/calendar/grid/use-calendar-grid-keyboard-navigation.js.map +1 -1
  8. package/calendar/grid/use-calendar-grid-rows.d.ts +3 -1
  9. package/calendar/grid/use-calendar-grid-rows.d.ts.map +1 -1
  10. package/calendar/grid/use-calendar-grid-rows.js +12 -3
  11. package/calendar/grid/use-calendar-grid-rows.js.map +1 -1
  12. package/calendar/index.d.ts +1 -1
  13. package/calendar/index.d.ts.map +1 -1
  14. package/calendar/index.js +2 -2
  15. package/calendar/index.js.map +1 -1
  16. package/calendar/interfaces.d.ts +21 -0
  17. package/calendar/interfaces.d.ts.map +1 -1
  18. package/calendar/interfaces.js.map +1 -1
  19. package/calendar/internal.d.ts +1 -1
  20. package/calendar/internal.d.ts.map +1 -1
  21. package/calendar/internal.js +19 -11
  22. package/calendar/internal.js.map +1 -1
  23. package/calendar/styles.css.js +20 -18
  24. package/calendar/styles.scoped.css +54 -40
  25. package/calendar/styles.selectors.js +20 -18
  26. package/calendar/use-calendar-labels.d.ts +2 -1
  27. package/calendar/use-calendar-labels.d.ts.map +1 -1
  28. package/calendar/use-calendar-labels.js +14 -7
  29. package/calendar/use-calendar-labels.js.map +1 -1
  30. package/calendar/utils/intl.d.ts +1 -0
  31. package/calendar/utils/intl.d.ts.map +1 -1
  32. package/calendar/utils/intl.js +5 -0
  33. package/calendar/utils/intl.js.map +1 -1
  34. package/calendar/utils/navigation.d.ts +11 -5
  35. package/calendar/utils/navigation.d.ts.map +1 -1
  36. package/calendar/utils/navigation.js +43 -7
  37. package/calendar/utils/navigation.js.map +1 -1
  38. package/date-input/internal.d.ts +4 -1
  39. package/date-input/internal.d.ts.map +1 -1
  40. package/date-input/internal.js +9 -10
  41. package/date-input/internal.js.map +1 -1
  42. package/date-picker/index.d.ts.map +1 -1
  43. package/date-picker/index.js +12 -11
  44. package/date-picker/index.js.map +1 -1
  45. package/date-picker/utils.d.ts +16 -0
  46. package/date-picker/utils.d.ts.map +1 -0
  47. package/date-picker/utils.js +14 -0
  48. package/date-picker/utils.js.map +1 -0
  49. package/i18n/messages/all.all.js +39 -0
  50. package/i18n/messages/all.all.json +52 -13
  51. package/i18n/messages/all.de.js +3 -0
  52. package/i18n/messages/all.de.json +4 -1
  53. package/i18n/messages/all.en-GB.js +3 -0
  54. package/i18n/messages/all.en-GB.json +4 -1
  55. package/i18n/messages/all.en.js +3 -0
  56. package/i18n/messages/all.en.json +4 -1
  57. package/i18n/messages/all.es.js +3 -0
  58. package/i18n/messages/all.es.json +4 -1
  59. package/i18n/messages/all.fr.js +3 -0
  60. package/i18n/messages/all.fr.json +4 -1
  61. package/i18n/messages/all.id.js +3 -0
  62. package/i18n/messages/all.id.json +4 -1
  63. package/i18n/messages/all.it.js +3 -0
  64. package/i18n/messages/all.it.json +4 -1
  65. package/i18n/messages/all.ja.js +3 -0
  66. package/i18n/messages/all.ja.json +4 -1
  67. package/i18n/messages/all.ko.js +3 -0
  68. package/i18n/messages/all.ko.json +4 -1
  69. package/i18n/messages/all.pt-BR.js +3 -0
  70. package/i18n/messages/all.pt-BR.json +4 -1
  71. package/i18n/messages/all.tr.js +3 -0
  72. package/i18n/messages/all.tr.json +4 -1
  73. package/i18n/messages/all.zh-CN.js +3 -0
  74. package/i18n/messages/all.zh-CN.json +4 -1
  75. package/i18n/messages/all.zh-TW.js +3 -0
  76. package/i18n/messages/all.zh-TW.json +4 -1
  77. package/i18n/messages-types.d.ts +3 -0
  78. package/i18n/messages-types.d.ts.map +1 -1
  79. package/i18n/messages-types.js.map +1 -1
  80. package/internal/base-component/styles.scoped.css +1 -0
  81. package/internal/environment.js +1 -1
  82. package/internal/environment.json +1 -1
  83. package/internal/generated/theming/index.cjs +11 -0
  84. package/internal/generated/theming/index.js +11 -0
  85. package/internal/manifest.json +1 -1
  86. package/internal/utils/date-time/format-date.d.ts +2 -1
  87. package/internal/utils/date-time/format-date.d.ts.map +1 -1
  88. package/internal/utils/date-time/format-date.js +4 -1
  89. package/internal/utils/date-time/format-date.js.map +1 -1
  90. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAK/D;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,SAAS;IACxB,aAAa,EAAE,eAAe,CAAC,qBAAqB,CAAC;IACrD,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,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;IACnC,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IACvC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;IACnC,sBAAsB,EAAE,CA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O,CAAC;IACvC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;IACnC,sBAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,MAAM,CAAC;IACzE,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,KAAK,OAAO,CAAC;IACpD,oBAAoB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC;CAC5D;AAED,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,GACrB,EAAE,SAAS,eAwEX"}
@@ -14,7 +14,9 @@ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSele
14
14
  focusedDateRef.current.focus();
15
15
  }
16
16
  }, [focusedDate]);
17
- return (React.createElement("table", { role: "grid", className: styles['calendar-grid'], "aria-labelledby": ariaLabelledby },
17
+ const rowLength = rows[0].length;
18
+ const denseGrid = rowLength > 3;
19
+ return (React.createElement("table", { role: "grid", className: clsx(styles['calendar-grid'], denseGrid && styles['calendar-grid-dense']), "aria-labelledby": ariaLabelledby },
18
20
  header,
19
21
  React.createElement("tbody", { onKeyDown: onGridKeyDownHandler }, rows.map((row, rowIndex) => (React.createElement("tr", { key: rowIndex, className: styles['calendar-row'] }, row.map((date, dateIndex) => {
20
22
  const isFocusable = !!focusableDate && isSameDate(date, focusableDate);
@@ -38,6 +40,7 @@ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSele
38
40
  [styles['calendar-date-enabled']]: isEnabled,
39
41
  [styles['calendar-date-selected']]: isSelected,
40
42
  [styles['calendar-date-current']]: isCurrentDate,
43
+ [styles['calendar-date-dense']]: denseGrid,
41
44
  }) },
42
45
  React.createElement("span", { className: styles['date-inner'], "aria-hidden": "true" }, renderDate(date)),
43
46
  React.createElement(ScreenreaderOnly, null, renderDateAnnouncement(date, isCurrentDate))));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["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,KAAK,EAAE,CAAC;SACpD;IACH,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,CACL,+BAAO,IAAI,EAAC,MAAM,EAAC,SAAS,EAAE,MAAM,CAAC,eAAe,CAAC,qBAAmB,cAAc;QACnF,MAAM;QACP,+BAAO,SAAS,EAAE,oBAAoB,IACnC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,CAC3B,4BAAI,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,IACjD,GAAG,CAAC,GAA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,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;iBACjD,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) => 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 return (\n <table role=\"grid\" className={styles['calendar-grid']} aria-labelledby={ariaLabelledby}>\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 })}\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 </tbody>\n </table>\n );\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["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,O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AAS,EAAE,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) => 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 </tbody>\n </table>\n );\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { CalendarProps } from '../interfaces';
3
- export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }: {
3
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }: {
4
4
  baseDate: Date;
5
5
  focusableDate: Date | null;
6
+ granularity: CalendarProps.Granularity;
6
7
  isDateEnabled: CalendarProps.IsDateEnabledFunction;
7
8
  onChangePage: (date: Date) => void;
8
9
  onFocusDate: (date: null | Date) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-keyboard-navigation.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC;IACf,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,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,WACsC,mBAAmB,UA2CzD"}
1
+ {"version":3,"file":"use-calendar-grid-keyboard-navigation.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAa9C,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,UA2CzD"}
@@ -1,9 +1,15 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { isSameMonth } from 'date-fns';
4
- import { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek } from '../utils/navigation';
3
+ import { isSameMonth, isSameYear } from 'date-fns';
4
+ import { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek, moveNextMonth, movePrevMonth, moveMonthDown, moveMonthUp, } from '../utils/navigation';
5
5
  import { KeyCode } from '../../internal/keycode';
6
- export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }) {
6
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, granularity, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }) {
7
+ const isMonthPicker = granularity === 'month';
8
+ const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;
9
+ const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;
10
+ const moveRight = isMonthPicker ? moveNextMonth : moveNextDay;
11
+ const moveUp = isMonthPicker ? moveMonthUp : movePrevWeek;
12
+ const isSamePage = isMonthPicker ? isSameYear : isSameMonth;
7
13
  const onGridKeyDownHandler = (event) => {
8
14
  let updatedFocusDate;
9
15
  if (focusableDate === null) {
@@ -20,24 +26,24 @@ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableD
20
26
  return;
21
27
  case KeyCode.right:
22
28
  event.preventDefault();
23
- updatedFocusDate = moveNextDay(focusableDate, isDateEnabled);
29
+ updatedFocusDate = moveRight(focusableDate, isDateEnabled);
24
30
  break;
25
31
  case KeyCode.left:
26
32
  event.preventDefault();
27
- updatedFocusDate = movePrevDay(focusableDate, isDateEnabled);
33
+ updatedFocusDate = moveLeft(focusableDate, isDateEnabled);
28
34
  break;
29
35
  case KeyCode.up:
30
36
  event.preventDefault();
31
- updatedFocusDate = movePrevWeek(focusableDate, isDateEnabled);
37
+ updatedFocusDate = moveUp(focusableDate, isDateEnabled);
32
38
  break;
33
39
  case KeyCode.down:
34
40
  event.preventDefault();
35
- updatedFocusDate = moveNextWeek(focusableDate, isDateEnabled);
41
+ updatedFocusDate = moveDown(focusableDate, isDateEnabled);
36
42
  break;
37
43
  default:
38
44
  return;
39
45
  }
40
- if (!isSameMonth(updatedFocusDate, baseDate)) {
46
+ if (!isSamePage(updatedFocusDate, baseDate)) {
41
47
  onChangePage(updatedFocusDate);
42
48
  }
43
49
  onFocusDate(updatedFocusDate);
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-keyboard-navigation.js","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAE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AAgB,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 } from 'date-fns';\nimport { CalendarProps } from '../interfaces';\nimport { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek } from '../utils/navigation';\nimport { KeyCode } from '../../internal/keycode';\n\nexport default function useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n isDateEnabled,\n onChangePage,\n onFocusDate,\n onSelectDate,\n}: {\n baseDate: Date;\n focusableDate: Date | null;\n isDateEnabled: CalendarProps.IsDateEnabledFunction;\n onChangePage: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onSelectDate: (date: Date) => void;\n}) {\n const onGridKeyDownHandler = (event: React.KeyboardEvent) => {\n let updatedFocusDate;\n\n if (focusableDate === null) {\n return;\n }\n\n switch (event.keyCode) {\n case KeyCode.space:\n case KeyCode.enter:\n event.preventDefault();\n if (focusableDate) {\n onFocusDate(null);\n onSelectDate(focusableDate);\n }\n return;\n case KeyCode.right:\n event.preventDefault();\n updatedFocusDate = moveNextDay(focusableDate, isDateEnabled);\n break;\n case KeyCode.left:\n event.preventDefault();\n updatedFocusDate = movePrevDay(focusableDate, isDateEnabled);\n break;\n case KeyCode.up:\n event.preventDefault();\n updatedFocusDate = movePrevWeek(focusableDate, isDateEnabled);\n break;\n case KeyCode.down:\n event.preventDefault();\n updatedFocusDate = moveNextWeek(focusableDate, isDateEnabled);\n break;\n default:\n return;\n }\n\n if (!isSameMonth(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":"lib/default/","sources":["calendar/grid/use-calendar-grid-keyboard-navigation.ts"],"names":[],"mappings":"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,aAAa,CAAC,CAAC;iBAC7B;gBACD,OAAO;YACT,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC1D,MAAM;YACR,KAAK,OAAO,CAAC,EAAE;gBACb,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC1D,MAAM;YACR;gBACE,OAAO;SACV;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';\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) => {\n let updatedFocusDate;\n\n if (focusableDate === null) {\n return;\n }\n\n switch (event.keyCode) {\n case KeyCode.space:\n case KeyCode.enter:\n event.preventDefault();\n if (focusableDate) {\n onFocusDate(null);\n onSelectDate(focusableDate);\n }\n return;\n case KeyCode.right:\n event.preventDefault();\n updatedFocusDate = moveRight(focusableDate, isDateEnabled);\n break;\n case KeyCode.left:\n event.preventDefault();\n updatedFocusDate = moveLeft(focusableDate, isDateEnabled);\n break;\n case KeyCode.up:\n event.preventDefault();\n updatedFocusDate = moveUp(focusableDate, isDateEnabled);\n break;\n case KeyCode.down:\n event.preventDefault();\n updatedFocusDate = moveDown(focusableDate, isDateEnabled);\n break;\n default:\n return;\n }\n\n if (!isSamePage(updatedFocusDate, baseDate)) {\n onChangePage(updatedFocusDate);\n }\n onFocusDate(updatedFocusDate);\n };\n\n return onGridKeyDownHandler;\n}\n"]}
@@ -1,5 +1,7 @@
1
- export default function useCalendarGridRows({ baseDate, locale, startOfWeek, }: {
1
+ import { CalendarProps } from '../interfaces.js';
2
+ export default function useCalendarGridRows({ baseDate, granularity, locale, startOfWeek, }: {
2
3
  baseDate: Date;
4
+ granularity: CalendarProps.Granularity;
3
5
  locale: string;
4
6
  startOfWeek?: number;
5
7
  }): Date[][];
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-rows.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-rows.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,YASA"}
1
+ {"version":3,"file":"use-calendar-grid-rows.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-rows.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,WAAW,EACX,MAAM,EACN,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,YAYA"}
@@ -3,9 +3,18 @@
3
3
  import { useMemo } from 'react';
4
4
  import { normalizeStartOfWeek } from '../../internal/utils/locale/index.js';
5
5
  import { getCalendarMonth } from 'mnth';
6
- export default function useCalendarGridRows({ baseDate, locale, startOfWeek, }) {
7
- const normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, locale);
8
- const rows = useMemo(() => getCalendarMonth(baseDate, { firstDayOfWeek: normalizedStartOfWeek }), [baseDate, normalizedStartOfWeek]);
6
+ export default function useCalendarGridRows({ baseDate, granularity, locale, startOfWeek, }) {
7
+ const isMonthPicker = granularity === 'month';
8
+ const rows = useMemo(() => isMonthPicker
9
+ ? getCalendarYear(baseDate)
10
+ : getCalendarMonth(baseDate, { firstDayOfWeek: normalizeStartOfWeek(startOfWeek, locale) }), [baseDate, isMonthPicker, startOfWeek, locale]);
9
11
  return rows;
10
12
  }
13
+ // Returns a 3-by-4 matrix with dates corresponding to the initial date-time of each month of the year for a given date.
14
+ function getCalendarYear(date) {
15
+ const year = date.getFullYear();
16
+ return new Array(4)
17
+ .fill(0)
18
+ .map((_, i) => new Array(3).fill(0).map((_, j) => new Date(year, i * 3 + j)));
19
+ }
11
20
  //# sourceMappingURL=use-calendar-grid-rows.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-calendar-grid-rows.js","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-rows.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,MAAM,EACN,WAAW,GAKZ;IACC,MAAM,qBAAqB,GAAG,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAExE,MAAM,IAAI,GAAG,OAAO,CAClB,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAAC,EAC3E,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAClC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useMemo } from 'react';\nimport { normalizeStartOfWeek } from '../../internal/utils/locale/index.js';\nimport { getCalendarMonth } from 'mnth';\n\nexport default function useCalendarGridRows({\n baseDate,\n locale,\n startOfWeek,\n}: {\n baseDate: Date;\n locale: string;\n startOfWeek?: number;\n}) {\n const normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, locale);\n\n const rows = useMemo<Date[][]>(\n () => getCalendarMonth(baseDate, { firstDayOfWeek: normalizedStartOfWeek }),\n [baseDate, normalizedStartOfWeek]\n );\n\n return rows;\n}\n"]}
1
+ {"version":3,"file":"use-calendar-grid-rows.js","sourceRoot":"lib/default/","sources":["calendar/grid/use-calendar-grid-rows.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGxC,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,WAAW,EACX,MAAM,EACN,WAAW,GAMZ;IACC,MAAM,aAAa,GAAG,WAAW,KAAK,OAAO,CAAC;IAE9C,MAAM,IAAI,GAAG,OAAO,CAClB,GAAG,EAAE,CACH,aAAa;QACX,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC,EAC/F,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,CAAC,CAC/C,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,wHAAwH;AACxH,SAAS,eAAe,CAAC,IAAU;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,CAAC,CAAC;SACP,GAAG,CAAC,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useMemo } from 'react';\nimport { normalizeStartOfWeek } from '../../internal/utils/locale/index.js';\nimport { getCalendarMonth } from 'mnth';\nimport { CalendarProps } from '../interfaces.js';\n\nexport default function useCalendarGridRows({\n baseDate,\n granularity,\n locale,\n startOfWeek,\n}: {\n baseDate: Date;\n granularity: CalendarProps.Granularity;\n locale: string;\n startOfWeek?: number;\n}) {\n const isMonthPicker = granularity === 'month';\n\n const rows = useMemo<Date[][]>(\n () =>\n isMonthPicker\n ? getCalendarYear(baseDate)\n : getCalendarMonth(baseDate, { firstDayOfWeek: normalizeStartOfWeek(startOfWeek, locale) }),\n [baseDate, isMonthPicker, startOfWeek, locale]\n );\n\n return rows;\n}\n\n// Returns a 3-by-4 matrix with dates corresponding to the initial date-time of each month of the year for a given date.\nfunction getCalendarYear(date: Date): Date[][] {\n const year = date.getFullYear();\n return new Array(4)\n .fill(0)\n .map((_, i: number) => new Array(3).fill(0).map((_, j: number) => new Date(year, i * 3 + j)));\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { CalendarProps } from './interfaces';
3
3
  export { CalendarProps };
4
- export default function Calendar({ locale, isDateEnabled, ...props }: CalendarProps): JSX.Element;
4
+ export default function Calendar({ locale, isDateEnabled, granularity, ...props }: CalendarProps): JSX.Element;
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/index.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,MAAW,EAAE,aAA0B,EAAE,GAAG,KAAK,EAAE,EAAE,aAAa,eAGpG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/index.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,MAAW,EACX,aAA0B,EAC1B,WAAmB,EACnB,GAAG,KAAK,EACT,EAAE,aAAa,eAWf"}
package/calendar/index.js CHANGED
@@ -6,9 +6,9 @@ import useBaseComponent from '../internal/hooks/use-base-component';
6
6
  import { applyDisplayName } from '../internal/utils/apply-display-name';
7
7
  import InternalCalendar from './internal';
8
8
  export default function Calendar(_a) {
9
- var { locale = '', isDateEnabled = () => true } = _a, props = __rest(_a, ["locale", "isDateEnabled"]);
9
+ var { locale = '', isDateEnabled = () => true, granularity = 'day' } = _a, props = __rest(_a, ["locale", "isDateEnabled", "granularity"]);
10
10
  const baseComponentProps = useBaseComponent('Calendar');
11
- return React.createElement(InternalCalendar, Object.assign({}, props, baseComponentProps, { locale: locale, isDateEnabled: isDateEnabled }));
11
+ return (React.createElement(InternalCalendar, Object.assign({}, props, baseComponentProps, { locale: locale, isDateEnabled: isDateEnabled, granularity: granularity })));
12
12
  }
13
13
  applyDisplayName(Calendar, 'Calendar');
14
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["calendar/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,gBAAgB,MAAM,YAAY,CAAC;AAI1C,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAoE;QAApE,EAAE,MAAM,GAAG,EAAE,EAAE,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,OAA2B,EAAtB,KAAK,cAAnD,2BAAqD,CAAF;IAClF,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxD,OAAO,oBAAC,gBAAgB,oBAAK,KAAK,EAAM,kBAAkB,IAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,IAAI,CAAC;AAC/G,CAAC;AAED,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,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 useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { CalendarProps } from './interfaces';\nimport InternalCalendar from './internal';\n\nexport { CalendarProps };\n\nexport default function Calendar({ locale = '', isDateEnabled = () => true, ...props }: CalendarProps) {\n const baseComponentProps = useBaseComponent('Calendar');\n return <InternalCalendar {...props} {...baseComponentProps} locale={locale} isDateEnabled={isDateEnabled} />;\n}\n\napplyDisplayName(Calendar, 'Calendar');\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["calendar/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,gBAAgB,MAAM,YAAY,CAAC;AAI1C,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAKjB;QALiB,EAC/B,MAAM,GAAG,EAAE,EACX,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,EAC1B,WAAW,GAAG,KAAK,OAEL,EADX,KAAK,cAJuB,0CAKhC,CADS;IAER,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxD,OAAO,CACL,oBAAC,gBAAgB,oBACX,KAAK,EACL,kBAAkB,IACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,IACxB,CACH,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,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 useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { CalendarProps } from './interfaces';\nimport InternalCalendar from './internal';\n\nexport { CalendarProps };\n\nexport default function Calendar({\n locale = '',\n isDateEnabled = () => true,\n granularity = 'day',\n ...props\n}: CalendarProps) {\n const baseComponentProps = useBaseComponent('Calendar');\n return (\n <InternalCalendar\n {...props}\n {...baseComponentProps}\n locale={locale}\n isDateEnabled={isDateEnabled}\n granularity={granularity}\n />\n );\n}\n\napplyDisplayName(Calendar, 'Calendar');\n"]}
@@ -63,6 +63,11 @@ export interface CalendarProps extends BaseComponentProps {
63
63
  * @i18n
64
64
  */
65
65
  i18nStrings?: CalendarProps.I18nStrings;
66
+ /**
67
+ * Specifies the granularity at which users will be able to select a date.
68
+ * Defaults to `day`.
69
+ **/
70
+ granularity?: CalendarProps.Granularity;
66
71
  }
67
72
  export declare namespace CalendarProps {
68
73
  interface ChangeDetail {
@@ -74,6 +79,7 @@ export declare namespace CalendarProps {
74
79
  interface IsDateEnabledFunction {
75
80
  (date: Date): boolean;
76
81
  }
82
+ type Granularity = 'day' | 'month';
77
83
  interface I18nStrings {
78
84
  /**
79
85
  * Used as part of the `aria-label` for today's date in the calendar.
@@ -87,6 +93,21 @@ export declare namespace CalendarProps {
87
93
  * Specifies an `aria-label` for the 'previous month' button.
88
94
  */
89
95
  previousMonthAriaLabel?: string;
96
+ /**
97
+ * Used as part of the `aria-label` for the current month in the calendar.
98
+ * @i18n
99
+ */
100
+ currentMonthAriaLabel?: string;
101
+ /**
102
+ * Specifies an `aria-label` for the 'next year' button.
103
+ * @i18n
104
+ */
105
+ nextYearAriaLabel?: string;
106
+ /**
107
+ * Specifies an `aria-label` for the 'previous year' button.
108
+ * @i18n
109
+ */
110
+ previousYearAriaLabel?: string;
90
111
  }
91
112
  }
92
113
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"lib/default/","sources":["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;CACzC;AAED,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,YAAY;QAC3B;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf;IAED,UAAiB,qBAAqB;Q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YAAY;QAC3B;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf;IAED,UAAiB,qBAAqB;QACpC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;KACvB;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":"lib/default/","sources":["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\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 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"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"lib/default/","sources":["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,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, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel, ...rest }: CalendarProps & InternalBaseComponentProps): JSX.Element;
4
+ export default function Calendar({ value, locale, startOfWeek, isDateEnabled, 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":"lib/default/","sources":["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,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,GAAG,IAAI,EACR,EAAE,aAAa,GAAG,0BAA0B,eAuI5C"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"lib/default/","sources":["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"}
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { __rest } from "tslib";
4
4
  import React, { useEffect, useRef, useState } from 'react';
5
- import { addMonths, isSameDay, isSameMonth } from 'date-fns';
5
+ import { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';
6
6
  import styles from './styles.css.js';
7
7
  import CalendarHeader from './header';
8
8
  import Grid from './grid';
@@ -12,7 +12,7 @@ import { fireNonCancelableEvent } from '../internal/events/index.js';
12
12
  import checkControlled from '../internal/hooks/check-controlled/index.js';
13
13
  import clsx from 'clsx';
14
14
  import { getBaseProps } from '../internal/base-component';
15
- import { getBaseDay } from './utils/navigation';
15
+ import { getBaseDay, getBaseMonth } from './utils/navigation';
16
16
  import { useDateCache } from '../internal/hooks/use-date-cache/index.js';
17
17
  import { useUniqueId } from '../internal/hooks/use-unique-id/index.js';
18
18
  import useCalendarLabels from './use-calendar-labels';
@@ -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, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel } = _a, rest = __rest(_a, ["value", "locale", "startOfWeek", "isDateEnabled", "ariaLabel", "ariaLabelledby", "ariaDescribedby", "onChange", "__internalRootRef", "i18nStrings", "previousMonthAriaLabel", "nextMonthAriaLabel", "todayAriaLabel"]);
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"]);
24
24
  checkControlled('Calendar', 'value', value, 'onChange', onChange);
25
25
  const baseProps = getBaseProps(rest);
26
26
  const normalizedLocale = normalizeLocale('Calendar', locale);
@@ -34,26 +34,32 @@ export default function Calendar(_a) {
34
34
  const defaultDisplayedDate = memoizedValue !== null && memoizedValue !== void 0 ? memoizedValue : new Date();
35
35
  const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);
36
36
  const headingId = useUniqueId('calendar-heading');
37
- const baseDate = getBaseDay(displayedDate, isDateEnabled);
38
- const isCurrentPage = (date) => isSameMonth(date, baseDate);
37
+ const isMonthPicker = granularity === 'month';
38
+ const baseDate = isMonthPicker
39
+ ? getBaseMonth(displayedDate, isDateEnabled)
40
+ : getBaseDay(displayedDate, isDateEnabled);
41
+ const isSameDate = isMonthPicker ? isSameMonth : isSameDay;
42
+ const isSamePage = isMonthPicker ? isSameYear : isSameMonth;
43
+ const isCurrentPage = (date) => isMonthPicker || isSameMonth(date, baseDate);
39
44
  const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } = useCalendarLabels({
45
+ granularity,
40
46
  i18nStrings,
41
47
  locale: normalizedLocale,
42
48
  previousMonthAriaLabel,
43
49
  nextMonthAriaLabel,
44
50
  todayAriaLabel,
45
51
  });
46
- const gridRows = useCalendarGridRows({ baseDate, startOfWeek, locale: normalizedLocale });
52
+ const gridRows = useCalendarGridRows({ baseDate, granularity, startOfWeek, locale: normalizedLocale });
47
53
  // Update displayed date if value changes.
48
54
  useEffect(() => {
49
55
  memoizedValue && setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));
50
56
  }, [memoizedValue]);
51
57
  const selectFocusedDate = (selected, baseDate) => {
52
- if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {
58
+ if (selected && isDateEnabled(selected) && isSamePage(selected, baseDate)) {
53
59
  return selected;
54
60
  }
55
61
  const today = new Date();
56
- if (isDateEnabled(today) && isSameMonth(today, baseDate)) {
62
+ if (isDateEnabled(today) && isSamePage(today, baseDate)) {
57
63
  return today;
58
64
  }
59
65
  if (isDateEnabled(baseDate)) {
@@ -63,7 +69,8 @@ export default function Calendar(_a) {
63
69
  };
64
70
  const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);
65
71
  const onHeaderChangePageHandler = (amount) => {
66
- const newDate = addMonths(baseDate, amount);
72
+ const movePage = isMonthPicker ? addYears : addMonths;
73
+ const newDate = movePage(baseDate, amount);
67
74
  onChangePageHandler(newDate);
68
75
  };
69
76
  const onChangePageHandler = (newDate) => {
@@ -76,7 +83,7 @@ export default function Calendar(_a) {
76
83
  }
77
84
  };
78
85
  const onGridSelectDateHandler = (date) => {
79
- fireNonCancelableEvent(onChange, { value: formatDate(date) });
86
+ fireNonCancelableEvent(onChange, { value: formatDate(date, granularity) });
80
87
  setFocusedDate(null);
81
88
  };
82
89
  const onGridBlur = (event) => {
@@ -89,6 +96,7 @@ export default function Calendar(_a) {
89
96
  const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({
90
97
  baseDate,
91
98
  focusableDate,
99
+ granularity,
92
100
  isDateEnabled,
93
101
  onChangePage: onChangePageHandler,
94
102
  onFocusDate: onGridFocusDateHandler,
@@ -99,6 +107,6 @@ export default function Calendar(_a) {
99
107
  React.createElement("div", { className: styles['calendar-inner'] },
100
108
  React.createElement(CalendarHeader, { formattedDate: headerText, onChange: onHeaderChangePageHandler, previousLabel: previousButtonLabel, nextLabel: nextButtonLabel, headingId: headingId }),
101
109
  React.createElement("div", { onBlur: onGridBlur, ref: gridWrapperRef },
102
- React.createElement(Grid, { isDateEnabled: isDateEnabled, focusedDate: focusedDate, focusableDate: focusableDate, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangePage: onChangePageHandler, selectedDate: memoizedValue, ariaLabelledby: headingId, header: React.createElement(CalendarGridHeader, { locale: normalizedLocale, rows: gridRows }), rows: gridRows, isCurrentPage: isCurrentPage, renderDate: renderDate, renderDateAnnouncement: renderDateAnnouncement, isSameDate: isSameDay, onGridKeyDownHandler: onGridKeyDownHandler })))));
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 })))));
103
111
  }
104
112
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"lib/default/","sources":["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,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC7D,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,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAC1E,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,iCAAiC,MAAM,8CAA8C,CAAC;AAC7F,OAAO,kBAAkB,MAAM,6BAA6B,CAAC;AAE7D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAeY;QAfZ,EAC/B,KAAK,EACL,MAAM,GAAG,EAAE,EACX,WAAW,EACX,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,EAC1B,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ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AE,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,oBAAC,kBAAkB,IAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAI,EACxE,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,SAAS,EACrB,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, isSameDay, isSameMonth } 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 } 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 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 baseDate = getBaseDay(displayedDate, isDateEnabled);\n\n const isCurrentPage = (date: Date) => isSameMonth(date, baseDate);\n\n const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } =\n useCalendarLabels({\n i18nStrings,\n locale: normalizedLocale,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n });\n\n const gridRows = useCalendarGridRows({ baseDate, 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) && isSameMonth(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSameMonth(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 newDate = addMonths(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) });\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 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={<CalendarGridHeader locale={normalizedLocale} rows={gridRows} />}\n rows={gridRows}\n isCurrentPage={isCurrentPage}\n renderDate={renderDate}\n renderDateAnnouncement={renderDateAnnouncement}\n isSameDate={isSameDay}\n onGridKeyDownHandler={onGridKeyDownHandler}\n />\n </div>\n </div>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"lib/default/","sources":["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,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAC1E,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAC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C,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,23 +1,25 @@
1
1
 
2
2
  import './styles.scoped.css';
3
3
  export default {
4
- "calendar": "awsui_calendar_1ykar_1hjus_99",
5
- "awsui-motion-fade-in-0": "awsui_awsui-motion-fade-in-0_1ykar_1hjus_1",
6
- "root": "awsui_root_1ykar_1hjus_130",
7
- "calendar-inner": "awsui_calendar-inner_1ykar_1hjus_171",
8
- "calendar-header": "awsui_calendar-header_1ykar_1hjus_175",
9
- "calendar-header-title": "awsui_calendar-header-title_1ykar_1hjus_180",
10
- "calendar-next-btn": "awsui_calendar-next-btn_1ykar_1hjus_188",
11
- "calendar-prev-btn": "awsui_calendar-prev-btn_1ykar_1hjus_191",
12
- "calendar-grid": "awsui_calendar-grid_1ykar_1hjus_194",
13
- "calendar-grid-cell": "awsui_calendar-grid-cell_1ykar_1hjus_199",
14
- "calendar-date-header": "awsui_calendar-date-header_1ykar_1hjus_204",
15
- "calendar-date": "awsui_calendar-date_1ykar_1hjus_204",
16
- "calendar-date-enabled": "awsui_calendar-date-enabled_1ykar_1hjus_224",
17
- "calendar-date-current-page": "awsui_calendar-date-current-page_1ykar_1hjus_234",
18
- "calendar-date-selected": "awsui_calendar-date-selected_1ykar_1hjus_245",
19
- "calendar-date-current": "awsui_calendar-date-current_1ykar_1hjus_234",
20
- "date-inner": "awsui_date-inner_1ykar_1hjus_267",
21
- "calendar-row": "awsui_calendar-row_1ykar_1hjus_342"
4
+ "calendar": "awsui_calendar_1ykar_12jvf_99",
5
+ "awsui-motion-fade-in-0": "awsui_awsui-motion-fade-in-0_1ykar_12jvf_1",
6
+ "root": "awsui_root_1ykar_12jvf_130",
7
+ "calendar-inner": "awsui_calendar-inner_1ykar_12jvf_171",
8
+ "calendar-header": "awsui_calendar-header_1ykar_12jvf_175",
9
+ "calendar-header-title": "awsui_calendar-header-title_1ykar_12jvf_180",
10
+ "calendar-next-btn": "awsui_calendar-next-btn_1ykar_12jvf_188",
11
+ "calendar-prev-btn": "awsui_calendar-prev-btn_1ykar_12jvf_191",
12
+ "calendar-grid": "awsui_calendar-grid_1ykar_12jvf_194",
13
+ "calendar-grid-dense": "awsui_calendar-grid-dense_1ykar_12jvf_198",
14
+ "calendar-grid-cell": "awsui_calendar-grid-cell_1ykar_12jvf_206",
15
+ "calendar-date-header": "awsui_calendar-date-header_1ykar_12jvf_211",
16
+ "calendar-date": "awsui_calendar-date_1ykar_12jvf_211",
17
+ "calendar-date-enabled": "awsui_calendar-date-enabled_1ykar_12jvf_231",
18
+ "calendar-date-current-page": "awsui_calendar-date-current-page_1ykar_12jvf_241",
19
+ "calendar-date-selected": "awsui_calendar-date-selected_1ykar_12jvf_252",
20
+ "calendar-date-current": "awsui_calendar-date-current_1ykar_12jvf_241",
21
+ "calendar-date-dense": "awsui_calendar-date-dense_1ykar_12jvf_273",
22
+ "date-inner": "awsui_date-inner_1ykar_12jvf_281",
23
+ "calendar-row": "awsui_calendar-row_1ykar_12jvf_356"
22
24
  };
23
25