@cloudscape-design/components 3.0.95 → 3.0.96

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.
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { DayIndex } from '../index';
3
- import { DateRangePickerProps } from '../../interfaces';
2
+ import { DateRangePickerProps, DayIndex } from '../../interfaces';
4
3
  /**
5
4
  * Calendar grid supports two mechanisms of keyboard navigation:
6
5
  * - Native screen-reader table navigation (semantic table markup);
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/grid.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAcvC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAOxD;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,IAAI,CAAC;IACf,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAE7B,cAAc,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAE1B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAEtD,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC,oBAAoB,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC;IACvD,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;IAEvE,aAAa,EAAE,oBAAoB,CAAC,qBAAqB,CAAC;IAE1D,MAAM,EAAE,M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CAAC;IAE1D,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,QAAQ,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,cAAc,EAEd,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EAEnB,aAAa,EAEb,MAAM,EACN,WAAW,EACX,cAAc,EACd,cAAc,EAEd,SAAS,GACV,EAAE,SAAS,eAuIX"}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/grid.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EACL,WAAW,EACX,OAAO,EACP,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,OAAO,GACR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,eAAe,MAAM,gDAAgD,CAAC;AAC7E,OAAO,gBAAgB,MAAM,yDAAyD,CAAC;AA0CvF,MAAM,UAAU,IAAI,CAAC,EAsBT;QArBV,QAAQ,cAAA,EACR,iBAAiB,uBAAA,EACjB,eAAe,qBAAA,EACf,cAAc,oBAAA,EACd,YAAY,kBAAA,EACZ,WAAW,iBAAA,EAEX,cAAc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AAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7G,OAAO,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo } from 'react';\nimport styles from './styles.css.js';\nimport {\n isSameMonth,\n isAfter,\n isBefore,\n isSameDay,\n addWeeks,\n addDays,\n isLastDayOfMonth,\n getDaysInMonth,\n isToday,\n} from 'date-fns';\nimport { getCalendarMonth } from 'mnth';\nimport { DayIndex } from '../index';\nimport { DateRangePickerProps } from '../../interfaces';\nimport { getDateLabel, renderDayName } from '../../../calendar/utils/intl';\nimport clsx from 'clsx';\nimport { formatDate } from '../../../internal/utils/date-time';\nimport useFocusVisible from '../../../internal/hooks/focus-visible/index.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 day is announced as \"not selected\";\n * - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;\n * - (keyboard navigation) Safari/Chrome+VO - days are not announced as interactive (clickable or selectable);\n * - (keyboard navigation) Safari/Chrome+VO - day announcements are not interruptive and can be missed if navigating fast.\n */\n\nexport interface GridProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n\n rangeStartDate: Date | null;\n rangeEndDate: Date | null;\n\n focusedDate: Date | null;\n focusedDateRef: React.RefObject<HTMLTableCellElement>;\n\n onSelectDate: (date: Date) => void;\n onGridKeyDownHandler: (e: React.KeyboardEvent) => void;\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n\n locale: string;\n startOfWeek: DayIndex;\n todayAriaLabel: string;\n ariaLabelledby: string;\n\n className?: string;\n}\n\nexport function Grid({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n rangeStartDate,\n rangeEndDate,\n focusedDate,\n\n focusedDateRef,\n\n onSelectDate,\n onGridKeyDownHandler,\n onFocusedDateChange,\n\n isDateEnabled,\n\n locale,\n startOfWeek,\n todayAriaLabel,\n ariaLabelledby,\n\n className,\n}: GridProps) {\n const baseDateTime = baseDate?.getTime();\n // `baseDateTime` is used as a more stable replacement for baseDate\n const weeks = useMemo<Date[][]>(\n () => getCalendarMonth(baseDate, { firstDayOfWeek: startOfWeek }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [baseDateTime, startOfWeek]\n );\n const weekdays = weeks[0].map(date => date.getDay());\n\n const focusVisible = useFocusVisible();\n\n return (\n <table role=\"grid\" aria-labelledby={ariaLabelledby} className={clsx(styles.grid, className)}>\n <thead>\n <tr>\n {weekdays.map(dayIndex => (\n <th key={dayIndex} scope=\"col\" className={clsx(styles['grid-cell'], styles['day-header'])}>\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 return (\n <tr key={weekIndex} className={styles.week}>\n {week.map((date, dateIndex) => {\n const isStartDate = !!selectedStartDate && isSameDay(date, selectedStartDate);\n const isEndDate = !!selectedEndDate && isSameDay(date, selectedEndDate);\n const isSelected = isStartDate || isEndDate;\n const isRangeStartDate = !!rangeStartDate && isSameDay(date, rangeStartDate);\n const isRangeEndDate = !!rangeEndDate && isSameDay(date, rangeEndDate);\n\n const isFocused = !!focusedDate && isSameDay(date, focusedDate) && isSameMonth(date, baseDate);\n\n const dateIsInRange = isStartDate || isEndDate || isInRange(date, rangeStartDate, rangeEndDate);\n const inRangeStartWeek =\n rangeStartDate && isInRange(date, rangeStartDate, addDays(addWeeks(rangeStartDate, 1), -1));\n const inRangeEndWeek =\n rangeEndDate && isInRange(date, rangeEndDate, addDays(addWeeks(rangeEndDate, -1), 1));\n const onlyOneSelected =\n !!rangeStartDate && !!rangeEndDate\n ? isSameDay(rangeStartDate, rangeEndDate)\n : !selectedStartDate || !selectedEndDate;\n\n const isEnabled = !isDateEnabled || isDateEnabled(date);\n const isFocusable = isFocused && isEnabled;\n\n const baseClasses = {\n [styles.day]: true,\n [styles['grid-cell']]: true,\n [styles['in-first-row']]: weekIndex === 0,\n [styles['in-first-column']]: dateIndex === 0,\n };\n\n if (!isSameMonth(date, baseDate)) {\n return (\n <td\n key={`${weekIndex}:${dateIndex}`}\n ref={isFocused ? focusedDateRef : undefined}\n className={clsx(baseClasses, {\n [styles['in-previous-month']]: isBefore(date, baseDate),\n [styles['last-day-of-month']]: isLastDayOfMonth(date),\n [styles['in-next-month']]: isAfter(date, baseDate),\n })}\n ></td>\n );\n }\n\n const handlers: React.HTMLAttributes<HTMLDivElement> = {};\n if (isEnabled) {\n handlers.onClick = () => onSelectDate(date);\n handlers.onFocus = () => onFocusedDateChange(date);\n }\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 day.\n let dayAnnouncement = getDateLabel(locale, date, 'short');\n if (isToday(date)) {\n dayAnnouncement += '. ' + todayAriaLabel;\n }\n\n return (\n <td\n ref={isFocused ? focusedDateRef : undefined}\n key={`${weekIndex}:${dateIndex}`}\n className={clsx(baseClasses, {\n [styles['in-current-month']]: isSameMonth(date, baseDate),\n [styles.enabled]: isEnabled,\n [styles.selected]: isSelected,\n [styles['start-date']]: isStartDate,\n [styles['end-date']]: isEndDate,\n [styles['range-start-date']]: isRangeStartDate,\n [styles['range-end-date']]: isRangeEndDate,\n [styles['no-range']]: isSelected && onlyOneSelected,\n [styles['in-range']]: dateIsInRange,\n [styles['in-range-border-top']]: !!inRangeStartWeek || date.getDate() <= 7,\n [styles['in-range-border-bottom']]: !!inRangeEndWeek || date.getDate() > getDaysInMonth(date) - 7,\n [styles['in-range-border-left']]: dateIndex === 0 || date.getDate() === 1 || isRangeStartDate,\n [styles['in-range-border-right']]:\n dateIndex === week.length - 1 || isLastDayOfMonth(date) || isRangeEndDate,\n [styles.today]: isToday(date),\n })}\n aria-selected={isEnabled ? isSelected || dateIsInRange : undefined}\n aria-current={isToday(date) ? 'date' : undefined}\n data-date={formatDate(date)}\n aria-disabled={!isEnabled}\n tabIndex={tabIndex}\n {...handlers}\n {...focusVisible}\n >\n <span className={styles['day-inner']} aria-hidden=\"true\">\n {date.getDate()}\n </span>\n <ScreenreaderOnly>{dayAnnouncement}</ScreenreaderOnly>\n </td>\n );\n })}\n </tr>\n );\n })}\n </tbody>\n </table>\n );\n}\n\nfunction isInRange(date: Date, dateOne: Date | null, dateTwo: Date | null) {\n if (!dateOne || !dateTwo || isSameDay(dateOne, dateTwo)) {\n return false;\n }\n\n const inRange =\n (isAfter(date, dateOne) && isBefore(date, dateTwo)) || (isAfter(date, dateTwo) && isBefore(date, dateOne));\n\n return inRange || isSameDay(date, dateOne) || isSameDay(date, dateTwo);\n}\n"]}
1
+ {"version":3,"file":"grid.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/grid.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAA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AC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,eACrC,UAAU,CAAC,IAAI,CAAC,mBACZ,CAAC,SAAS,EACzB,QAAQ,EAAE,QAAQ,IACd,QAAQ,EACR,YAAY;oBAEhB,8BAAM,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAc,MAAM,IACrD,IAAI,CAAC,OAAO,EAAE,CACV;oBACP,oBAAC,gBAAgB,QAAE,eAAe,CAAoB,CACnD,CACN,CAAC;YACJ,CAAC,CAAC,CACC,CACN,CAAC;QACJ,CAAC,CAAC,CACI,CACF,CACT,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAU,EAAE,OAAoB,EAAE,OAAoB;IACvE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE;QACvD,OAAO,KAAK,CAAC;KACd;IAED,IAAM,OAAO,GACX,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7G,OAAO,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo } from 'react';\nimport styles from './styles.css.js';\nimport {\n isSameMonth,\n isAfter,\n isBefore,\n isSameDay,\n addWeeks,\n addDays,\n isLastDayOfMonth,\n getDaysInMonth,\n isToday,\n} from 'date-fns';\nimport { getCalendarMonth } from 'mnth';\nimport { DateRangePickerProps, DayIndex } from '../../interfaces';\nimport { getDateLabel, renderDayName } from '../../../calendar/utils/intl';\nimport clsx from 'clsx';\nimport { formatDate } from '../../../internal/utils/date-time';\nimport useFocusVisible from '../../../internal/hooks/focus-visible/index.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 day is announced as \"not selected\";\n * - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;\n * - (keyboard navigation) Safari/Chrome+VO - days are not announced as interactive (clickable or selectable);\n * - (keyboard navigation) Safari/Chrome+VO - day announcements are not interruptive and can be missed if navigating fast.\n */\n\nexport interface GridProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n\n rangeStartDate: Date | null;\n rangeEndDate: Date | null;\n\n focusedDate: Date | null;\n focusedDateRef: React.RefObject<HTMLTableCellElement>;\n\n onSelectDate: (date: Date) => void;\n onGridKeyDownHandler: (e: React.KeyboardEvent) => void;\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n\n locale: string;\n startOfWeek: DayIndex;\n todayAriaLabel: string;\n ariaLabelledby: string;\n\n className?: string;\n}\n\nexport function Grid({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n rangeStartDate,\n rangeEndDate,\n focusedDate,\n\n focusedDateRef,\n\n onSelectDate,\n onGridKeyDownHandler,\n onFocusedDateChange,\n\n isDateEnabled,\n\n locale,\n startOfWeek,\n todayAriaLabel,\n ariaLabelledby,\n\n className,\n}: GridProps) {\n const baseDateTime = baseDate?.getTime();\n // `baseDateTime` is used as a more stable replacement for baseDate\n const weeks = useMemo<Date[][]>(\n () => getCalendarMonth(baseDate, { firstDayOfWeek: startOfWeek }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [baseDateTime, startOfWeek]\n );\n const weekdays = weeks[0].map(date => date.getDay());\n\n const focusVisible = useFocusVisible();\n\n return (\n <table role=\"grid\" aria-labelledby={ariaLabelledby} className={clsx(styles.grid, className)}>\n <thead>\n <tr>\n {weekdays.map(dayIndex => (\n <th key={dayIndex} scope=\"col\" className={clsx(styles['grid-cell'], styles['day-header'])}>\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 return (\n <tr key={weekIndex} className={styles.week}>\n {week.map((date, dateIndex) => {\n const isStartDate = !!selectedStartDate && isSameDay(date, selectedStartDate);\n const isEndDate = !!selectedEndDate && isSameDay(date, selectedEndDate);\n const isSelected = isStartDate || isEndDate;\n const isRangeStartDate = !!rangeStartDate && isSameDay(date, rangeStartDate);\n const isRangeEndDate = !!rangeEndDate && isSameDay(date, rangeEndDate);\n\n const isFocused = !!focusedDate && isSameDay(date, focusedDate) && isSameMonth(date, baseDate);\n\n const dateIsInRange = isStartDate || isEndDate || isInRange(date, rangeStartDate, rangeEndDate);\n const inRangeStartWeek =\n rangeStartDate && isInRange(date, rangeStartDate, addDays(addWeeks(rangeStartDate, 1), -1));\n const inRangeEndWeek =\n rangeEndDate && isInRange(date, rangeEndDate, addDays(addWeeks(rangeEndDate, -1), 1));\n const onlyOneSelected =\n !!rangeStartDate && !!rangeEndDate\n ? isSameDay(rangeStartDate, rangeEndDate)\n : !selectedStartDate || !selectedEndDate;\n\n const isEnabled = !isDateEnabled || isDateEnabled(date);\n const isFocusable = isFocused && isEnabled;\n\n const baseClasses = {\n [styles.day]: true,\n [styles['grid-cell']]: true,\n [styles['in-first-row']]: weekIndex === 0,\n [styles['in-first-column']]: dateIndex === 0,\n };\n\n if (!isSameMonth(date, baseDate)) {\n return (\n <td\n key={`${weekIndex}:${dateIndex}`}\n ref={isFocused ? focusedDateRef : undefined}\n className={clsx(baseClasses, {\n [styles['in-previous-month']]: isBefore(date, baseDate),\n [styles['last-day-of-month']]: isLastDayOfMonth(date),\n [styles['in-next-month']]: isAfter(date, baseDate),\n })}\n ></td>\n );\n }\n\n const handlers: React.HTMLAttributes<HTMLDivElement> = {};\n if (isEnabled) {\n handlers.onClick = () => onSelectDate(date);\n handlers.onFocus = () => onFocusedDateChange(date);\n }\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 day.\n let dayAnnouncement = getDateLabel(locale, date, 'short');\n if (isToday(date)) {\n dayAnnouncement += '. ' + todayAriaLabel;\n }\n\n return (\n <td\n ref={isFocused ? focusedDateRef : undefined}\n key={`${weekIndex}:${dateIndex}`}\n className={clsx(baseClasses, {\n [styles['in-current-month']]: isSameMonth(date, baseDate),\n [styles.enabled]: isEnabled,\n [styles.selected]: isSelected,\n [styles['start-date']]: isStartDate,\n [styles['end-date']]: isEndDate,\n [styles['range-start-date']]: isRangeStartDate,\n [styles['range-end-date']]: isRangeEndDate,\n [styles['no-range']]: isSelected && onlyOneSelected,\n [styles['in-range']]: dateIsInRange,\n [styles['in-range-border-top']]: !!inRangeStartWeek || date.getDate() <= 7,\n [styles['in-range-border-bottom']]: !!inRangeEndWeek || date.getDate() > getDaysInMonth(date) - 7,\n [styles['in-range-border-left']]: dateIndex === 0 || date.getDate() === 1 || isRangeStartDate,\n [styles['in-range-border-right']]:\n dateIndex === week.length - 1 || isLastDayOfMonth(date) || isRangeEndDate,\n [styles.today]: isToday(date),\n })}\n aria-selected={isEnabled ? isSelected || dateIsInRange : undefined}\n aria-current={isToday(date) ? 'date' : undefined}\n data-date={formatDate(date)}\n aria-disabled={!isEnabled}\n tabIndex={tabIndex}\n {...handlers}\n {...focusVisible}\n >\n <span className={styles['day-inner']} aria-hidden=\"true\">\n {date.getDate()}\n </span>\n <ScreenreaderOnly>{dayAnnouncement}</ScreenreaderOnly>\n </td>\n );\n })}\n </tr>\n );\n })}\n </tbody>\n </table>\n );\n}\n\nfunction isInRange(date: Date, dateOne: Date | null, dateTwo: Date | null) {\n if (!dateOne || !dateTwo || isSameDay(dateOne, dateTwo)) {\n return false;\n }\n\n const inRange =\n (isAfter(date, dateOne) && isBefore(date, dateTwo)) || (isAfter(date, dateTwo) && isBefore(date, dateOne));\n\n return inRange || isSameDay(date, dateOne) || isSameDay(date, dateTwo);\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { DayIndex } from '../index';
3
- import { DateRangePickerProps } from '../../interfaces';
2
+ import { DateRangePickerProps, DayIndex } from '../../interfaces';
4
3
  export interface GridProps {
5
4
  baseDate: Date;
6
5
  selectedStartDate: Date | null;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAI3D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAoBxD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,IAAI,CAAC;IACf,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAE7B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,CA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C,IAAI,EACtD,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAClD,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,UAAG,eAAe,eAAY,GAC9C,CACH;YACD,oBAAC,IAAI,IACH,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,EAChC,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,EACtD,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAClD,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,UAAG,eAAe,kBAAe,GACjD,CACmB,CACnB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport { KeyCode } from '../../../internal/keycode';\nimport { isSameMonth, isAfter, isBefore, addMonths, min, max } from 'date-fns';\n\nimport { DayIndex } from '../index';\nimport { DateRangePickerProps } from '../../interfaces';\nimport InternalSpaceBetween from '../../../space-between/internal';\nimport { Grid } from './grid';\nimport styles from '../../styles.css.js';\n\nimport useFocusVisible from '../../../internal/hooks/focus-visible/index';\nimport { hasValue } from '../../../internal/utils/has-value';\nimport { useDateCache } from '../../../internal/hooks/use-date-cache';\nimport { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek, getBaseDate } from '../../../calendar/utils/navigation';\n\nfunction isVisible(date: Date, baseDate: Date, isSingleGrid: boolean) {\n if (isSingleGrid) {\n return isSameMonth(date, baseDate);\n }\n\n const previousMonth = addMonths(baseDate, -1);\n\n return isSameMonth(date, previousMonth) || isSameMonth(date, baseDate);\n}\n\nexport interface GridProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n\n focusedDate: Date | null;\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n isSingleGrid: boolean;\n\n onSelectDate: (date: Date) => void;\n onChangeMonth: (date: Date) => void;\n\n locale: string;\n startOfWeek: DayIndex;\n todayAriaLabel: string;\n headingIdPrefix: string;\n}\n\nexport function selectFocusedDate(\n selected: Date | null,\n baseDate: Date,\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction\n) {\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\nexport const Grids = ({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n\n focusedDate,\n onFocusedDateChange,\n\n isDateEnabled,\n isSingleGrid,\n\n onSelectDate,\n onChangeMonth,\n\n locale,\n startOfWeek,\n todayAriaLabel,\n headingIdPrefix,\n}: GridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n const dateCache = useDateCache();\n baseDate = dateCache(baseDate);\n focusedDate = focusedDate ? dateCache(focusedDate) : null;\n\n useEffect(() => {\n if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid)) {\n const direction = isAfter(focusedDate, baseDate) ? -1 : 1;\n\n const newMonth = !isSingleGrid && direction === -1 ? addMonths(baseDate, -1) : baseDate;\n const nearestBaseDate = getBaseDate(newMonth, isDateEnabled);\n\n const newFocusedDate = selectFocusedDate(focusedDate, nearestBaseDate, isDateEnabled);\n\n onFocusedDateChange(newFocusedDate);\n }\n }, [baseDate, focusedDate, isSingleGrid, isDateEnabled, onFocusedDateChange]);\n\n const onGridKeyDownHandler = (e: React.KeyboardEvent) => {\n let updatedFocusDate;\n\n if (focusedDate === null) {\n return;\n }\n\n switch (e.keyCode) {\n case KeyCode.space:\n case KeyCode.enter:\n e.preventDefault();\n if (focusedDate) {\n onSelectDate(focusedDate);\n }\n return;\n case KeyCode.right:\n e.preventDefault();\n updatedFocusDate = moveNextDay(focusedDate, isDateEnabled);\n break;\n case KeyCode.left:\n e.preventDefault();\n updatedFocusDate = movePrevDay(focusedDate, isDateEnabled);\n break;\n case KeyCode.up:\n e.preventDefault();\n updatedFocusDate = movePrevWeek(focusedDate, isDateEnabled);\n break;\n case KeyCode.down:\n e.preventDefault();\n updatedFocusDate = moveNextWeek(focusedDate, isDateEnabled);\n break;\n default:\n return;\n }\n\n const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid);\n\n if (!updatedDateIsVisible) {\n const newMonthIsOnLeftSide = !isSingleGrid && isBefore(updatedFocusDate, baseDate);\n\n onChangeMonth(newMonthIsOnLeftSide ? addMonths(updatedFocusDate, 1) : updatedFocusDate);\n }\n onFocusedDateChange(updatedFocusDate);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar\n if (focusedDate !== null && gridHasFocus) {\n if (focusedDateRef.current && focusedDateRef.current !== document.activeElement) {\n focusedDateRef.current.focus();\n }\n }\n }, [focusedDate, gridHasFocus]);\n\n const onGridBlur = (event: React.FocusEvent) => {\n /*\n IE11 does not support event.relatedTarget, but sets document.activeElement to the newly\n focused element before the onBlur handler is called.\n\n However, other browsers do not make any guarantees for the value of document.activeElement\n during the execution of an onBlur handler. Therefore, we have to use event.relatedTarget\n instead.\n */\n const newFocusTarget = event.relatedTarget || document.activeElement;\n const newFocusTargetIsInGrid = containerRef.current?.contains(newFocusTarget as Node);\n if (newFocusTarget && !newFocusTargetIsInGrid && gridHasFocus) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n const focusVisible = useFocusVisible();\n\n const isRangeVisible =\n (selectedStartDate && selectedEndDate) || (gridHasFocus && !!focusVisible['data-awsui-focus-visible']);\n\n const rangeEnds: Date[] = [selectedStartDate ?? focusedDate, selectedEndDate ?? focusedDate].filter(hasValue);\n\n const rangeStartDate = min(rangeEnds);\n const rangeEndDate = max(rangeEnds);\n\n return (\n <div ref={containerRef} onFocus={onGridFocus} onBlur={onGridBlur}>\n <InternalSpaceBetween size=\"xs\" direction=\"horizontal\">\n {!isSingleGrid && (\n <Grid\n className={styles['first-grid']}\n baseDate={addMonths(baseDate, -1)}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-prevmonth`}\n />\n )}\n <Grid\n className={styles['second-grid']}\n baseDate={baseDate}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-currentmonth`}\n />\n </InternalSpaceBetween>\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/E,OAAO,oBAAoB,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEvH,SAAS,SAAS,CAAC,IAAU,EAAE,QAAc,EAAE,YAAqB;IAClE,IAAI,YAAY,EAAE;QAChB,OAAO,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KACpC;IAED,IAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IAE9C,OAAO,WAAW,CAAC,IAAI,EAAE,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C,CAAC,CAAC,IAAI,EAClD,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,UAAG,eAAe,eAAY,GAC9C,CACH;YACD,oBAAC,IAAI,IACH,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,EAChC,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,EACtD,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAClD,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,UAAG,eAAe,kBAAe,GACjD,CACmB,CACnB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport { KeyCode } from '../../../internal/keycode';\nimport { isSameMonth, isAfter, isBefore, addMonths, min, max } from 'date-fns';\n\nimport { DateRangePickerProps, DayIndex } from '../../interfaces';\nimport InternalSpaceBetween from '../../../space-between/internal';\nimport { Grid } from './grid';\nimport styles from '../../styles.css.js';\n\nimport useFocusVisible from '../../../internal/hooks/focus-visible/index';\nimport { hasValue } from '../../../internal/utils/has-value';\nimport { useDateCache } from '../../../internal/hooks/use-date-cache';\nimport { moveNextDay, movePrevDay, moveNextWeek, movePrevWeek, getBaseDate } from '../../../calendar/utils/navigation';\n\nfunction isVisible(date: Date, baseDate: Date, isSingleGrid: boolean) {\n if (isSingleGrid) {\n return isSameMonth(date, baseDate);\n }\n\n const previousMonth = addMonths(baseDate, -1);\n\n return isSameMonth(date, previousMonth) || isSameMonth(date, baseDate);\n}\n\nexport interface GridProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n\n focusedDate: Date | null;\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n isSingleGrid: boolean;\n\n onSelectDate: (date: Date) => void;\n onChangeMonth: (date: Date) => void;\n\n locale: string;\n startOfWeek: DayIndex;\n todayAriaLabel: string;\n headingIdPrefix: string;\n}\n\nexport function selectFocusedDate(\n selected: Date | null,\n baseDate: Date,\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction\n) {\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\nexport const Grids = ({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n\n focusedDate,\n onFocusedDateChange,\n\n isDateEnabled,\n isSingleGrid,\n\n onSelectDate,\n onChangeMonth,\n\n locale,\n startOfWeek,\n todayAriaLabel,\n headingIdPrefix,\n}: GridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n const dateCache = useDateCache();\n baseDate = dateCache(baseDate);\n focusedDate = focusedDate ? dateCache(focusedDate) : null;\n\n useEffect(() => {\n if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid)) {\n const direction = isAfter(focusedDate, baseDate) ? -1 : 1;\n\n const newMonth = !isSingleGrid && direction === -1 ? addMonths(baseDate, -1) : baseDate;\n const nearestBaseDate = getBaseDate(newMonth, isDateEnabled);\n\n const newFocusedDate = selectFocusedDate(focusedDate, nearestBaseDate, isDateEnabled);\n\n onFocusedDateChange(newFocusedDate);\n }\n }, [baseDate, focusedDate, isSingleGrid, isDateEnabled, onFocusedDateChange]);\n\n const onGridKeyDownHandler = (e: React.KeyboardEvent) => {\n let updatedFocusDate;\n\n if (focusedDate === null) {\n return;\n }\n\n switch (e.keyCode) {\n case KeyCode.space:\n case KeyCode.enter:\n e.preventDefault();\n if (focusedDate) {\n onSelectDate(focusedDate);\n }\n return;\n case KeyCode.right:\n e.preventDefault();\n updatedFocusDate = moveNextDay(focusedDate, isDateEnabled);\n break;\n case KeyCode.left:\n e.preventDefault();\n updatedFocusDate = movePrevDay(focusedDate, isDateEnabled);\n break;\n case KeyCode.up:\n e.preventDefault();\n updatedFocusDate = movePrevWeek(focusedDate, isDateEnabled);\n break;\n case KeyCode.down:\n e.preventDefault();\n updatedFocusDate = moveNextWeek(focusedDate, isDateEnabled);\n break;\n default:\n return;\n }\n\n const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid);\n\n if (!updatedDateIsVisible) {\n const newMonthIsOnLeftSide = !isSingleGrid && isBefore(updatedFocusDate, baseDate);\n\n onChangeMonth(newMonthIsOnLeftSide ? addMonths(updatedFocusDate, 1) : updatedFocusDate);\n }\n onFocusedDateChange(updatedFocusDate);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar\n if (focusedDate !== null && gridHasFocus) {\n if (focusedDateRef.current && focusedDateRef.current !== document.activeElement) {\n focusedDateRef.current.focus();\n }\n }\n }, [focusedDate, gridHasFocus]);\n\n const onGridBlur = (event: React.FocusEvent) => {\n /*\n IE11 does not support event.relatedTarget, but sets document.activeElement to the newly\n focused element before the onBlur handler is called.\n\n However, other browsers do not make any guarantees for the value of document.activeElement\n during the execution of an onBlur handler. Therefore, we have to use event.relatedTarget\n instead.\n */\n const newFocusTarget = event.relatedTarget || document.activeElement;\n const newFocusTargetIsInGrid = containerRef.current?.contains(newFocusTarget as Node);\n if (newFocusTarget && !newFocusTargetIsInGrid && gridHasFocus) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n const focusVisible = useFocusVisible();\n\n const isRangeVisible =\n (selectedStartDate && selectedEndDate) || (gridHasFocus && !!focusVisible['data-awsui-focus-visible']);\n\n const rangeEnds: Date[] = [selectedStartDate ?? focusedDate, selectedEndDate ?? focusedDate].filter(hasValue);\n\n const rangeStartDate = min(rangeEnds);\n const rangeEndDate = max(rangeEnds);\n\n return (\n <div ref={containerRef} onFocus={onGridFocus} onBlur={onGridBlur}>\n <InternalSpaceBetween size=\"xs\" direction=\"horizontal\">\n {!isSingleGrid && (\n <Grid\n className={styles['first-grid']}\n baseDate={addMonths(baseDate, -1)}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-prevmonth`}\n />\n )}\n <Grid\n className={styles['second-grid']}\n baseDate={baseDate}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-currentmonth`}\n />\n </InternalSpaceBetween>\n </div>\n );\n};\n"]}
@@ -1,22 +1,17 @@
1
1
  import React from 'react';
2
2
  import { BaseComponentProps } from '../../internal/base-component';
3
- import { DateRangePickerProps, Focusable } from '../interfaces';
3
+ import { Focusable, RangeCalendarI18nStrings, RangeCalendarValue } from '../interfaces';
4
4
  import { TimeInputProps } from '../../time-input/interfaces';
5
- export declare type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
6
- export interface RangeCalendarValue {
7
- startDate: string;
8
- endDate: string;
9
- }
10
- export interface CalendarProps extends BaseComponentProps {
5
+ export interface DateRangePickerCalendarProps extends BaseComponentProps {
11
6
  value: null | RangeCalendarValue;
12
7
  onChange: (value: RangeCalendarValue) => void;
13
- locale: string;
14
- startOfWeek: number | undefined;
15
- isDateEnabled: (date: Date) => boolean;
16
- i18nStrings: DateRangePickerProps.I18nStrings;
8
+ locale?: string;
9
+ startOfWeek?: number;
10
+ isDateEnabled?: (date: Date) => boolean;
11
+ i18nStrings: RangeCalendarI18nStrings;
17
12
  dateOnly?: boolean;
18
13
  timeInputFormat?: TimeInputProps.Format;
19
14
  }
20
- declare const _default: React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<Focusable>>;
15
+ declare const _default: React.ForwardRefExoticComponent<DateRangePickerCalendarProps & React.RefAttributes<Focusable>>;
21
16
  export default _default;
22
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/date-range-picker/calendar/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAuE,MAAM,OAAO,CAAC;AAG5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAA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,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IACxC,WAAW,EAAE,wBAAwB,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC;CACzC;;AAED,wBAAmD"}
@@ -5,25 +5,24 @@ import { addMonths, endOfDay, isBefore, startOfDay, startOfMonth, isAfter, isSam
5
5
  import styles from '../styles.css.js';
6
6
  import CalendarHeader from './header';
7
7
  import { Grids, selectFocusedDate } from './grids';
8
- import InternalFormField from '../../form-field/internal';
9
- import InternalDateInput from '../../date-input/internal';
10
- import InternalTimeInput from '../../time-input/internal';
11
8
  import clsx from 'clsx';
12
9
  import { useUniqueId } from '../../internal/hooks/use-unique-id';
13
10
  import { getDateLabel, renderTimeLabel } from '../../calendar/utils/intl';
14
11
  import LiveRegion from '../../internal/components/live-region';
15
- import { normalizeStartOfWeek } from '../../calendar/utils/locales';
12
+ import { normalizeLocale, normalizeStartOfWeek } from '../../calendar/utils/locales';
16
13
  import { formatDate, formatTime, joinDateTime, parseDate } from '../../internal/utils/date-time';
17
14
  import { getBaseDate } from '../../calendar/utils/navigation';
18
15
  import { useMobile } from '../../internal/hooks/use-mobile/index.js';
19
- export default forwardRef(RangeCalendar);
20
- function RangeCalendar(_a, ref) {
16
+ import RangeInputs from './range-inputs.js';
17
+ export default forwardRef(DateRangePickerCalendar);
18
+ function DateRangePickerCalendar(_a, ref) {
21
19
  var _b, _c;
22
20
  var _d, _e;
23
- var value = _a.value, onChange = _a.onChange, locale = _a.locale, startOfWeek = _a.startOfWeek, isDateEnabled = _a.isDateEnabled, i18nStrings = _a.i18nStrings, _f = _a.dateOnly, dateOnly = _f === void 0 ? false : _f, _g = _a.timeInputFormat, timeInputFormat = _g === void 0 ? 'hh:mm:ss' : _g;
21
+ var value = _a.value, onChange = _a.onChange, _f = _a.locale, locale = _f === void 0 ? '' : _f, startOfWeek = _a.startOfWeek, _g = _a.isDateEnabled, isDateEnabled = _g === void 0 ? function () { return true; } : _g, i18nStrings = _a.i18nStrings, _h = _a.dateOnly, dateOnly = _h === void 0 ? false : _h, _j = _a.timeInputFormat, timeInputFormat = _j === void 0 ? 'hh:mm:ss' : _j;
24
22
  var elementRef = useRef(null);
25
23
  var isSingleGrid = useMobile();
26
- var normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, locale);
24
+ var normalizedLocale = normalizeLocale('DateRangePicker', locale);
25
+ var normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, normalizedLocale);
27
26
  useImperativeHandle(ref, function () { return ({
28
27
  focus: function () {
29
28
  if (elementRef.current) {
@@ -34,16 +33,16 @@ function RangeCalendar(_a, ref) {
34
33
  }); });
35
34
  var initialStartDate = (_d = value === null || value === void 0 ? void 0 : value.startDate) !== null && _d !== void 0 ? _d : '';
36
35
  var initialEndDate = (_e = value === null || value === void 0 ? void 0 : value.endDate) !== null && _e !== void 0 ? _e : '';
37
- var _h = initialStartDate.split('T'), _j = _h[0], initialStartDateString = _j === void 0 ? '' : _j, _k = _h[1], initialStartTimeString = _k === void 0 ? '' : _k;
38
- var _l = initialEndDate.split('T'), _m = _l[0], initialEndDateString = _m === void 0 ? '' : _m, _o = _l[1], initialEndTimeString = _o === void 0 ? '' : _o;
39
- var _p = useState(initialStartDateString), startDateString = _p[0], setStartDateString = _p[1];
40
- var _q = useState(initialStartTimeString), startTimeString = _q[0], setStartTimeString = _q[1];
41
- var _r = useState(initialEndDateString), endDateString = _r[0], setEndDateString = _r[1];
42
- var _s = useState(initialEndTimeString), endTimeString = _s[0], setEndTimeString = _s[1];
36
+ var _k = initialStartDate.split('T'), _l = _k[0], initialStartDateString = _l === void 0 ? '' : _l, _m = _k[1], initialStartTimeString = _m === void 0 ? '' : _m;
37
+ var _o = initialEndDate.split('T'), _p = _o[0], initialEndDateString = _p === void 0 ? '' : _p, _q = _o[1], initialEndTimeString = _q === void 0 ? '' : _q;
38
+ var _r = useState(initialStartDateString), startDateString = _r[0], setStartDateString = _r[1];
39
+ var _s = useState(initialStartTimeString), startTimeString = _s[0], setStartTimeString = _s[1];
40
+ var _t = useState(initialEndDateString), endDateString = _t[0], setEndDateString = _t[1];
41
+ var _u = useState(initialEndTimeString), endTimeString = _u[0], setEndTimeString = _u[1];
43
42
  var selectedStartDate = parseDate(startDateString, true);
44
43
  var selectedEndDate = parseDate(endDateString, true);
45
- var _t = useState(''), announcement = _t[0], setAnnouncement = _t[1];
46
- var _u = useState(function () {
44
+ var _v = useState(''), announcement = _v[0], setAnnouncement = _v[1];
45
+ var _w = useState(function () {
47
46
  if (startDateString) {
48
47
  var startDate = parseDate(startDateString);
49
48
  if (isSingleGrid) {
@@ -55,8 +54,8 @@ function RangeCalendar(_a, ref) {
55
54
  return startOfMonth(parseDate(endDateString));
56
55
  }
57
56
  return startOfMonth(Date.now());
58
- }), currentMonth = _u[0], setCurrentMonth = _u[1];
59
- var _v = useState(function () {
57
+ }), currentMonth = _w[0], setCurrentMonth = _w[1];
58
+ var _x = useState(function () {
60
59
  if (selectedStartDate) {
61
60
  if (isSameMonth(selectedStartDate, currentMonth)) {
62
61
  return selectedStartDate;
@@ -66,9 +65,9 @@ function RangeCalendar(_a, ref) {
66
65
  }
67
66
  }
68
67
  return selectFocusedDate(selectedStartDate, currentMonth, isDateEnabled);
69
- }), focusedDate = _v[0], setFocusedDate = _v[1];
68
+ }), focusedDate = _x[0], setFocusedDate = _x[1];
69
+ // This effect "synchronizes" the local state update back up to the parent component.
70
70
  useEffect(function () {
71
- // This effect "synchronizes" the local state update back up to the overall DateRangePicker component
72
71
  var startDate = joinDateTime(startDateString, startTimeString);
73
72
  var endDate = joinDateTime(endDateString, endTimeString);
74
73
  if (startDate !== initialStartDate || endDate !== initialEndDate) {
@@ -81,28 +80,28 @@ function RangeCalendar(_a, ref) {
81
80
  var announceStart = function (startDate) {
82
81
  return (i18nStrings.startDateLabel +
83
82
  ', ' +
84
- getDateLabel(locale, startDate) +
83
+ getDateLabel(normalizedLocale, startDate) +
85
84
  ', ' +
86
85
  i18nStrings.startTimeLabel +
87
86
  ', ' +
88
- renderTimeLabel(locale, startDate, timeInputFormat) +
87
+ renderTimeLabel(normalizedLocale, startDate, timeInputFormat) +
89
88
  '. ');
90
89
  };
91
90
  var announceEnd = function (endDate) {
92
91
  return (i18nStrings.endDateLabel +
93
92
  ', ' +
94
- getDateLabel(locale, endDate) +
93
+ getDateLabel(normalizedLocale, endDate) +
95
94
  ', ' +
96
95
  i18nStrings.endTimeLabel +
97
96
  ', ' +
98
- renderTimeLabel(locale, endDate, timeInputFormat) +
97
+ renderTimeLabel(normalizedLocale, endDate, timeInputFormat) +
99
98
  '. ');
100
99
  };
101
100
  var announceRange = function (startDate, endDate) {
102
101
  if (!i18nStrings.renderSelectedAbsoluteRangeAriaLive) {
103
- return "".concat(getDateLabel(locale, startDate), " \u2013 ").concat(getDateLabel(locale, endDate));
102
+ return "".concat(getDateLabel(normalizedLocale, startDate), " \u2013 ").concat(getDateLabel(normalizedLocale, endDate));
104
103
  }
105
- return i18nStrings.renderSelectedAbsoluteRangeAriaLive(getDateLabel(locale, startDate), getDateLabel(locale, endDate));
104
+ return i18nStrings.renderSelectedAbsoluteRangeAriaLive(getDateLabel(normalizedLocale, startDate), getDateLabel(normalizedLocale, endDate));
106
105
  };
107
106
  // If both fields are empty, we set the start date
108
107
  if (!startDateString && !endDateString) {
@@ -173,15 +172,15 @@ function RangeCalendar(_a, ref) {
173
172
  var newBaseDate = getBaseDate(newBaseDateMonth, isDateEnabled);
174
173
  setFocusedDate(newBaseDate);
175
174
  };
176
- var onChangeStartDate = function (e) {
177
- setStartDateString(e.detail.value);
178
- if (e.detail.value.length >= 8) {
179
- var newCurrentMonth = startOfMonth(parseDate(e.detail.value));
175
+ var onChangeStartDate = function (value) {
176
+ setStartDateString(value);
177
+ if (value.length >= 8) {
178
+ var newCurrentMonth = startOfMonth(parseDate(value));
180
179
  setCurrentMonth(isSingleGrid ? newCurrentMonth : addMonths(newCurrentMonth, 1));
181
180
  }
182
181
  };
183
- var onChangeEndDate = function (e) {
184
- setEndDateString(e.detail.value);
182
+ var onChangeEndDate = function (value) {
183
+ setEndDateString(value);
185
184
  };
186
185
  var headingIdPrefix = useUniqueId('date-range-picker-calendar-heading');
187
186
  return (React.createElement(React.Fragment, null,
@@ -191,20 +190,9 @@ function RangeCalendar(_a, ref) {
191
190
  React.createElement("div", { ref: elementRef, className: clsx(styles.calendar, (_c = {},
192
191
  _c[styles['one-grid']] = isSingleGrid,
193
192
  _c)) },
194
- React.createElement(CalendarHeader, { baseDate: currentMonth, locale: locale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: i18nStrings.previousMonthAriaLabel, nextMonthLabel: i18nStrings.nextMonthAriaLabel, isSingleGrid: isSingleGrid, headingIdPrefix: headingIdPrefix }),
195
- React.createElement(Grids, { isSingleGrid: isSingleGrid, locale: locale, baseDate: currentMonth, focusedDate: focusedDate, onFocusedDateChange: setFocusedDate, isDateEnabled: isDateEnabled, onSelectDate: onSelectDateHandler, onChangeMonth: setCurrentMonth, startOfWeek: normalizedStartOfWeek, todayAriaLabel: i18nStrings.todayAriaLabel, selectedStartDate: selectedStartDate, selectedEndDate: selectedEndDate, headingIdPrefix: headingIdPrefix })),
196
- React.createElement(InternalFormField, { constraintText: i18nStrings.dateTimeConstraintText },
197
- React.createElement("div", { className: styles['date-and-time-container'] },
198
- React.createElement("div", { className: styles['date-and-time-wrapper'] },
199
- React.createElement(InternalFormField, { label: i18nStrings.startDateLabel, stretch: true },
200
- React.createElement(InternalDateInput, { value: startDateString, className: styles['start-date-input'], onChange: onChangeStartDate, placeholder: "YYYY/MM/DD" })),
201
- !dateOnly && (React.createElement(InternalFormField, { label: i18nStrings.startTimeLabel, stretch: true },
202
- React.createElement(InternalTimeInput, { value: startTimeString, onChange: function (e) { return setStartTimeString(e.detail.value); }, format: timeInputFormat, placeholder: timeInputFormat, className: styles['start-time-input'] })))),
203
- React.createElement("div", { className: styles['date-and-time-wrapper'] },
204
- React.createElement(InternalFormField, { label: i18nStrings.endDateLabel, stretch: true },
205
- React.createElement(InternalDateInput, { value: endDateString, className: styles['end-date-input'], onChange: onChangeEndDate, placeholder: "YYYY/MM/DD" })),
206
- !dateOnly && (React.createElement(InternalFormField, { label: i18nStrings.endTimeLabel, stretch: true },
207
- React.createElement(InternalTimeInput, { value: endTimeString, onChange: function (e) { return setEndTimeString(e.detail.value); }, format: timeInputFormat, placeholder: timeInputFormat, className: styles['end-time-input'] }))))))),
193
+ React.createElement(CalendarHeader, { baseDate: currentMonth, locale: normalizedLocale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: i18nStrings.previousMonthAriaLabel, nextMonthLabel: i18nStrings.nextMonthAriaLabel, isSingleGrid: isSingleGrid, headingIdPrefix: headingIdPrefix }),
194
+ React.createElement(Grids, { isSingleGrid: isSingleGrid, locale: normalizedLocale, baseDate: currentMonth, focusedDate: focusedDate, onFocusedDateChange: setFocusedDate, isDateEnabled: isDateEnabled, onSelectDate: onSelectDateHandler, onChangeMonth: setCurrentMonth, startOfWeek: normalizedStartOfWeek, todayAriaLabel: i18nStrings.todayAriaLabel, selectedStartDate: selectedStartDate, selectedEndDate: selectedEndDate, headingIdPrefix: headingIdPrefix })),
195
+ React.createElement(RangeInputs, { startDate: startDateString, onChangeStartDate: onChangeStartDate, startTime: startTimeString, onChangeStartTime: setStartTimeString, endDate: endDateString, onChangeEndDate: onChangeEndDate, endTime: endTimeString, onChangeEndTime: setEndTimeString, i18nStrings: i18nStrings, dateOnly: dateOnly, timeInputFormat: timeInputFormat })),
208
196
  React.createElement(LiveRegion, { className: styles['calendar-aria-live'] }, announcement)));
209
197
  }
210
198
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date-range-picker/calendar/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,E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B,CACrB,CACG,CACF,CACY,CAChB;QACN,oBAAC,UAAU,IAAC,SAAS,EAAE,MAAM,CAAC,oBAAoB,CAAC,IAAG,YAAY,CAAc,CAC/E,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';\nimport { addMonths, endOfDay, isBefore, startOfDay, startOfMonth, isAfter, isSameMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport { DateRangePickerProps, Focusable } from '../interfaces';\nimport CalendarHeader from './header';\nimport { Grids, selectFocusedDate } from './grids';\nimport InternalFormField from '../../form-field/internal';\nimport { InputProps } from '../../input/interfaces';\nimport InternalDateInput from '../../date-input/internal';\nimport { TimeInputProps } from '../../time-input/interfaces';\nimport InternalTimeInput from '../../time-input/internal';\nimport clsx from 'clsx';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport { getDateLabel, renderTimeLabel } from '../../calendar/utils/intl';\nimport LiveRegion from '../../internal/components/live-region';\nimport { normalizeStartOfWeek } from '../../calendar/utils/locales';\nimport { formatDate, formatTime, joinDateTime, parseDate } from '../../internal/utils/date-time';\nimport { getBaseDate } from '../../calendar/utils/navigation';\nimport { useMobile } from '../../internal/hooks/use-mobile/index.js';\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface HeaderChangeMonthHandler {\n (isPreviousButtonClick?: boolean): void;\n}\n\nexport interface RangeCalendarValue {\n startDate: string;\n endDate: string;\n}\n\nexport interface CalendarProps extends BaseComponentProps {\n value: null | RangeCalendarValue;\n onChange: (value: RangeCalendarValue) => void;\n locale: string;\n startOfWeek: number | undefined;\n isDateEnabled: (date: Date) => boolean;\n i18nStrings: DateRangePickerProps.I18nStrings;\n dateOnly?: boolean;\n timeInputFormat?: TimeInputProps.Format;\n}\n\nexport default forwardRef(RangeCalendar);\n\nfunction RangeCalendar(\n {\n value,\n onChange,\n locale,\n startOfWeek,\n isDateEnabled,\n i18nStrings,\n dateOnly = false,\n timeInputFormat = 'hh:mm:ss',\n }: CalendarProps,\n ref: React.Ref<Focusable>\n) {\n const elementRef = useRef<HTMLDivElement>(null);\n const isSingleGrid = useMobile();\n\n const normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, locale);\n\n useImperativeHandle(ref, () => ({\n focus() {\n if (elementRef.current) {\n const prevButton = elementRef.current.getElementsByClassName(styles['calendar-prev-month-btn'])[0];\n (prevButton as undefined | HTMLButtonElement)?.focus();\n }\n },\n }));\n\n const initialStartDate = value?.startDate ?? '';\n const initialEndDate = value?.endDate ?? '';\n const [initialStartDateString = '', initialStartTimeString = ''] = initialStartDate.split('T');\n const [initialEndDateString = '', initialEndTimeString = ''] = initialEndDate.split('T');\n\n const [startDateString, setStartDateString] = useState(initialStartDateString);\n const [startTimeString, setStartTimeString] = useState(initialStartTimeString);\n\n const [endDateString, setEndDateString] = useState(initialEndDateString);\n const [endTimeString, setEndTimeString] = useState(initialEndTimeString);\n\n const selectedStartDate = parseDate(startDateString, true);\n const selectedEndDate = parseDate(endDateString, true);\n\n const [announcement, setAnnouncement] = useState('');\n\n const [currentMonth, setCurrentMonth] = useState(() => {\n if (startDateString) {\n const startDate = parseDate(startDateString);\n if (isSingleGrid) {\n return startOfMonth(startDate);\n }\n return startOfMonth(addMonths(startDate, 1));\n }\n if (endDateString) {\n return startOfMonth(parseDate(endDateString));\n }\n return startOfMonth(Date.now());\n });\n\n const [focusedDate, setFocusedDate] = useState<Date | null>(() => {\n if (selectedStartDate) {\n if (isSameMonth(selectedStartDate, currentMonth)) {\n return selectedStartDate;\n }\n if (!isSingleGrid && isSameMonth(selectedStartDate, addMonths(currentMonth, -1))) {\n return selectedStartDate;\n }\n }\n return selectFocusedDate(selectedStartDate, currentMonth, isDateEnabled);\n });\n\n useEffect(() => {\n // This effect \"synchronizes\" the local state update back up to the overall DateRangePicker component\n\n const startDate = joinDateTime(startDateString, startTimeString);\n const endDate = joinDateTime(endDateString, endTimeString);\n\n if (startDate !== initialStartDate || endDate !== initialEndDate) {\n onChange({ startDate, endDate });\n }\n }, [startDateString, startTimeString, endDateString, endTimeString, onChange, initialStartDate, initialEndDate]);\n\n const onSelectDateHandler = (selectedDate: Date) => {\n // recommended to include the start/end time announced with the selection\n // because the user is not aware of the fact that a start/end time is also set as soon as they select a date\n const announceStart = (startDate: Date) => {\n return (\n i18nStrings.startDateLabel +\n ', ' +\n getDateLabel(locale, startDate) +\n ', ' +\n i18nStrings.startTimeLabel +\n ', ' +\n renderTimeLabel(locale, startDate, timeInputFormat) +\n '. '\n );\n };\n\n const announceEnd = (endDate: Date) => {\n return (\n i18nStrings.endDateLabel +\n ', ' +\n getDateLabel(locale, endDate) +\n ', ' +\n i18nStrings.endTimeLabel +\n ', ' +\n renderTimeLabel(locale, endDate, timeInputFormat) +\n '. '\n );\n };\n\n const announceRange = (startDate: Date, endDate: Date) => {\n if (!i18nStrings.renderSelectedAbsoluteRangeAriaLive) {\n return `${getDateLabel(locale, startDate)} – ${getDateLabel(locale, endDate)}`;\n }\n return i18nStrings.renderSelectedAbsoluteRangeAriaLive(\n getDateLabel(locale, startDate),\n getDateLabel(locale, endDate)\n );\n };\n\n // If both fields are empty, we set the start date\n if (!startDateString && !endDateString) {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n setAnnouncement(announceStart(startDate));\n return;\n }\n\n // If both fields are set, we start new\n if (startDateString && endDateString) {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString('');\n setEndTimeString('');\n setAnnouncement(announceStart(startDate));\n return;\n }\n\n // If only the END date is empty, we fill it (and swap dates if needed)\n if (startDateString && !endDateString) {\n const parsedStartDate = parseDate(startDateString);\n\n if (isBefore(selectedDate, parsedStartDate)) {\n // The user has selected the range backwards, so we swap start and end\n\n const startDate = startOfDay(selectedDate);\n const endDate = endOfDay(parsedStartDate);\n\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceStart(startDate) + announceRange(startDate, endDate));\n } else {\n const endDate = endOfDay(selectedDate);\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceEnd(endDate) + announceRange(parsedStartDate, endDate));\n }\n return;\n }\n\n // If only the START date is empty, we fill it (and swap dates if needed)\n if (!startDateString && endDateString) {\n const existingEndDate = parseDate(endDateString);\n\n if (isAfter(selectedDate, existingEndDate)) {\n // The user has selected the range backwards, so we swap start and end\n\n const startDate = startOfDay(existingEndDate);\n const endDate = endOfDay(selectedDate);\n\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceEnd(endDate) + announceRange(startDate, endDate));\n } else {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n setAnnouncement(announceStart(startDate) + announceRange(startDate, existingEndDate));\n }\n return;\n }\n // All possible conditions are covered above\n };\n\n const onHeaderChangeMonthHandler: HeaderChangeMonthHandler = isPrevious => {\n const newCurrentMonth = addMonths(currentMonth, isPrevious ? -1 : 1);\n setCurrentMonth(newCurrentMonth);\n\n const newBaseDateMonth = isSingleGrid ? newCurrentMonth : addMonths(newCurrentMonth, -1);\n const newBaseDate = getBaseDate(newBaseDateMonth, isDateEnabled);\n setFocusedDate(newBaseDate);\n };\n\n const onChangeStartDate: InputProps['onChange'] = e => {\n setStartDateString(e.detail.value);\n\n if (e.detail.value.length >= 8) {\n const newCurrentMonth = startOfMonth(parseDate(e.detail.value));\n setCurrentMonth(isSingleGrid ? newCurrentMonth : addMonths(newCurrentMonth, 1));\n }\n };\n\n const onChangeEndDate: InputProps['onChange'] = e => {\n setEndDateString(e.detail.value);\n };\n\n const headingIdPrefix = useUniqueId('date-range-picker-calendar-heading');\n return (\n <>\n <div\n className={clsx(styles['calendar-container'], {\n [styles['one-grid']]: isSingleGrid,\n })}\n >\n <div\n ref={elementRef}\n className={clsx(styles.calendar, {\n [styles['one-grid']]: isSingleGrid,\n })}\n >\n <CalendarHeader\n baseDate={currentMonth}\n locale={locale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={i18nStrings.previousMonthAriaLabel}\n nextMonthLabel={i18nStrings.nextMonthAriaLabel}\n isSingleGrid={isSingleGrid}\n headingIdPrefix={headingIdPrefix}\n />\n\n <Grids\n isSingleGrid={isSingleGrid}\n locale={locale}\n baseDate={currentMonth}\n focusedDate={focusedDate}\n onFocusedDateChange={setFocusedDate}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDateHandler}\n onChangeMonth={setCurrentMonth}\n startOfWeek={normalizedStartOfWeek}\n todayAriaLabel={i18nStrings.todayAriaLabel}\n selectedStartDate={selectedStartDate}\n selectedEndDate={selectedEndDate}\n headingIdPrefix={headingIdPrefix}\n />\n </div>\n <InternalFormField constraintText={i18nStrings.dateTimeConstraintText}>\n <div className={styles['date-and-time-container']}>\n <div className={styles['date-and-time-wrapper']}>\n <InternalFormField label={i18nStrings.startDateLabel} stretch={true}>\n <InternalDateInput\n value={startDateString}\n className={styles['start-date-input']}\n onChange={onChangeStartDate}\n placeholder=\"YYYY/MM/DD\"\n />\n </InternalFormField>\n {!dateOnly && (\n <InternalFormField label={i18nStrings.startTimeLabel} stretch={true}>\n <InternalTimeInput\n value={startTimeString}\n onChange={e => setStartTimeString(e.detail.value)}\n format={timeInputFormat}\n placeholder={timeInputFormat}\n className={styles['start-time-input']}\n />\n </InternalFormField>\n )}\n </div>\n\n <div className={styles['date-and-time-wrapper']}>\n <InternalFormField label={i18nStrings.endDateLabel} stretch={true}>\n <InternalDateInput\n value={endDateString}\n className={styles['end-date-input']}\n onChange={onChangeEndDate}\n placeholder=\"YYYY/MM/DD\"\n />\n </InternalFormField>\n {!dateOnly && (\n <InternalFormField label={i18nStrings.endTimeLabel} stretch={true}>\n <InternalTimeInput\n value={endTimeString}\n onChange={e => setEndTimeString(e.detail.value)}\n format={timeInputFormat}\n placeholder={timeInputFormat}\n className={styles['end-time-input']}\n />\n </InternalFormField>\n )}\n </div>\n </div>\n </InternalFormField>\n </div>\n <LiveRegion className={styles['calendar-aria-live']}>{announcement}</LiveRegion>\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date-range-picker/calendar/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACzG,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAGtC,OAAO,cAAc,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,UAAU,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,SAAS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WAAW,EACxB,mBAAmB,EAAE,cAAc,EACnC,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,mBAAmB,EACjC,aAAa,EAAE,eAAe,EAC9B,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,WAAW,CAAC,cAAc,EAC1C,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,eAAe,GAChC,CACE;YAEN,oBAAC,WAAW,IACV,SAAS,EAAE,eAAe,EAC1B,iBAAiB,EAAE,iBAAiB,EACpC,SAAS,EAAE,eAAe,EAC1B,iBAAiB,EAAE,kBAAkB,EACrC,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,gBAAgB,EACjC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,GAChC,CACE;QACN,oBAAC,UAAU,IAAC,SAAS,EAAE,MAAM,CAAC,oBAAoB,CAAC,IAAG,YAAY,CAAc,CAC/E,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';\nimport { addMonths, endOfDay, isBefore, startOfDay, startOfMonth, isAfter, isSameMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport { Focusable, RangeCalendarI18nStrings, RangeCalendarValue } from '../interfaces';\nimport CalendarHeader from './header';\nimport { Grids, selectFocusedDate } from './grids';\nimport { TimeInputProps } from '../../time-input/interfaces';\nimport clsx from 'clsx';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport { getDateLabel, renderTimeLabel } from '../../calendar/utils/intl';\nimport LiveRegion from '../../internal/components/live-region';\nimport { normalizeLocale, normalizeStartOfWeek } from '../../calendar/utils/locales';\nimport { formatDate, formatTime, joinDateTime, parseDate } from '../../internal/utils/date-time';\nimport { getBaseDate } from '../../calendar/utils/navigation';\nimport { useMobile } from '../../internal/hooks/use-mobile/index.js';\nimport RangeInputs from './range-inputs.js';\n\nexport interface DateRangePickerCalendarProps extends BaseComponentProps {\n value: null | RangeCalendarValue;\n onChange: (value: RangeCalendarValue) => void;\n locale?: string;\n startOfWeek?: number;\n isDateEnabled?: (date: Date) => boolean;\n i18nStrings: RangeCalendarI18nStrings;\n dateOnly?: boolean;\n timeInputFormat?: TimeInputProps.Format;\n}\n\nexport default forwardRef(DateRangePickerCalendar);\n\nfunction DateRangePickerCalendar(\n {\n value,\n onChange,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n i18nStrings,\n dateOnly = false,\n timeInputFormat = 'hh:mm:ss',\n }: DateRangePickerCalendarProps,\n ref: React.Ref<Focusable>\n) {\n const elementRef = useRef<HTMLDivElement>(null);\n const isSingleGrid = useMobile();\n\n const normalizedLocale = normalizeLocale('DateRangePicker', locale);\n const normalizedStartOfWeek = normalizeStartOfWeek(startOfWeek, normalizedLocale);\n\n useImperativeHandle(ref, () => ({\n focus() {\n if (elementRef.current) {\n const prevButton = elementRef.current.getElementsByClassName(styles['calendar-prev-month-btn'])[0];\n (prevButton as undefined | HTMLButtonElement)?.focus();\n }\n },\n }));\n\n const initialStartDate = value?.startDate ?? '';\n const initialEndDate = value?.endDate ?? '';\n const [initialStartDateString = '', initialStartTimeString = ''] = initialStartDate.split('T');\n const [initialEndDateString = '', initialEndTimeString = ''] = initialEndDate.split('T');\n\n const [startDateString, setStartDateString] = useState(initialStartDateString);\n const [startTimeString, setStartTimeString] = useState(initialStartTimeString);\n\n const [endDateString, setEndDateString] = useState(initialEndDateString);\n const [endTimeString, setEndTimeString] = useState(initialEndTimeString);\n\n const selectedStartDate = parseDate(startDateString, true);\n const selectedEndDate = parseDate(endDateString, true);\n\n const [announcement, setAnnouncement] = useState('');\n\n const [currentMonth, setCurrentMonth] = useState(() => {\n if (startDateString) {\n const startDate = parseDate(startDateString);\n if (isSingleGrid) {\n return startOfMonth(startDate);\n }\n return startOfMonth(addMonths(startDate, 1));\n }\n if (endDateString) {\n return startOfMonth(parseDate(endDateString));\n }\n return startOfMonth(Date.now());\n });\n\n const [focusedDate, setFocusedDate] = useState<Date | null>(() => {\n if (selectedStartDate) {\n if (isSameMonth(selectedStartDate, currentMonth)) {\n return selectedStartDate;\n }\n if (!isSingleGrid && isSameMonth(selectedStartDate, addMonths(currentMonth, -1))) {\n return selectedStartDate;\n }\n }\n return selectFocusedDate(selectedStartDate, currentMonth, isDateEnabled);\n });\n\n // This effect \"synchronizes\" the local state update back up to the parent component.\n useEffect(() => {\n const startDate = joinDateTime(startDateString, startTimeString);\n const endDate = joinDateTime(endDateString, endTimeString);\n\n if (startDate !== initialStartDate || endDate !== initialEndDate) {\n onChange({ startDate, endDate });\n }\n }, [startDateString, startTimeString, endDateString, endTimeString, onChange, initialStartDate, initialEndDate]);\n\n const onSelectDateHandler = (selectedDate: Date) => {\n // recommended to include the start/end time announced with the selection\n // because the user is not aware of the fact that a start/end time is also set as soon as they select a date\n const announceStart = (startDate: Date) => {\n return (\n i18nStrings.startDateLabel +\n ', ' +\n getDateLabel(normalizedLocale, startDate) +\n ', ' +\n i18nStrings.startTimeLabel +\n ', ' +\n renderTimeLabel(normalizedLocale, startDate, timeInputFormat) +\n '. '\n );\n };\n\n const announceEnd = (endDate: Date) => {\n return (\n i18nStrings.endDateLabel +\n ', ' +\n getDateLabel(normalizedLocale, endDate) +\n ', ' +\n i18nStrings.endTimeLabel +\n ', ' +\n renderTimeLabel(normalizedLocale, endDate, timeInputFormat) +\n '. '\n );\n };\n\n const announceRange = (startDate: Date, endDate: Date) => {\n if (!i18nStrings.renderSelectedAbsoluteRangeAriaLive) {\n return `${getDateLabel(normalizedLocale, startDate)} – ${getDateLabel(normalizedLocale, endDate)}`;\n }\n return i18nStrings.renderSelectedAbsoluteRangeAriaLive(\n getDateLabel(normalizedLocale, startDate),\n getDateLabel(normalizedLocale, endDate)\n );\n };\n\n // If both fields are empty, we set the start date\n if (!startDateString && !endDateString) {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n setAnnouncement(announceStart(startDate));\n return;\n }\n\n // If both fields are set, we start new\n if (startDateString && endDateString) {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString('');\n setEndTimeString('');\n setAnnouncement(announceStart(startDate));\n return;\n }\n\n // If only the END date is empty, we fill it (and swap dates if needed)\n if (startDateString && !endDateString) {\n const parsedStartDate = parseDate(startDateString);\n\n if (isBefore(selectedDate, parsedStartDate)) {\n // The user has selected the range backwards, so we swap start and end\n\n const startDate = startOfDay(selectedDate);\n const endDate = endOfDay(parsedStartDate);\n\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceStart(startDate) + announceRange(startDate, endDate));\n } else {\n const endDate = endOfDay(selectedDate);\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceEnd(endDate) + announceRange(parsedStartDate, endDate));\n }\n return;\n }\n\n // If only the START date is empty, we fill it (and swap dates if needed)\n if (!startDateString && endDateString) {\n const existingEndDate = parseDate(endDateString);\n\n if (isAfter(selectedDate, existingEndDate)) {\n // The user has selected the range backwards, so we swap start and end\n\n const startDate = startOfDay(existingEndDate);\n const endDate = endOfDay(selectedDate);\n\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n\n setEndDateString(formatDate(endDate));\n setEndTimeString(formatTime(endDate));\n setAnnouncement(announceEnd(endDate) + announceRange(startDate, endDate));\n } else {\n const startDate = startOfDay(selectedDate);\n setStartDateString(formatDate(startDate));\n setStartTimeString(formatTime(startDate));\n setAnnouncement(announceStart(startDate) + announceRange(startDate, existingEndDate));\n }\n return;\n }\n // All possible conditions are covered above\n };\n\n const onHeaderChangeMonthHandler = (isPrevious?: boolean) => {\n const newCurrentMonth = addMonths(currentMonth, isPrevious ? -1 : 1);\n setCurrentMonth(newCurrentMonth);\n\n const newBaseDateMonth = isSingleGrid ? newCurrentMonth : addMonths(newCurrentMonth, -1);\n const newBaseDate = getBaseDate(newBaseDateMonth, isDateEnabled);\n setFocusedDate(newBaseDate);\n };\n\n const onChangeStartDate = (value: string) => {\n setStartDateString(value);\n\n if (value.length >= 8) {\n const newCurrentMonth = startOfMonth(parseDate(value));\n setCurrentMonth(isSingleGrid ? newCurrentMonth : addMonths(newCurrentMonth, 1));\n }\n };\n\n const onChangeEndDate = (value: string) => {\n setEndDateString(value);\n };\n\n const headingIdPrefix = useUniqueId('date-range-picker-calendar-heading');\n return (\n <>\n <div\n className={clsx(styles['calendar-container'], {\n [styles['one-grid']]: isSingleGrid,\n })}\n >\n <div\n ref={elementRef}\n className={clsx(styles.calendar, {\n [styles['one-grid']]: isSingleGrid,\n })}\n >\n <CalendarHeader\n baseDate={currentMonth}\n locale={normalizedLocale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={i18nStrings.previousMonthAriaLabel}\n nextMonthLabel={i18nStrings.nextMonthAriaLabel}\n isSingleGrid={isSingleGrid}\n headingIdPrefix={headingIdPrefix}\n />\n\n <Grids\n isSingleGrid={isSingleGrid}\n locale={normalizedLocale}\n baseDate={currentMonth}\n focusedDate={focusedDate}\n onFocusedDateChange={setFocusedDate}\n isDateEnabled={isDateEnabled}\n onSelectDate={onSelectDateHandler}\n onChangeMonth={setCurrentMonth}\n startOfWeek={normalizedStartOfWeek}\n todayAriaLabel={i18nStrings.todayAriaLabel}\n selectedStartDate={selectedStartDate}\n selectedEndDate={selectedEndDate}\n headingIdPrefix={headingIdPrefix}\n />\n </div>\n\n <RangeInputs\n startDate={startDateString}\n onChangeStartDate={onChangeStartDate}\n startTime={startTimeString}\n onChangeStartTime={setStartTimeString}\n endDate={endDateString}\n onChangeEndDate={onChangeEndDate}\n endTime={endTimeString}\n onChangeEndTime={setEndTimeString}\n i18nStrings={i18nStrings}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n />\n </div>\n <LiveRegion className={styles['calendar-aria-live']}>{announcement}</LiveRegion>\n </>\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { BaseComponentProps } from '../../internal/base-component';
2
+ import { RangeCalendarI18nStrings } from '../interfaces';
3
+ import { TimeInputProps } from '../../time-input/interfaces';
4
+ declare type I18nStrings = Pick<RangeCalendarI18nStrings, 'dateTimeConstraintText' | 'startDateLabel' | 'startTimeLabel' | 'endDateLabel' | 'endTimeLabel'>;
5
+ export interface RangeInputsProps extends BaseComponentProps {
6
+ startDate: string;
7
+ onChangeStartDate: (value: string) => void;
8
+ startTime: string;
9
+ onChangeStartTime: (value: string) => void;
10
+ endDate: string;
11
+ onChangeEndDate: (value: string) => void;
12
+ endTime: string;
13
+ onChangeEndTime: (value: string) => void;
14
+ i18nStrings: I18nStrings;
15
+ dateOnly: boolean;
16
+ timeInputFormat: TimeInputProps.Format;
17
+ }
18
+ export default function RangeInputs({ startDate, onChangeStartDate, startTime, onChangeStartTime, endDate, onChangeEndDate, endTime, onChangeEndTime, i18nStrings, dateOnly, timeInputFormat, }: RangeInputsProps): JSX.Element;
19
+ export {};
20
+ //# sourceMappingURL=range-inputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range-inputs.d.ts","sourceRoot":"","sources":["../../../../src/date-range-picker/calendar/range-inputs.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,aAAK,WAAW,GAAG,IAAI,CACrB,wBAAwB,EACxB,wBAAwB,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,cAAc,GAAG,cAAc,CACjG,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC;CACxC;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,OAAO,EACP,eAAe,EACf,OAAO,EACP,eAAe,EACf,WAAW,EACX,QAAQ,EACR,eAAe,GAChB,EAAE,gBAAgB,eAkDlB"}
@@ -0,0 +1,23 @@
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 styles from '../styles.css.js';
5
+ import InternalFormField from '../../form-field/internal';
6
+ import InternalDateInput from '../../date-input/internal';
7
+ import InternalTimeInput from '../../time-input/internal';
8
+ export default function RangeInputs(_a) {
9
+ var startDate = _a.startDate, onChangeStartDate = _a.onChangeStartDate, startTime = _a.startTime, onChangeStartTime = _a.onChangeStartTime, endDate = _a.endDate, onChangeEndDate = _a.onChangeEndDate, endTime = _a.endTime, onChangeEndTime = _a.onChangeEndTime, i18nStrings = _a.i18nStrings, dateOnly = _a.dateOnly, timeInputFormat = _a.timeInputFormat;
10
+ return (React.createElement(InternalFormField, { constraintText: i18nStrings.dateTimeConstraintText },
11
+ React.createElement("div", { className: styles['date-and-time-container'] },
12
+ React.createElement("div", { className: styles['date-and-time-wrapper'] },
13
+ React.createElement(InternalFormField, { label: i18nStrings.startDateLabel, stretch: true },
14
+ React.createElement(InternalDateInput, { value: startDate, className: styles['start-date-input'], onChange: function (event) { return onChangeStartDate(event.detail.value); }, placeholder: "YYYY/MM/DD" })),
15
+ !dateOnly && (React.createElement(InternalFormField, { label: i18nStrings.startTimeLabel, stretch: true },
16
+ React.createElement(InternalTimeInput, { value: startTime, onChange: function (event) { return onChangeStartTime(event.detail.value); }, format: timeInputFormat, placeholder: timeInputFormat, className: styles['start-time-input'] })))),
17
+ React.createElement("div", { className: styles['date-and-time-wrapper'] },
18
+ React.createElement(InternalFormField, { label: i18nStrings.endDateLabel, stretch: true },
19
+ React.createElement(InternalDateInput, { value: endDate, className: styles['end-date-input'], onChange: function (event) { return onChangeEndDate(event.detail.value); }, placeholder: "YYYY/MM/DD" })),
20
+ !dateOnly && (React.createElement(InternalFormField, { label: i18nStrings.endTimeLabel, stretch: true },
21
+ React.createElement(InternalTimeInput, { value: endTime, onChange: function (event) { return onChangeEndTime(event.detail.value); }, format: timeInputFormat, placeholder: timeInputFormat, className: styles['end-time-input'] })))))));
22
+ }
23
+ //# sourceMappingURL=range-inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range-inputs.js","sourceRoot":"","sources":["../../../../src/date-range-picker/calendar/range-inputs.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAGtC,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAE1D,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAqB1D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAYjB;QAXjB,SAAS,eAAA,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AE,OAAO,EACd,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,EACnC,QAAQ,EAAE,UAAA,KAAK,IAAI,OAAA,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAnC,CAAmC,EACtD,WAAW,EAAC,YAAY,GACxB,CACgB;gBACnB,CAAC,QAAQ,IAAI,CACZ,oBAAC,iBAAiB,IAAC,KAAK,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI;oBAC/D,oBAAC,iBAAiB,IAChB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,UAAA,KAAK,IAAI,OAAA,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAnC,CAAmC,EACtD,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,eAAe,EAC5B,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,GACnC,CACgB,CACrB,CACG,CACF,CACY,CACrB,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 styles from '../styles.css.js';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport { RangeCalendarI18nStrings } from '../interfaces';\nimport InternalFormField from '../../form-field/internal';\nimport InternalDateInput from '../../date-input/internal';\nimport { TimeInputProps } from '../../time-input/interfaces';\nimport InternalTimeInput from '../../time-input/internal';\n\ntype I18nStrings = Pick<\n RangeCalendarI18nStrings,\n 'dateTimeConstraintText' | 'startDateLabel' | 'startTimeLabel' | 'endDateLabel' | 'endTimeLabel'\n>;\n\nexport interface RangeInputsProps extends BaseComponentProps {\n startDate: string;\n onChangeStartDate: (value: string) => void;\n startTime: string;\n onChangeStartTime: (value: string) => void;\n endDate: string;\n onChangeEndDate: (value: string) => void;\n endTime: string;\n onChangeEndTime: (value: string) => void;\n i18nStrings: I18nStrings;\n dateOnly: boolean;\n timeInputFormat: TimeInputProps.Format;\n}\n\nexport default function RangeInputs({\n startDate,\n onChangeStartDate,\n startTime,\n onChangeStartTime,\n endDate,\n onChangeEndDate,\n endTime,\n onChangeEndTime,\n i18nStrings,\n dateOnly,\n timeInputFormat,\n}: RangeInputsProps) {\n return (\n <InternalFormField constraintText={i18nStrings.dateTimeConstraintText}>\n <div className={styles['date-and-time-container']}>\n <div className={styles['date-and-time-wrapper']}>\n <InternalFormField label={i18nStrings.startDateLabel} stretch={true}>\n <InternalDateInput\n value={startDate}\n className={styles['start-date-input']}\n onChange={event => onChangeStartDate(event.detail.value)}\n placeholder=\"YYYY/MM/DD\"\n />\n </InternalFormField>\n {!dateOnly && (\n <InternalFormField label={i18nStrings.startTimeLabel} stretch={true}>\n <InternalTimeInput\n value={startTime}\n onChange={event => onChangeStartTime(event.detail.value)}\n format={timeInputFormat}\n placeholder={timeInputFormat}\n className={styles['start-time-input']}\n />\n </InternalFormField>\n )}\n </div>\n\n <div className={styles['date-and-time-wrapper']}>\n <InternalFormField label={i18nStrings.endDateLabel} stretch={true}>\n <InternalDateInput\n value={endDate}\n className={styles['end-date-input']}\n onChange={event => onChangeEndDate(event.detail.value)}\n placeholder=\"YYYY/MM/DD\"\n />\n </InternalFormField>\n {!dateOnly && (\n <InternalFormField label={i18nStrings.endTimeLabel} stretch={true}>\n <InternalTimeInput\n value={endTime}\n onChange={event => onChangeEndTime(event.detail.value)}\n format={timeInputFormat}\n placeholder={timeInputFormat}\n className={styles['end-time-input']}\n />\n </InternalFormField>\n )}\n </div>\n </div>\n </InternalFormField>\n );\n}\n"]}
@@ -65,7 +65,7 @@ var DateRangePicker = React.forwardRef(function (_a, ref) {
65
65
  var dropdownId = useUniqueId('date-range-picker-dropdown');
66
66
  useFocusTracker({ rootRef: rootRef, onBlur: onBlur, onFocus: onFocus, viewportId: expandToViewport ? dropdownId : '' });
67
67
  var _s = useState(false), isDropDownOpen = _s[0], setIsDropDownOpen = _s[1];
68
- var normalizedLocale = normalizeLocale('DateRangePicker', locale !== null && locale !== void 0 ? locale : '');
68
+ var normalizedLocale = normalizeLocale('DateRangePicker', locale);
69
69
  var closeDropdown = function (focusTrigger) {
70
70
  var _a;
71
71
  if (focusTrigger === void 0) { focusTrigger = false; }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,sBAAsB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AE,cAAc,EACpB,eAAe,EAAE,cAAM,OAAA,aAAa,EAAE,EAAf,CAAe,EACtC,OAAO,EAAE,OAAO,EAChB,qBAAqB,EAAE,KAAK,EAC5B,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,IAErB,cAAc,IAAI,CACjB,oBAAC,uBAAuB,IACtB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,cAAM,OAAA,aAAa,CAAC,IAAI,CAAC,EAAnB,CAAmB,EAC1C,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,GAChC,CACH,CACQ,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AACrD,eAAe,eAAe,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useEffect, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { DateRangePickerProps } from './interfaces';\nimport { normalizeLocale } from '../calendar/utils/locales';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { KeyCode } from '../internal/keycode';\nimport clsx from 'clsx';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport InternalBox from '../box/internal';\nimport { DateRangePickerDropdown } from './dropdown';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport Dropdown from '../internal/components/dropdown';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport ButtonTrigger from '../internal/components/button-trigger';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport InternalIcon from '../icon/internal';\nimport { normalizeTimeOffset, shiftTimeOffset } from './time-offset';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport { isDevelopment } from '../internal/is-development.js';\nimport { warnOnce } from '../internal/logging.js';\nimport { usePrevious } from '../internal/hooks/use-previous/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { formatDateRange, isIsoDateOnly } from '../internal/utils/date-time';\nimport { formatValue } from './utils.js';\n\nexport { DateRangePickerProps };\n\nfunction renderDateRange(\n range: null | DateRangePickerProps.Value,\n placeholder: string,\n formatRelativeRange: DateRangePickerProps.I18nStrings['formatRelativeRange'],\n timeOffset: { startDate?: number; endDate?: number }\n) {\n if (!range) {\n return (\n <span className={styles['label-text']} aria-disabled={true}>\n {placeholder}\n </span>\n );\n }\n\n const formatted =\n range.type === 'relative' ? (\n formatRelativeRange(range)\n ) : (\n <BreakSpaces text={formatDateRange(range.startDate, range.endDate, timeOffset)} />\n );\n\n return (\n <InternalBox fontWeight=\"normal\" display=\"inline\" color=\"inherit\" variant=\"span\">\n {formatted}\n </InternalBox>\n );\n}\n\nfunction BreakSpaces({ text }: { text: string }) {\n const tokens = text.split(/( )/);\n return (\n <>\n {tokens.map((token, index) => (\n <React.Fragment key={index}>\n {token.length > 1 ? <span className={styles['label-token-nowrap']}>{token}</span> : token}\n {token === ' ' && <wbr />}\n </React.Fragment>\n ))}\n </>\n );\n}\n\nfunction isDateOnly(value: null | DateRangePickerProps.Value) {\n if (!value || value.type !== 'absolute') {\n return false;\n }\n return isIsoDateOnly(value.startDate) && isIsoDateOnly(value.endDate);\n}\n\nconst DateRangePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n value,\n placeholder,\n readOnly = false,\n disabled = false,\n onChange,\n onBlur,\n onFocus,\n relativeOptions = [],\n i18nStrings,\n isValidRange = () => ({ valid: true }),\n showClearButton = true,\n dateOnly = false,\n timeOffset,\n getTimeOffset,\n timeInputFormat = 'hh:mm:ss',\n expandToViewport = false,\n rangeSelectorMode = 'default',\n ...rest\n }: DateRangePickerProps,\n ref: Ref<DateRangePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DateRangePicker');\n checkControlled('DateRangePicker', 'value', value, 'onChange', onChange);\n\n const normalizedTimeOffset = normalizeTimeOffset(value, getTimeOffset, timeOffset);\n value = isDateOnly(value) ? value : shiftTimeOffset(value, normalizedTimeOffset);\n\n const baseProps = getBaseProps(rest);\n const { invalid, controlId, ariaDescribedby, ariaLabelledby } = useFormFieldContext({\n ariaLabelledby: rest.ariaLabelledby ?? i18nStrings.ariaLabelledby,\n ariaDescribedby: rest.ariaDescribedby ?? i18nStrings.ariaDescribedby,\n ...rest,\n });\n const isSingleGrid = useMobile();\n\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n useForwardFocus(ref, triggerRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('date-range-picker-dropdown');\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n\n const normalizedLocale = normalizeLocale('DateRangePicker', locale ?? '');\n\n const closeDropdown = (focusTrigger = false) => {\n setIsDropDownOpen(false);\n if (focusTrigger) {\n triggerRef.current?.focus();\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape) {\n closeDropdown(true);\n }\n };\n\n const onClear = () => {\n fireNonCancelableEvent(onChange, { value: null });\n };\n\n const onApply = (newValue: null | DateRangePickerProps.Value): DateRangePickerProps.ValidationResult => {\n const validationResult = isValidRange(newValue);\n if (validationResult?.valid === false) {\n return validationResult;\n }\n\n if (isDevelopment) {\n if (newValue?.type === 'absolute') {\n const [startDateWithoutTime] = newValue.startDate.split('T');\n const [endDateWithoutTime] = newValue.endDate.split('T');\n if (!startDateWithoutTime || !endDateWithoutTime) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided an `isValidRange` prop that did not catch a missing start or end date.'\n );\n }\n }\n }\n fireNonCancelableEvent(onChange, {\n value: formatValue(newValue, {\n dateOnly,\n timeOffset: normalizeTimeOffset(newValue, getTimeOffset, timeOffset),\n }),\n });\n return validationResult || { valid: true };\n };\n\n const prevDateOnly = usePrevious(dateOnly);\n useEffect(() => {\n if (prevDateOnly !== undefined && prevDateOnly !== dateOnly) {\n warnOnce(\n 'DateRangePicker',\n `The provided \\`dateOnly\\` flag has been changed from \"${prevDateOnly}\" to \"${dateOnly}\" which can lead to unexpected value format. Consider using separate components.`\n );\n }\n }, [prevDateOnly, dateOnly]);\n\n if (value && value.type !== 'absolute' && value.type !== 'relative') {\n warnOnce('DateRangePicker', 'You provided an invalid value. Reverting back to default.');\n value = null;\n }\n\n if (\n (value?.type === 'absolute' && rangeSelectorMode === 'relative-only') ||\n (value?.type === 'relative' && rangeSelectorMode === 'absolute-only')\n ) {\n warnOnce(\n 'DateRangePicker',\n 'The provided value does not correspond to the current range selector mode. Reverting back to default.'\n );\n value = null;\n }\n\n const trigger = (\n <div className={styles['trigger-wrapper']}>\n <ButtonTrigger\n ref={triggerRef}\n id={controlId}\n invalid={invalid}\n ariaLabel={i18nStrings.ariaLabel}\n ariaDescribedby={ariaDescribedby}\n ariaLabelledby={ariaLabelledby}\n className={clsx(styles.label, {\n [styles['label-enabled']]: !readOnly && !disabled,\n })}\n hideCaret={true}\n onClick={() => {\n if (!readOnly && !disabled) {\n setIsDropDownOpen(true);\n }\n }}\n disabled={disabled}\n readOnly={readOnly}\n ariaHasPopup=\"true\"\n >\n <span className={styles['trigger-flexbox']}>\n <span className={styles['icon-wrapper']}>\n <InternalIcon name=\"calendar\" variant={disabled || readOnly ? 'disabled' : 'normal'} />\n </span>\n {renderDateRange(value, placeholder ?? '', i18nStrings.formatRelativeRange, normalizedTimeOffset)}\n </span>\n </ButtonTrigger>\n </div>\n );\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(baseProps.className, styles.root)}\n onKeyDown={onWrapperKeyDownHandler}\n >\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={() => closeDropdown()}\n trigger={trigger}\n stretchToTriggerWidth={false}\n expandToViewport={expandToViewport}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <DateRangePickerDropdown\n startOfWeek={startOfWeek}\n locale={normalizedLocale}\n isSingleGrid={isSingleGrid}\n onDropdownClose={() => closeDropdown(true)}\n value={value}\n showClearButton={showClearButton}\n isDateEnabled={isDateEnabled}\n i18nStrings={i18nStrings}\n onClear={onClear}\n onApply={onApply}\n relativeOptions={relativeOptions}\n isValidRange={isValidRange}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n rangeSelectorMode={rangeSelectorMode}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n />\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DateRangePicker, 'DateRangePicker');\nexport default DateRangePicker;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,O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ChB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,GAChC,CACH,CACQ,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AACrD,eAAe,eAAe,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useEffect, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { DateRangePickerProps } from './interfaces';\nimport { normalizeLocale } from '../calendar/utils/locales';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { KeyCode } from '../internal/keycode';\nimport clsx from 'clsx';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport InternalBox from '../box/internal';\nimport { DateRangePickerDropdown } from './dropdown';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport Dropdown from '../internal/components/dropdown';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport ButtonTrigger from '../internal/components/button-trigger';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport InternalIcon from '../icon/internal';\nimport { normalizeTimeOffset, shiftTimeOffset } from './time-offset';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport { isDevelopment } from '../internal/is-development.js';\nimport { warnOnce } from '../internal/logging.js';\nimport { usePrevious } from '../internal/hooks/use-previous/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { formatDateRange, isIsoDateOnly } from '../internal/utils/date-time';\nimport { formatValue } from './utils.js';\n\nexport { DateRangePickerProps };\n\nfunction renderDateRange(\n range: null | DateRangePickerProps.Value,\n placeholder: string,\n formatRelativeRange: DateRangePickerProps.I18nStrings['formatRelativeRange'],\n timeOffset: { startDate?: number; endDate?: number }\n) {\n if (!range) {\n return (\n <span className={styles['label-text']} aria-disabled={true}>\n {placeholder}\n </span>\n );\n }\n\n const formatted =\n range.type === 'relative' ? (\n formatRelativeRange(range)\n ) : (\n <BreakSpaces text={formatDateRange(range.startDate, range.endDate, timeOffset)} />\n );\n\n return (\n <InternalBox fontWeight=\"normal\" display=\"inline\" color=\"inherit\" variant=\"span\">\n {formatted}\n </InternalBox>\n );\n}\n\nfunction BreakSpaces({ text }: { text: string }) {\n const tokens = text.split(/( )/);\n return (\n <>\n {tokens.map((token, index) => (\n <React.Fragment key={index}>\n {token.length > 1 ? <span className={styles['label-token-nowrap']}>{token}</span> : token}\n {token === ' ' && <wbr />}\n </React.Fragment>\n ))}\n </>\n );\n}\n\nfunction isDateOnly(value: null | DateRangePickerProps.Value) {\n if (!value || value.type !== 'absolute') {\n return false;\n }\n return isIsoDateOnly(value.startDate) && isIsoDateOnly(value.endDate);\n}\n\nconst DateRangePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n value,\n placeholder,\n readOnly = false,\n disabled = false,\n onChange,\n onBlur,\n onFocus,\n relativeOptions = [],\n i18nStrings,\n isValidRange = () => ({ valid: true }),\n showClearButton = true,\n dateOnly = false,\n timeOffset,\n getTimeOffset,\n timeInputFormat = 'hh:mm:ss',\n expandToViewport = false,\n rangeSelectorMode = 'default',\n ...rest\n }: DateRangePickerProps,\n ref: Ref<DateRangePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DateRangePicker');\n checkControlled('DateRangePicker', 'value', value, 'onChange', onChange);\n\n const normalizedTimeOffset = normalizeTimeOffset(value, getTimeOffset, timeOffset);\n value = isDateOnly(value) ? value : shiftTimeOffset(value, normalizedTimeOffset);\n\n const baseProps = getBaseProps(rest);\n const { invalid, controlId, ariaDescribedby, ariaLabelledby } = useFormFieldContext({\n ariaLabelledby: rest.ariaLabelledby ?? i18nStrings.ariaLabelledby,\n ariaDescribedby: rest.ariaDescribedby ?? i18nStrings.ariaDescribedby,\n ...rest,\n });\n const isSingleGrid = useMobile();\n\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n useForwardFocus(ref, triggerRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('date-range-picker-dropdown');\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n\n const normalizedLocale = normalizeLocale('DateRangePicker', locale);\n\n const closeDropdown = (focusTrigger = false) => {\n setIsDropDownOpen(false);\n if (focusTrigger) {\n triggerRef.current?.focus();\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape) {\n closeDropdown(true);\n }\n };\n\n const onClear = () => {\n fireNonCancelableEvent(onChange, { value: null });\n };\n\n const onApply = (newValue: null | DateRangePickerProps.Value): DateRangePickerProps.ValidationResult => {\n const validationResult = isValidRange(newValue);\n if (validationResult?.valid === false) {\n return validationResult;\n }\n\n if (isDevelopment) {\n if (newValue?.type === 'absolute') {\n const [startDateWithoutTime] = newValue.startDate.split('T');\n const [endDateWithoutTime] = newValue.endDate.split('T');\n if (!startDateWithoutTime || !endDateWithoutTime) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided an `isValidRange` prop that did not catch a missing start or end date.'\n );\n }\n }\n }\n fireNonCancelableEvent(onChange, {\n value: formatValue(newValue, {\n dateOnly,\n timeOffset: normalizeTimeOffset(newValue, getTimeOffset, timeOffset),\n }),\n });\n return validationResult || { valid: true };\n };\n\n const prevDateOnly = usePrevious(dateOnly);\n useEffect(() => {\n if (prevDateOnly !== undefined && prevDateOnly !== dateOnly) {\n warnOnce(\n 'DateRangePicker',\n `The provided \\`dateOnly\\` flag has been changed from \"${prevDateOnly}\" to \"${dateOnly}\" which can lead to unexpected value format. Consider using separate components.`\n );\n }\n }, [prevDateOnly, dateOnly]);\n\n if (value && value.type !== 'absolute' && value.type !== 'relative') {\n warnOnce('DateRangePicker', 'You provided an invalid value. Reverting back to default.');\n value = null;\n }\n\n if (\n (value?.type === 'absolute' && rangeSelectorMode === 'relative-only') ||\n (value?.type === 'relative' && rangeSelectorMode === 'absolute-only')\n ) {\n warnOnce(\n 'DateRangePicker',\n 'The provided value does not correspond to the current range selector mode. Reverting back to default.'\n );\n value = null;\n }\n\n const trigger = (\n <div className={styles['trigger-wrapper']}>\n <ButtonTrigger\n ref={triggerRef}\n id={controlId}\n invalid={invalid}\n ariaLabel={i18nStrings.ariaLabel}\n ariaDescribedby={ariaDescribedby}\n ariaLabelledby={ariaLabelledby}\n className={clsx(styles.label, {\n [styles['label-enabled']]: !readOnly && !disabled,\n })}\n hideCaret={true}\n onClick={() => {\n if (!readOnly && !disabled) {\n setIsDropDownOpen(true);\n }\n }}\n disabled={disabled}\n readOnly={readOnly}\n ariaHasPopup=\"true\"\n >\n <span className={styles['trigger-flexbox']}>\n <span className={styles['icon-wrapper']}>\n <InternalIcon name=\"calendar\" variant={disabled || readOnly ? 'disabled' : 'normal'} />\n </span>\n {renderDateRange(value, placeholder ?? '', i18nStrings.formatRelativeRange, normalizedTimeOffset)}\n </span>\n </ButtonTrigger>\n </div>\n );\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(baseProps.className, styles.root)}\n onKeyDown={onWrapperKeyDownHandler}\n >\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={() => closeDropdown()}\n trigger={trigger}\n stretchToTriggerWidth={false}\n expandToViewport={expandToViewport}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <DateRangePickerDropdown\n startOfWeek={startOfWeek}\n locale={normalizedLocale}\n isSingleGrid={isSingleGrid}\n onDropdownClose={() => closeDropdown(true)}\n value={value}\n showClearButton={showClearButton}\n isDateEnabled={isDateEnabled}\n i18nStrings={i18nStrings}\n onClear={onClear}\n onApply={onApply}\n relativeOptions={relativeOptions}\n isValidRange={isValidRange}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n rangeSelectorMode={rangeSelectorMode}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n />\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DateRangePicker, 'DateRangePicker');\nexport default DateRangePicker;\n"]}
@@ -310,6 +310,12 @@ export declare namespace DateRangePickerProps {
310
310
  renderSelectedAbsoluteRangeAriaLive?: (startDate: string, endDate: string) => string;
311
311
  }
312
312
  }
313
+ export declare type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ export interface RangeCalendarValue {
315
+ startDate: string;
316
+ endDate: string;
317
+ }
318
+ export declare type RangeCalendarI18nStrings = Pick<DateRangePickerProps.I18nStrings, 'todayAriaLabel' | 'nextMonthAriaLabel' | 'previousMonthAriaLabel' | 'startDateLabel' | 'startTimeLabel' | 'endDateLabel' | 'endTimeLabel' | 'dateTimeConstraintText' | 'renderSelectedAbsoluteRangeAriaLive'>;
313
319
  export interface Focusable {
314
320
  focus(): void;
315
321
  }
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,MAAM,W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WAAW,EAC9B,gBAAgB,GAChB,oBAAoB,GACpB,wBAAwB,GACxB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,wBAAwB,GACxB,qCAAqC,CACxC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { NonCancelableEventHandler } from '../internal/events';\nimport { TimeInputProps } from '../time-input/interfaces';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\n\nexport interface DateRangePickerBaseProps {\n /**\n * The current date range value. Can be either an absolute time range\n * or a relative time range.\n */\n value: null | DateRangePickerProps.Value;\n\n /**\n * A list of relative time ranges that are shown as suggestions.\n */\n relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;\n\n /**\n * A function that defines whether a particular date should be enabled\n * in the calendar or not. Note that disabling a date in the calendar\n * still allows users to enter this date via keyboard. We therefore\n * recommend that you also validate these constraints client- and\n * server-side, in the same way as for other form elements.\n */\n isDateEnabled?: DateRangePickerProps.IsDateEnabledFunction;\n\n /**\n * The locale to be used for rendering month names and defining the\n * starting date of the week. If not provided, it will be determined\n * from the page and browser locales. Supported values and formats\n * are as-per the [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 * Starting day of the week. [0-6] maps to [Sunday-Saturday].\n * By default the starting day of the week is defined by the locale,\n * but you can override it using this property.\n */\n startOfWeek?: number;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n */\n i18nStrings: DateRangePickerProps.I18nStrings;\n\n /**\n * Hides time inputs and changes the input format to date-only, e.g. 2021-04-06.\n *\n * Do not use `dateOnly` flag conditionally. The component does not trigger the value update\n * when the flag changes which means the value format can become inconsistent.\n *\n * Default: `false`.\n */\n dateOnly?: boolean;\n\n /**\n * Determines the range selector mode as follows:\n * * `default` for combined absolute/relative range selector.\n * * `absolute-only` for absolute-only range selector.\n * * `relative-only` for relative-only range selector.\n *\n * By default, the range selector mode is `default`.\n */\n rangeSelectorMode?: DateRangePickerProps.RangeSelectorMode;\n\n /**\n * Specifies the format of the time input for absolute ranges.\n *\n * Use to restrict the granularity of time that the user can enter.\n *\n * Has no effect when `dateOnly` is true.\n */\n timeInputFormat?: TimeInputProps.Format;\n\n /**\n * Fired whenever a user changes the component's value.\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;\n\n /**\n * The time offset from UTC in minutes that should be used to\n * display and produce values.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n *\n * This property is deprecated. Use getTimeOffset instead.\n * @deprecated\n */\n timeOffset?: number;\n\n /**\n * A function that defines timezone offset from UTC in minutes for selected dates.\n * Use it to define time relative to the desired timezone.\n *\n * The function is called for the start date and the end date and takes a UTC date\n * corresponding the selected value as an argument.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n */\n getTimeOffset?: DateRangePickerProps.GetTimeOffsetFunction;\n}\nexport interface DateRangePickerProps\n extends BaseComponentProps,\n FormFieldValidationControlProps,\n ExpandToViewport,\n DateRangePickerBaseProps {\n /**\n * Specifies the placeholder text that is rendered when the value is empty.\n */\n placeholder?: string;\n\n /**\n * Specifies that the component is disabled, preventing the user from\n * modifying the value. A disabled component cannot receive focus.\n */\n disabled?: boolean;\n\n /**\n * Specifies that the component is read-only, preventing the user from\n * modifying the value. A read-only component can receive focus.\n */\n readOnly?: boolean;\n\n /**\n * Fired when keyboard focus is set onto the UI control.\n */\n onFocus?: NonCancelableEventHandler<null>;\n\n /**\n * Fired when keyboard focus is removed from the UI control.\n */\n onBlur?: NonCancelableEventHandler<null>;\n\n /**\n * A function that defines whether a particular range is valid or not.\n *\n * Ensure that your function checks for missing fields in the value.\n */\n isValidRange: DateRangePickerProps.ValidationFunction;\n\n /**\n * Specifies whether the component should show a button that\n * allows the user to clear the selected value.\n */\n showClearButton?: boolean;\n}\n\nexport namespace DateRangePickerProps {\n export type Value = AbsoluteValue | RelativeValue;\n export interface AbsoluteValue {\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n startDate: string;\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n endDate: string;\n type: 'absolute';\n }\n\n export interface RelativeValue {\n /**\n * If provided, used to match this value\n * to a provided relative option.\n */\n key?: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n export interface RelativeOption {\n /**\n * Used to uniquely identify this relative option.\n */\n key: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n\n export type TimeUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n\n export type ValidationFunction = (value: Value | null) => ValidationResult;\n\n export type ValidationResult = ValidRangeResult | InvalidRangeResult;\n\n export interface ValidRangeResult {\n valid: true;\n }\n\n export interface InvalidRangeResult {\n valid: false;\n errorMessage: string;\n }\n\n export interface ChangeDetail {\n /**\n * The newly selected range of this date range picker.\n */\n value: null | Value;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface GetTimeOffsetFunction {\n (date: Date): number;\n }\n\n export type RangeSelectorMode = 'default' | 'absolute-only' | 'relative-only';\n\n export interface Ref {\n /**\n * Sets the browser focus on the UI control\n */\n focus(): void;\n }\n\n export interface I18nStrings {\n /**\n * Adds `aria-label` to the trigger and dropdown.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the trigger and dropdown.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the trigger and dropdown.\n */\n ariaDescribedby?: string;\n\n /**\n * Segment title of the relative range selection mode\n */\n relativeModeTitle: string;\n\n /**\n * Segment title of the absolute range selection mode\n */\n absoluteModeTitle: string;\n\n /**\n * Heading for the relative range selection area\n */\n relativeRangeSelectionHeading: string;\n\n /**\n * Visible label of the Cancel button\n */\n cancelButtonLabel: string;\n /**\n * Visible label of the Clear and dismiss button\n */\n clearButtonLabel: string;\n /**\n * Visible label of the Apply button\n */\n applyButtonLabel: string;\n\n /**\n * Formatting function for relative ranges.\n * This function must convert a relative range to a human-readable string.\n */\n formatRelativeRange: (value: RelativeValue) => string;\n\n /**\n * Formatting function for time units.\n *\n * This function must return a localized form of the unit that fits the provided time value.\n */\n formatUnit: (unit: TimeUnit, value: number) => string;\n\n /**\n * Visible label for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionLabel: string;\n\n /**\n * Visible description for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionDescription: string;\n\n /**\n * Visible label for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationLabel: string;\n /**\n * Placeholder for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationPlaceholder: string;\n /**\n * Visible label for the unit selector for the\n * custom relative range.\n */\n customRelativeRangeUnitLabel: string;\n\n /**\n * Used as part of the aria label for today's date in the calendar.\n */\n todayAriaLabel: string;\n\n /**\n * An aria label for the 'next month' button.\n */\n nextMonthAriaLabel: string;\n\n /**\n * An aria label for the 'previous month' button.\n */\n previousMonthAriaLabel: string;\n\n /**\n * Visible label for the Start Date input for the\n * absolute range.\n */\n startDateLabel: string;\n /**\n * Visible label for the Start Time input for the\n * absolute range.\n */\n startTimeLabel: string;\n /**\n * Visible label for the End Date input for the\n * absolute range.\n */\n endDateLabel: string;\n /**\n * Visible label for the End Time input for the\n * absolute range.\n */\n endTimeLabel: string;\n\n /**\n * Constraint text for the input fields for the\n * absolute range.\n */\n dateTimeConstraintText?: string;\n\n /**\n * Provides a text alternative for the error icon in the error alert.\n */\n errorIconAriaLabel?: string;\n\n /**\n * When the property is set, screen readers announce the selected range when the absolute range gets selected.\n */\n renderSelectedAbsoluteRangeAriaLive?: (startDate: string, endDate: string) => string;\n }\n}\n\nexport interface Focusable {\n focus(): void;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { NonCancelableEventHandler } from '../internal/events';\nimport { TimeInputProps } from '../time-input/interfaces';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\n\nexport interface DateRangePickerBaseProps {\n /**\n * The current date range value. Can be either an absolute time range\n * or a relative time range.\n */\n value: null | DateRangePickerProps.Value;\n\n /**\n * A list of relative time ranges that are shown as suggestions.\n */\n relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;\n\n /**\n * A function that defines whether a particular date should be enabled\n * in the calendar or not. Note that disabling a date in the calendar\n * still allows users to enter this date via keyboard. We therefore\n * recommend that you also validate these constraints client- and\n * server-side, in the same way as for other form elements.\n */\n isDateEnabled?: DateRangePickerProps.IsDateEnabledFunction;\n\n /**\n * The locale to be used for rendering month names and defining the\n * starting date of the week. If not provided, it will be determined\n * from the page and browser locales. Supported values and formats\n * are as-per the [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 * Starting day of the week. [0-6] maps to [Sunday-Saturday].\n * By default the starting day of the week is defined by the locale,\n * but you can override it using this property.\n */\n startOfWeek?: number;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n */\n i18nStrings: DateRangePickerProps.I18nStrings;\n\n /**\n * Hides time inputs and changes the input format to date-only, e.g. 2021-04-06.\n *\n * Do not use `dateOnly` flag conditionally. The component does not trigger the value update\n * when the flag changes which means the value format can become inconsistent.\n *\n * Default: `false`.\n */\n dateOnly?: boolean;\n\n /**\n * Determines the range selector mode as follows:\n * * `default` for combined absolute/relative range selector.\n * * `absolute-only` for absolute-only range selector.\n * * `relative-only` for relative-only range selector.\n *\n * By default, the range selector mode is `default`.\n */\n rangeSelectorMode?: DateRangePickerProps.RangeSelectorMode;\n\n /**\n * Specifies the format of the time input for absolute ranges.\n *\n * Use to restrict the granularity of time that the user can enter.\n *\n * Has no effect when `dateOnly` is true.\n */\n timeInputFormat?: TimeInputProps.Format;\n\n /**\n * Fired whenever a user changes the component's value.\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;\n\n /**\n * The time offset from UTC in minutes that should be used to\n * display and produce values.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n *\n * This property is deprecated. Use getTimeOffset instead.\n * @deprecated\n */\n timeOffset?: number;\n\n /**\n * A function that defines timezone offset from UTC in minutes for selected dates.\n * Use it to define time relative to the desired timezone.\n *\n * The function is called for the start date and the end date and takes a UTC date\n * corresponding the selected value as an argument.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n */\n getTimeOffset?: DateRangePickerProps.GetTimeOffsetFunction;\n}\nexport interface DateRangePickerProps\n extends BaseComponentProps,\n FormFieldValidationControlProps,\n ExpandToViewport,\n DateRangePickerBaseProps {\n /**\n * Specifies the placeholder text that is rendered when the value is empty.\n */\n placeholder?: string;\n\n /**\n * Specifies that the component is disabled, preventing the user from\n * modifying the value. A disabled component cannot receive focus.\n */\n disabled?: boolean;\n\n /**\n * Specifies that the component is read-only, preventing the user from\n * modifying the value. A read-only component can receive focus.\n */\n readOnly?: boolean;\n\n /**\n * Fired when keyboard focus is set onto the UI control.\n */\n onFocus?: NonCancelableEventHandler<null>;\n\n /**\n * Fired when keyboard focus is removed from the UI control.\n */\n onBlur?: NonCancelableEventHandler<null>;\n\n /**\n * A function that defines whether a particular range is valid or not.\n *\n * Ensure that your function checks for missing fields in the value.\n */\n isValidRange: DateRangePickerProps.ValidationFunction;\n\n /**\n * Specifies whether the component should show a button that\n * allows the user to clear the selected value.\n */\n showClearButton?: boolean;\n}\n\nexport namespace DateRangePickerProps {\n export type Value = AbsoluteValue | RelativeValue;\n export interface AbsoluteValue {\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n startDate: string;\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n endDate: string;\n type: 'absolute';\n }\n\n export interface RelativeValue {\n /**\n * If provided, used to match this value\n * to a provided relative option.\n */\n key?: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n export interface RelativeOption {\n /**\n * Used to uniquely identify this relative option.\n */\n key: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n\n export type TimeUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n\n export type ValidationFunction = (value: Value | null) => ValidationResult;\n\n export type ValidationResult = ValidRangeResult | InvalidRangeResult;\n\n export interface ValidRangeResult {\n valid: true;\n }\n\n export interface InvalidRangeResult {\n valid: false;\n errorMessage: string;\n }\n\n export interface ChangeDetail {\n /**\n * The newly selected range of this date range picker.\n */\n value: null | Value;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface GetTimeOffsetFunction {\n (date: Date): number;\n }\n\n export type RangeSelectorMode = 'default' | 'absolute-only' | 'relative-only';\n\n export interface Ref {\n /**\n * Sets the browser focus on the UI control\n */\n focus(): void;\n }\n\n export interface I18nStrings {\n /**\n * Adds `aria-label` to the trigger and dropdown.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the trigger and dropdown.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the trigger and dropdown.\n */\n ariaDescribedby?: string;\n\n /**\n * Segment title of the relative range selection mode\n */\n relativeModeTitle: string;\n\n /**\n * Segment title of the absolute range selection mode\n */\n absoluteModeTitle: string;\n\n /**\n * Heading for the relative range selection area\n */\n relativeRangeSelectionHeading: string;\n\n /**\n * Visible label of the Cancel button\n */\n cancelButtonLabel: string;\n /**\n * Visible label of the Clear and dismiss button\n */\n clearButtonLabel: string;\n /**\n * Visible label of the Apply button\n */\n applyButtonLabel: string;\n\n /**\n * Formatting function for relative ranges.\n * This function must convert a relative range to a human-readable string.\n */\n formatRelativeRange: (value: RelativeValue) => string;\n\n /**\n * Formatting function for time units.\n *\n * This function must return a localized form of the unit that fits the provided time value.\n */\n formatUnit: (unit: TimeUnit, value: number) => string;\n\n /**\n * Visible label for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionLabel: string;\n\n /**\n * Visible description for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionDescription: string;\n\n /**\n * Visible label for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationLabel: string;\n /**\n * Placeholder for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationPlaceholder: string;\n /**\n * Visible label for the unit selector for the\n * custom relative range.\n */\n customRelativeRangeUnitLabel: string;\n\n /**\n * Used as part of the aria label for today's date in the calendar.\n */\n todayAriaLabel: string;\n\n /**\n * An aria label for the 'next month' button.\n */\n nextMonthAriaLabel: string;\n\n /**\n * An aria label for the 'previous month' button.\n */\n previousMonthAriaLabel: string;\n\n /**\n * Visible label for the Start Date input for the\n * absolute range.\n */\n startDateLabel: string;\n /**\n * Visible label for the Start Time input for the\n * absolute range.\n */\n startTimeLabel: string;\n /**\n * Visible label for the End Date input for the\n * absolute range.\n */\n endDateLabel: string;\n /**\n * Visible label for the End Time input for the\n * absolute range.\n */\n endTimeLabel: string;\n\n /**\n * Constraint text for the input fields for the\n * absolute range.\n */\n dateTimeConstraintText?: string;\n\n /**\n * Provides a text alternative for the error icon in the error alert.\n */\n errorIconAriaLabel?: string;\n\n /**\n * When the property is set, screen readers announce the selected range when the absolute range gets selected.\n */\n renderSelectedAbsoluteRangeAriaLive?: (startDate: string, endDate: string) => string;\n }\n}\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\nexport interface RangeCalendarValue {\n startDate: string;\n endDate: string;\n}\n\nexport type RangeCalendarI18nStrings = Pick<\n DateRangePickerProps.I18nStrings,\n | 'todayAriaLabel'\n | 'nextMonthAriaLabel'\n | 'previousMonthAriaLabel'\n | 'startDateLabel'\n | 'startTimeLabel'\n | 'endDateLabel'\n | 'endTimeLabel'\n | 'dateTimeConstraintText'\n | 'renderSelectedAbsoluteRangeAriaLive'\n>;\n\nexport interface Focusable {\n focus(): void;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
 
2
- export var PACKAGE_VERSION = '3.0.0 (87f69bc)';
2
+ export var PACKAGE_VERSION = '3.0.0 (490148f)';
3
3
  export var THEME = 'open-source-visual-refresh';
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
5
5
 
package/package.json CHANGED
@@ -112,6 +112,6 @@
112
112
  "./internal/base-component/index.js",
113
113
  "./internal/base-component/styles.css.js"
114
114
  ],
115
- "version": "3.0.95",
115
+ "version": "3.0.96",
116
116
  "license": "Apache-2.0"
117
117
  }
@@ -2,27 +2,27 @@ var ARROW_OFFSET = 12;
2
2
  export var PRIORITY_MAPPING = {
3
3
  top: [
4
4
  'top-center',
5
+ 'top-right',
6
+ 'top-left',
5
7
  'bottom-center',
8
+ 'bottom-right',
9
+ 'bottom-left',
6
10
  'right-top',
7
11
  'right-bottom',
8
12
  'left-top',
9
13
  'left-bottom',
10
- 'top-right',
11
- 'top-left',
12
- 'bottom-right',
13
- 'bottom-left',
14
14
  ],
15
15
  bottom: [
16
16
  'bottom-center',
17
+ 'bottom-right',
18
+ 'bottom-left',
17
19
  'top-center',
20
+ 'top-right',
21
+ 'top-left',
18
22
  'right-top',
19
23
  'right-bottom',
20
24
  'left-top',
21
25
  'left-bottom',
22
- 'bottom-right',
23
- 'bottom-left',
24
- 'top-right',
25
- 'top-left',
26
26
  ],
27
27
  left: [
28
28
  'left-top',
@@ -1 +1 @@
1
- {"version":3,"file":"positions.js","sourceRoot":"","sources":["../../../../src/popover/utils/positions.ts"],"names":[],"mappings":"AAiBA,IAAM,YAAY,GAAG,EAAE,CAAC;AAExB,MAAM,CAAC,IAAM,gBAAgB,GAAsD;IACjF,GAAG,EAAE;QACH,YAAY;QACZ,eAAe;QACf,WAAW;QACX,cAAc;QACd,UAAU;QACV,aAAa;QACb,WAAW;QACX,UAAU;QACV,cAAc;QACd,aAAa;KACd;IACD,MAAM,EAAE;QACN,eAAe;QACf,YAAY;QACZ,WAAW;QACX,cAAc;QACd,UAAU;QACV,aAAa;QACb,cAAc;QACd,aAAa;QACb,WAAW;QACX,UAAU;KACX;IACD,IAAI,EAAE;QACJ,UAAU;QACV,aAAa;QACb,WAAW;QACX,cAAc;QACd,eAAe;QACf,YAAY;QACZ,aAAa;QACb,UAAU;QACV,cAAc;QACd,WAAW;KACZ;IACD,KAAK,EAAE;QACL,WAAW;QACX,cAAc;QACd,UAAU;QACV,aAAa;QACb,eAAe;QACf,YAAY;QACZ,cAAc;QACd,WAAW;QACX,aAAa;QACb,UAAU;KACX;CACF,CAAC;AAEF,IAAM,sBAAsB,GAAkE;IAC5F,YAAY,EAAE,UAAC,EAAwB;YAAtB,IAAI,UAAA,EAAE,OAAO,aAAA,EAAE,KAAK,WAAA;QACnC,OAAO;YACL,GAAG,EAAE,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM;YAC7C,IAAI,EAAE,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;YACvD,KAAK,EAAE,IAAI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,CAAE,gBAAgB,KAAI,WAAW,CAAC;IACtF,uCAAuC;IACvC,IAAM,aAAa,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,MAAA,EAAE,OAAO,SAAA,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;IACzF,kEAAkE;IAClE,IAAM,eAAe,GAAG,gBAAgB,CACtC,aAAa,EACb,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAClE,CAAC;IACF,uEAAuE;IACvE,IAAM,UAAU,GAAG,eAAe,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;IAEjE,OAAO,EAAE,gBAAgB,kBAAA,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,YAAA,EAAE,CAAC;AAC3E,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PopoverProps, InternalPosition, BoundingOffset, BoundingBox } from '../interfaces';\n\n// A structure describing how the popover should be positioned\nexport interface CalculatePosition {\n scrollable?: boolean;\n internalPosition: InternalPosition;\n boundingOffset: BoundingOffset;\n}\n\ninterface ElementGroup {\n body: BoundingBox;\n trigger: BoundingOffset;\n arrow: BoundingBox;\n}\n\nconst ARROW_OFFSET = 12;\n\nexport const PRIORITY_MAPPING: Record<PopoverProps.Position, InternalPosition[]> = {\n top: [\n 'top-center',\n 'bottom-center',\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n 'top-right',\n 'top-left',\n 'bottom-right',\n 'bottom-left',\n ],\n bottom: [\n 'bottom-center',\n 'top-center',\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n 'bottom-right',\n 'bottom-left',\n 'top-right',\n 'top-left',\n ],\n left: [\n 'left-top',\n 'left-bottom',\n 'right-top',\n 'right-bottom',\n 'bottom-center',\n 'top-center',\n 'bottom-left',\n 'top-left',\n 'bottom-right',\n 'top-right',\n ],\n right: [\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n 'bottom-center',\n 'top-center',\n 'bottom-right',\n 'top-right',\n 'bottom-left',\n 'top-left',\n ],\n};\n\nconst RECTANGLE_CALCULATIONS: Record<InternalPosition, (r: ElementGroup) => BoundingOffset> = {\n 'top-center': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left + trigger.width / 2 - body.width / 2,\n width: body.width,\n height: body.height,\n };\n },\n 'top-right': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left,\n width: body.width,\n height: body.height,\n };\n },\n 'top-left': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left + trigger.width - body.width,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-center': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left + trigger.width / 2 - body.width / 2,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-right': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-left': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left + trigger.width - body.width,\n width: body.width,\n height: body.height,\n };\n },\n 'right-top': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - ARROW_OFFSET - arrow.height,\n left: trigger.left + trigger.width + arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'right-bottom': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - body.height + ARROW_OFFSET + arrow.height,\n left: trigger.left + trigger.width + arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'left-top': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - ARROW_OFFSET - arrow.height,\n left: trigger.left - body.width - arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'left-bottom': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - body.height + ARROW_OFFSET + arrow.height,\n left: trigger.left - body.width - arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n};\n\n/**\n * Returns whether one rectangle fits in another.\n */\nfunction canRectFit(inner: BoundingOffset, outer: BoundingOffset): boolean {\n return (\n inner.left >= outer.left &&\n inner.top >= outer.top &&\n inner.left + inner.width <= outer.left + outer.width &&\n inner.top + inner.height <= outer.top + outer.height\n );\n}\n\nfunction fitIntoContainer(inner: BoundingOffset, outer: BoundingOffset): BoundingOffset {\n let { left, width, top, height } = inner;\n\n // Adjust left boundary.\n if (left < outer.left) {\n width = left + width - outer.left;\n left = outer.left;\n }\n // Adjust right boundary.\n else if (left + width > outer.left + outer.width) {\n width = outer.left + outer.width - left;\n }\n // Adjust top boundary.\n if (top < outer.top) {\n height = top + height - outer.top;\n top = outer.top;\n }\n // Adjust bottom boundary.\n else if (top + height > outer.top + outer.height) {\n height = outer.top + outer.height - top;\n }\n\n return { left, width, top, height };\n}\n\nfunction getLargestRect(rect1: BoundingOffset, rect2: BoundingOffset): BoundingOffset {\n const area1 = rect1.height * rect1.width;\n const area2 = rect2.height * rect2.width;\n return area1 >= area2 ? rect1 : rect2;\n}\n\n/**\n * Returns the area of the intersection of passed in rectangles or a null, if there is no intersection\n */\nexport function intersectRectangles(rectangles: BoundingOffset[]): number | null {\n let boundingOffset: BoundingOffset | null = null;\n for (const currentRect of rectangles) {\n if (!boundingOffset) {\n boundingOffset = currentRect;\n continue;\n }\n const left = Math.max(boundingOffset.left, currentRect.left);\n const top = Math.max(boundingOffset.top, currentRect.top);\n const right = Math.min(boundingOffset.left + boundingOffset.width, currentRect.left + currentRect.width);\n const bottom = Math.min(boundingOffset.top + boundingOffset.height, currentRect.top + currentRect.height);\n if (right < left || bottom < top) {\n return null;\n }\n boundingOffset = {\n left,\n top,\n width: right - left,\n height: bottom - top,\n };\n }\n return boundingOffset && boundingOffset.height * boundingOffset.width;\n}\n\n/**\n * A functions that returns the correct popover position based on screen dimensions.\n */\nexport function calculatePosition(\n preferred: PopoverProps.Position,\n trigger: BoundingOffset,\n arrow: BoundingBox,\n body: BoundingBox,\n container: BoundingOffset,\n viewport: BoundingOffset,\n // the popover is only bound by the viewport if it is rendered in a portal\n renderWithPortal?: boolean\n): CalculatePosition {\n let bestPositionOutsideViewport: CalculatePosition | null = null;\n let largestArea = 0;\n\n // Attempt to position the popover based on the priority list for this position,\n // trying to fit it inside the container and inside the viewport.\n for (const internalPosition of PRIORITY_MAPPING[preferred]) {\n const boundingOffset = RECTANGLE_CALCULATIONS[internalPosition]({ body, trigger, arrow });\n const fitsInContainer = renderWithPortal || canRectFit(boundingOffset, container);\n const fitsInViewport = canRectFit(boundingOffset, viewport);\n if (fitsInContainer && fitsInViewport) {\n return { internalPosition, boundingOffset };\n }\n const boundingRectangles = [boundingOffset, viewport];\n if (!renderWithPortal) {\n boundingRectangles.push(container);\n }\n const availableArea = intersectRectangles(boundingRectangles);\n if (availableArea && availableArea > largestArea) {\n bestPositionOutsideViewport = { internalPosition, boundingOffset };\n largestArea = availableArea;\n }\n }\n\n // Use best possible placement.\n const internalPosition = bestPositionOutsideViewport?.internalPosition || 'right-top';\n // Get default rect for that placement.\n const defaultOffset = RECTANGLE_CALCULATIONS[internalPosition]({ body, trigger, arrow });\n // Get largest possible rect that fits into viewport or container.\n const optimisedOffset = fitIntoContainer(\n defaultOffset,\n renderWithPortal ? viewport : getLargestRect(container, viewport)\n );\n // If largest possible rect is smaller than original - set body scroll.\n const scrollable = optimisedOffset.height < defaultOffset.height;\n\n return { internalPosition, boundingOffset: optimisedOffset, scrollable };\n}\n"]}
1
+ {"version":3,"file":"positions.js","sourceRoot":"","sources":["../../../../src/popover/utils/positions.ts"],"names":[],"mappings":"AAiBA,IAAM,YAAY,GAAG,EAAE,CAAC;AAExB,MAAM,CAAC,IAAM,gBAAgB,GAA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F,uEAAuE;IACvE,IAAM,UAAU,GAAG,eAAe,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;IAEjE,OAAO,EAAE,gBAAgB,kBAAA,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,YAAA,EAAE,CAAC;AAC3E,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PopoverProps, InternalPosition, BoundingOffset, BoundingBox } from '../interfaces';\n\n// A structure describing how the popover should be positioned\nexport interface CalculatePosition {\n scrollable?: boolean;\n internalPosition: InternalPosition;\n boundingOffset: BoundingOffset;\n}\n\ninterface ElementGroup {\n body: BoundingBox;\n trigger: BoundingOffset;\n arrow: BoundingBox;\n}\n\nconst ARROW_OFFSET = 12;\n\nexport const PRIORITY_MAPPING: Record<PopoverProps.Position, InternalPosition[]> = {\n top: [\n 'top-center',\n 'top-right',\n 'top-left',\n 'bottom-center',\n 'bottom-right',\n 'bottom-left',\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n ],\n bottom: [\n 'bottom-center',\n 'bottom-right',\n 'bottom-left',\n 'top-center',\n 'top-right',\n 'top-left',\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n ],\n left: [\n 'left-top',\n 'left-bottom',\n 'right-top',\n 'right-bottom',\n 'bottom-center',\n 'top-center',\n 'bottom-left',\n 'top-left',\n 'bottom-right',\n 'top-right',\n ],\n right: [\n 'right-top',\n 'right-bottom',\n 'left-top',\n 'left-bottom',\n 'bottom-center',\n 'top-center',\n 'bottom-right',\n 'top-right',\n 'bottom-left',\n 'top-left',\n ],\n};\n\nconst RECTANGLE_CALCULATIONS: Record<InternalPosition, (r: ElementGroup) => BoundingOffset> = {\n 'top-center': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left + trigger.width / 2 - body.width / 2,\n width: body.width,\n height: body.height,\n };\n },\n 'top-right': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left,\n width: body.width,\n height: body.height,\n };\n },\n 'top-left': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top - body.height - arrow.height,\n left: trigger.left + trigger.width - body.width,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-center': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left + trigger.width / 2 - body.width / 2,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-right': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left,\n width: body.width,\n height: body.height,\n };\n },\n 'bottom-left': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height + arrow.height,\n left: trigger.left + trigger.width - body.width,\n width: body.width,\n height: body.height,\n };\n },\n 'right-top': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - ARROW_OFFSET - arrow.height,\n left: trigger.left + trigger.width + arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'right-bottom': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - body.height + ARROW_OFFSET + arrow.height,\n left: trigger.left + trigger.width + arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'left-top': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - ARROW_OFFSET - arrow.height,\n left: trigger.left - body.width - arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n 'left-bottom': ({ body, trigger, arrow }) => {\n return {\n top: trigger.top + trigger.height / 2 - body.height + ARROW_OFFSET + arrow.height,\n left: trigger.left - body.width - arrow.height,\n width: body.width,\n height: body.height,\n };\n },\n};\n\n/**\n * Returns whether one rectangle fits in another.\n */\nfunction canRectFit(inner: BoundingOffset, outer: BoundingOffset): boolean {\n return (\n inner.left >= outer.left &&\n inner.top >= outer.top &&\n inner.left + inner.width <= outer.left + outer.width &&\n inner.top + inner.height <= outer.top + outer.height\n );\n}\n\nfunction fitIntoContainer(inner: BoundingOffset, outer: BoundingOffset): BoundingOffset {\n let { left, width, top, height } = inner;\n\n // Adjust left boundary.\n if (left < outer.left) {\n width = left + width - outer.left;\n left = outer.left;\n }\n // Adjust right boundary.\n else if (left + width > outer.left + outer.width) {\n width = outer.left + outer.width - left;\n }\n // Adjust top boundary.\n if (top < outer.top) {\n height = top + height - outer.top;\n top = outer.top;\n }\n // Adjust bottom boundary.\n else if (top + height > outer.top + outer.height) {\n height = outer.top + outer.height - top;\n }\n\n return { left, width, top, height };\n}\n\nfunction getLargestRect(rect1: BoundingOffset, rect2: BoundingOffset): BoundingOffset {\n const area1 = rect1.height * rect1.width;\n const area2 = rect2.height * rect2.width;\n return area1 >= area2 ? rect1 : rect2;\n}\n\n/**\n * Returns the area of the intersection of passed in rectangles or a null, if there is no intersection\n */\nexport function intersectRectangles(rectangles: BoundingOffset[]): number | null {\n let boundingOffset: BoundingOffset | null = null;\n for (const currentRect of rectangles) {\n if (!boundingOffset) {\n boundingOffset = currentRect;\n continue;\n }\n const left = Math.max(boundingOffset.left, currentRect.left);\n const top = Math.max(boundingOffset.top, currentRect.top);\n const right = Math.min(boundingOffset.left + boundingOffset.width, currentRect.left + currentRect.width);\n const bottom = Math.min(boundingOffset.top + boundingOffset.height, currentRect.top + currentRect.height);\n if (right < left || bottom < top) {\n return null;\n }\n boundingOffset = {\n left,\n top,\n width: right - left,\n height: bottom - top,\n };\n }\n return boundingOffset && boundingOffset.height * boundingOffset.width;\n}\n\n/**\n * A functions that returns the correct popover position based on screen dimensions.\n */\nexport function calculatePosition(\n preferred: PopoverProps.Position,\n trigger: BoundingOffset,\n arrow: BoundingBox,\n body: BoundingBox,\n container: BoundingOffset,\n viewport: BoundingOffset,\n // the popover is only bound by the viewport if it is rendered in a portal\n renderWithPortal?: boolean\n): CalculatePosition {\n let bestPositionOutsideViewport: CalculatePosition | null = null;\n let largestArea = 0;\n\n // Attempt to position the popover based on the priority list for this position,\n // trying to fit it inside the container and inside the viewport.\n for (const internalPosition of PRIORITY_MAPPING[preferred]) {\n const boundingOffset = RECTANGLE_CALCULATIONS[internalPosition]({ body, trigger, arrow });\n const fitsInContainer = renderWithPortal || canRectFit(boundingOffset, container);\n const fitsInViewport = canRectFit(boundingOffset, viewport);\n if (fitsInContainer && fitsInViewport) {\n return { internalPosition, boundingOffset };\n }\n const boundingRectangles = [boundingOffset, viewport];\n if (!renderWithPortal) {\n boundingRectangles.push(container);\n }\n const availableArea = intersectRectangles(boundingRectangles);\n if (availableArea && availableArea > largestArea) {\n bestPositionOutsideViewport = { internalPosition, boundingOffset };\n largestArea = availableArea;\n }\n }\n\n // Use best possible placement.\n const internalPosition = bestPositionOutsideViewport?.internalPosition || 'right-top';\n // Get default rect for that placement.\n const defaultOffset = RECTANGLE_CALCULATIONS[internalPosition]({ body, trigger, arrow });\n // Get largest possible rect that fits into viewport or container.\n const optimisedOffset = fitIntoContainer(\n defaultOffset,\n renderWithPortal ? viewport : getLargestRect(container, viewport)\n );\n // If largest possible rect is smaller than original - set body scroll.\n const scrollable = optimisedOffset.height < defaultOffset.height;\n\n return { internalPosition, boundingOffset: optimisedOffset, scrollable };\n}\n"]}