@cloudscape-design/components 3.0.529 → 3.0.531

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 (47) hide show
  1. package/calendar/grid/calendar-grid-header.d.ts +6 -0
  2. package/calendar/grid/calendar-grid-header.d.ts.map +1 -0
  3. package/calendar/grid/calendar-grid-header.js +16 -0
  4. package/calendar/grid/calendar-grid-header.js.map +1 -0
  5. package/calendar/grid/index.d.ts +10 -8
  6. package/calendar/grid/index.d.ts.map +1 -1
  7. package/calendar/grid/index.js +12 -65
  8. package/calendar/grid/index.js.map +1 -1
  9. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts +11 -0
  10. package/calendar/grid/use-calendar-grid-keyboard-navigation.d.ts.map +1 -0
  11. package/calendar/grid/use-calendar-grid-keyboard-navigation.js +47 -0
  12. package/calendar/grid/use-calendar-grid-keyboard-navigation.js.map +1 -0
  13. package/calendar/grid/use-calendar-grid-rows.d.ts +6 -0
  14. package/calendar/grid/use-calendar-grid-rows.d.ts.map +1 -0
  15. package/calendar/grid/use-calendar-grid-rows.js +11 -0
  16. package/calendar/grid/use-calendar-grid-rows.js.map +1 -0
  17. package/calendar/header/header-button.d.ts +3 -4
  18. package/calendar/header/header-button.d.ts.map +1 -1
  19. package/calendar/header/header-button.js +4 -5
  20. package/calendar/header/header-button.js.map +1 -1
  21. package/calendar/header/index.d.ts +5 -6
  22. package/calendar/header/index.d.ts.map +1 -1
  23. package/calendar/header/index.js +5 -6
  24. package/calendar/header/index.js.map +1 -1
  25. package/calendar/internal.d.ts +1 -2
  26. package/calendar/internal.d.ts.map +1 -1
  27. package/calendar/internal.js +34 -19
  28. package/calendar/internal.js.map +1 -1
  29. package/calendar/styles.css.js +18 -18
  30. package/calendar/styles.scoped.css +39 -39
  31. package/calendar/styles.selectors.js +18 -18
  32. package/calendar/use-calendar-labels.d.ts +16 -0
  33. package/calendar/use-calendar-labels.d.ts.map +1 -0
  34. package/calendar/use-calendar-labels.js +28 -0
  35. package/calendar/use-calendar-labels.js.map +1 -0
  36. package/calendar/utils/navigation.d.ts +1 -1
  37. package/calendar/utils/navigation.d.ts.map +1 -1
  38. package/calendar/utils/navigation.js +10 -11
  39. package/calendar/utils/navigation.js.map +1 -1
  40. package/date-range-picker/calendar/grids/index.js +2 -2
  41. package/date-range-picker/calendar/grids/index.js.map +1 -1
  42. package/date-range-picker/calendar/index.js +2 -2
  43. package/date-range-picker/calendar/index.js.map +1 -1
  44. package/internal/environment.js +1 -1
  45. package/internal/environment.json +1 -1
  46. package/internal/manifest.json +1 -1
  47. package/package.json +1 -1
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export default function CalendarGridHeader({ locale, rows }: {
3
+ locale: string;
4
+ rows: Date[][];
5
+ }): JSX.Element;
6
+ //# sourceMappingURL=calendar-grid-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar-grid-header.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/calendar-grid-header.tsx"],"names":[],"mappings":";AASA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;CAAE,eAmB9F"}
@@ -0,0 +1,16 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React from 'react';
4
+ import clsx from 'clsx';
5
+ import ScreenreaderOnly from '../../internal/components/screenreader-only';
6
+ import { renderDayName } from '../utils/intl';
7
+ import styles from '../styles.css.js';
8
+ export default function CalendarGridHeader({ locale, rows }) {
9
+ return (React.createElement("thead", null,
10
+ React.createElement("tr", null, rows[0]
11
+ .map(date => date.getDay())
12
+ .map(dayIndex => (React.createElement("th", { key: dayIndex, scope: "col", className: clsx(styles['calendar-grid-cell'], styles['calendar-date-header']) },
13
+ React.createElement("span", { "aria-hidden": "true" }, renderDayName(locale, dayIndex, 'short')),
14
+ React.createElement(ScreenreaderOnly, null, renderDayName(locale, dayIndex, 'long'))))))));
15
+ }
16
+ //# sourceMappingURL=calendar-grid-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar-grid-header.js","sourceRoot":"lib/default/","sources":["calendar/grid/calendar-grid-header.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,gBAAgB,MAAM,6CAA6C,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAsC;IAC7F,OAAO,CACL;QACE,gCACG,IAAI,CAAC,CAAC,CAAC;aACL,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;aAC1B,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CACf,4BACE,GAAG,EAAE,QAAQ,EACb,KAAK,EAAC,KAAK,EACX,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,sBAAsB,CAAC,CAAC;YAE7E,6CAAkB,MAAM,IAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAQ;YAC1E,oBAAC,gBAAgB,QAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAoB,CAC3E,CACN,CAAC,CACD,CACC,CACT,CAAC;AACJ,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 clsx from 'clsx';\nimport ScreenreaderOnly from '../../internal/components/screenreader-only';\nimport { renderDayName } from '../utils/intl';\nimport styles from '../styles.css.js';\n\nexport default function CalendarGridHeader({ locale, rows }: { locale: string; rows: Date[][] }) {\n return (\n <thead>\n <tr>\n {rows[0]\n .map(date => date.getDay())\n .map(dayIndex => (\n <th\n key={dayIndex}\n scope=\"col\"\n className={clsx(styles['calendar-grid-cell'], styles['calendar-date-header'])}\n >\n <span aria-hidden=\"true\">{renderDayName(locale, dayIndex, 'short')}</span>\n <ScreenreaderOnly>{renderDayName(locale, dayIndex, 'long')}</ScreenreaderOnly>\n </th>\n ))}\n </tr>\n </thead>\n );\n}\n"]}
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
- import { DayIndex } from '../internal';
1
+ import React from 'react';
3
2
  import { DatePickerProps } from '../../date-picker/interfaces';
4
3
  /**
5
4
  * Calendar grid supports two mechanisms of keyboard navigation:
@@ -16,18 +15,21 @@ import { DatePickerProps } from '../../date-picker/interfaces';
16
15
  * - (keyboard navigation) Safari/Chrome+VO - date announcements are not interruptive and can be missed if navigating fast.
17
16
  */
18
17
  export interface GridProps {
19
- locale: string;
20
- baseDate: Date;
21
18
  isDateEnabled: DatePickerProps.IsDateEnabledFunction;
22
19
  focusedDate: Date | null;
23
20
  focusableDate: Date | null;
24
21
  onSelectDate: (date: Date) => void;
25
22
  onFocusDate: (date: null | Date) => void;
26
- onChangeMonth: (date: Date) => void;
27
- startOfWeek: DayIndex;
28
- todayAriaLabel?: string;
23
+ onChangePage: (date: Date) => void;
29
24
  selectedDate: Date | null;
30
25
  ariaLabelledby: string;
26
+ header?: React.ReactNode;
27
+ rows: ReadonlyArray<ReadonlyArray<Date>>;
28
+ isCurrentPage: (date: Date) => boolean;
29
+ renderDate: (date: Date) => string;
30
+ renderDateAnnouncement: (date: Date, isOnCurrentDate: boolean) => string;
31
+ isSameDate: (date: Date, baseDate: Date) => boolean;
32
+ onGridKeyDownHandler: (event: React.KeyboardEvent) => void;
31
33
  }
32
- export default function Grid({ locale, baseDate, isDateEnabled, focusedDate, focusableDate, onSelectDate, onFocusDate, onChangeMonth, startOfWeek, todayAriaLabel, selectedDate, ariaLabelledby, }: GridProps): JSX.Element;
34
+ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSelectDate, selectedDate, ariaLabelledby, header, rows, isCurrentPage, renderDate, renderDateAnnouncement, isSameDate, onGridKeyDownHandler, }: GridProps): JSX.Element;
33
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/grid/index.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAO/D;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,IAAI,CAAC;IACf,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,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACpC,WAAW,EAAE,QAAQ,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,MAAM,EACN,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,cAAc,GACf,EAAE,SAAS,eAiI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,IAAI,EACJ,aAAa,EACb,UAAU,EACV,sBAAsB,EACtB,UAAU,EACV,oBAAoB,GACrB,EAAE,SAAS,eA+DX"}
@@ -1,55 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import React, { useMemo, useRef } from 'react';
3
+ import React, { useRef } from 'react';
4
4
  import styles from '../styles.css.js';
5
- import { KeyCode } from '../../internal/keycode';
6
- import { isSameDay, isSameMonth } from 'date-fns';
7
- import { getCalendarMonth } from 'mnth';
8
- import { getDateLabel, renderDayName } from '../utils/intl';
9
5
  import clsx from 'clsx';
10
6
  import { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';
11
7
  import ScreenreaderOnly from '../../internal/components/screenreader-only/index.js';
12
- import { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek } from '../utils/navigation';
13
- export default function Grid({ locale, baseDate, isDateEnabled, focusedDate, focusableDate, onSelectDate, onFocusDate, onChangeMonth, startOfWeek, todayAriaLabel, selectedDate, ariaLabelledby, }) {
8
+ export default function Grid({ isDateEnabled, focusedDate, focusableDate, onSelectDate, selectedDate, ariaLabelledby, header, rows, isCurrentPage, renderDate, renderDateAnnouncement, isSameDate, onGridKeyDownHandler, }) {
14
9
  const focusedDateRef = useRef(null);
15
- const onGridKeyDownHandler = (event) => {
16
- let updatedFocusDate;
17
- if (focusableDate === null) {
18
- return;
19
- }
20
- switch (event.keyCode) {
21
- case KeyCode.space:
22
- case KeyCode.enter:
23
- event.preventDefault();
24
- if (focusableDate) {
25
- onFocusDate(null);
26
- onSelectDate(focusableDate);
27
- }
28
- return;
29
- case KeyCode.right:
30
- event.preventDefault();
31
- updatedFocusDate = moveNextDay(focusableDate, isDateEnabled);
32
- break;
33
- case KeyCode.left:
34
- event.preventDefault();
35
- updatedFocusDate = movePrevDay(focusableDate, isDateEnabled);
36
- break;
37
- case KeyCode.up:
38
- event.preventDefault();
39
- updatedFocusDate = movePrevWeek(focusableDate, isDateEnabled);
40
- break;
41
- case KeyCode.down:
42
- event.preventDefault();
43
- updatedFocusDate = moveNextWeek(focusableDate, isDateEnabled);
44
- break;
45
- default:
46
- return;
47
- }
48
- if (!isSameMonth(updatedFocusDate, baseDate)) {
49
- onChangeMonth(updatedFocusDate);
50
- }
51
- onFocusDate(updatedFocusDate);
52
- };
53
10
  // The focused date changes as a feedback to keyboard navigation in the grid.
54
11
  // Once changed, the corresponding date button needs to receive the actual focus.
55
12
  useEffectOnUpdate(() => {
@@ -57,18 +14,13 @@ export default function Grid({ locale, baseDate, isDateEnabled, focusedDate, foc
57
14
  focusedDateRef.current.focus();
58
15
  }
59
16
  }, [focusedDate]);
60
- const weeks = useMemo(() => getCalendarMonth(baseDate, { firstDayOfWeek: startOfWeek }), [baseDate, startOfWeek]);
61
- const weekdays = weeks[0].map(date => date.getDay());
62
17
  return (React.createElement("table", { role: "grid", className: styles['calendar-grid'], "aria-labelledby": ariaLabelledby },
63
- React.createElement("thead", null,
64
- React.createElement("tr", null, weekdays.map(dayIndex => (React.createElement("th", { key: dayIndex, scope: "col", className: clsx(styles['calendar-grid-cell'], styles['calendar-date-header']) },
65
- React.createElement("span", { "aria-hidden": "true" }, renderDayName(locale, dayIndex, 'short')),
66
- React.createElement(ScreenreaderOnly, null, renderDayName(locale, dayIndex, 'long'))))))),
67
- React.createElement("tbody", { onKeyDown: onGridKeyDownHandler }, weeks.map((week, weekIndex) => (React.createElement("tr", { key: weekIndex, className: styles['calendar-row'] }, week.map((date, dateIndex) => {
68
- const isFocusable = !!focusableDate && isSameDay(date, focusableDate);
69
- const isSelected = !!selectedDate && isSameDay(date, selectedDate);
18
+ header,
19
+ React.createElement("tbody", { onKeyDown: onGridKeyDownHandler }, rows.map((row, rowIndex) => (React.createElement("tr", { key: rowIndex, className: styles['calendar-row'] }, row.map((date, dateIndex) => {
20
+ const isFocusable = !!focusableDate && isSameDate(date, focusableDate);
21
+ const isSelected = !!selectedDate && isSameDate(date, selectedDate);
70
22
  const isEnabled = !isDateEnabled || isDateEnabled(date);
71
- const isDateOnSameDay = isSameDay(date, new Date());
23
+ const isCurrentDate = isSameDate(date, new Date());
72
24
  // Can't be focused.
73
25
  let tabIndex = undefined;
74
26
  if (isFocusable && isEnabled) {
@@ -79,21 +31,16 @@ export default function Grid({ locale, baseDate, isDateEnabled, focusedDate, foc
79
31
  // Can be focused programmatically.
80
32
  tabIndex = -1;
81
33
  }
82
- // Screen-reader announcement for the focused date.
83
- let dayAnnouncement = getDateLabel(locale, date, 'short');
84
- if (isDateOnSameDay && todayAriaLabel) {
85
- dayAnnouncement += '. ' + todayAriaLabel;
86
- }
87
- return (React.createElement("td", { key: `${weekIndex}:${dateIndex}`, ref: tabIndex === 0 ? focusedDateRef : undefined, tabIndex: tabIndex, "aria-current": isDateOnSameDay ? 'date' : undefined, "aria-selected": isEnabled ? isSelected : undefined, "aria-disabled": !isEnabled,
34
+ 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,
88
35
  // Do not attach click event when the date is disabled, otherwise VO+safari announces clickable
89
36
  onClick: isEnabled ? () => onSelectDate(date) : undefined, className: clsx(styles['calendar-grid-cell'], styles['calendar-date'], {
90
- [styles['calendar-date-current-page']]: isSameMonth(date, baseDate),
37
+ [styles['calendar-date-current-page']]: isCurrentPage(date),
91
38
  [styles['calendar-date-enabled']]: isEnabled,
92
39
  [styles['calendar-date-selected']]: isSelected,
93
- [styles['calendar-date-current']]: isDateOnSameDay,
40
+ [styles['calendar-date-current']]: isCurrentDate,
94
41
  }) },
95
- React.createElement("span", { className: styles['date-inner'], "aria-hidden": "true" }, date.getDate()),
96
- React.createElement(ScreenreaderOnly, null, dayAnnouncement)));
42
+ React.createElement("span", { className: styles['date-inner'], "aria-hidden": "true" }, renderDate(date)),
43
+ React.createElement(ScreenreaderOnly, null, renderDateAnnouncement(date, isCurrentDate))));
97
44
  })))))));
98
45
  }
99
46
  //# sourceMappingURL=index.js.map
@@ -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,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,gBAAgB,MAAM,sDAAsD,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAgC3F,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,MAAM,EACN,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,cAAc,GACJ;IACV,MAAM,cAAc,GAAG,MAAM,CAAuB,IAAI,CAAC,CAAC;IAE1D,MAAM,oBAAoB,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC1D,IAAI,gBAAgB,CAAC;QAErB,IAAI,aAAa,KAAK,IAAI,EAAE;YAC1B,OAAO;SACR;QAED,QAAQ,KAAK,CAAC,OAAO,EAAE;YACrB,KAAK,OAAO,CAAC,KAAK,CAAC;YACnB,KAAK,OAAO,CAAC,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uBAAuB,CAAC,CAAC,EAAE,eAAe;iBACnD,CAAC;gBAEF,8BAAM,SAAS,EAAE,MAAM,CAAC,YAAY,CAAC,iBAAc,MAAM,IACtD,IAAI,CAAC,OAAO,EAAE,CACV;gBACP,oBAAC,gBAAgB,QAAE,eAAe,CAAoB,CACnD,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, { useMemo, useRef } from 'react';\nimport styles from '../styles.css.js';\nimport { KeyCode } from '../../internal/keycode';\nimport { isSameDay, isSameMonth } from 'date-fns';\nimport { getCalendarMonth } from 'mnth';\nimport { DayIndex } from '../internal';\nimport { DatePickerProps } from '../../date-picker/interfaces';\nimport { getDateLabel, renderDayName } from '../utils/intl';\nimport clsx from 'clsx';\nimport { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';\nimport ScreenreaderOnly from '../../internal/components/screenreader-only/index.js';\nimport { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek } from '../utils/navigation';\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 locale: string;\n baseDate: Date;\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n focusedDate: Date | null;\n focusableDate: Date | null;\n onSelectDate: (date: Date) => void;\n onFocusDate: (date: null | Date) => void;\n onChangeMonth: (date: Date) => void;\n startOfWeek: DayIndex;\n todayAriaLabel?: string;\n selectedDate: Date | null;\n ariaLabelledby: string;\n}\n\nexport default function Grid({\n locale,\n baseDate,\n isDateEnabled,\n focusedDate,\n focusableDate,\n onSelectDate,\n onFocusDate,\n onChangeMonth,\n startOfWeek,\n todayAriaLabel,\n selectedDate,\n ariaLabelledby,\n}: GridProps) {\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\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 onChangeMonth(updatedFocusDate);\n }\n onFocusDate(updatedFocusDate);\n };\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 weeks = useMemo<Date[][]>(\n () => getCalendarMonth(baseDate, { firstDayOfWeek: startOfWeek }),\n [baseDate, startOfWeek]\n );\n const weekdays = weeks[0].map(date => date.getDay());\n\n return (\n <table role=\"grid\" className={styles['calendar-grid']} aria-labelledby={ariaLabelledby}>\n <thead>\n <tr>\n {weekdays.map(dayIndex => (\n <th\n key={dayIndex}\n scope=\"col\"\n className={clsx(styles['calendar-grid-cell'], styles['calendar-date-header'])}\n >\n <span aria-hidden=\"true\">{renderDayName(locale, dayIndex, 'short')}</span>\n <ScreenreaderOnly>{renderDayName(locale, dayIndex, 'long')}</ScreenreaderOnly>\n </th>\n ))}\n </tr>\n </thead>\n <tbody onKeyDown={onGridKeyDownHandler}>\n {weeks.map((week, weekIndex) => (\n <tr key={weekIndex} className={styles['calendar-row']}>\n {week.map((date, dateIndex) => {\n const isFocusable = !!focusableDate && isSameDay(date, focusableDate);\n const isSelected = !!selectedDate && isSameDay(date, selectedDate);\n const isEnabled = !isDateEnabled || isDateEnabled(date);\n const isDateOnSameDay = isSameDay(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 // Screen-reader announcement for the focused date.\n let dayAnnouncement = getDateLabel(locale, date, 'short');\n if (isDateOnSameDay && todayAriaLabel) {\n dayAnnouncement += '. ' + todayAriaLabel;\n }\n\n return (\n <td\n key={`${weekIndex}:${dateIndex}`}\n ref={tabIndex === 0 ? focusedDateRef : undefined}\n tabIndex={tabIndex}\n aria-current={isDateOnSameDay ? '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']]: isSameMonth(date, baseDate),\n [styles['calendar-date-enabled']]: isEnabled,\n [styles['calendar-date-selected']]: isSelected,\n [styles['calendar-date-current']]: isDateOnSameDay,\n })}\n >\n <span className={styles['date-inner']} aria-hidden=\"true\">\n {date.getDate()}\n </span>\n <ScreenreaderOnly>{dayAnnouncement}</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,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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AC,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;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"]}
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { CalendarProps } from '../interfaces';
3
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }: {
4
+ baseDate: Date;
5
+ focusableDate: Date | null;
6
+ isDateEnabled: CalendarProps.IsDateEnabledFunction;
7
+ onChangePage: (date: Date) => void;
8
+ onFocusDate: (date: null | Date) => void;
9
+ onSelectDate: (date: Date) => void;
10
+ }): (event: React.KeyboardEvent) => void;
11
+ //# sourceMappingURL=use-calendar-grid-keyboard-navigation.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,47 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { isSameMonth } from 'date-fns';
4
+ import { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek } from '../utils/navigation';
5
+ import { KeyCode } from '../../internal/keycode';
6
+ export default function useCalendarGridKeyboardNavigation({ baseDate, focusableDate, isDateEnabled, onChangePage, onFocusDate, onSelectDate, }) {
7
+ const onGridKeyDownHandler = (event) => {
8
+ let updatedFocusDate;
9
+ if (focusableDate === null) {
10
+ return;
11
+ }
12
+ switch (event.keyCode) {
13
+ case KeyCode.space:
14
+ case KeyCode.enter:
15
+ event.preventDefault();
16
+ if (focusableDate) {
17
+ onFocusDate(null);
18
+ onSelectDate(focusableDate);
19
+ }
20
+ return;
21
+ case KeyCode.right:
22
+ event.preventDefault();
23
+ updatedFocusDate = moveNextDay(focusableDate, isDateEnabled);
24
+ break;
25
+ case KeyCode.left:
26
+ event.preventDefault();
27
+ updatedFocusDate = movePrevDay(focusableDate, isDateEnabled);
28
+ break;
29
+ case KeyCode.up:
30
+ event.preventDefault();
31
+ updatedFocusDate = movePrevWeek(focusableDate, isDateEnabled);
32
+ break;
33
+ case KeyCode.down:
34
+ event.preventDefault();
35
+ updatedFocusDate = moveNextWeek(focusableDate, isDateEnabled);
36
+ break;
37
+ default:
38
+ return;
39
+ }
40
+ if (!isSameMonth(updatedFocusDate, baseDate)) {
41
+ onChangePage(updatedFocusDate);
42
+ }
43
+ onFocusDate(updatedFocusDate);
44
+ };
45
+ return onGridKeyDownHandler;
46
+ }
47
+ //# sourceMappingURL=use-calendar-grid-keyboard-navigation.js.map
@@ -0,0 +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;AAEjD,MAAM,CAAC,OAAO,UAAU,iCAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,YAAY,GAQb;IACC,MAAM,oBAAoB,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC1D,IAAI,gBAAgB,CAAC;QAErB,IAAI,aAAa,KAAK,IAAI,EAAE;YAC1B,OAAO;SACR;QAED,QAAQ,KAAK,CAAC,OAAO,EAAE;YACrB,KAAK,OAAO,CAAC,KAAK,CAAC;YACnB,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,aAAa,EAAE;oBACjB,WAAW,CAAC,IAAI,CAAC,CAAC;oBAClB,YAAY,CAAC,aAAa,CAAC,CAAC;iBAC7B;gBACD,OAAO;YACT,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,WAAW,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC7D,MAAM;YACR,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,WAAW,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC7D,MAAM;YACR,KAAK,OAAO,CAAC,EAAE;gBACb,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,YAAY,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC9D,MAAM;YACR,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,gBAAgB,GAAG,YAAY,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;gBAC9D,MAAM;YACR;gBACE,OAAO;SACV;QAED,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE;YAC5C,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 } 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"]}
@@ -0,0 +1,6 @@
1
+ export default function useCalendarGridRows({ baseDate, locale, startOfWeek, }: {
2
+ baseDate: Date;
3
+ locale: string;
4
+ startOfWeek?: number;
5
+ }): Date[][];
6
+ //# sourceMappingURL=use-calendar-grid-rows.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { useMemo } from 'react';
4
+ import { normalizeStartOfWeek } from '../../internal/utils/locale/index.js';
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]);
9
+ return rows;
10
+ }
11
+ //# sourceMappingURL=use-calendar-grid-rows.js.map
@@ -0,0 +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,10 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  interface HeaderButtonProps {
3
3
  ariaLabel?: string;
4
- baseDate: Date;
5
- onChangeMonth: (date: Date) => void;
4
+ onChange: (n: number) => void;
6
5
  }
7
- export declare function PrevMonthButton({ ariaLabel, baseDate, onChangeMonth }: HeaderButtonProps): JSX.Element;
8
- export declare function NextMonthButton({ ariaLabel, baseDate, onChangeMonth }: HeaderButtonProps): JSX.Element;
6
+ export declare function HeaderPrevButton({ ariaLabel, onChange }: HeaderButtonProps): JSX.Element;
7
+ export declare function HeaderNextButton({ ariaLabel, onChange }: HeaderButtonProps): JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=header-button.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"header-button.d.ts","sourceRoot":"lib/default/","sources":["calendar/header/header-button.tsx"],"names":[],"mappings":";AAQA,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,IAAI,CAAC;IACf,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACrC;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,iBAAiB,eAWxF;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,iBAAiB,eAWxF"}
1
+ {"version":3,"file":"header-button.d.ts","sourceRoot":"lib/default/","sources":["calendar/header/header-button.tsx"],"names":[],"mappings":";AAOA,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAW1E;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAW1E"}
@@ -3,11 +3,10 @@
3
3
  import React from 'react';
4
4
  import { InternalButton } from '../../button/internal';
5
5
  import styles from '../styles.css.js';
6
- import { addMonths } from 'date-fns';
7
- export function PrevMonthButton({ ariaLabel, baseDate, onChangeMonth }) {
8
- return (React.createElement(InternalButton, { iconName: "angle-left", ariaLabel: ariaLabel, variant: "icon", onClick: () => onChangeMonth(addMonths(baseDate, -1)), formAction: "none", className: styles['calendar-prev-btn'] }));
6
+ export function HeaderPrevButton({ ariaLabel, onChange }) {
7
+ return (React.createElement(InternalButton, { iconName: "angle-left", ariaLabel: ariaLabel, variant: "icon", onClick: () => onChange(-1), formAction: "none", className: styles['calendar-prev-btn'] }));
9
8
  }
10
- export function NextMonthButton({ ariaLabel, baseDate, onChangeMonth }) {
11
- return (React.createElement(InternalButton, { iconName: "angle-right", ariaLabel: ariaLabel, variant: "icon", onClick: () => onChangeMonth(addMonths(baseDate, 1)), formAction: "none", className: styles['calendar-next-btn'] }));
9
+ export function HeaderNextButton({ ariaLabel, onChange }) {
10
+ return (React.createElement(InternalButton, { iconName: "angle-right", ariaLabel: ariaLabel, variant: "icon", onClick: () => onChange(1), formAction: "none", className: styles['calendar-next-btn'] }));
12
11
  }
13
12
  //# sourceMappingURL=header-button.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"header-button.js","sourceRoot":"lib/default/","sources":["calendar/header/header-button.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAQrC,MAAM,UAAU,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAqB;IACvF,OAAO,CACL,oBAAC,cAAc,IACb,QAAQ,EAAC,YAAY,EACrB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EACrD,UAAU,EAAC,MAAM,EACjB,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC,GACtC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAqB;IACvF,OAAO,CACL,oBAAC,cAAc,IACb,QAAQ,EAAC,aAAa,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EACpD,UAAU,EAAC,MAAM,EACjB,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC,GACtC,CACH,CAAC;AACJ,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 { InternalButton } from '../../button/internal';\nimport styles from '../styles.css.js';\nimport { addMonths } from 'date-fns';\n\ninterface HeaderButtonProps {\n ariaLabel?: string;\n baseDate: Date;\n onChangeMonth: (date: Date) => void;\n}\n\nexport function PrevMonthButton({ ariaLabel, baseDate, onChangeMonth }: HeaderButtonProps) {\n return (\n <InternalButton\n iconName=\"angle-left\"\n ariaLabel={ariaLabel}\n variant=\"icon\"\n onClick={() => onChangeMonth(addMonths(baseDate, -1))}\n formAction=\"none\"\n className={styles['calendar-prev-btn']}\n />\n );\n}\n\nexport function NextMonthButton({ ariaLabel, baseDate, onChangeMonth }: HeaderButtonProps) {\n return (\n <InternalButton\n iconName=\"angle-right\"\n ariaLabel={ariaLabel}\n variant=\"icon\"\n onClick={() => onChangeMonth(addMonths(baseDate, 1))}\n formAction=\"none\"\n className={styles['calendar-next-btn']}\n />\n );\n}\n"]}
1
+ {"version":3,"file":"header-button.js","sourceRoot":"lib/default/","sources":["calendar/header/header-button.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAOtC,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAqB;IACzE,OAAO,CACL,oBAAC,cAAc,IACb,QAAQ,EAAC,YAAY,EACrB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC3B,UAAU,EAAC,MAAM,EACjB,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC,GACtC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAqB;IACzE,OAAO,CACL,oBAAC,cAAc,IACb,QAAQ,EAAC,aAAa,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,MAAM,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC1B,UAAU,EAAC,MAAM,EACjB,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC,GACtC,CACH,CAAC;AACJ,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 { InternalButton } from '../../button/internal';\nimport styles from '../styles.css.js';\n\ninterface HeaderButtonProps {\n ariaLabel?: string;\n onChange: (n: number) => void;\n}\n\nexport function HeaderPrevButton({ ariaLabel, onChange }: HeaderButtonProps) {\n return (\n <InternalButton\n iconName=\"angle-left\"\n ariaLabel={ariaLabel}\n variant=\"icon\"\n onClick={() => onChange(-1)}\n formAction=\"none\"\n className={styles['calendar-prev-btn']}\n />\n );\n}\n\nexport function HeaderNextButton({ ariaLabel, onChange }: HeaderButtonProps) {\n return (\n <InternalButton\n iconName=\"angle-right\"\n ariaLabel={ariaLabel}\n variant=\"icon\"\n onClick={() => onChange(1)}\n formAction=\"none\"\n className={styles['calendar-next-btn']}\n />\n );\n}\n"]}
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  interface CalendarHeaderProps {
3
- baseDate: Date;
4
- locale: string;
5
- onChangeMonth: (date: Date) => void;
6
- previousMonthLabel?: string;
7
- nextMonthLabel?: string;
3
+ formattedDate: string;
4
+ onChange: (n: number) => void;
5
+ previousLabel?: string;
6
+ nextLabel?: string;
8
7
  headingId: string;
9
8
  }
10
- declare const CalendarHeader: ({ baseDate, locale, onChangeMonth, previousMonthLabel, nextMonthLabel, headingId, }: CalendarHeaderProps) => JSX.Element;
9
+ declare const CalendarHeader: ({ formattedDate, onChange, previousLabel, nextLabel, headingId }: CalendarHeaderProps) => JSX.Element;
11
10
  export default CalendarHeader;
12
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/header/index.tsx"],"names":[],"mappings":";AAOA,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,QAAA,MAAM,cAAc,wFAOjB,mBAAmB,gBAUrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["calendar/header/index.tsx"],"names":[],"mappings":";AAMA,UAAU,mBAAmB;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,QAAA,MAAM,cAAc,qEAAsE,mBAAmB,gBAU5G,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -2,13 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import React from 'react';
4
4
  import styles from '../styles.css.js';
5
- import { renderMonthAndYear } from '../utils/intl';
6
- import { PrevMonthButton, NextMonthButton } from './header-button';
7
- const CalendarHeader = ({ baseDate, locale, onChangeMonth, previousMonthLabel, nextMonthLabel, headingId, }) => {
5
+ import { HeaderPrevButton, HeaderNextButton } from './header-button';
6
+ const CalendarHeader = ({ formattedDate, onChange, previousLabel, nextLabel, headingId }) => {
8
7
  return (React.createElement("div", { className: styles['calendar-header'] },
9
- React.createElement(PrevMonthButton, { ariaLabel: previousMonthLabel, baseDate: baseDate, onChangeMonth: onChangeMonth }),
10
- React.createElement("h2", { className: styles['calendar-header-month'], id: headingId }, renderMonthAndYear(locale, baseDate)),
11
- React.createElement(NextMonthButton, { ariaLabel: nextMonthLabel, baseDate: baseDate, onChangeMonth: onChangeMonth })));
8
+ React.createElement(HeaderPrevButton, { ariaLabel: previousLabel, onChange: onChange }),
9
+ React.createElement("h2", { className: styles['calendar-header-title'], id: headingId }, formattedDate),
10
+ React.createElement(HeaderNextButton, { ariaLabel: nextLabel, onChange: onChange })));
12
11
  };
13
12
  export default CalendarHeader;
14
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["calendar/header/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWnE,MAAM,cAAc,GAAG,CAAC,EACtB,QAAQ,EACR,MAAM,EACN,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,SAAS,GACW,EAAE,EAAE;IACxB,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC;QACvC,oBAAC,eAAe,IAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,GAAI;QACpG,4BAAI,SAAS,EAAE,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,EAAE,SAAS,IAC1D,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC;QACL,oBAAC,eAAe,IAAC,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,GAAI,CAC5F,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport styles from '../styles.css.js';\nimport { renderMonthAndYear } from '../utils/intl';\nimport { PrevMonthButton, NextMonthButton } from './header-button';\n\ninterface CalendarHeaderProps {\n baseDate: Date;\n locale: string;\n onChangeMonth: (date: Date) => void;\n previousMonthLabel?: string;\n nextMonthLabel?: string;\n headingId: string;\n}\n\nconst CalendarHeader = ({\n baseDate,\n locale,\n onChangeMonth,\n previousMonthLabel,\n nextMonthLabel,\n headingId,\n}: CalendarHeaderProps) => {\n return (\n <div className={styles['calendar-header']}>\n <PrevMonthButton ariaLabel={previousMonthLabel} baseDate={baseDate} onChangeMonth={onChangeMonth} />\n <h2 className={styles['calendar-header-month']} id={headingId}>\n {renderMonthAndYear(locale, baseDate)}\n </h2>\n <NextMonthButton ariaLabel={nextMonthLabel} baseDate={baseDate} onChangeMonth={onChangeMonth} />\n </div>\n );\n};\n\nexport default CalendarHeader;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["calendar/header/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAUrE,MAAM,cAAc,GAAG,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAuB,EAAE,EAAE;IAC/G,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC;QACvC,oBAAC,gBAAgB,IAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAI;QAClE,4BAAI,SAAS,EAAE,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,EAAE,SAAS,IAC1D,aAAa,CACX;QACL,oBAAC,gBAAgB,IAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAC1D,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport styles from '../styles.css.js';\nimport { HeaderPrevButton, HeaderNextButton } from './header-button';\n\ninterface CalendarHeaderProps {\n formattedDate: string;\n onChange: (n: number) => void;\n previousLabel?: string;\n nextLabel?: string;\n headingId: string;\n}\n\nconst CalendarHeader = ({ formattedDate, onChange, previousLabel, nextLabel, headingId }: CalendarHeaderProps) => {\n return (\n <div className={styles['calendar-header']}>\n <HeaderPrevButton ariaLabel={previousLabel} onChange={onChange} />\n <h2 className={styles['calendar-header-title']} id={headingId}>\n {formattedDate}\n </h2>\n <HeaderNextButton ariaLabel={nextLabel} onChange={onChange} />\n </div>\n );\n};\n\nexport default CalendarHeader;\n"]}
@@ -1,6 +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 type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
5
- export default function Calendar({ value, locale, startOfWeek, isDateEnabled, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, ...rest }: CalendarProps & InternalBaseComponentProps): JSX.Element;
4
+ export default function Calendar({ value, locale, startOfWeek, isDateEnabled, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel, ...rest }: CalendarProps & InternalBaseComponentProps): JSX.Element;
6
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;AAM3F,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjD,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,GAAG,IAAI,EACR,EAAE,aAAa,GAAG,0BAA0B,eAoH5C"}
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"}
@@ -2,27 +2,28 @@
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 { isSameMonth } from 'date-fns';
5
+ import { addMonths, isSameDay, isSameMonth } from 'date-fns';
6
6
  import styles from './styles.css.js';
7
7
  import CalendarHeader from './header';
8
8
  import Grid from './grid';
9
- import { normalizeLocale, normalizeStartOfWeek } from '../internal/utils/locale';
9
+ import { normalizeLocale } from '../internal/utils/locale';
10
10
  import { formatDate, parseDate } from '../internal/utils/date-time';
11
11
  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 { getBaseDate } from './utils/navigation';
15
+ import { getBaseDay } 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
- import { useInternalI18n } from '../i18n/context.js';
18
+ import useCalendarLabels from './use-calendar-labels';
19
+ import useCalendarGridRows from './grid/use-calendar-grid-rows';
20
+ import useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';
21
+ import CalendarGridHeader from './grid/calendar-grid-header';
19
22
  export default function Calendar(_a) {
20
- var _b, _c, _d;
21
- var { value, locale = '', startOfWeek, isDateEnabled = () => true, ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings } = _a, rest = __rest(_a, ["value", "locale", "startOfWeek", "isDateEnabled", "ariaLabel", "ariaLabelledby", "ariaDescribedby", "onChange", "__internalRootRef", "i18nStrings"]);
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"]);
22
24
  checkControlled('Calendar', 'value', value, 'onChange', onChange);
23
25
  const baseProps = getBaseProps(rest);
24
26
  const normalizedLocale = normalizeLocale('Calendar', locale);
25
- const normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, normalizedLocale);
26
27
  const gridWrapperRef = useRef(null);
27
28
  const [focusedDate, setFocusedDate] = useState(null);
28
29
  const valueDateCache = useDateCache();
@@ -33,10 +34,16 @@ export default function Calendar(_a) {
33
34
  const defaultDisplayedDate = memoizedValue !== null && memoizedValue !== void 0 ? memoizedValue : new Date();
34
35
  const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);
35
36
  const headingId = useUniqueId('calendar-heading');
36
- const i18n = useInternalI18n('calendar');
37
- const nextMonthAriaLabel = i18n('nextMonthAriaLabel', (_b = i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.nextMonthAriaLabel) !== null && _b !== void 0 ? _b : rest.nextMonthAriaLabel);
38
- const previousMonthAriaLabel = i18n('previousMonthAriaLabel', (_c = i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.previousMonthAriaLabel) !== null && _c !== void 0 ? _c : rest.previousMonthAriaLabel);
39
- const todayAriaLabel = i18n('todayAriaLabel', (_d = i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.todayAriaLabel) !== null && _d !== void 0 ? _d : rest.todayAriaLabel);
37
+ const baseDate = getBaseDay(displayedDate, isDateEnabled);
38
+ const isCurrentPage = (date) => isSameMonth(date, baseDate);
39
+ const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } = useCalendarLabels({
40
+ i18nStrings,
41
+ locale: normalizedLocale,
42
+ previousMonthAriaLabel,
43
+ nextMonthAriaLabel,
44
+ todayAriaLabel,
45
+ });
46
+ const gridRows = useCalendarGridRows({ baseDate, startOfWeek, locale: normalizedLocale });
40
47
  // Update displayed date if value changes.
41
48
  useEffect(() => {
42
49
  memoizedValue && setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));
@@ -54,14 +61,13 @@ export default function Calendar(_a) {
54
61
  }
55
62
  return null;
56
63
  };
57
- const baseDate = getBaseDate(displayedDate, isDateEnabled);
58
64
  const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);
59
- const onHeaderChangeMonthHandler = (date) => {
60
- setDisplayedDate(date);
61
- setFocusedDate(null);
65
+ const onHeaderChangePageHandler = (amount) => {
66
+ const newDate = addMonths(baseDate, amount);
67
+ onChangePageHandler(newDate);
62
68
  };
63
- const onGridChangeMonthHandler = (newMonth) => {
64
- setDisplayedDate(newMonth);
69
+ const onChangePageHandler = (newDate) => {
70
+ setDisplayedDate(newDate);
65
71
  setFocusedDate(null);
66
72
  };
67
73
  const onGridFocusDateHandler = (date) => {
@@ -80,10 +86,19 @@ export default function Calendar(_a) {
80
86
  setFocusedDate(null);
81
87
  }
82
88
  };
89
+ const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({
90
+ baseDate,
91
+ focusableDate,
92
+ isDateEnabled,
93
+ onChangePage: onChangePageHandler,
94
+ onFocusDate: onGridFocusDateHandler,
95
+ onSelectDate: onGridSelectDateHandler,
96
+ });
97
+ const headerText = renderHeaderText(baseDate);
83
98
  return (React.createElement("div", Object.assign({ ref: __internalRootRef }, baseProps, { role: "group", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, className: clsx(styles.root, styles.calendar, baseProps.className) }),
84
99
  React.createElement("div", { className: styles['calendar-inner'] },
85
- React.createElement(CalendarHeader, { baseDate: baseDate, locale: normalizedLocale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: previousMonthAriaLabel, nextMonthLabel: nextMonthAriaLabel, headingId: headingId }),
100
+ React.createElement(CalendarHeader, { formattedDate: headerText, onChange: onHeaderChangePageHandler, previousLabel: previousButtonLabel, nextLabel: nextButtonLabel, headingId: headingId }),
86
101
  React.createElement("div", { onBlur: onGridBlur, ref: gridWrapperRef },
87
- React.createElement(Grid, { locale: normalizedLocale, baseDate: baseDate, isDateEnabled: isDateEnabled, focusedDate: focusedDate, focusableDate: focusableDate, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangeMonth: onGridChangeMonthHandler, startOfWeek: normalizedStartOfWeek, todayAriaLabel: todayAriaLabel, selectedDate: memoizedValue, ariaLabelledby: headingId })))));
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 })))));
88
103
  }
89
104
  //# sourceMappingURL=internal.js.map