first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarProps } from './Calendar.types';
export declare const CalendarBase: React.FunctionComponent<ICalendarProps>;
@@ -0,0 +1,261 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarBase = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var date_time_utilities_1 = require("@fluentui/date-time-utilities");
var CalendarDay_1 = require("./CalendarDay/CalendarDay");
var CalendarMonth_1 = require("./CalendarMonth/CalendarMonth");
var utilities_1 = require("@fluentui/utilities");
var react_hooks_1 = require("@fluentui/react-hooks");
var defaults_1 = require("./defaults");
var MIN_SIZE_FORCE_OVERLAY = 440;
var getClassNames = (0, utilities_1.classNamesFunction)();
var defaultWorkWeekDays = [
date_time_utilities_1.DayOfWeek.Monday,
date_time_utilities_1.DayOfWeek.Tuesday,
date_time_utilities_1.DayOfWeek.Wednesday,
date_time_utilities_1.DayOfWeek.Thursday,
date_time_utilities_1.DayOfWeek.Friday,
];
var DEFAULT_PROPS = {
isMonthPickerVisible: true,
isDayPickerVisible: true,
showMonthPickerAsOverlay: false,
today: new Date(),
firstDayOfWeek: date_time_utilities_1.DayOfWeek.Sunday,
dateRangeType: date_time_utilities_1.DateRangeType.Day,
showGoToToday: true,
strings: date_time_utilities_1.DEFAULT_CALENDAR_STRINGS,
highlightCurrentMonth: false,
highlightSelectedMonth: false,
navigationIcons: defaults_1.defaultCalendarNavigationIcons,
showWeekNumbers: false,
firstWeekOfYear: date_time_utilities_1.FirstWeekOfYear.FirstDay,
dateTimeFormatter: date_time_utilities_1.DEFAULT_DATE_FORMATTING,
showSixWeeksByDefault: false,
workWeekDays: defaultWorkWeekDays,
showCloseButton: false,
allFocusable: false,
};
function useDateState(props) {
var value = props.value, todayProp = props.today, onSelectDate = props.onSelectDate;
var today = React.useMemo(function () {
if (todayProp === undefined) {
return new Date();
}
return todayProp;
}, [todayProp]);
/** The currently selected date in the calendar */
var _a = (0, react_hooks_1.useControllableValue)(value, today), _b = _a[0], selectedDate = _b === void 0 ? today : _b, setSelectedDate = _a[1];
/** The currently focused date in the day picker, but not necessarily selected */
var _c = React.useState(value), _d = _c[0], navigatedDay = _d === void 0 ? today : _d, setNavigatedDay = _c[1];
/** The currently focused date in the month picker, but not necessarily selected */
var _e = React.useState(value), _f = _e[0], navigatedMonth = _f === void 0 ? today : _f, setNavigatedMonth = _e[1];
/** If using a controlled value, when that value changes, navigate to that date */
var _g = React.useState(value), _h = _g[0], lastSelectedDate = _h === void 0 ? today : _h, setLastSelectedDate = _g[1];
if (value && lastSelectedDate.valueOf() !== value.valueOf()) {
setNavigatedDay(value);
setNavigatedMonth(value);
setLastSelectedDate(value);
}
var navigateMonth = function (date) {
setNavigatedMonth(date);
};
var navigateDay = function (date) {
setNavigatedMonth(date);
setNavigatedDay(date);
};
var onDateSelected = function (date, selectedDateRangeArray) {
setNavigatedMonth(date);
setNavigatedDay(date);
setSelectedDate(date);
onSelectDate === null || onSelectDate === void 0 ? void 0 : onSelectDate(date, selectedDateRangeArray);
};
return [selectedDate, navigatedDay, navigatedMonth, onDateSelected, navigateDay, navigateMonth];
}
function useVisibilityState(props) {
/** State used to show/hide month picker */
var _a = (0, react_hooks_1.useControllableValue)(getShowMonthPickerAsOverlay(props) ? undefined : props.isMonthPickerVisible, false), _b = _a[0], isMonthPickerVisible = _b === void 0 ? true : _b, setIsMonthPickerVisible = _a[1];
/** State used to show/hide day picker */
var _c = (0, react_hooks_1.useControllableValue)(getShowMonthPickerAsOverlay(props) ? undefined : props.isDayPickerVisible, true), _d = _c[0], isDayPickerVisible = _d === void 0 ? true : _d, setIsDayPickerVisible = _c[1];
var toggleDayMonthPickerVisibility = function () {
setIsMonthPickerVisible(!isMonthPickerVisible);
setIsDayPickerVisible(!isDayPickerVisible);
};
return [isMonthPickerVisible, isDayPickerVisible, toggleDayMonthPickerVisibility];
}
function useFocusLogic(_a, isDayPickerVisible, isMonthPickerVisible) {
var componentRef = _a.componentRef;
var dayPicker = React.useRef(null);
var monthPicker = React.useRef(null);
var focusOnUpdate = React.useRef(false);
var focus = React.useCallback(function () {
if (isDayPickerVisible && dayPicker.current) {
(0, utilities_1.focusAsync)(dayPicker.current);
}
else if (isMonthPickerVisible && monthPicker.current) {
(0, utilities_1.focusAsync)(monthPicker.current);
}
}, [isDayPickerVisible, isMonthPickerVisible]);
React.useImperativeHandle(componentRef, function () { return ({ focus: focus }); }, [focus]);
React.useEffect(function () {
if (focusOnUpdate.current) {
focus();
focusOnUpdate.current = false;
}
});
var focusOnNextUpdate = function () {
focusOnUpdate.current = true;
};
return [dayPicker, monthPicker, focusOnNextUpdate];
}
exports.CalendarBase = React.forwardRef(function (propsWithoutDefaults, forwardedRef) {
var props = (0, utilities_1.getPropsWithDefaults)(DEFAULT_PROPS, propsWithoutDefaults);
var _a = useDateState(props), selectedDate = _a[0], navigatedDay = _a[1], navigatedMonth = _a[2], onDateSelected = _a[3], navigateDay = _a[4], navigateMonth = _a[5];
var _b = useVisibilityState(props), isMonthPickerVisible = _b[0], isDayPickerVisible = _b[1], toggleDayMonthPickerVisibility = _b[2];
var _c = useFocusLogic(props, isDayPickerVisible, isMonthPickerVisible), dayPicker = _c[0], monthPicker = _c[1], focusOnNextUpdate = _c[2];
var renderGoToTodayButton = function () {
var goTodayEnabled = showGoToToday;
if (goTodayEnabled && today) {
goTodayEnabled =
navigatedDay.getFullYear() !== today.getFullYear() ||
navigatedDay.getMonth() !== today.getMonth() ||
navigatedMonth.getFullYear() !== today.getFullYear() ||
navigatedMonth.getMonth() !== today.getMonth();
}
return (showGoToToday && (React.createElement("button", { className: (0, utilities_1.css)('js-goToday', classes.goTodayButton), onClick: onGotoToday, onKeyDown: onButtonKeyDown(onGotoToday), type: "button", disabled: !goTodayEnabled }, strings.goToToday)));
};
var onNavigateDayDate = function (date, focusOnNavigatedDay) {
navigateDay(date);
if (focusOnNavigatedDay) {
focusOnNextUpdate();
}
};
var onNavigateMonthDate = function (date, focusOnNavigatedDay) {
if (focusOnNavigatedDay) {
focusOnNextUpdate();
}
if (!focusOnNavigatedDay) {
navigateMonth(date);
return;
}
if (monthPickerOnly) {
onDateSelected(date);
}
navigateDay(date);
};
var onHeaderSelect = getShowMonthPickerAsOverlay(props)
? function () {
toggleDayMonthPickerVisibility();
focusOnNextUpdate();
}
: undefined;
var onGotoToday = function () {
navigateDay(today);
focusOnNextUpdate();
};
var onButtonKeyDown = function (callback) {
return function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
switch (ev.which) {
case utilities_1.KeyCodes.enter:
case utilities_1.KeyCodes.space:
callback();
break;
}
};
};
var onDatePickerPopupKeyDown = function (ev) {
var _a;
// eslint-disable-next-line @typescript-eslint/no-deprecated
switch (ev.which) {
case utilities_1.KeyCodes.enter:
ev.preventDefault();
break;
case utilities_1.KeyCodes.backspace:
ev.preventDefault();
break;
case utilities_1.KeyCodes.escape:
(_a = props.onDismiss) === null || _a === void 0 ? void 0 : _a.call(props);
break;
case utilities_1.KeyCodes.pageUp:
if (ev.ctrlKey) {
// go to next year
navigateDay((0, date_time_utilities_1.addYears)(navigatedDay, 1));
}
else {
// go to next month
navigateDay((0, date_time_utilities_1.addMonths)(navigatedDay, 1));
}
ev.preventDefault();
break;
case utilities_1.KeyCodes.pageDown:
if (ev.ctrlKey) {
// go to previous year
navigateDay((0, date_time_utilities_1.addYears)(navigatedDay, -1));
}
else {
// go to previous month
navigateDay((0, date_time_utilities_1.addMonths)(navigatedDay, -1));
}
ev.preventDefault();
break;
default:
break;
}
};
var rootClass = 'ms-DatePicker';
var firstDayOfWeek = props.firstDayOfWeek, dateRangeType = props.dateRangeType, strings = props.strings, showGoToToday = props.showGoToToday, highlightCurrentMonth = props.highlightCurrentMonth, highlightSelectedMonth = props.highlightSelectedMonth, navigationIcons = props.navigationIcons, minDate = props.minDate, maxDate = props.maxDate, restrictedDates = props.restrictedDates, id = props.id, className = props.className, showCloseButton = props.showCloseButton, allFocusable = props.allFocusable, styles = props.styles, showWeekNumbers = props.showWeekNumbers, theme = props.theme, calendarDayProps = props.calendarDayProps, calendarMonthProps = props.calendarMonthProps, dateTimeFormatter = props.dateTimeFormatter, _d = props.today, today = _d === void 0 ? new Date() : _d;
var showMonthPickerAsOverlay = getShowMonthPickerAsOverlay(props);
var monthPickerOnly = !showMonthPickerAsOverlay && !isDayPickerVisible;
var overlaidWithButton = showMonthPickerAsOverlay && showGoToToday;
var classes = getClassNames(styles, {
theme: theme,
className: className,
isMonthPickerVisible: isMonthPickerVisible,
isDayPickerVisible: isDayPickerVisible,
monthPickerOnly: monthPickerOnly,
showMonthPickerAsOverlay: showMonthPickerAsOverlay,
overlaidWithButton: overlaidWithButton,
overlayedWithButton: overlaidWithButton,
showGoToToday: showGoToToday,
showWeekNumbers: showWeekNumbers,
});
var todayDateString = '';
var selectedDateString = '';
if (dateTimeFormatter && strings.todayDateFormatString) {
todayDateString = (0, utilities_1.format)(strings.todayDateFormatString, dateTimeFormatter.formatMonthDayYear(today, strings));
}
if (dateTimeFormatter && strings.selectedDateFormatString) {
var dateStringFormatter = monthPickerOnly
? dateTimeFormatter.formatMonthYear
: dateTimeFormatter.formatMonthDayYear;
selectedDateString = (0, utilities_1.format)(strings.selectedDateFormatString, dateStringFormatter(selectedDate, strings));
}
var selectionAndTodayString = selectedDateString + ', ' + todayDateString;
return (React.createElement("div", { id: id, ref: forwardedRef, role: "group", "aria-label": selectionAndTodayString, className: (0, utilities_1.css)(rootClass, classes.root, className, 'ms-slideDownIn10'), onKeyDown: onDatePickerPopupKeyDown },
React.createElement("div", { className: classes.liveRegion, "aria-live": "polite", "aria-atomic": "true" },
React.createElement("span", null, selectedDateString)),
isDayPickerVisible && (React.createElement(CalendarDay_1.CalendarDay, tslib_1.__assign({ selectedDate: selectedDate, navigatedDate: navigatedDay, today: props.today, onSelectDate: onDateSelected,
// eslint-disable-next-line react/jsx-no-bind
onNavigateDate: onNavigateDayDate, onDismiss: props.onDismiss, firstDayOfWeek: firstDayOfWeek, dateRangeType: dateRangeType, strings: strings,
// eslint-disable-next-line react/jsx-no-bind
onHeaderSelect: onHeaderSelect, navigationIcons: navigationIcons, showWeekNumbers: props.showWeekNumbers, firstWeekOfYear: props.firstWeekOfYear, dateTimeFormatter: props.dateTimeFormatter, showSixWeeksByDefault: props.showSixWeeksByDefault, minDate: minDate, maxDate: maxDate, restrictedDates: restrictedDates, workWeekDays: props.workWeekDays, componentRef: dayPicker, showCloseButton: showCloseButton, allFocusable: allFocusable }, calendarDayProps))),
isDayPickerVisible && isMonthPickerVisible && React.createElement("div", { className: classes.divider }),
isMonthPickerVisible ? (React.createElement("div", { className: classes.monthPickerWrapper },
React.createElement(CalendarMonth_1.CalendarMonth, tslib_1.__assign({ navigatedDate: navigatedMonth, selectedDate: navigatedDay, strings: strings,
// eslint-disable-next-line react/jsx-no-bind
onNavigateDate: onNavigateMonthDate, today: props.today, highlightCurrentMonth: highlightCurrentMonth, highlightSelectedMonth: highlightSelectedMonth,
// eslint-disable-next-line react/jsx-no-bind
onHeaderSelect: onHeaderSelect, navigationIcons: navigationIcons, dateTimeFormatter: props.dateTimeFormatter, minDate: minDate, maxDate: maxDate, componentRef: monthPicker }, calendarMonthProps)),
renderGoToTodayButton())) : (renderGoToTodayButton()),
React.createElement(utilities_1.FocusRects, null)));
});
exports.CalendarBase.displayName = 'CalendarBase';
function getShowMonthPickerAsOverlay(_a) {
var showMonthPickerAsOverlay = _a.showMonthPickerAsOverlay, isDayPickerVisible = _a.isDayPickerVisible;
var win = (0, utilities_1.getWindow)();
return showMonthPickerAsOverlay || (isDayPickerVisible && win && win.innerWidth <= MIN_SIZE_FORCE_OVERLAY);
}
//# sourceMappingURL=Calendar.base.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarProps } from './Calendar.types';
export declare const Calendar: React.FunctionComponent<ICalendarProps>;
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Calendar = void 0;
var utilities_1 = require("@fluentui/utilities");
var Calendar_base_1 = require("./Calendar.base");
var Calendar_styles_1 = require("./Calendar.styles");
exports.Calendar = (0, utilities_1.styled)(Calendar_base_1.CalendarBase, Calendar_styles_1.styles, undefined, {
scope: 'Calendar',
});
//# sourceMappingURL=Calendar.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Calendar.js","sourceRoot":"../src/","sources":["components/Calendar/Calendar.tsx"],"names":[],"mappings":";;;AACA,iDAA6C;AAC7C,iDAA+C;AAC/C,qDAA2C;AAG9B,QAAA,QAAQ,GAA4C,IAAA,kBAAM,EAAC,4BAAY,EAAE,wBAAM,EAAE,SAAS,EAAE;IACvG,KAAK,EAAE,UAAU;CAClB,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { styled } from '@fluentui/utilities';\nimport { CalendarBase } from './Calendar.base';\nimport { styles } from './Calendar.styles';\nimport type { ICalendarProps } from './Calendar.types';\n\nexport const Calendar: React.FunctionComponent<ICalendarProps> = styled(CalendarBase, styles, undefined, {\n scope: 'Calendar',\n});\n"]}
@@ -0,0 +1,2 @@
import type { ICalendarStyleProps, ICalendarStyles } from './Calendar.types';
export declare const styles: (props: ICalendarStyleProps) => ICalendarStyles;
@@ -0,0 +1,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.styles = void 0;
var style_utilities_1 = require("@fluentui/style-utilities");
var styles = function (props) {
var _a;
var className = props.className, theme = props.theme, isDayPickerVisible = props.isDayPickerVisible, isMonthPickerVisible = props.isMonthPickerVisible, showWeekNumbers = props.showWeekNumbers;
var palette = theme.palette;
var totalWidth = isDayPickerVisible && isMonthPickerVisible ? 440 : 220;
if (showWeekNumbers && isDayPickerVisible) {
totalWidth += 30;
}
return {
root: [
style_utilities_1.normalize,
{
display: 'flex',
width: totalWidth,
},
!isMonthPickerVisible && {
flexDirection: 'column',
},
className,
],
divider: {
top: 0,
borderRight: '1px solid',
borderColor: palette.neutralLight,
},
monthPickerWrapper: [
{
display: 'flex',
flexDirection: 'column',
},
],
goTodayButton: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: -1 }),
{
bottom: 0,
color: palette.neutralPrimary,
height: 30,
lineHeight: 30,
backgroundColor: 'transparent',
border: 'none',
boxSizing: 'content-box',
padding: '0 4px',
alignSelf: 'flex-end',
marginRight: 16,
marginTop: 3,
fontSize: style_utilities_1.FontSizes.small,
fontFamily: 'inherit',
overflow: 'visible', // explicitly specify for IE11
selectors: {
'& div': {
fontSize: style_utilities_1.FontSizes.small,
},
'&:hover': {
color: palette.themePrimary,
backgroundColor: 'transparent',
cursor: 'pointer',
selectors: (_a = {},
_a[style_utilities_1.HighContrastSelector] = {
outline: '1px solid Buttontext',
borderRadius: '2px',
},
_a),
},
'&:active': {
color: palette.themeDark,
},
'&:disabled': {
color: palette.neutralTertiaryAlt,
pointerEvents: 'none',
},
},
},
],
liveRegion: {
border: 0,
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: 0,
width: '1px',
position: 'absolute',
},
};
};
exports.styles = styles;
//# sourceMappingURL=Calendar.styles.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Calendar.styles.js","sourceRoot":"../src/","sources":["components/Calendar/Calendar.styles.ts"],"names":[],"mappings":";;;AAAA,6DAAsG;AAG/F,IAAM,MAAM,GAAG,UAAC,KAA0B;;IACvC,IAAA,SAAS,GAAuE,KAAK,UAA5E,EAAE,KAAK,GAAgE,KAAK,MAArE,EAAE,kBAAkB,GAA4C,KAAK,mBAAjD,EAAE,oBAAoB,GAAsB,KAAK,qBAA3B,EAAE,eAAe,GAAK,KAAK,gBAAV,CAAW;IACtF,IAAA,OAAO,GAAK,KAAK,QAAV,CAAW;IAE1B,IAAI,UAAU,GAAG,kBAAkB,IAAI,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACxE,IAAI,eAAe,IAAI,kBAAkB,EAAE,CAAC;QAC1C,UAAU,IAAI,EAAE,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE;YACJ,2BAAS;YACT;gBACE,OAAO,EAAE,MAAM;gBACf,KAAK,EAAE,UAAU;aAClB;YACD,CAAC,oBAAoB,IAAI;gBACvB,aAAa,EAAE,QAAQ;aACxB;YACD,SAAS;SACV;QACD,OAAO,EAAE;YACP,GAAG,EAAE,CAAC;YACN,WAAW,EAAE,WAAW;YACxB,WAAW,EAAE,OAAO,CAAC,YAAY;SAClC;QACD,kBAAkB,EAAE;YAClB;gBACE,OAAO,EAAE,MAAM;gBACf,aAAa,EAAE,QAAQ;aACxB;SACF;QACD,aAAa,EAAE;YACb,IAAA,+BAAa,EAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;YACnC;gBACE,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,OAAO,CAAC,cAAc;gBAC7B,MAAM,EAAE,EAAE;gBACV,UAAU,EAAE,EAAE;gBACd,eAAe,EAAE,aAAa;gBAC9B,MAAM,EAAE,MAAM;gBACd,SAAS,EAAE,aAAa;gBACxB,OAAO,EAAE,OAAO;gBAChB,SAAS,EAAE,UAAU;gBACrB,WAAW,EAAE,EAAE;gBACf,SAAS,EAAE,CAAC;gBACZ,QAAQ,EAAE,2BAAS,CAAC,KAAK;gBACzB,UAAU,EAAE,SAAS;gBACrB,QAAQ,EAAE,SAAS,EAAE,8BAA8B;gBACnD,SAAS,EAAE;oBACT,OAAO,EAAE;wBACP,QAAQ,EAAE,2BAAS,CAAC,KAAK;qBAC1B;oBACD,SAAS,EAAE;wBACT,KAAK,EAAE,OAAO,CAAC,YAAY;wBAC3B,eAAe,EAAE,aAAa;wBAC9B,MAAM,EAAE,SAAS;wBACjB,SAAS;4BACP,GAAC,sCAAoB,IAAG;gCACtB,OAAO,EAAE,sBAAsB;gCAC/B,YAAY,EAAE,KAAK;6BACpB;+BACF;qBACF;oBACD,UAAU,EAAE;wBACV,KAAK,EAAE,OAAO,CAAC,SAAS;qBACzB;oBACD,YAAY,EAAE;wBACZ,KAAK,EAAE,OAAO,CAAC,kBAAkB;wBACjC,aAAa,EAAE,MAAM;qBACtB;iBACF;aACF;SACF;QACD,UAAU,EAAE;YACV,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,CAAC;YACV,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,UAAU;SACrB;KACF,CAAC;AACJ,CAAC,CAAC;AApFW,QAAA,MAAM,UAoFjB","sourcesContent":["import { normalize, FontSizes, getFocusStyle, HighContrastSelector } from '@fluentui/style-utilities';\nimport type { ICalendarStyleProps, ICalendarStyles } from './Calendar.types';\n\nexport const styles = (props: ICalendarStyleProps): ICalendarStyles => {\n const { className, theme, isDayPickerVisible, isMonthPickerVisible, showWeekNumbers } = props;\n const { palette } = theme;\n\n let totalWidth = isDayPickerVisible && isMonthPickerVisible ? 440 : 220;\n if (showWeekNumbers && isDayPickerVisible) {\n totalWidth += 30;\n }\n\n return {\n root: [\n normalize,\n {\n display: 'flex',\n width: totalWidth,\n },\n !isMonthPickerVisible && {\n flexDirection: 'column',\n },\n className,\n ],\n divider: {\n top: 0,\n borderRight: '1px solid',\n borderColor: palette.neutralLight,\n },\n monthPickerWrapper: [\n {\n display: 'flex',\n flexDirection: 'column',\n },\n ],\n goTodayButton: [\n getFocusStyle(theme, { inset: -1 }),\n {\n bottom: 0,\n color: palette.neutralPrimary,\n height: 30,\n lineHeight: 30,\n backgroundColor: 'transparent',\n border: 'none',\n boxSizing: 'content-box',\n padding: '0 4px',\n alignSelf: 'flex-end',\n marginRight: 16,\n marginTop: 3,\n fontSize: FontSizes.small,\n fontFamily: 'inherit',\n overflow: 'visible', // explicitly specify for IE11\n selectors: {\n '& div': {\n fontSize: FontSizes.small,\n },\n '&:hover': {\n color: palette.themePrimary,\n backgroundColor: 'transparent',\n cursor: 'pointer',\n selectors: {\n [HighContrastSelector]: {\n outline: '1px solid Buttontext',\n borderRadius: '2px',\n },\n },\n },\n '&:active': {\n color: palette.themeDark,\n },\n '&:disabled': {\n color: palette.neutralTertiaryAlt,\n pointerEvents: 'none',\n },\n },\n },\n ],\n liveRegion: {\n border: 0,\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n width: '1px',\n position: 'absolute',\n },\n };\n};\n"]}
@@ -0,0 +1,261 @@
import * as React from 'react';
import { DayOfWeek, FirstWeekOfYear, DateRangeType } from '@fluentui/date-time-utilities';
import type { IRefObject, IBaseProps, IStyleFunctionOrObject } from '@fluentui/utilities';
import type { IStyle, ITheme } from '@fluentui/style-utilities';
import type { ICalendarDayProps } from './CalendarDay/CalendarDay.types';
import type { ICalendarMonthProps } from './CalendarMonth/CalendarMonth.types';
import type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';
/**
* {@docCategory Calendar}
*/
export interface ICalendar {
/** Sets focus to the selected date. */
focus: () => void;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarProps extends IBaseProps<ICalendar>, React.RefAttributes<HTMLDivElement> {
/**
* Optional callback to access the ICalendar interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ICalendar>;
/**
* Customized styles for the calendar component
*/
styles?: IStyleFunctionOrObject<ICalendarStyleProps, ICalendarStyles>;
/**
* Customized props for the calendar day
*/
calendarDayProps?: Partial<ICalendarDayProps>;
/**
* Customized props for the calendar month
*/
calendarMonthProps?: Partial<ICalendarMonthProps>;
/**
* Theme provided by High-Order Component.
*/
theme?: ITheme;
/**
* Optional class name to add to the root element.
*/
className?: string;
/**
* Callback for when a date is selected
* @param date - The date the user selected
* @param selectedDateRangeArray - The resultant list of dates that are selected based on the date range type set
* for the component.
*/
onSelectDate?: (date: Date, selectedDateRangeArray?: Date[]) => void;
/**
* Callback for when calendar is closed
*/
onDismiss?: () => void;
/**
* ID for the calendar
*/
id?: string;
/**
* Default value of the Calendar, if any
*/
value?: Date;
/**
* Value of today. If unspecified, current time in client machine will be used.
*/
today?: Date;
/**
* The date range type indicating how many days should be selected as the user
* selects days
* @defaultValue DateRangeType.Day
*/
dateRangeType?: DateRangeType;
/**
* The first day of the week for your locale.
* @defaultvalue DayOfWeek.Sunday
*/
firstDayOfWeek?: DayOfWeek;
/**
* Defines when the first week of the year should start.
* @defaultvalue FirstWeekOfYear.FirstDay
*/
firstWeekOfYear?: FirstWeekOfYear;
/**
* Whether the month picker is shown beside the day picker or hidden.
* @defaultvalue true
*/
isMonthPickerVisible?: boolean;
/**
* Whether the day picker is shown beside the month picker or hidden.
* @defaultvalue true
*/
isDayPickerVisible?: boolean;
/**
* Show month picker on top of date picker when visible.
* @defaultvalue false
*/
showMonthPickerAsOverlay?: boolean;
/**
* Whether the "Go to today" link should be shown or not
*/
showGoToToday?: boolean;
/**
* Whether the calendar should show the week number (weeks 1 to 53) before each week row
* @defaultvalue false
*/
showWeekNumbers?: boolean;
/**
* Localized strings to use in the Calendar
*/
strings?: ICalendarStrings;
/**
* Custom navigation icons.
*/
navigationIcons?: ICalendarNavigationIcons;
/**
* Apply additional formatting to dates, for example localized date formatting.
*/
dateTimeFormatter?: IDateFormatting;
/**
* If set the Calendar will not allow navigation to or selection of a date earlier than this value.
*/
minDate?: Date;
/**
* If set the Calendar will not allow navigation to or selection of a date later than this value.
*/
maxDate?: Date;
/**
* If set the Calendar will not allow selection of dates in this array.
*/
restrictedDates?: Date[];
/**
* Whether the calendar should show 6 weeks by default.
* @defaultvalue false
*/
showSixWeeksByDefault?: boolean;
/**
* The days that are selectable when `dateRangeType` is `WorkWeek`.
* If `dateRangeType` is not `WorkWeek` this property does nothing.
* @defaultvalue [Monday,Tuesday,Wednesday,Thursday,Friday]
*/
workWeekDays?: DayOfWeek[];
/**
* Whether the month picker should highlight the current month
* @defaultvalue false
*/
highlightCurrentMonth?: boolean;
/**
* Whether the month picker should highlight the selected month
* @defaultvalue false
*/
highlightSelectedMonth?: boolean;
/**
* Whether the close button should be shown or not
* @defaultvalue false
*/
showCloseButton?: boolean;
/**
* Allows all dates and buttons to be focused, including disabled ones
* @defaultvalue false
*/
allFocusable?: boolean;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarNavigationIcons {
/**
* FabricMDL2Icons name for the left navigation icon. Previous default: ChevronLeft.
* @defaultvalue 'Up'
*/
leftNavigation?: string;
/**
* FabricMDL2Icons name for the right navigation icon. Previous default: ChevronRight.
* @defaultvalue 'Down'
*/
rightNavigation?: string;
/**
* Close icon
* @defaultvalue 'CalculatorMultiply'
*/
closeIcon?: string;
}
/**
* @deprecated Use `ICalendarNavigationIcons`
*/
export type ICalendarIconStrings = ICalendarNavigationIcons;
/**
* @deprecated Use `IDateFormatting`
*/
export type ICalendarFormatDateCallbacks = IDateFormatting;
/**
* {@docCategory Calendar}
*/
export interface ICalendarStyleProps {
/**
* Theme provided by higher-order component.
*/
theme: ITheme;
/**
* Custom CSS class for the calendar.
*/
className?: string;
/**
* Whether the month picker is visible
*/
isMonthPickerVisible?: boolean;
/**
* Whether the day picker is visible
*/
isDayPickerVisible?: boolean;
/**
* Whether only month picker is shown
*/
monthPickerOnly?: boolean;
/**
* Whether the month picker is overlaid on the day picker
*/
showMonthPickerAsOverlay?: boolean;
/**
* @deprecated Use `overlaidWithButton`
*/
overlayedWithButton?: boolean;
/**
* Whether the month and day picker are overlaid and the 'go to today' button is shown
*/
overlaidWithButton?: boolean;
/**
* Whether the go to today button is shown
*/
showGoToToday?: boolean;
/**
* Whether the week numbers are shown
*/
showWeekNumbers?: boolean;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarStyles {
/**
* Style for the root element.
*/
root: IStyle;
divider: IStyle;
goTodayButton: IStyle;
monthPickerWrapper: IStyle;
liveRegion: IStyle;
}
/**
* {@docCategory Calendar}
*/
export declare enum AnimationDirection {
/**
* Grid will transition out and in horizontally
*/
Horizontal = 0,
/**
* Grid will transition out and in vertically
*/
Vertical = 1
}
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimationDirection = void 0;
/**
* {@docCategory Calendar}
*/
var AnimationDirection;
(function (AnimationDirection) {
/**
* Grid will transition out and in horizontally
*/
AnimationDirection[AnimationDirection["Horizontal"] = 0] = "Horizontal";
/**
* Grid will transition out and in vertically
*/
AnimationDirection[AnimationDirection["Vertical"] = 1] = "Vertical";
})(AnimationDirection || (exports.AnimationDirection = AnimationDirection = {}));
//# sourceMappingURL=Calendar.types.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarDayProps } from './CalendarDay.types';
export declare const CalendarDayBase: React.FunctionComponent<ICalendarDayProps>;
@@ -0,0 +1,87 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarDayBase = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var utilities_1 = require("@fluentui/utilities");
var Icon_1 = require("../../../Icon");
var date_time_utilities_1 = require("@fluentui/date-time-utilities");
var CalendarDayGrid_1 = require("../../CalendarDayGrid/CalendarDayGrid");
var react_hooks_1 = require("@fluentui/react-hooks");
var getClassNames = (0, utilities_1.classNamesFunction)();
var CalendarDayBase = function (props) {
var dayGrid = React.useRef(null);
React.useImperativeHandle(props.componentRef, function () { return ({
focus: function () {
var _a, _b;
(_b = (_a = dayGrid.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
},
}); }, []);
var strings = props.strings, navigatedDate = props.navigatedDate, dateTimeFormatter = props.dateTimeFormatter, styles = props.styles, theme = props.theme, className = props.className, onHeaderSelect = props.onHeaderSelect, showSixWeeksByDefault = props.showSixWeeksByDefault, minDate = props.minDate, maxDate = props.maxDate, restrictedDates = props.restrictedDates, onNavigateDate = props.onNavigateDate, showWeekNumbers = props.showWeekNumbers, dateRangeType = props.dateRangeType, animationDirection = props.animationDirection;
var monthAndYearId = (0, react_hooks_1.useId)();
var classNames = getClassNames(styles, {
theme: theme,
className: className,
headerIsClickable: !!onHeaderSelect,
showWeekNumbers: showWeekNumbers,
animationDirection: animationDirection,
});
var monthAndYear = dateTimeFormatter.formatMonthYear(navigatedDate, strings);
var HeaderButtonComponentType = onHeaderSelect ? 'button' : 'div';
var headerAriaLabel = strings.yearPickerHeaderAriaLabel
? (0, utilities_1.format)(strings.yearPickerHeaderAriaLabel, monthAndYear)
: monthAndYear;
return (React.createElement("div", { className: classNames.root },
React.createElement("div", { className: classNames.header },
React.createElement(HeaderButtonComponentType, { "aria-label": onHeaderSelect ? headerAriaLabel : undefined, className: classNames.monthAndYear, onClick: onHeaderSelect, "data-is-focusable": !!onHeaderSelect, tabIndex: onHeaderSelect ? 0 : -1, onKeyDown: onButtonKeyDown(onHeaderSelect), type: "button" },
React.createElement("span", { id: monthAndYearId, "aria-live": "polite", "aria-atomic": "true" }, monthAndYear)),
React.createElement(CalendarDayNavigationButtons, tslib_1.__assign({}, props, { classNames: classNames }))),
React.createElement(CalendarDayGrid_1.CalendarDayGrid, tslib_1.__assign({}, props, { styles: styles, componentRef: dayGrid, strings: strings, navigatedDate: navigatedDate, weeksToShow: showSixWeeksByDefault ? 6 : undefined, dateTimeFormatter: dateTimeFormatter, minDate: minDate, maxDate: maxDate, restrictedDates: restrictedDates, onNavigateDate: onNavigateDate, labelledBy: monthAndYearId, dateRangeType: dateRangeType }))));
};
exports.CalendarDayBase = CalendarDayBase;
exports.CalendarDayBase.displayName = 'CalendarDayBase';
var CalendarDayNavigationButtons = function (props) {
var _a, _b;
var minDate = props.minDate, maxDate = props.maxDate, navigatedDate = props.navigatedDate, allFocusable = props.allFocusable, strings = props.strings, navigationIcons = props.navigationIcons, showCloseButton = props.showCloseButton, classNames = props.classNames, onNavigateDate = props.onNavigateDate, onDismiss = props.onDismiss;
var onSelectNextMonth = function () {
onNavigateDate((0, date_time_utilities_1.addMonths)(navigatedDate, 1), false);
};
var onSelectPrevMonth = function () {
onNavigateDate((0, date_time_utilities_1.addMonths)(navigatedDate, -1), false);
};
var leftNavigationIcon = navigationIcons.leftNavigation;
var rightNavigationIcon = navigationIcons.rightNavigation;
var closeNavigationIcon = navigationIcons.closeIcon;
// determine if previous/next months are in bounds
var prevMonthInBounds = minDate ? (0, date_time_utilities_1.compareDatePart)(minDate, (0, date_time_utilities_1.getMonthStart)(navigatedDate)) < 0 : true;
var nextMonthInBounds = maxDate ? (0, date_time_utilities_1.compareDatePart)((0, date_time_utilities_1.getMonthEnd)(navigatedDate), maxDate) < 0 : true;
// use aria-disabled instead of disabled so focus is not lost
// when a prev/next button becomes disabled after being clicked
return (React.createElement("div", { className: classNames.monthComponents },
React.createElement("button", { className: (0, utilities_1.css)(classNames.headerIconButton, (_a = {},
_a[classNames.disabledStyle] = !prevMonthInBounds,
_a)), tabIndex: prevMonthInBounds ? undefined : allFocusable ? 0 : -1, "aria-disabled": !prevMonthInBounds, onClick: prevMonthInBounds ? onSelectPrevMonth : undefined, onKeyDown: prevMonthInBounds ? onButtonKeyDown(onSelectPrevMonth) : undefined, title: strings.prevMonthAriaLabel
? strings.prevMonthAriaLabel + ' ' + strings.months[(0, date_time_utilities_1.addMonths)(navigatedDate, -1).getMonth()]
: undefined, type: "button" },
React.createElement(Icon_1.Icon, { iconName: leftNavigationIcon })),
React.createElement("button", { className: (0, utilities_1.css)(classNames.headerIconButton, (_b = {},
_b[classNames.disabledStyle] = !nextMonthInBounds,
_b)), tabIndex: nextMonthInBounds ? undefined : allFocusable ? 0 : -1, "aria-disabled": !nextMonthInBounds, onClick: nextMonthInBounds ? onSelectNextMonth : undefined, onKeyDown: nextMonthInBounds ? onButtonKeyDown(onSelectNextMonth) : undefined, title: strings.nextMonthAriaLabel
? strings.nextMonthAriaLabel + ' ' + strings.months[(0, date_time_utilities_1.addMonths)(navigatedDate, 1).getMonth()]
: undefined, type: "button" },
React.createElement(Icon_1.Icon, { iconName: rightNavigationIcon })),
showCloseButton && (React.createElement("button", { className: (0, utilities_1.css)(classNames.headerIconButton), onClick: onDismiss, onKeyDown: onButtonKeyDown(onDismiss), title: strings.closeButtonAriaLabel, type: "button" },
React.createElement(Icon_1.Icon, { iconName: closeNavigationIcon })))));
};
CalendarDayNavigationButtons.displayName = 'CalendarDayNavigationButtons';
var onButtonKeyDown = function (callback) {
return function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
switch (ev.which) {
case utilities_1.KeyCodes.enter:
callback === null || callback === void 0 ? void 0 : callback();
break;
}
};
};
//# sourceMappingURL=CalendarDay.base.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarDayProps } from './CalendarDay.types';
export declare const CalendarDay: React.FunctionComponent<ICalendarDayProps>;
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarDay = void 0;
var CalendarDay_base_1 = require("./CalendarDay.base");
var CalendarDay_styles_1 = require("./CalendarDay.styles");
var Utilities_1 = require("../../../Utilities");
exports.CalendarDay = (0, Utilities_1.styled)(CalendarDay_base_1.CalendarDayBase, CalendarDay_styles_1.styles, undefined, {
scope: 'CalendarDay',
});
//# sourceMappingURL=CalendarDay.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarDay.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarDay/CalendarDay.tsx"],"names":[],"mappings":";;;AACA,uDAAqD;AACrD,2DAA8C;AAC9C,gDAA4C;AAG/B,QAAA,WAAW,GAA+C,IAAA,kBAAM,EAAC,kCAAe,EAAE,2BAAM,EAAE,SAAS,EAAE;IAChH,KAAK,EAAE,aAAa;CACrB,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { CalendarDayBase } from './CalendarDay.base';\nimport { styles } from './CalendarDay.styles';\nimport { styled } from '../../../Utilities';\nimport type { ICalendarDayProps } from './CalendarDay.types';\n\nexport const CalendarDay: React.FunctionComponent<ICalendarDayProps> = styled(CalendarDayBase, styles, undefined, {\n scope: 'CalendarDay',\n});\n"]}
@@ -0,0 +1,2 @@
import type { ICalendarDayStyleProps, ICalendarDayStyles } from './CalendarDay.types';
export declare const styles: (props: ICalendarDayStyleProps) => ICalendarDayStyles;
@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.styles = void 0;
var tslib_1 = require("tslib");
var style_utilities_1 = require("@fluentui/style-utilities");
var styles = function (props) {
var _a;
var className = props.className, theme = props.theme, headerIsClickable = props.headerIsClickable, showWeekNumbers = props.showWeekNumbers;
var palette = theme.palette;
var disabledStyle = {
selectors: (_a = {
'&, &:disabled, & button': {
color: palette.neutralTertiaryAlt,
pointerEvents: 'none',
}
},
_a[style_utilities_1.HighContrastSelector] = {
color: 'GrayText',
forcedColorAdjust: 'none',
},
_a),
};
return {
root: [
style_utilities_1.normalize,
{
width: 196,
padding: 12,
boxSizing: 'content-box',
},
showWeekNumbers && {
width: 226,
},
className,
],
header: {
position: 'relative',
display: 'inline-flex',
height: 28,
lineHeight: 44,
width: '100%',
},
monthAndYear: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: 1 }),
tslib_1.__assign(tslib_1.__assign({}, style_utilities_1.AnimationStyles.fadeIn200), { alignItems: 'center', fontSize: style_utilities_1.FontSizes.medium, fontFamily: 'inherit', color: palette.neutralPrimary, display: 'inline-block', flexGrow: 1, fontWeight: style_utilities_1.FontWeights.semibold, padding: '0 4px 0 10px', border: 'none', backgroundColor: 'transparent', borderRadius: 2, lineHeight: 28, overflow: 'hidden', whiteSpace: 'nowrap', textAlign: 'left', textOverflow: 'ellipsis' }),
headerIsClickable && {
selectors: {
'&:hover': {
cursor: 'pointer',
background: palette.neutralLight,
color: palette.black,
},
},
},
],
monthComponents: {
display: 'inline-flex',
alignSelf: 'flex-end',
},
headerIconButton: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: -1 }),
{
width: 28,
height: 28,
display: 'block',
textAlign: 'center',
lineHeight: 28,
fontSize: style_utilities_1.FontSizes.small,
fontFamily: 'inherit',
color: palette.neutralPrimary,
borderRadius: 2,
position: 'relative',
backgroundColor: 'transparent',
border: 'none',
padding: 0,
overflow: 'visible', // explicitly specify for IE11
selectors: {
'&:hover': {
color: palette.neutralDark,
backgroundColor: palette.neutralLight,
cursor: 'pointer',
outline: '1px solid transparent',
},
},
},
],
disabledStyle: disabledStyle,
};
};
exports.styles = styles;
//# sourceMappingURL=CalendarDay.styles.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,145 @@
import type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';
import type { ICalendarNavigationIcons } from '../Calendar.types';
import type { IStyle, ITheme } from '@fluentui/style-utilities';
import type { ICalendarDayGridProps, ICalendarDayGridStyleProps, ICalendarDayGridStyles } from '../../CalendarDayGrid/CalendarDayGrid.types';
import type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';
/**
* {@docCategory Calendar}
*/
export interface ICalendarDay {
focus(): void;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarDayProps extends IBaseProps<ICalendarDay>, ICalendarDayGridProps {
/**
* Optional callback to access the ICalendarDay interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ICalendarDay>;
/**
* Customized styles for the calendar day component
*/
styles?: IStyleFunctionOrObject<ICalendarDayStyleProps, ICalendarDayStyles>;
/**
* Theme (provided through customization).
*/
theme?: ITheme;
/**
* Additional CSS class(es) to apply to the CalendarDay.
*/
className?: string;
/**
* Localized strings to use in the Calendar
*/
strings: ICalendarStrings;
/**
* The currently navigated date
*/
navigatedDate: Date;
/**
* Callback issued when a date in the calendar is navigated
* @param date - The date that is navigated to
* @param focusOnNavigatedDay - Whether to set the focus to the navigated date.
*/
onNavigateDate: (date: Date, focusOnNavigatedDay: boolean) => void;
/**
* Callback issued when calendar day is closed
*/
onDismiss?: () => void;
/**
* Custom navigation icons.
*/
navigationIcons: ICalendarNavigationIcons;
/**
* Callback function when the header is selected
*/
onHeaderSelect?: () => void;
/**
* Whether the calendar should show the week number (weeks 1 to 53) before each week row
* @defaultvalue false
*/
showWeekNumbers?: boolean;
/**
* Apply additional formatting to dates, for example localized date formatting.
*/
dateTimeFormatter: IDateFormatting;
/**
* Whether the calendar should show 6 weeks by default.
* @defaultvalue false
*/
showSixWeeksByDefault?: boolean;
/**
* If set the Calendar will not allow navigation to or selection of a date earlier than this value.
*/
minDate?: Date;
/**
* If set the Calendar will not allow navigation to or selection of a date later than this value.
*/
maxDate?: Date;
/**
* If set the Calendar will not allow selection of dates in this array.
*/
restrictedDates?: Date[];
/**
* Whether the close button should be shown or not
* @defaultvalue false
*/
showCloseButton?: boolean;
/**
* Allows all dates and buttons to be focused, including disabled ones
* @defaultvalue false
*/
allFocusable?: boolean;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarDayStyleProps extends ICalendarDayGridStyleProps {
/**
* Theme provided by High-Order Component.
*/
theme: ITheme;
/**
* Accept custom classNames
*/
className?: string;
/**
* Whether the header is clickable
*/
headerIsClickable?: boolean;
/**
* Whether week numbers are being shown
*/
showWeekNumbers?: boolean;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarDayStyles extends Partial<ICalendarDayGridStyles> {
/**
* Style for the root element.
*/
root: IStyle;
/**
* The style for the header button and forward/back navigation button container
*/
header: IStyle;
/**
* The style for the title text inside the header
*/
monthAndYear: IStyle;
/**
* The style for the wrapper around forward/back/close buttons
*/
monthComponents: IStyle;
/**
* The style for the forward/back/close buttons
*/
headerIconButton: IStyle;
/**
* The style to apply for disabled elements
*/
disabledStyle: IStyle;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=CalendarDay.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarDay.types.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarDay/CalendarDay.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';\nimport type { ICalendarNavigationIcons } from '../Calendar.types';\nimport type { IStyle, ITheme } from '@fluentui/style-utilities';\nimport type {\n ICalendarDayGridProps,\n ICalendarDayGridStyleProps,\n ICalendarDayGridStyles,\n} from '../../CalendarDayGrid/CalendarDayGrid.types';\nimport type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarDay {\n focus(): void;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarDayProps extends IBaseProps<ICalendarDay>, ICalendarDayGridProps {\n /**\n * Optional callback to access the ICalendarDay interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<ICalendarDay>;\n\n /**\n * Customized styles for the calendar day component\n */\n styles?: IStyleFunctionOrObject<ICalendarDayStyleProps, ICalendarDayStyles>;\n\n /**\n * Theme (provided through customization).\n */\n theme?: ITheme;\n\n /**\n * Additional CSS class(es) to apply to the CalendarDay.\n */\n className?: string;\n\n /**\n * Localized strings to use in the Calendar\n */\n strings: ICalendarStrings;\n\n /**\n * The currently navigated date\n */\n navigatedDate: Date;\n\n /**\n * Callback issued when a date in the calendar is navigated\n * @param date - The date that is navigated to\n * @param focusOnNavigatedDay - Whether to set the focus to the navigated date.\n */\n onNavigateDate: (date: Date, focusOnNavigatedDay: boolean) => void;\n\n /**\n * Callback issued when calendar day is closed\n */\n onDismiss?: () => void;\n\n /**\n * Custom navigation icons.\n */\n navigationIcons: ICalendarNavigationIcons;\n\n /**\n * Callback function when the header is selected\n */\n onHeaderSelect?: () => void;\n\n /**\n * Whether the calendar should show the week number (weeks 1 to 53) before each week row\n * @defaultvalue false\n */\n showWeekNumbers?: boolean;\n\n /**\n * Apply additional formatting to dates, for example localized date formatting.\n */\n dateTimeFormatter: IDateFormatting;\n\n /**\n * Whether the calendar should show 6 weeks by default.\n * @defaultvalue false\n */\n showSixWeeksByDefault?: boolean;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a date earlier than this value.\n */\n minDate?: Date;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a date later than this value.\n */\n maxDate?: Date;\n\n /**\n * If set the Calendar will not allow selection of dates in this array.\n */\n restrictedDates?: Date[];\n\n /**\n * Whether the close button should be shown or not\n * @defaultvalue false\n */\n showCloseButton?: boolean;\n\n /**\n * Allows all dates and buttons to be focused, including disabled ones\n * @defaultvalue false\n */\n allFocusable?: boolean;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarDayStyleProps extends ICalendarDayGridStyleProps {\n /**\n * Theme provided by High-Order Component.\n */\n theme: ITheme;\n\n /**\n * Accept custom classNames\n */\n className?: string;\n\n // Insert CalendarDay style props below\n\n /**\n * Whether the header is clickable\n */\n headerIsClickable?: boolean;\n\n /**\n * Whether week numbers are being shown\n */\n showWeekNumbers?: boolean;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarDayStyles extends Partial<ICalendarDayGridStyles> {\n /**\n * Style for the root element.\n */\n root: IStyle;\n\n /**\n * The style for the header button and forward/back navigation button container\n */\n header: IStyle;\n\n /**\n * The style for the title text inside the header\n */\n monthAndYear: IStyle;\n\n /**\n * The style for the wrapper around forward/back/close buttons\n */\n monthComponents: IStyle;\n\n /**\n * The style for the forward/back/close buttons\n */\n headerIconButton: IStyle;\n\n /**\n * The style to apply for disabled elements\n */\n disabledStyle: IStyle;\n}\n"]}
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarMonthProps } from './CalendarMonth.types';
export declare const CalendarMonthBase: React.FunctionComponent<ICalendarMonthProps>;
@@ -0,0 +1,227 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarMonthBase = void 0;
var React = require("react");
var FocusZone_1 = require("../../../FocusZone");
var date_time_utilities_1 = require("@fluentui/date-time-utilities");
var Icon_1 = require("../../../Icon");
var CalendarMonth_styles_1 = require("./CalendarMonth.styles");
var utilities_1 = require("@fluentui/utilities");
var CalendarYear_1 = require("../CalendarYear/CalendarYear");
var react_hooks_1 = require("@fluentui/react-hooks");
var defaults_1 = require("../defaults");
var MONTHS_PER_ROW = 4;
var getClassNames = (0, utilities_1.classNamesFunction)();
var DEFAULT_PROPS = {
styles: CalendarMonth_styles_1.getStyles,
strings: undefined,
navigationIcons: defaults_1.defaultCalendarNavigationIcons,
dateTimeFormatter: date_time_utilities_1.DEFAULT_DATE_FORMATTING,
yearPickerHidden: false,
};
function useAnimateBackwards(_a) {
var navigatedDate = _a.navigatedDate;
var currentYear = navigatedDate.getFullYear();
var previousYear = (0, react_hooks_1.usePrevious)(currentYear);
if (previousYear === undefined || previousYear === currentYear) {
return undefined;
}
else {
return previousYear > currentYear;
}
}
function useFocusLogic(_a) {
var componentRef = _a.componentRef;
var navigatedMonthRef = React.useRef(null);
var calendarYearRef = React.useRef(null);
var focusOnUpdate = React.useRef(false);
var focus = React.useCallback(function () {
if (calendarYearRef.current) {
calendarYearRef.current.focus();
}
else if (navigatedMonthRef.current) {
navigatedMonthRef.current.focus();
}
}, []);
React.useImperativeHandle(componentRef, function () { return ({ focus: focus }); }, [focus]);
React.useEffect(function () {
if (focusOnUpdate.current) {
focus();
focusOnUpdate.current = false;
}
});
var focusOnNextUpdate = function () {
focusOnUpdate.current = true;
};
return [navigatedMonthRef, calendarYearRef, focusOnNextUpdate];
}
var CalendarMonthBase = function (propsWithoutDefaults) {
var _a, _b;
var props = (0, utilities_1.getPropsWithDefaults)(DEFAULT_PROPS, propsWithoutDefaults);
var _c = useFocusLogic(props), navigatedMonthRef = _c[0], calendarYearRef = _c[1], focusOnNextUpdate = _c[2];
var _d = React.useState(false), isYearPickerVisible = _d[0], setIsYearPickerVisible = _d[1];
var animateBackwards = useAnimateBackwards(props);
var navigatedDate = props.navigatedDate, selectedDate = props.selectedDate, strings = props.strings, _e = props.today, today = _e === void 0 ? new Date() : _e, navigationIcons = props.navigationIcons, dateTimeFormatter = props.dateTimeFormatter, minDate = props.minDate, maxDate = props.maxDate, theme = props.theme, styles = props.styles, className = props.className, allFocusable = props.allFocusable, highlightCurrentMonth = props.highlightCurrentMonth, highlightSelectedMonth = props.highlightSelectedMonth, animationDirection = props.animationDirection, yearPickerHidden = props.yearPickerHidden, onNavigateDate = props.onNavigateDate;
var selectMonthCallback = function (newMonth) {
return function () { return onSelectMonth(newMonth); };
};
var onSelectNextYear = function () {
onNavigateDate((0, date_time_utilities_1.addYears)(navigatedDate, 1), false);
};
var onSelectPrevYear = function () {
onNavigateDate((0, date_time_utilities_1.addYears)(navigatedDate, -1), false);
};
var onSelectMonth = function (newMonth) {
var _a;
// If header is clickable the calendars are overlayed, switch back to day picker when month is clicked
(_a = props.onHeaderSelect) === null || _a === void 0 ? void 0 : _a.call(props);
onNavigateDate((0, date_time_utilities_1.setMonth)(navigatedDate, newMonth), true);
};
var onHeaderSelect = function () {
var _a;
if (!yearPickerHidden) {
focusOnNextUpdate();
setIsYearPickerVisible(true);
}
else {
(_a = props.onHeaderSelect) === null || _a === void 0 ? void 0 : _a.call(props);
}
};
var onSelectYear = function (selectedYear) {
focusOnNextUpdate();
var navYear = navigatedDate.getFullYear();
if (navYear !== selectedYear) {
var newNavigationDate = new Date(navigatedDate.getTime());
newNavigationDate.setFullYear(selectedYear);
// for min and max dates, adjust the new navigation date - perhaps this should be
// checked on the master navigation date handler (i.e. in Calendar)
if (maxDate && newNavigationDate > maxDate) {
newNavigationDate = (0, date_time_utilities_1.setMonth)(newNavigationDate, maxDate.getMonth());
}
else if (minDate && newNavigationDate < minDate) {
newNavigationDate = (0, date_time_utilities_1.setMonth)(newNavigationDate, minDate.getMonth());
}
onNavigateDate(newNavigationDate, true);
}
setIsYearPickerVisible(false);
};
var onYearPickerHeaderSelect = function (focus) {
focusOnNextUpdate();
setIsYearPickerVisible(false);
};
// navigationIcons has a default value in defaultProps, but typescript doesn't recognize this
var leftNavigationIcon = navigationIcons.leftNavigation;
var rightNavigationIcon = navigationIcons.rightNavigation;
var dateFormatter = dateTimeFormatter;
// determine if previous/next years are in bounds
var isPrevYearInBounds = minDate ? (0, date_time_utilities_1.compareDatePart)(minDate, (0, date_time_utilities_1.getYearStart)(navigatedDate)) < 0 : true;
var isNextYearInBounds = maxDate ? (0, date_time_utilities_1.compareDatePart)((0, date_time_utilities_1.getYearEnd)(navigatedDate), maxDate) < 0 : true;
var classNames = getClassNames(styles, {
theme: theme,
className: className,
hasHeaderClickCallback: !!props.onHeaderSelect || !yearPickerHidden,
highlightCurrent: highlightCurrentMonth,
highlightSelected: highlightSelectedMonth,
animateBackwards: animateBackwards,
animationDirection: animationDirection,
});
if (isYearPickerVisible) {
var _f = getYearStrings(props), onRenderYear = _f[0], yearStrings = _f[1];
// use navigated date for the year picker
return (React.createElement(CalendarYear_1.CalendarYear, { key: 'calendarYear', minYear: minDate ? minDate.getFullYear() : undefined, maxYear: maxDate ? maxDate.getFullYear() : undefined,
// eslint-disable-next-line react/jsx-no-bind
onSelectYear: onSelectYear, navigationIcons: navigationIcons,
// eslint-disable-next-line react/jsx-no-bind
onHeaderSelect: onYearPickerHeaderSelect, selectedYear: selectedDate ? selectedDate.getFullYear() : navigatedDate ? navigatedDate.getFullYear() : undefined, navigatedYear: navigatedDate.getFullYear(), onRenderYear: onRenderYear, strings: yearStrings, componentRef: calendarYearRef, styles: styles, highlightCurrentYear: highlightCurrentMonth, highlightSelectedYear: highlightSelectedMonth, animationDirection: animationDirection }));
}
var rowIndexes = [];
for (var i = 0; i < strings.shortMonths.length / MONTHS_PER_ROW; i++) {
rowIndexes.push(i);
}
var yearString = dateFormatter.formatYear(navigatedDate);
var headerAriaLabel = strings.monthPickerHeaderAriaLabel
? (0, utilities_1.format)(strings.monthPickerHeaderAriaLabel, yearString)
: yearString;
return (React.createElement("div", { className: classNames.root },
React.createElement("div", { className: classNames.headerContainer },
React.createElement("button", { className: classNames.currentItemButton, onClick: onHeaderSelect, onKeyDown: onButtonKeyDown(onHeaderSelect), "aria-label": headerAriaLabel, "data-is-focusable": !!props.onHeaderSelect || !yearPickerHidden, tabIndex: !!props.onHeaderSelect || !yearPickerHidden ? 0 : -1, type: "button" },
React.createElement("span", { "aria-live": "polite", "aria-atomic": "true" }, yearString)),
React.createElement("div", { className: classNames.navigationButtonsContainer },
React.createElement("button", { className: (0, utilities_1.css)(classNames.navigationButton, (_a = {},
_a[classNames.disabled] = !isPrevYearInBounds,
_a)), "aria-disabled": !isPrevYearInBounds, tabIndex: isPrevYearInBounds ? undefined : allFocusable ? 0 : -1, onClick: isPrevYearInBounds ? onSelectPrevYear : undefined, onKeyDown: isPrevYearInBounds ? onButtonKeyDown(onSelectPrevYear) : undefined, title: strings.prevYearAriaLabel
? strings.prevYearAriaLabel + ' ' + dateFormatter.formatYear((0, date_time_utilities_1.addYears)(navigatedDate, -1))
: undefined, type: "button" },
React.createElement(Icon_1.Icon, { iconName: (0, utilities_1.getRTL)() ? rightNavigationIcon : leftNavigationIcon })),
React.createElement("button", { className: (0, utilities_1.css)(classNames.navigationButton, (_b = {},
_b[classNames.disabled] = !isNextYearInBounds,
_b)), "aria-disabled": !isNextYearInBounds, tabIndex: isNextYearInBounds ? undefined : allFocusable ? 0 : -1, onClick: isNextYearInBounds ? onSelectNextYear : undefined, onKeyDown: isNextYearInBounds ? onButtonKeyDown(onSelectNextYear) : undefined, title: strings.nextYearAriaLabel
? strings.nextYearAriaLabel + ' ' + dateFormatter.formatYear((0, date_time_utilities_1.addYears)(navigatedDate, 1))
: undefined, type: "button" },
React.createElement(Icon_1.Icon, { iconName: (0, utilities_1.getRTL)() ? leftNavigationIcon : rightNavigationIcon })))),
React.createElement(FocusZone_1.FocusZone, null,
React.createElement("div", { className: classNames.gridContainer, role: "grid", "aria-label": yearString }, rowIndexes.map(function (rowNum) {
var monthsForRow = strings.shortMonths.slice(rowNum * MONTHS_PER_ROW, (rowNum + 1) * MONTHS_PER_ROW);
return (React.createElement("div", { key: 'monthRow_' + rowNum + navigatedDate.getFullYear(), role: "row", className: classNames.buttonRow }, monthsForRow.map(function (month, index) {
var _a;
var monthIndex = rowNum * MONTHS_PER_ROW + index;
var indexedMonth = (0, date_time_utilities_1.setMonth)(navigatedDate, monthIndex);
var isNavigatedMonth = navigatedDate.getMonth() === monthIndex;
var isSelectedMonth = selectedDate.getMonth() === monthIndex;
var isSelectedYear = selectedDate.getFullYear() === navigatedDate.getFullYear();
var isInBounds = (minDate ? (0, date_time_utilities_1.compareDatePart)(minDate, (0, date_time_utilities_1.getMonthEnd)(indexedMonth)) < 1 : true) &&
(maxDate ? (0, date_time_utilities_1.compareDatePart)((0, date_time_utilities_1.getMonthStart)(indexedMonth), maxDate) < 1 : true);
return (React.createElement("button", { ref: isNavigatedMonth ? navigatedMonthRef : undefined, role: 'gridcell', className: (0, utilities_1.css)(classNames.itemButton, (_a = {},
_a[classNames.current] = highlightCurrentMonth && isCurrentMonth(monthIndex, navigatedDate.getFullYear(), today),
_a[classNames.selected] = highlightSelectedMonth && isSelectedMonth && isSelectedYear,
_a[classNames.disabled] = !isInBounds,
_a)), disabled: !allFocusable && !isInBounds, key: monthIndex, onClick: isInBounds ? selectMonthCallback(monthIndex) : undefined, onKeyDown: isInBounds ? onButtonKeyDown(selectMonthCallback(monthIndex)) : undefined, "aria-label": dateFormatter.formatMonth(indexedMonth, strings), "aria-selected": isNavigatedMonth, "data-is-focusable": isInBounds ? true : undefined, type: "button" }, month));
})));
})))));
};
exports.CalendarMonthBase = CalendarMonthBase;
exports.CalendarMonthBase.displayName = 'CalendarMonthBase';
function getYearStrings(_a) {
var strings = _a.strings, navigatedDate = _a.navigatedDate, dateTimeFormatter = _a.dateTimeFormatter;
var yearToString = function (year) {
if (dateTimeFormatter) {
// create a date based on the current nav date
var yearFormattingDate = new Date(navigatedDate.getTime());
yearFormattingDate.setFullYear(year);
return dateTimeFormatter.formatYear(yearFormattingDate);
}
return String(year);
};
var yearRangeToString = function (yearRange) {
return "".concat(yearToString(yearRange.fromYear), " - ").concat(yearToString(yearRange.toYear));
};
var yearRangeToNextDecadeLabel = function (yearRange) {
return strings.nextYearRangeAriaLabel ? "".concat(strings.nextYearRangeAriaLabel, " ").concat(yearRangeToString(yearRange)) : '';
};
var yearRangeToPrevDecadeLabel = function (yearRange) {
return strings.prevYearRangeAriaLabel ? "".concat(strings.prevYearRangeAriaLabel, " ").concat(yearRangeToString(yearRange)) : '';
};
return [
yearToString,
{
rangeAriaLabel: yearRangeToString,
prevRangeAriaLabel: yearRangeToPrevDecadeLabel,
nextRangeAriaLabel: yearRangeToNextDecadeLabel,
headerAriaLabelFormatString: strings.yearPickerHeaderAriaLabel,
},
];
}
function isCurrentMonth(month, year, today) {
return today.getFullYear() === year && today.getMonth() === month;
}
function onButtonKeyDown(callback) {
return function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
switch (ev.which) {
case utilities_1.KeyCodes.enter:
callback();
break;
}
};
}
//# sourceMappingURL=CalendarMonth.base.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarMonthProps } from './CalendarMonth.types';
export declare const CalendarMonth: React.FunctionComponent<ICalendarMonthProps>;
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarMonth = void 0;
var CalendarMonth_base_1 = require("./CalendarMonth.base");
var CalendarMonth_styles_1 = require("./CalendarMonth.styles");
var Utilities_1 = require("../../../Utilities");
exports.CalendarMonth = (0, Utilities_1.styled)(CalendarMonth_base_1.CalendarMonthBase, CalendarMonth_styles_1.getStyles, undefined, { scope: 'CalendarMonth' });
//# sourceMappingURL=CalendarMonth.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarMonth.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarMonth/CalendarMonth.tsx"],"names":[],"mappings":";;;AACA,2DAAyD;AACzD,+DAAmD;AACnD,gDAA4C;AAG/B,QAAA,aAAa,GAAiD,IAAA,kBAAM,EAC/E,sCAAiB,EACjB,gCAAS,EACT,SAAS,EACT,EAAE,KAAK,EAAE,eAAe,EAAE,CAC3B,CAAC","sourcesContent":["import * as React from 'react';\nimport { CalendarMonthBase } from './CalendarMonth.base';\nimport { getStyles } from './CalendarMonth.styles';\nimport { styled } from '../../../Utilities';\nimport type { ICalendarMonthProps } from './CalendarMonth.types';\n\nexport const CalendarMonth: React.FunctionComponent<ICalendarMonthProps> = styled(\n CalendarMonthBase,\n getStyles,\n undefined,\n { scope: 'CalendarMonth' },\n);\n"]}
@@ -0,0 +1,2 @@
import type { ICalendarMonthStyleProps, ICalendarMonthStyles } from './CalendarMonth.types';
export declare const getStyles: (props: ICalendarMonthStyleProps) => ICalendarMonthStyles;
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStyles = void 0;
var CalendarPicker_styles_1 = require("../CalendarPicker/CalendarPicker.styles");
var getStyles = function (props) {
/* Return styles from the base class.
* If this component has extra styles not in the base, apply them here i.e.:
* const myStyle: IStyle = {
* display: "block"
* }; *
* return {...getPickerStyles(props), myStyle};
*/
return (0, CalendarPicker_styles_1.getStyles)(props);
};
exports.getStyles = getStyles;
//# sourceMappingURL=CalendarMonth.styles.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarMonth.styles.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarMonth/CalendarMonth.styles.ts"],"names":[],"mappings":";;;AAAA,iFAAuF;AAGhF,IAAM,SAAS,GAAG,UAAC,KAA+B;IACvD;;;;;;OAMG;IAEH,OAAO,IAAA,iCAAe,EAAC,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAVW,QAAA,SAAS,aAUpB","sourcesContent":["import { getStyles as getPickerStyles } from '../CalendarPicker/CalendarPicker.styles';\nimport type { ICalendarMonthStyleProps, ICalendarMonthStyles } from './CalendarMonth.types';\n\nexport const getStyles = (props: ICalendarMonthStyleProps): ICalendarMonthStyles => {\n /* Return styles from the base class.\n * If this component has extra styles not in the base, apply them here i.e.:\n * const myStyle: IStyle = {\n * display: \"block\"\n * }; *\n * return {...getPickerStyles(props), myStyle};\n */\n\n return getPickerStyles(props);\n};\n"]}
@@ -0,0 +1,117 @@
import { AnimationDirection } from '../Calendar.types';
import type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';
import type { ICalendarNavigationIcons } from '../Calendar.types';
import type { ITheme } from '@fluentui/style-utilities';
import type { ICalendarPickerStyleProps, ICalendarPickerStyles } from '../CalendarPicker/CalendarPicker.types';
import type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';
/**
* {@docCategory Calendar}
*/
export interface ICalendarMonth {
focus(): void;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarMonthProps extends IBaseProps<ICalendarMonth> {
/**
* Optional callback to access the ICalendarMonth interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ICalendarMonth>;
/**
* Customized styles for the calendar month component
*/
styles?: IStyleFunctionOrObject<ICalendarMonthStyleProps, ICalendarMonthStyles>;
/**
* Theme (provided through customization).
*/
theme?: ITheme;
/**
* Localized strings to use in the Calendar
*/
strings: ICalendarStrings;
/**
* The currently selected date
*/
selectedDate: Date;
/**
* The currently navigated date
*/
navigatedDate: Date;
/**
* Callback issued when a month is selected
* @param date - The date the user selected
* @param selectedDateRangeArray - The resultant list of dates that are selected based on the date range type set
* for the component.
*/
onSelectDate?: (date: Date, selectedDateRangeArray?: Date[]) => void;
/**
* Callback issued when the year is navigated
* @param date - The date that is navigated to
* @param focusOnNavigatedDay - Whether to set the focus to the navigated date.
*/
onNavigateDate: (date: Date, focusOnNavigatedDay: boolean) => void;
/**
* Custom navigation icons.
*/
navigationIcons?: ICalendarNavigationIcons;
/**
* Value of today. If unspecified, current time in client machine will be used.
*/
today?: Date;
/**
* Callback function when the header is selected
*/
onHeaderSelect?: () => void;
/**
* Apply additional formatting to dates, for example localized date formatting.
*/
dateTimeFormatter?: IDateFormatting;
/**
* If set the Calendar will not allow navigation to or selection of a date earlier than this value.
*/
minDate?: Date;
/**
* If set the Calendar will not allow navigation to or selection of a date later than this value.
*/
maxDate?: Date;
/**
* Whether the month picker should highlight the current month
* @defaultvalue false
*/
highlightCurrentMonth?: boolean;
/**
* Whether the month picker should highlight the selected month
* @defaultvalue false
*/
highlightSelectedMonth?: boolean;
/**
* Allows all dates and buttons to be focused, including disabled ones
* @defaultvalue false
*/
allFocusable?: boolean;
/**
* Additional CSS class(es) to apply to the CalendarMonth.
*/
className?: string;
/**
* Whether the year picker is hidden
* @defaultvalue false
*/
yearPickerHidden?: boolean;
/**
* The cardinal directions for animation to occur during transitions, either horizontal or veritcal
*/
animationDirection?: AnimationDirection;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarMonthStyleProps extends ICalendarPickerStyleProps {
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarMonthStyles extends ICalendarPickerStyles {
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=CalendarMonth.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarMonth.types.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarMonth/CalendarMonth.types.ts"],"names":[],"mappings":"","sourcesContent":["import { AnimationDirection } from '../Calendar.types';\nimport type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';\nimport type { ICalendarNavigationIcons } from '../Calendar.types';\nimport type { ITheme } from '@fluentui/style-utilities';\nimport type { ICalendarPickerStyleProps, ICalendarPickerStyles } from '../CalendarPicker/CalendarPicker.types';\nimport type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarMonth {\n focus(): void;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarMonthProps extends IBaseProps<ICalendarMonth> {\n /**\n * Optional callback to access the ICalendarMonth interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<ICalendarMonth>;\n\n /**\n * Customized styles for the calendar month component\n */\n styles?: IStyleFunctionOrObject<ICalendarMonthStyleProps, ICalendarMonthStyles>;\n\n /**\n * Theme (provided through customization).\n */\n theme?: ITheme;\n\n /**\n * Localized strings to use in the Calendar\n */\n strings: ICalendarStrings;\n\n /**\n * The currently selected date\n */\n selectedDate: Date;\n\n /**\n * The currently navigated date\n */\n navigatedDate: Date;\n\n /**\n * Callback issued when a month is selected\n * @param date - The date the user selected\n * @param selectedDateRangeArray - The resultant list of dates that are selected based on the date range type set\n * for the component.\n */\n onSelectDate?: (date: Date, selectedDateRangeArray?: Date[]) => void;\n\n /**\n * Callback issued when the year is navigated\n * @param date - The date that is navigated to\n * @param focusOnNavigatedDay - Whether to set the focus to the navigated date.\n */\n onNavigateDate: (date: Date, focusOnNavigatedDay: boolean) => void;\n\n /**\n * Custom navigation icons.\n */\n navigationIcons?: ICalendarNavigationIcons;\n\n /**\n * Value of today. If unspecified, current time in client machine will be used.\n */\n today?: Date;\n\n /**\n * Callback function when the header is selected\n */\n onHeaderSelect?: () => void;\n\n /**\n * Apply additional formatting to dates, for example localized date formatting.\n */\n dateTimeFormatter?: IDateFormatting;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a date earlier than this value.\n */\n minDate?: Date;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a date later than this value.\n */\n maxDate?: Date;\n\n /**\n * Whether the month picker should highlight the current month\n * @defaultvalue false\n */\n highlightCurrentMonth?: boolean;\n\n /**\n * Whether the month picker should highlight the selected month\n * @defaultvalue false\n */\n highlightSelectedMonth?: boolean;\n\n /**\n * Allows all dates and buttons to be focused, including disabled ones\n * @defaultvalue false\n */\n allFocusable?: boolean;\n\n /**\n * Additional CSS class(es) to apply to the CalendarMonth.\n */\n className?: string;\n\n /**\n * Whether the year picker is hidden\n * @defaultvalue false\n */\n yearPickerHidden?: boolean;\n\n /**\n * The cardinal directions for animation to occur during transitions, either horizontal or veritcal\n */\n animationDirection?: AnimationDirection;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarMonthStyleProps extends ICalendarPickerStyleProps {}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarMonthStyles extends ICalendarPickerStyles {}\n"]}
@@ -0,0 +1,2 @@
import type { ICalendarPickerStyleProps, ICalendarPickerStyles } from './CalendarPicker.types';
export declare const getStyles: (props: ICalendarPickerStyleProps) => ICalendarPickerStyles;
@@ -0,0 +1,190 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStyles = void 0;
var tslib_1 = require("tslib");
var style_utilities_1 = require("@fluentui/style-utilities");
var Calendar_types_1 = require("../Calendar.types");
var getStyles = function (props) {
var _a, _b, _c, _d, _e, _f, _g;
var className = props.className, theme = props.theme, hasHeaderClickCallback = props.hasHeaderClickCallback, highlightCurrent = props.highlightCurrent, highlightSelected = props.highlightSelected, animateBackwards = props.animateBackwards, animationDirection = props.animationDirection;
var palette = theme.palette;
var animationStyle = {};
if (animateBackwards !== undefined) {
if (animationDirection === Calendar_types_1.AnimationDirection.Horizontal) {
animationStyle = animateBackwards ? style_utilities_1.AnimationStyles.slideRightIn20 : style_utilities_1.AnimationStyles.slideLeftIn20;
}
else {
animationStyle = animateBackwards ? style_utilities_1.AnimationStyles.slideDownIn20 : style_utilities_1.AnimationStyles.slideUpIn20;
}
}
var headerAnimationStyle = animateBackwards !== undefined ? style_utilities_1.AnimationStyles.fadeIn200 : {};
return {
root: [
style_utilities_1.normalize,
{
width: 196,
padding: 12,
boxSizing: 'content-box',
overflow: 'hidden',
},
className,
],
headerContainer: {
display: 'flex',
},
currentItemButton: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: -1 }),
tslib_1.__assign(tslib_1.__assign({}, headerAnimationStyle), { fontSize: style_utilities_1.FontSizes.medium, fontWeight: style_utilities_1.FontWeights.semibold, fontFamily: 'inherit', textAlign: 'left', color: 'inherit', backgroundColor: 'transparent', flexGrow: 1, padding: '0 4px 0 10px', border: 'none', overflow: 'visible' }),
hasHeaderClickCallback && {
selectors: {
'&:hover, &:active': {
cursor: !hasHeaderClickCallback ? 'default' : 'pointer',
color: palette.neutralDark,
outline: '1px solid transparent',
backgroundColor: palette.neutralLight,
},
},
},
],
navigationButtonsContainer: {
display: 'flex',
alignItems: 'center',
},
navigationButton: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: -1 }),
{
fontFamily: 'inherit',
width: 28,
minWidth: 28,
height: 28,
minHeight: 28,
display: 'block',
textAlign: 'center',
lineHeight: 28,
fontSize: style_utilities_1.FontSizes.small,
color: palette.neutralPrimary,
borderRadius: 2,
position: 'relative',
backgroundColor: 'transparent',
border: 'none',
padding: 0,
overflow: 'visible', // explicitly specify for IE11
selectors: {
'&:hover': {
color: palette.neutralDark,
cursor: 'pointer',
outline: '1px solid transparent',
backgroundColor: palette.neutralLight,
},
},
},
],
gridContainer: {
marginTop: 4,
},
buttonRow: tslib_1.__assign(tslib_1.__assign({}, animationStyle), { marginBottom: 16, selectors: {
'&:nth-child(n + 3)': {
marginBottom: 0,
},
} }),
itemButton: [
(0, style_utilities_1.getFocusStyle)(theme, { inset: -1 }),
{
width: 40,
height: 40,
minWidth: 40,
minHeight: 40,
lineHeight: 40,
fontSize: style_utilities_1.FontSizes.small,
fontFamily: 'inherit',
padding: 0,
margin: '0 12px 0 0',
color: palette.neutralPrimary,
backgroundColor: 'transparent',
border: 'none',
borderRadius: 2,
overflow: 'visible', // explicitly specify for IE11
selectors: {
'&:nth-child(4n + 4)': {
marginRight: 0,
},
'&:nth-child(n + 9)': {
marginBottom: 0,
},
'& div': {
fontWeight: style_utilities_1.FontWeights.regular,
},
'&:hover': {
color: palette.neutralDark,
backgroundColor: palette.neutralLight,
cursor: 'pointer',
outline: '1px solid transparent',
selectors: (_a = {},
_a[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ background: 'Window', color: 'WindowText', outline: '1px solid Highlight' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_a),
},
'&:active': {
backgroundColor: palette.themeLight,
selectors: (_b = {},
_b[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ background: 'Window', color: 'Highlight' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_b),
},
},
},
],
current: highlightCurrent
? {
color: palette.white,
backgroundColor: palette.themePrimary,
selectors: (_c = {
'& div': {
fontWeight: style_utilities_1.FontWeights.semibold,
},
'&:hover': {
backgroundColor: palette.themePrimary,
selectors: (_d = {},
_d[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ backgroundColor: 'WindowText', color: 'Window' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_d),
}
},
_c[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ backgroundColor: 'WindowText', color: 'Window' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_c),
}
: {},
selected: highlightSelected
? {
color: palette.neutralPrimary,
backgroundColor: palette.themeLight,
fontWeight: style_utilities_1.FontWeights.semibold,
selectors: (_e = {
'& div': {
fontWeight: style_utilities_1.FontWeights.semibold,
},
'&:hover, &:active': {
backgroundColor: palette.themeLight,
selectors: (_f = {},
_f[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ color: 'Window', background: 'Highlight' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_f),
}
},
_e[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ background: 'Highlight', color: 'Window' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_e),
}
: {},
disabled: {
selectors: (_g = {
'&, &:disabled, & button': {
color: palette.neutralTertiaryAlt,
pointerEvents: 'none',
}
},
_g[style_utilities_1.HighContrastSelector] = {
color: 'GrayText',
forcedColorAdjust: 'none',
},
_g),
},
};
};
exports.getStyles = getStyles;
//# sourceMappingURL=CalendarPicker.styles.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,54 @@
import { AnimationDirection } from '../Calendar.types';
import type { IStyle, ITheme } from '@fluentui/style-utilities';
/**
* {@docCategory Calendar}
*/
export interface ICalendarPickerStyleProps {
/**
* Theme provided by High-Order Component.
*/
theme: ITheme;
/**
* Accept custom classNames
*/
className?: string;
/**
* Whether the header can be clicked
*/
hasHeaderClickCallback?: boolean;
/**
* Whether the picker should highlight the current item
*/
highlightCurrent?: boolean;
/**
* Whether the picker should highlight the selected item
*/
highlightSelected?: boolean;
/**
* The cardinal directions for animation to occur during transitions, either horizontal or veritcal
*/
animationDirection?: AnimationDirection;
/**
* Whether grid entering animation should be forwards or backwards
*/
animateBackwards?: boolean;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarPickerStyles {
/**
* Style for the root element.
*/
root: IStyle;
headerContainer: IStyle;
currentItemButton: IStyle;
navigationButtonsContainer: IStyle;
navigationButton: IStyle;
gridContainer: IStyle;
buttonRow: IStyle;
itemButton: IStyle;
current: IStyle;
selected: IStyle;
disabled: IStyle;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=CalendarPicker.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarPicker.types.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarPicker/CalendarPicker.types.ts"],"names":[],"mappings":"","sourcesContent":["import { AnimationDirection } from '../Calendar.types';\nimport type { IStyle, ITheme } from '@fluentui/style-utilities';\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarPickerStyleProps {\n /**\n * Theme provided by High-Order Component.\n */\n theme: ITheme;\n\n /**\n * Accept custom classNames\n */\n className?: string;\n\n /**\n * Whether the header can be clicked\n */\n hasHeaderClickCallback?: boolean;\n\n /**\n * Whether the picker should highlight the current item\n */\n highlightCurrent?: boolean;\n\n /**\n * Whether the picker should highlight the selected item\n */\n highlightSelected?: boolean;\n\n /**\n * The cardinal directions for animation to occur during transitions, either horizontal or veritcal\n */\n animationDirection?: AnimationDirection;\n\n /**\n * Whether grid entering animation should be forwards or backwards\n */\n animateBackwards?: boolean;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarPickerStyles {\n /**\n * Style for the root element.\n */\n root: IStyle;\n\n headerContainer: IStyle;\n\n currentItemButton: IStyle;\n\n navigationButtonsContainer: IStyle;\n\n navigationButton: IStyle;\n\n gridContainer: IStyle;\n\n buttonRow: IStyle;\n\n itemButton: IStyle;\n\n current: IStyle;\n\n selected: IStyle;\n\n disabled: IStyle;\n}\n"]}
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarYearProps } from './CalendarYear.types';
export declare const CalendarYearBase: React.FunctionComponent<ICalendarYearProps>;
@@ -0,0 +1,255 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarYearBase = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var Utilities_1 = require("../../../Utilities");
var FocusZone_1 = require("../../../FocusZone");
var Icon_1 = require("../../../Icon");
var react_hooks_1 = require("@fluentui/react-hooks");
var defaults_1 = require("../defaults");
var getClassNames = (0, Utilities_1.classNamesFunction)();
var CELL_COUNT = 12;
var CELLS_PER_ROW = 4;
var DefaultCalendarYearStrings = {
prevRangeAriaLabel: undefined,
nextRangeAriaLabel: undefined,
};
var CalendarYearGridCell = function (props) {
var _a;
var _b;
var styles = props.styles, theme = props.theme, className = props.className, highlightCurrentYear = props.highlightCurrentYear, highlightSelectedYear = props.highlightSelectedYear, year = props.year, selected = props.selected, disabled = props.disabled, componentRef = props.componentRef, onSelectYear = props.onSelectYear, onRenderYear = props.onRenderYear;
var buttonRef = React.useRef(null);
React.useImperativeHandle(componentRef, function () { return ({
focus: function () {
var _a, _b;
(_b = (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
},
}); }, []);
var onClick = function () {
onSelectYear === null || onSelectYear === void 0 ? void 0 : onSelectYear(year);
};
var onKeyDown = function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (ev.which === Utilities_1.KeyCodes.enter) {
onSelectYear === null || onSelectYear === void 0 ? void 0 : onSelectYear(year);
}
};
var classNames = getClassNames(styles, {
theme: theme,
className: className,
highlightCurrent: highlightCurrentYear,
highlightSelected: highlightSelectedYear,
});
return (React.createElement("button", { className: (0, Utilities_1.css)(classNames.itemButton, (_a = {},
_a[classNames.selected] = selected,
_a[classNames.disabled] = disabled,
_a)), type: "button", role: "gridcell", onClick: !disabled ? onClick : undefined, onKeyDown: !disabled ? onKeyDown : undefined, disabled: disabled, "aria-selected": selected, ref: buttonRef }, (_b = onRenderYear === null || onRenderYear === void 0 ? void 0 : onRenderYear(year)) !== null && _b !== void 0 ? _b : year));
};
CalendarYearGridCell.displayName = 'CalendarYearGridCell';
var CalendarYearGrid = function (props) {
var styles = props.styles, theme = props.theme, className = props.className, fromYear = props.fromYear, toYear = props.toYear, animationDirection = props.animationDirection, animateBackwards = props.animateBackwards, minYear = props.minYear, maxYear = props.maxYear, onSelectYear = props.onSelectYear, selectedYear = props.selectedYear, componentRef = props.componentRef;
var selectedCellRef = React.useRef(null);
var currentCellRef = React.useRef(null);
React.useImperativeHandle(componentRef, function () { return ({
focus: function () {
var _a, _b;
(_b = (_a = (selectedCellRef.current || currentCellRef.current)) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
},
}); }, []);
var renderCell = function (yearToRender) {
var selected = yearToRender === selectedYear;
var disabled = (minYear !== undefined && yearToRender < minYear) || (maxYear !== undefined && yearToRender > maxYear);
var current = yearToRender === new Date().getFullYear();
return (React.createElement(CalendarYearGridCell, tslib_1.__assign({}, props, { key: yearToRender, year: yearToRender, selected: selected, current: current, disabled: disabled, onSelectYear: onSelectYear, componentRef: selected ? selectedCellRef : current ? currentCellRef : undefined, theme: theme })));
};
var classNames = getClassNames(styles, {
theme: theme,
className: className,
animateBackwards: animateBackwards,
animationDirection: animationDirection,
});
var onRenderYear = function (value) {
var _a, _b;
return (_b = (_a = props.onRenderYear) === null || _a === void 0 ? void 0 : _a.call(props, value)) !== null && _b !== void 0 ? _b : value;
};
var gridAriaLabel = "".concat(onRenderYear(fromYear), " - ").concat(onRenderYear(toYear));
var year = fromYear;
var cells = [];
for (var i = 0; i < (toYear - fromYear + 1) / CELLS_PER_ROW; i++) {
cells.push([]);
for (var j = 0; j < CELLS_PER_ROW; j++) {
cells[i].push(renderCell(year));
year++;
}
}
return (React.createElement(FocusZone_1.FocusZone, null,
React.createElement("div", { className: classNames.gridContainer, role: "grid", "aria-label": gridAriaLabel }, cells.map(function (cellRow, index) {
return (React.createElement.apply(React, tslib_1.__spreadArray(["div", { key: 'yearPickerRow_' + index + '_' + fromYear, role: "row", className: classNames.buttonRow }], cellRow, false)));
}))));
};
CalendarYearGrid.displayName = 'CalendarYearGrid';
var CalendarYearNavDirection;
(function (CalendarYearNavDirection) {
CalendarYearNavDirection[CalendarYearNavDirection["Previous"] = 0] = "Previous";
CalendarYearNavDirection[CalendarYearNavDirection["Next"] = 1] = "Next";
})(CalendarYearNavDirection || (CalendarYearNavDirection = {}));
var CalendarYearNavArrow = function (props) {
var _a;
var styles = props.styles, theme = props.theme, className = props.className, _b = props.navigationIcons, navigationIcons = _b === void 0 ? defaults_1.defaultCalendarNavigationIcons : _b, _c = props.strings, strings = _c === void 0 ? DefaultCalendarYearStrings : _c, direction = props.direction, onSelectPrev = props.onSelectPrev, onSelectNext = props.onSelectNext, fromYear = props.fromYear, toYear = props.toYear, maxYear = props.maxYear, minYear = props.minYear;
var classNames = getClassNames(styles, {
theme: theme,
className: className,
});
var ariaLabel = direction === CalendarYearNavDirection.Previous ? strings.prevRangeAriaLabel : strings.nextRangeAriaLabel;
var newRangeOffset = direction === CalendarYearNavDirection.Previous ? -CELL_COUNT : CELL_COUNT;
var newRange = { fromYear: fromYear + newRangeOffset, toYear: toYear + newRangeOffset };
var ariaLabelString = ariaLabel ? (typeof ariaLabel === 'string' ? ariaLabel : ariaLabel(newRange)) : undefined;
var disabled = direction === CalendarYearNavDirection.Previous
? minYear !== undefined && fromYear < minYear
: maxYear !== undefined && props.fromYear + CELL_COUNT > maxYear;
var onNavigate = function () {
direction === CalendarYearNavDirection.Previous ? onSelectPrev === null || onSelectPrev === void 0 ? void 0 : onSelectPrev() : onSelectNext === null || onSelectNext === void 0 ? void 0 : onSelectNext();
};
var onKeyDown = function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (ev.which === Utilities_1.KeyCodes.enter) {
onNavigate();
}
};
// can be condensed, but leaving verbose for clarity due to regressions
var isLeftNavigation = (0, Utilities_1.getRTL)()
? direction === CalendarYearNavDirection.Next
: direction === CalendarYearNavDirection.Previous;
return (React.createElement("button", { className: (0, Utilities_1.css)(classNames.navigationButton, (_a = {},
_a[classNames.disabled] = disabled,
_a)), onClick: !disabled ? onNavigate : undefined, onKeyDown: !disabled ? onKeyDown : undefined, type: "button", title: ariaLabelString, disabled: disabled },
React.createElement(Icon_1.Icon, { iconName: isLeftNavigation ? navigationIcons.leftNavigation : navigationIcons.rightNavigation })));
};
CalendarYearNavArrow.displayName = 'CalendarYearNavArrow';
var CalendarYearNav = function (props) {
var styles = props.styles, theme = props.theme, className = props.className;
var classNames = getClassNames(styles, {
theme: theme,
className: className,
});
return (React.createElement("div", { className: classNames.navigationButtonsContainer },
React.createElement(CalendarYearNavArrow, tslib_1.__assign({}, props, { direction: CalendarYearNavDirection.Previous })),
React.createElement(CalendarYearNavArrow, tslib_1.__assign({}, props, { direction: CalendarYearNavDirection.Next }))));
};
CalendarYearNav.displayName = 'CalendarYearNav';
var CalendarYearTitle = function (props) {
var styles = props.styles, theme = props.theme, className = props.className, fromYear = props.fromYear, toYear = props.toYear, _a = props.strings, strings = _a === void 0 ? DefaultCalendarYearStrings : _a, animateBackwards = props.animateBackwards, animationDirection = props.animationDirection;
var onHeaderSelect = function () {
var _a;
(_a = props.onHeaderSelect) === null || _a === void 0 ? void 0 : _a.call(props, true);
};
var onHeaderKeyDown = function (ev) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (ev.which === Utilities_1.KeyCodes.enter || ev.which === Utilities_1.KeyCodes.space) {
onHeaderSelect();
}
};
var onRenderYear = function (year) {
var _a, _b;
return (_b = (_a = props.onRenderYear) === null || _a === void 0 ? void 0 : _a.call(props, year)) !== null && _b !== void 0 ? _b : year;
};
var classNames = getClassNames(styles, {
theme: theme,
className: className,
hasHeaderClickCallback: !!props.onHeaderSelect,
animateBackwards: animateBackwards,
animationDirection: animationDirection,
});
if (props.onHeaderSelect) {
var rangeAriaLabel = strings.rangeAriaLabel;
var headerAriaLabelFormatString = strings.headerAriaLabelFormatString;
var currentDateRange = rangeAriaLabel
? typeof rangeAriaLabel === 'string'
? rangeAriaLabel
: rangeAriaLabel(props)
: undefined;
var ariaLabel = headerAriaLabelFormatString
? (0, Utilities_1.format)(headerAriaLabelFormatString, currentDateRange)
: currentDateRange;
return (React.createElement("button", { className: classNames.currentItemButton, onClick: onHeaderSelect, onKeyDown: onHeaderKeyDown, "aria-label": ariaLabel, role: "button", type: "button" },
React.createElement("span", { "aria-live": "assertive", "aria-atomic": "true" },
onRenderYear(fromYear),
" - ",
onRenderYear(toYear))));
}
return (React.createElement("div", { className: classNames.current },
onRenderYear(fromYear),
" - ",
onRenderYear(toYear)));
};
CalendarYearTitle.displayName = 'CalendarYearTitle';
var CalendarYearHeader = function (props) {
var _a;
var styles = props.styles, theme = props.theme, className = props.className, animateBackwards = props.animateBackwards, animationDirection = props.animationDirection, onRenderTitle = props.onRenderTitle;
var classNames = getClassNames(styles, {
theme: theme,
className: className,
hasHeaderClickCallback: !!props.onHeaderSelect,
animateBackwards: animateBackwards,
animationDirection: animationDirection,
});
return (React.createElement("div", { className: classNames.headerContainer }, (_a = onRenderTitle === null || onRenderTitle === void 0 ? void 0 : onRenderTitle(props)) !== null && _a !== void 0 ? _a : React.createElement(CalendarYearTitle, tslib_1.__assign({}, props)),
React.createElement(CalendarYearNav, tslib_1.__assign({}, props))));
};
CalendarYearHeader.displayName = 'CalendarYearHeader';
function useAnimateBackwards(_a) {
var selectedYear = _a.selectedYear, navigatedYear = _a.navigatedYear;
var rangeYear = selectedYear || navigatedYear || new Date().getFullYear();
var fromYear = Math.floor(rangeYear / 10) * 10;
var previousFromYear = (0, react_hooks_1.usePrevious)(fromYear);
if (!previousFromYear || previousFromYear === fromYear) {
return undefined;
}
else if (previousFromYear > fromYear) {
return true;
}
else {
return false;
}
}
function useYearRangeState(_a) {
var selectedYear = _a.selectedYear, navigatedYear = _a.navigatedYear;
var rangeYear = React.useMemo(function () {
return selectedYear || navigatedYear || Math.floor(new Date().getFullYear() / 10) * 10;
}, [navigatedYear, selectedYear]);
var _b = React.useState(rangeYear), fromYear = _b[0], setFromYear = _b[1];
var onNavNext = function () {
setFromYear(function (year) { return year + CELL_COUNT; });
};
var onNavPrevious = function () {
setFromYear(function (year) { return year - CELL_COUNT; });
};
React.useEffect(function () {
setFromYear(rangeYear);
}, [rangeYear]);
var toYear = fromYear + CELL_COUNT - 1;
return [fromYear, toYear, onNavNext, onNavPrevious];
}
var CalendarYearBase = function (props) {
var animateBackwards = useAnimateBackwards(props);
var _a = useYearRangeState(props), fromYear = _a[0], toYear = _a[1], onNavNext = _a[2], onNavPrevious = _a[3];
var gridRef = React.useRef(null);
React.useImperativeHandle(props.componentRef, function () { return ({
focus: function () {
var _a, _b;
(_b = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
},
}); });
var styles = props.styles, theme = props.theme, className = props.className;
var classNames = getClassNames(styles, {
theme: theme,
className: className,
});
return (React.createElement("div", { className: classNames.root },
React.createElement(CalendarYearHeader, tslib_1.__assign({}, props, { fromYear: fromYear, toYear: toYear, onSelectPrev: onNavPrevious, onSelectNext: onNavNext, animateBackwards: animateBackwards })),
React.createElement(CalendarYearGrid, tslib_1.__assign({}, props, { fromYear: fromYear, toYear: toYear, animateBackwards: animateBackwards, componentRef: gridRef }))));
};
exports.CalendarYearBase = CalendarYearBase;
exports.CalendarYearBase.displayName = 'CalendarYearBase';
//# sourceMappingURL=CalendarYear.base.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICalendarYearProps } from './CalendarYear.types';
export declare const CalendarYear: React.FunctionComponent<ICalendarYearProps>;
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarYear = void 0;
var CalendarYear_styles_1 = require("./CalendarYear.styles");
var Utilities_1 = require("../../../Utilities");
var CalendarYear_base_1 = require("./CalendarYear.base");
exports.CalendarYear = (0, Utilities_1.styled)(CalendarYear_base_1.CalendarYearBase, CalendarYear_styles_1.getStyles, undefined, { scope: 'CalendarYear' });
//# sourceMappingURL=CalendarYear.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarYear.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarYear/CalendarYear.tsx"],"names":[],"mappings":";;;AACA,6DAAkD;AAClD,gDAA4C;AAC5C,yDAAuD;AAG1C,QAAA,YAAY,GAAgD,IAAA,kBAAM,EAC7E,oCAAgB,EAChB,+BAAS,EACT,SAAS,EACT,EAAE,KAAK,EAAE,cAAc,EAAE,CAC1B,CAAC","sourcesContent":["import * as React from 'react';\nimport { getStyles } from './CalendarYear.styles';\nimport { styled } from '../../../Utilities';\nimport { CalendarYearBase } from './CalendarYear.base';\nimport type { ICalendarYearProps } from './CalendarYear.types';\n\nexport const CalendarYear: React.FunctionComponent<ICalendarYearProps> = styled(\n CalendarYearBase,\n getStyles,\n undefined,\n { scope: 'CalendarYear' },\n);\n"]}
@@ -0,0 +1,2 @@
import type { ICalendarYearStyleProps, ICalendarYearStyles } from './CalendarYear.types';
export declare const getStyles: (props: ICalendarYearStyleProps) => ICalendarYearStyles;
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStyles = void 0;
var CalendarPicker_styles_1 = require("../CalendarPicker/CalendarPicker.styles");
var getStyles = function (props) {
/* Return styles from the base class.
* If this component has extra styles not in the base, apply them here i.e.:
* const myStyle: IStyle = {
* display: "block"
* };
* return {...getPickerStyles(props), myStyle};
*/
return (0, CalendarPicker_styles_1.getStyles)(props);
};
exports.getStyles = getStyles;
//# sourceMappingURL=CalendarYear.styles.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarYear.styles.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarYear/CalendarYear.styles.ts"],"names":[],"mappings":";;;AAAA,iFAAuF;AAGhF,IAAM,SAAS,GAAG,UAAC,KAA8B;IACtD;;;;;;OAMG;IAEH,OAAO,IAAA,iCAAe,EAAC,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAVW,QAAA,SAAS,aAUpB","sourcesContent":["import { getStyles as getPickerStyles } from '../CalendarPicker/CalendarPicker.styles';\nimport type { ICalendarYearStyleProps, ICalendarYearStyles } from './CalendarYear.types';\n\nexport const getStyles = (props: ICalendarYearStyleProps): ICalendarYearStyles => {\n /* Return styles from the base class.\n * If this component has extra styles not in the base, apply them here i.e.:\n * const myStyle: IStyle = {\n * display: \"block\"\n * };\n * return {...getPickerStyles(props), myStyle};\n */\n\n return getPickerStyles(props);\n};\n"]}
@@ -0,0 +1,129 @@
import * as React from 'react';
import { AnimationDirection } from '../Calendar.types';
import type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';
import type { ICalendarNavigationIcons } from '../Calendar.types';
import type { ITheme } from '@fluentui/style-utilities';
import type { ICalendarPickerStyleProps, ICalendarPickerStyles } from '../CalendarPicker/CalendarPicker.types';
/**
* {@docCategory Calendar}
*/
export interface ICalendarYear {
focus(): void;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarYearRange {
fromYear: number;
toYear: number;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarYearRangeToString {
(range: ICalendarYearRange): string;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarYearStrings {
rangeAriaLabel?: string | ICalendarYearRangeToString;
prevRangeAriaLabel?: string | ICalendarYearRangeToString;
nextRangeAriaLabel?: string | ICalendarYearRangeToString;
headerAriaLabelFormatString?: string;
}
/**
* {@docCategory Calendar}
*/
export interface ICalendarYearProps extends IBaseProps<ICalendarYear> {
/**
* Optional callback to access the ICalendarYear interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ICalendarYear>;
/**
* Customized styles for the calendar month component
*/
styles?: IStyleFunctionOrObject<ICalendarYearStyleProps, ICalendarYearStyles>;
/**
* Theme (provided through customization).
*/
theme?: ITheme;
/**
* Localized strings to use in the Calendar
*/
strings?: ICalendarYearStrings;
/**
* The currently selected year
*/
selectedYear?: number;
/**
* The currently navigated year
*/
navigatedYear?: number;
/**
* Callback action when a year is selected
* @param year - The year the user selected
*/
onSelectYear?: (year: number) => void;
/**
* Custom navigation icons.
*/
navigationIcons?: ICalendarNavigationIcons;
/**
* Callback action when the header is selected
*/
onHeaderSelect?: (focus: boolean) => void;
/**
* If set the Calendar will not allow navigation to or selection of a year earlier than this value.
*/
minYear?: number;
/**
* If set the Calendar will not allow navigation to or selection of a year later than this value.
*/
maxYear?: number;
/**
* Whether the year picker should highlight the current year
* @defaultvalue false
*/
highlightCurrentYear?: boolean;
/**
* Whether the year picker should highlight the selected year
* @defaultvalue false
*/
highlightSelectedYear?: boolean;
/**
* Accept custom classNames
*/
className?: string;
/**
* Custom renderer for the title
*/
onRenderTitle?: (props: ICalendarYearHeaderProps) => React.ReactNode;
/**
* Custom renderer for the year
*/
onRenderYear?: (year: number) => React.ReactNode;
/**
* The cardinal directions for animation to occur during transitions, either horizontal or veritcal
*/
animationDirection?: AnimationDirection;
}
export interface ICalendarYearStyleProps extends ICalendarPickerStyleProps {
}
export interface ICalendarYearStyles extends ICalendarPickerStyles {
}
export interface ICalendarYearHeaderProps extends ICalendarYearProps, ICalendarYearRange {
/**
* Callback action when the 'previous' navigation button is selected
*/
onSelectPrev?: () => void;
/**
* Callback action when the 'next' navigation button is selected
*/
onSelectNext?: () => void;
/**
* Whether title entering animation should be forwards or backwards
*/
animateBackwards?: boolean;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=CalendarYear.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CalendarYear.types.js","sourceRoot":"../src/","sources":["components/Calendar/CalendarYear/CalendarYear.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { AnimationDirection } from '../Calendar.types';\nimport type { IBaseProps, IRefObject, IStyleFunctionOrObject } from '@fluentui/utilities';\nimport type { ICalendarNavigationIcons } from '../Calendar.types';\nimport type { ITheme } from '@fluentui/style-utilities';\nimport type { ICalendarPickerStyleProps, ICalendarPickerStyles } from '../CalendarPicker/CalendarPicker.types';\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarYear {\n focus(): void;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarYearRange {\n fromYear: number;\n toYear: number;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarYearRangeToString {\n (range: ICalendarYearRange): string;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarYearStrings {\n rangeAriaLabel?: string | ICalendarYearRangeToString;\n prevRangeAriaLabel?: string | ICalendarYearRangeToString;\n nextRangeAriaLabel?: string | ICalendarYearRangeToString;\n headerAriaLabelFormatString?: string;\n}\n\n/**\n * {@docCategory Calendar}\n */\nexport interface ICalendarYearProps extends IBaseProps<ICalendarYear> {\n /**\n * Optional callback to access the ICalendarYear interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<ICalendarYear>;\n\n /**\n * Customized styles for the calendar month component\n */\n styles?: IStyleFunctionOrObject<ICalendarYearStyleProps, ICalendarYearStyles>;\n\n /**\n * Theme (provided through customization).\n */\n theme?: ITheme;\n\n /**\n * Localized strings to use in the Calendar\n */\n strings?: ICalendarYearStrings;\n\n /**\n * The currently selected year\n */\n selectedYear?: number;\n\n /**\n * The currently navigated year\n */\n navigatedYear?: number;\n\n /**\n * Callback action when a year is selected\n * @param year - The year the user selected\n */\n onSelectYear?: (year: number) => void;\n\n /**\n * Custom navigation icons.\n */\n navigationIcons?: ICalendarNavigationIcons;\n\n /**\n * Callback action when the header is selected\n */\n onHeaderSelect?: (focus: boolean) => void;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a year earlier than this value.\n */\n minYear?: number;\n\n /**\n * If set the Calendar will not allow navigation to or selection of a year later than this value.\n */\n maxYear?: number;\n\n /**\n * Whether the year picker should highlight the current year\n * @defaultvalue false\n */\n highlightCurrentYear?: boolean;\n\n /**\n * Whether the year picker should highlight the selected year\n * @defaultvalue false\n */\n highlightSelectedYear?: boolean;\n\n /**\n * Accept custom classNames\n */\n className?: string;\n\n /**\n * Custom renderer for the title\n */\n onRenderTitle?: (props: ICalendarYearHeaderProps) => React.ReactNode;\n\n /**\n * Custom renderer for the year\n */\n onRenderYear?: (year: number) => React.ReactNode;\n\n /**\n * The cardinal directions for animation to occur during transitions, either horizontal or veritcal\n */\n animationDirection?: AnimationDirection;\n}\n\nexport interface ICalendarYearStyleProps extends ICalendarPickerStyleProps {}\n\nexport interface ICalendarYearStyles extends ICalendarPickerStyles {}\n\nexport interface ICalendarYearHeaderProps extends ICalendarYearProps, ICalendarYearRange {\n /**\n * Callback action when the 'previous' navigation button is selected\n */\n onSelectPrev?: () => void;\n\n /**\n * Callback action when the 'next' navigation button is selected\n */\n onSelectNext?: () => void;\n\n /**\n * Whether title entering animation should be forwards or backwards\n */\n animateBackwards?: boolean;\n}\n"]}
@@ -0,0 +1,8 @@
import type { ICalendarNavigationIcons } from './Calendar.types';
import type { ICalendarStrings } from '@fluentui/date-time-utilities';
export declare const defaultCalendarStrings: ICalendarStrings;
/**
* @deprecated Use `defaultCalendarStrings`
*/
export declare const defaultDayPickerStrings: ICalendarStrings;
export declare const defaultCalendarNavigationIcons: ICalendarNavigationIcons;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultCalendarNavigationIcons = exports.defaultDayPickerStrings = exports.defaultCalendarStrings = void 0;
var date_time_utilities_1 = require("@fluentui/date-time-utilities");
exports.defaultCalendarStrings = date_time_utilities_1.DEFAULT_CALENDAR_STRINGS;
/**
* @deprecated Use `defaultCalendarStrings`
*/
exports.defaultDayPickerStrings = exports.defaultCalendarStrings;
exports.defaultCalendarNavigationIcons = {
leftNavigation: 'Up',
rightNavigation: 'Down',
closeIcon: 'CalculatorMultiply',
};
//# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
{"version":3,"file":"defaults.js","sourceRoot":"../src/","sources":["components/Calendar/defaults.ts"],"names":[],"mappings":";;;AAAA,qEAAyE;AAI5D,QAAA,sBAAsB,GAAqB,8CAAwB,CAAC;AAEjF;;GAEG;AACU,QAAA,uBAAuB,GAAG,8BAAsB,CAAC;AAEjD,QAAA,8BAA8B,GAA6B;IACtE,cAAc,EAAE,IAAI;IACpB,eAAe,EAAE,MAAM;IACvB,SAAS,EAAE,oBAAoB;CAChC,CAAC","sourcesContent":["import { DEFAULT_CALENDAR_STRINGS } from '@fluentui/date-time-utilities';\nimport type { ICalendarNavigationIcons } from './Calendar.types';\nimport type { ICalendarStrings } from '@fluentui/date-time-utilities';\n\nexport const defaultCalendarStrings: ICalendarStrings = DEFAULT_CALENDAR_STRINGS;\n\n/**\n * @deprecated Use `defaultCalendarStrings`\n */\nexport const defaultDayPickerStrings = defaultCalendarStrings;\n\nexport const defaultCalendarNavigationIcons: ICalendarNavigationIcons = {\n leftNavigation: 'Up',\n rightNavigation: 'Down',\n closeIcon: 'CalculatorMultiply',\n};\n"]}
@@ -0,0 +1,10 @@
export * from './Calendar';
export * from './Calendar.types';
export * from './CalendarDay/CalendarDay.types';
export * from './CalendarMonth/CalendarMonth.types';
export * from './CalendarPicker/CalendarPicker.types';
export * from './CalendarYear/CalendarYear.types';
export * from '../CalendarDayGrid/CalendarDayGrid.types';
export * from './defaults';
export { DayOfWeek, DateRangeType, FirstWeekOfYear } from '@fluentui/date-time-utilities';
export type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FirstWeekOfYear = exports.DateRangeType = exports.DayOfWeek = void 0;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./Calendar"), exports);
tslib_1.__exportStar(require("./Calendar.types"), exports);
tslib_1.__exportStar(require("./CalendarDay/CalendarDay.types"), exports);
tslib_1.__exportStar(require("./CalendarMonth/CalendarMonth.types"), exports);
tslib_1.__exportStar(require("./CalendarPicker/CalendarPicker.types"), exports);
tslib_1.__exportStar(require("./CalendarYear/CalendarYear.types"), exports);
tslib_1.__exportStar(require("../CalendarDayGrid/CalendarDayGrid.types"), exports);
tslib_1.__exportStar(require("./defaults"), exports);
var date_time_utilities_1 = require("@fluentui/date-time-utilities");
Object.defineProperty(exports, "DayOfWeek", { enumerable: true, get: function () { return date_time_utilities_1.DayOfWeek; } });
Object.defineProperty(exports, "DateRangeType", { enumerable: true, get: function () { return date_time_utilities_1.DateRangeType; } });
Object.defineProperty(exports, "FirstWeekOfYear", { enumerable: true, get: function () { return date_time_utilities_1.FirstWeekOfYear; } });
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Calendar/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA2B;AAC3B,2DAAiC;AACjC,0EAAgD;AAChD,8EAAoD;AACpD,gFAAsD;AACtD,4EAAkD;AAClD,mFAAyD;AACzD,qDAA2B;AAC3B,qEAA0F;AAAjF,gHAAA,SAAS,OAAA;AAAE,oHAAA,aAAa,OAAA;AAAE,sHAAA,eAAe,OAAA","sourcesContent":["export * from './Calendar';\nexport * from './Calendar.types';\nexport * from './CalendarDay/CalendarDay.types';\nexport * from './CalendarMonth/CalendarMonth.types';\nexport * from './CalendarPicker/CalendarPicker.types';\nexport * from './CalendarYear/CalendarYear.types';\nexport * from '../CalendarDayGrid/CalendarDayGrid.types';\nexport * from './defaults';\nexport { DayOfWeek, DateRangeType, FirstWeekOfYear } from '@fluentui/date-time-utilities';\nexport type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';\n"]}