Skip to content

Commit a89ca09

Browse files
committed
Add JSDoc documentation
1 parent 87e4098 commit a89ca09

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

packages/react-daterange-picker/src/DateRangePicker.tsx

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,265 @@ type CalendarProps = Omit<
7070
type EventProps = ReturnType<typeof makeEventProps>;
7171

7272
export type DateRangePickerProps = {
73+
/**
74+
* Automatically focuses the input on mount.
75+
*
76+
* @example true
77+
*/
7378
autoFocus?: boolean;
79+
/**
80+
* `aria-label` for the calendar button.
81+
*
82+
* @example 'Toggle calendar'
83+
*/
7484
calendarAriaLabel?: string;
85+
/**
86+
* Class name(s) that will be added along with `"react-calendar"` to the main React-Calendar `<div>` element.
87+
*
88+
* @example 'class1 class2'
89+
* @example ['class1', 'class2 class3']
90+
*/
7591
calendarClassName?: ClassName;
92+
/**
93+
* Content of the calendar button. Setting the value explicitly to `null` will hide the icon.
94+
*
95+
* @example 'Calendar'
96+
* @example <CalendarIcon />
97+
* @example CalendarIcon
98+
*/
7699
calendarIcon?: IconOrRenderFunction | null;
100+
/**
101+
* Class name(s) that will be added along with `"react-daterange-picker"` to the main React-DateRange-Picker `<div>` element.
102+
*
103+
* @example 'class1 class2'
104+
* @example ['class1', 'class2 class3']
105+
*/
77106
className?: ClassName;
107+
/**
108+
* `aria-label` for the clear button.
109+
*
110+
* @example 'Clear value'
111+
*/
78112
clearAriaLabel?: string;
113+
/**
114+
* Content of the clear button. Setting the value explicitly to `null` will hide the icon.
115+
*
116+
* @example 'Clear'
117+
* @example <ClearIcon />
118+
* @example ClearIcon
119+
*/
79120
clearIcon?: IconOrRenderFunction | null;
121+
/**
122+
* Whether to close the calendar on value selection.
123+
*
124+
* **Note**: It's recommended to use `shouldCloseCalendar` function instead.
125+
*
126+
* @default true
127+
* @example false
128+
*/
80129
closeCalendar?: boolean;
130+
/**
131+
* `data-testid` attribute for the main React-DateRange-Picker `<div>` element.
132+
*
133+
* @example 'daterange-picker'
134+
*/
81135
'data-testid'?: string;
136+
/**
137+
* `aria-label` for the day input.
138+
*
139+
* @example 'Day'
140+
*/
82141
dayAriaLabel?: string;
142+
/**
143+
* `placeholder` for the day input.
144+
*
145+
* @default '--'
146+
* @example 'dd'
147+
*/
83148
dayPlaceholder?: string;
149+
/**
150+
* When set to `true`, will remove the calendar and the button toggling its visibility.
151+
*
152+
* @default false
153+
* @example true
154+
*/
84155
disableCalendar?: boolean;
156+
/**
157+
* Whether the date range picker should be disabled.
158+
*
159+
* @default false
160+
* @example true
161+
*/
85162
disabled?: boolean;
163+
/**
164+
* Input format based on [Unicode Technical Standard #35](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). Supported values are: `y`, `M`, `MM`, `MMM`, `MMMM`, `d`, `dd`.
165+
*
166+
* **Note**: When using SSR, setting this prop may help resolving hydration errors caused by locale mismatch between server and client.
167+
*
168+
* @example 'y-MM-dd'
169+
*/
86170
format?: string;
171+
/**
172+
* `id` attribute for the main React-DateRange-Picker `<div>` element.
173+
*
174+
* @example 'daterange-picker'
175+
*/
87176
id?: string;
177+
/**
178+
* Whether the calendar should be opened.
179+
*
180+
* @default false
181+
* @example true
182+
*/
88183
isOpen?: boolean;
184+
/**
185+
* Locale that should be used by the date range picker and the calendar. Can be any [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
186+
*
187+
* **Note**: When using SSR, setting this prop may help resolving hydration errors caused by locale mismatch between server and client.
188+
*
189+
* @example 'hu-HU'
190+
*/
89191
locale?: string;
192+
/**
193+
* Maximum date that the user can select. Periods partially overlapped by maxDate will also be selectable, although React-DateRange-Picker will ensure that no later date is selected.
194+
*
195+
* @example new Date()
196+
*/
90197
maxDate?: Date;
198+
/**
199+
* The most detailed calendar view that the user shall see. View defined here also becomes the one on which clicking an item in the calendar will select a date and pass it to onChange. Can be `"month"`, `"year"`, `"decade"` or
200+
*
201+
* @default 'month'
202+
* @example 'year'
203+
*/
91204
maxDetail?: Detail;
205+
/**
206+
* Minimum date that the user can select. Periods partially overlapped by minDate will also be selectable, although React-DateRange-Picker will ensure that no earlier date is selected.
207+
*
208+
* @example new Date()
209+
*/
92210
minDate?: Date;
211+
/**
212+
* `aria-label` for the month input.
213+
*
214+
* @example 'Month'
215+
*/
93216
monthAriaLabel?: string;
217+
/**
218+
* `placeholder` for the month input.
219+
*
220+
* @default '--'
221+
* @example 'mm'
222+
*/
94223
monthPlaceholder?: string;
224+
/**
225+
* Input name.
226+
*
227+
* @default 'daterange'
228+
*/
95229
name?: string;
230+
/**
231+
* `aria-label` for the native date input.
232+
*
233+
* @example 'Date'
234+
*/
96235
nativeInputAriaLabel?: string;
236+
/**
237+
* Function called when the calendar closes.
238+
*
239+
* @example () => alert('Calendar closed')
240+
*/
97241
onCalendarClose?: () => void;
242+
/**
243+
* Function called when the calendar opens.
244+
*
245+
* @example () => alert('Calendar opened')
246+
*/
98247
onCalendarOpen?: () => void;
248+
/**
249+
* Function called when the user picks a valid date. If any of the fields were excluded using custom `format`, `new Date(y, 0, 1, 0, 0, 0)`, where `y` is the current year, is going to serve as a "base".
250+
*
251+
* @example (value) => alert('New date is: ', value)
252+
*/
99253
onChange?: (value: Value) => void;
254+
/**
255+
* Function called when the user focuses an input.
256+
*
257+
* @example (event) => alert('Focused input: ', event.target.name)
258+
*/
100259
onFocus?: (event: React.FocusEvent<HTMLDivElement>) => void;
260+
/**
261+
* Function called when the user picks an invalid date.
262+
*
263+
* @example () => alert('Invalid date')
264+
*/
101265
onInvalidChange?: () => void;
266+
/**
267+
* Whether to open the calendar on input focus. **Note**: It's recommended to use `shouldOpenCalendar` function instead.
268+
*
269+
* @default true
270+
* @example false
271+
*/
102272
openCalendarOnFocus?: boolean;
273+
/**
274+
* Element to render the calendar in using portal.
275+
*
276+
* @example document.getElementById('my-div')
277+
*/
103278
portalContainer?: HTMLElement | null;
279+
/**
280+
* Divider between date inputs.
281+
*
282+
* @default '–'
283+
* @example ' to '
284+
*/
104285
rangeDivider?: React.ReactNode;
286+
/**
287+
* Whether date input should be required.
288+
*
289+
* @default false
290+
* @example true
291+
*/
105292
required?: boolean;
293+
/**
294+
* Function called before the calendar closes. `reason` can be `"buttonClick"`, `"escape"`, `"outsideAction"`, or `"select"`. If it returns `false`, the calendar will not close.
295+
*
296+
* @example ({ reason }) => reason !== 'outsideAction'
297+
*/
106298
shouldCloseCalendar?: (props: { reason: CloseReason }) => boolean;
299+
/**
300+
* Function called before the calendar opens. `reason` can be `"buttonClick"` or `"focus"`. If it returns `false`, the calendar will not open.
301+
*
302+
* @example ({ reason }) => reason !== 'focus'
303+
*/
107304
shouldOpenCalendar?: (props: { reason: OpenReason }) => boolean;
305+
/**
306+
* Whether leading zeros should be rendered in date inputs.
307+
*
308+
* @default false
309+
* @example true
310+
*/
108311
showLeadingZeros?: boolean;
312+
/**
313+
* Input value.
314+
*
315+
* @example new Date(2017, 0, 1)
316+
* @example [new Date(2017, 0, 1), new Date(2017, 7, 1)]
317+
* @example ['2017-01-01', '2017-08-01']
318+
*/
109319
value?: LooseValue;
320+
/**
321+
* `aria-label` for the year input.
322+
*
323+
* @example 'Year'
324+
*/
110325
yearAriaLabel?: string;
326+
/**
327+
* `placeholder` for the year input.
328+
*
329+
* @default '----'
330+
* @example 'yyyy'
331+
*/
111332
yearPlaceholder?: string;
112333
} & CalendarProps &
113334
Omit<EventProps, 'onChange' | 'onFocus'>;

0 commit comments

Comments
 (0)