import * as React from 'react'; import { DefaultButton, FocusTrapZone, Callout, DirectionalHint } from 'office-ui-fabric-react'; import { Calendar, DayOfWeek, defaultDayPickerStrings } from '@uifabric/date-time'; export interface ICalendarButtonExampleState { showCalendar: boolean; selectedDate?: Date; } export interface ICalendarButtonExampleProps { isDayPickerVisible?: boolean; isMonthPickerVisible?: boolean; highlightCurrentMonth?: boolean; highlightSelectedMonth?: boolean; buttonString?: string; showMonthPickerAsOverlay?: boolean; showGoToToday?: boolean; } export class CalendarButtonExample extends React.Component { public static defaultProps: ICalendarButtonExampleProps = { showMonthPickerAsOverlay: false, isDayPickerVisible: true, isMonthPickerVisible: true, showGoToToday: true, buttonString: 'Click for Calendar', }; private _calendarButtonElement: HTMLElement; public constructor(props: ICalendarButtonExampleProps) { super(props); this.state = { showCalendar: false, selectedDate: undefined, }; } public render(): JSX.Element { return (
(this._calendarButtonElement = calendarBtn!)}>
{this.state.showCalendar && ( )}
); } private _onClick = (): void => { this.setState((prevState: ICalendarButtonExampleState) => { prevState.showCalendar = !prevState.showCalendar; return prevState; }); }; private _onDismiss = (): void => { this.setState((prevState: ICalendarButtonExampleState) => { prevState.showCalendar = false; return prevState; }); }; private _onSelectDate = (date: Date): void => { this.setState((prevState: ICalendarButtonExampleState) => { prevState.showCalendar = false; prevState.selectedDate = date; return prevState; }); }; }