UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

41 lines (40 loc) 1.97 kB
import { __assign } from "tslib"; import React from 'react'; import styles from '../../../styles.css.js'; import { isSameDay, isSameMonth } from 'date-fns'; import { renderDayLabel } from '../../utils/intl'; import clsx from 'clsx'; var GridDay = function (_a) { var _b; var locale = _a.locale, baseDate = _a.baseDate, date = _a.date, selectedDate = _a.selectedDate, focusedDate = _a.focusedDate, isDateEnabled = _a.isDateEnabled, todayAriaLabel = _a.todayAriaLabel, onSelectDate = _a.onSelectDate, isDateInLastWeek = _a.isDateInLastWeek; var labels = [renderDayLabel(locale, date)]; var isFocusable = !!focusedDate && isSameDay(date, focusedDate); var isSelected = !!selectedDate && isSameDay(date, selectedDate); var isEnabled = !isDateEnabled || isDateEnabled(date); var isDateOnSameDay = isSameDay(date, new Date()); var computedAttributes = {}; var classNames = clsx(styles['calendar-day'], (_b = {}, _b[styles['calendar-day-in-last-week']] = isDateInLastWeek, _b[styles['calendar-day-current-month']] = isSameMonth(date, baseDate), _b[styles['calendar-day-enabled']] = isEnabled, _b[styles['calendar-day-selected']] = isSelected, _b[styles['calendar-day-today']] = isDateOnSameDay, _b[styles['calendar-day-focusable']] = isFocusable && isEnabled, _b)); if (isSelected) { computedAttributes['aria-current'] = 'date'; } if (isDateOnSameDay) { labels.push(todayAriaLabel); } if (isEnabled) { computedAttributes.onClick = function () { return onSelectDate(date); }; computedAttributes.tabIndex = -1; } if (isFocusable && isEnabled) { computedAttributes.tabIndex = 0; } return (React.createElement("div", __assign({ className: classNames, "aria-label": labels.join('. '), role: "button" }, computedAttributes), React.createElement("span", null, date.getDate()))); }; export default GridDay;