UNPKG

7.89 kBTypeScriptView Raw
1import * as React from 'react';
2import { DayOfWeek, FirstWeekOfYear } from '@fluentui/date-time-utilities';
3import type { ICalendarProps } from '../../Calendar';
4import type { ICalendarStrings, IDateFormatting } from '@fluentui/date-time-utilities';
5import type { IStyle, ITheme } from '@fluentui/style-utilities';
6import type { IRefObject, IBaseProps, IStyleFunctionOrObject, IComponentAs } from '@fluentui/utilities';
7import type { ICalloutProps } from '../../Callout';
8import type { ITextFieldProps } from '../../TextField';
9/**
10 * {@docCategory DatePicker}
11 */
12export interface IDatePicker {
13 /** Sets focus to the text field */
14 focus(): void;
15 /** Reset the state of the picker to the default */
16 reset(): void;
17 /** Open the datepicker callout */
18 showDatePickerPopup(): void;
19}
20/**
21 * {@docCategory DatePicker}
22 */
23export interface IDatePickerProps extends IBaseProps<IDatePicker>, React.HTMLAttributes<HTMLElement>, React.RefAttributes<HTMLDivElement> {
24 /**
25 * Optional callback to access the IDatePicker interface. Use this instead of ref for accessing
26 * the public methods and properties of the component.
27 */
28 componentRef?: IRefObject<IDatePicker>;
29 /**
30 * Call to provide customized styling that will layer on top of the variant rules.
31 */
32 styles?: IStyleFunctionOrObject<IDatePickerStyleProps, IDatePickerStyles>;
33 /**
34 * Theme provided by High-Order Component.
35 */
36 theme?: ITheme;
37 /**
38 * Pass callout props to callout component
39 */
40 calloutProps?: ICalloutProps;
41 /**
42 * Pass calendar props to calendar component
43 */
44 calendarProps?: ICalendarProps;
45 /**
46 * Pass textField props to textField component.
47 * Prop name is "textField" for compatibility with upcoming slots work.
48 */
49 textField?: ITextFieldProps;
50 /**
51 * Custom Calendar to be used for date picking
52 */
53 calendarAs?: IComponentAs<ICalendarProps>;
54 /**
55 * Callback issued when a date is selected
56 */
57 onSelectDate?: (date: Date | null | undefined) => void;
58 /**
59 * Label for the DatePicker
60 */
61 label?: string;
62 /**
63 * Whether the DatePicker is a required field or not
64 * @defaultvalue false
65 */
66 isRequired?: boolean;
67 /**
68 * Disabled state of the DatePicker.
69 * @defaultvalue false
70 */
71 disabled?: boolean;
72 /**
73 * Aria Label for TextField of the DatePicker for screen reader users.
74 */
75 ariaLabel?: string;
76 /**
77 * Whether or not the Textfield of the DatePicker is underlined.
78 * @defaultvalue false
79 */
80 underlined?: boolean;
81 /**
82 * Aria label for date picker popup for screen reader users.
83 * @defaultvalue Calendar
84 */
85 pickerAriaLabel?: string;
86 /**
87 * Whether the month picker is shown beside the day picker or hidden.
88 * @defaultvalue true
89 */
90 isMonthPickerVisible?: boolean;
91 /**
92 * Show month picker on top of date picker when visible.
93 * @defaultvalue false
94 */
95 showMonthPickerAsOverlay?: boolean;
96 /**
97 * Whether the DatePicker allows input a date string directly or not
98 * @defaultvalue false
99 */
100 allowTextInput?: boolean;
101 /**
102 * Whether the DatePicker should open automatically when the control is focused
103 * WARNING: setting this to false creates an accessibility violation and is not recommended
104 * @defaultvalue true
105 */
106 disableAutoFocus?: boolean;
107 /**
108 * Whether the DatePicker should open when the input is clicked
109 * @defaultvalue true
110 */
111 openOnClick?: boolean;
112 /**
113 * Placeholder text for the DatePicker
114 */
115 placeholder?: string;
116 /**
117 * Value of today. If unspecified, current time in client machine will be used.
118 */
119 today?: Date;
120 /**
121 * Default value of the DatePicker, if any
122 */
123 value?: Date;
124 /**
125 * Optional method to format the chosen date to a string to display in the DatePicker
126 * @defaultvalue date.toString()
127 */
128 formatDate?: (date?: Date) => string;
129 /**
130 * Optional method to parse the text input value to date, it is only useful when allowTextInput is set to true
131 * @defaultvalue new Date(Date.parse(dateStr))
132 */
133 parseDateFromString?: (dateStr: string) => Date | null;
134 /**
135 * The first day of the week for your locale.
136 * @defaultvalue DayOfWeek.Sunday
137 */
138 firstDayOfWeek?: DayOfWeek;
139 /**
140 * Localized strings to use in the DatePicker
141 */
142 strings?: IDatePickerStrings;
143 /**
144 * Whether the month picker should highlight the current month
145 * @defaultvalue false
146 */
147 highlightCurrentMonth?: boolean;
148 /**
149 * Whether the month picker should highlight the selected month
150 * @defaultvalue false
151 */
152 highlightSelectedMonth?: boolean;
153 /**
154 * Whether the calendar should show the week number (weeks 1 to 53) before each week row
155 * @defaultvalue false
156 */
157 showWeekNumbers?: boolean;
158 /**
159 * Defines when the first week of the year should start, FirstWeekOfYear.FirstDay,
160 * FirstWeekOfYear.FirstFullWeek or FirstWeekOfYear.FirstFourDayWeek are the possible values
161 * @defaultvalue FirstWeekOfYear.FirstFullWeek
162 */
163 firstWeekOfYear?: FirstWeekOfYear;
164 /**
165 * Whether the "Go to today" link should be shown or not
166 */
167 showGoToToday?: boolean;
168 /**
169 * Determines if the DatePicker has a border.
170 * @defaultvalue false
171 */
172 borderless?: boolean;
173 /**
174 * Optional CSS class for the DatePicker root element.
175 */
176 className?: string;
177 /**
178 * Apply additional formatting to dates, for example localized date formatting.
179 */
180 dateTimeFormatter?: IDateFormatting;
181 /**
182 * The minimum allowable date.
183 */
184 minDate?: Date;
185 /**
186 * The maximum allowable date.
187 */
188 maxDate?: Date;
189 /**
190 * The initially highlighted date.
191 */
192 initialPickerDate?: Date;
193 /**
194 * Allows all elements to be focused, including disabled ones
195 * @defaultvalue false
196 */
197 allFocusable?: boolean;
198 /**
199 * Callback that runs after DatePicker's menu (Calendar) is closed
200 */
201 onAfterMenuDismiss?: () => void;
202 /**
203 * Whether the CalendarDay close button should be shown or not.
204 */
205 showCloseButton?: boolean;
206 /**
207 * The tabIndex of the TextField
208 */
209 tabIndex?: number;
210}
211/**
212 * {@docCategory DatePicker}
213 */
214export interface IDatePickerStrings extends ICalendarStrings {
215 /**
216 * Error message to render for TextField if isRequired validation fails.
217 */
218 isRequiredErrorMessage?: string;
219 /**
220 * Error message to render for TextField if input date string parsing fails.
221 */
222 invalidInputErrorMessage?: string;
223 /**
224 * Error message to render for TextField if date boundary (minDate, maxDate) validation fails.
225 */
226 isOutOfBoundsErrorMessage?: string;
227 /**
228 * Status message to render for TextField the input date parsing fails,
229 * and the typed value is cleared and reset to the previous value.
230 * e.g. "Invalid entry `{0}`, date reset to `{1}`"
231 */
232 isResetStatusMessage?: string;
233}
234/**
235 * {@docCategory DatePicker}
236 */
237export interface IDatePickerStyleProps {
238 /**
239 * Theme provided by High-Order Component.
240 */
241 theme: ITheme;
242 /**
243 * Accept custom classNames
244 */
245 className?: string;
246 disabled?: boolean;
247 underlined?: boolean;
248 label?: boolean;
249 isDatePickerShown?: boolean;
250}
251/**
252 * {@docCategory DatePicker}
253 */
254export interface IDatePickerStyles {
255 /**
256 * Style for the root element.
257 */
258 root: IStyle;
259 textField: IStyle;
260 callout: IStyle;
261 icon: IStyle;
262 statusMessage?: IStyle;
263 wrapper?: IStyle;
264 readOnlyTextField?: IStyle;
265 readOnlyPlaceholder?: IStyle;
266}