import * as React from 'react'; import { addMonths, addYears, addDays } from 'office-ui-fabric-react/lib/utilities/dateMath/DateMath'; import { Calendar, DateRangeType, DayOfWeek, defaultDayPickerStrings } from '@uifabric/date-time'; import * as styles from './Calendar.Example.scss'; const today = new Date(); const minDate = addMonths(today, -1); const maxDate = addYears(today, 1); const restrictedDates = [addDays(today, -2), addDays(today, -8), addDays(today, 2), addDays(today, 8)]; export interface ICalendarInlineExampleState { selectedDate?: Date; } export class CalendarInlineDateBoundariesExample extends React.Component<{}, ICalendarInlineExampleState> { public constructor(props: {}) { super(props); this.state = { selectedDate: today, }; } public render(): JSX.Element { return (
Selected date(s):{' '} {!this.state.selectedDate ? 'Not set' : this.state.selectedDate.toLocaleString()}
{(minDate || maxDate) && (
Date boundary: {' '} {minDate ? minDate.toLocaleDateString() : 'Not set'}-{maxDate ? maxDate.toLocaleDateString() : 'Not set'}
)} {restrictedDates && (
Disabled date(s): {' '} {restrictedDates.length > 0 ? restrictedDates.map((d: Date) => d.toLocaleDateString()).join(', ') : 'Not set'}
)}
); } private _onSelectDate = (date: Date, dateRangeArray: Date[]): void => { this.setState((prevState: ICalendarInlineExampleState) => { return { selectedDate: date, selectedDateRange: dateRangeArray, }; }); }; }