UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

106 lines (93 loc) 2.92 kB
let { Dropdown, IDropdownOption, DatePicker, DayOfWeek, IDatePickerStrings, Fabric } = window.Fabric; const DayPickerStrings: IDatePickerStrings = { months: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], goToToday: 'Go to today', prevMonthAriaLabel: 'Go to previous month', nextMonthAriaLabel: 'Go to next month', prevYearAriaLabel: 'Go to previous year', nextYearAriaLabel: 'Go to next year', closeButtonAriaLabel: 'Close date picker' }; interface IDatePickerBasicExampleState { firstDayOfWeek?: DayOfWeek; } class DatePickerBasicExample extends React.Component<{}, IDatePickerBasicExampleState> { public constructor(props: {}) { super(props); this.state = { firstDayOfWeek: DayOfWeek.Sunday }; } public render() { const { firstDayOfWeek } = this.state; return ( <div className="docs-DatePickerExample"> <DatePicker firstDayOfWeek={firstDayOfWeek} strings={DayPickerStrings} placeholder="Select a date..." // tslint:disable:jsx-no-lambda onAfterMenuDismiss={() => console.log('onAfterMenuDismiss called')} // tslint:enable:jsx-no-lambda /> <Dropdown label="Select the first day of the week" options={[ { text: 'Sunday', key: DayOfWeek[DayOfWeek.Sunday] }, { text: 'Monday', key: DayOfWeek[DayOfWeek.Monday] }, { text: 'Tuesday', key: DayOfWeek[DayOfWeek.Tuesday] }, { text: 'Wednesday', key: DayOfWeek[DayOfWeek.Wednesday] }, { text: 'Thursday', key: DayOfWeek[DayOfWeek.Thursday] }, { text: 'Friday', key: DayOfWeek[DayOfWeek.Friday] }, { text: 'Saturday', key: DayOfWeek[DayOfWeek.Saturday] } ]} selectedKey={DayOfWeek[firstDayOfWeek!]} onChange={this._onDropdownChange} /> </div> ); } private _onDropdownChange = (event: React.FormEvent<HTMLDivElement>, option: IDropdownOption): void => { this.setState({ firstDayOfWeek: (DayOfWeek as any)[option.key] }); }; } ReactDOM.render(<DatePickerBasicExample />, document.getElementById('content'));