@mirohq/design-system-calendar 0.1.0-calendar-component.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js ADDED
@@ -0,0 +1,683 @@
1
+ import { Flex as Flex$1, mergeRefs as mergeRefs$1, Primitive as Primitive$1 } from '@mirohq/design-system';
2
+ import { styled } from '@mirohq/design-system-stitches';
3
+ import * as React from 'react';
4
+ import React__default, { useRef, useCallback } from 'react';
5
+ import { useDateSegment, useLocale, useDateField, useButton, useFocusRing, mergeProps, useDialog, usePopover, Overlay, DismissButton, useDateFormatter, useCalendarCell, useCalendarGrid, useDateRangePicker, useRangeCalendar, useCalendar, useDatePicker } from 'react-aria';
6
+ import { createCalendar, isSameMonth, isSameDay, getDayOfWeek, isWeekend, isToday, getLocalTimeZone, getWeeksInMonth } from '@internationalized/date';
7
+ import { useDateFieldState, useDateRangePickerState, useRangeCalendarState, useCalendarState, useDatePickerState } from 'react-stately';
8
+ import { Flex } from '@mirohq/design-system-flex';
9
+ import { IconChevronLeft, IconChevronRight, IconCalendarBlank } from '@mirohq/design-system-icons';
10
+ import { mergeRefs } from '@mirohq/design-system-utils';
11
+ import { Button as Button$1 } from '@mirohq/design-system-button';
12
+ import { Primitive } from '@mirohq/design-system-primitive';
13
+
14
+ const StyledDataSegment = styled(Primitive.div, {
15
+ color: "$text-neutrals-subtle",
16
+ "&[data-value]": {
17
+ color: "$text-neutrals"
18
+ },
19
+ "& span": {
20
+ pointerEvents: "none",
21
+ "&[data-placeholder]": {
22
+ display: "none",
23
+ height: "0",
24
+ color: "$text-neutrals-subtle"
25
+ }
26
+ }
27
+ });
28
+
29
+ const FieldDateSegment = React__default.forwardRef(({ segment, state }) => {
30
+ const ref = useRef(null);
31
+ const { segmentProps } = useDateSegment(segment, state, ref);
32
+ return /* @__PURE__ */ React__default.createElement(StyledDataSegment, {
33
+ ...segmentProps,
34
+ ref,
35
+ "data-value": state.value !== null ? "" : void 0
36
+ }, /* @__PURE__ */ React__default.createElement("span", {
37
+ "aria-hidden": "true",
38
+ "data-placeholder": !segment.isPlaceholder ? "" : void 0
39
+ }, segment.placeholder), segment.isPlaceholder ? "" : segment.text);
40
+ });
41
+ const TextField = (props) => {
42
+ const ref = useRef(null);
43
+ const { locale } = useLocale();
44
+ const state = useDateFieldState({
45
+ ...props,
46
+ isReadOnly: true,
47
+ locale,
48
+ createCalendar
49
+ });
50
+ const { fieldProps } = useDateField(props, state, ref);
51
+ return /* @__PURE__ */ React__default.createElement(Flex, {
52
+ ...fieldProps,
53
+ ref
54
+ }, state.segments.map((segment, i) => /* @__PURE__ */ React__default.createElement(FieldDateSegment, {
55
+ key: i,
56
+ segment,
57
+ state
58
+ })));
59
+ };
60
+
61
+ const StyledButton = styled(Primitive.button, {
62
+ padding: "0",
63
+ background: "transparent",
64
+ border: "none",
65
+ cursor: "pointer",
66
+ color: "$text-neutrals",
67
+ "&[disabled]": {
68
+ cursor: "not-allowed"
69
+ }
70
+ });
71
+ const StyledFieldButton = styled(Primitive.button, {
72
+ padding: "0",
73
+ background: "transparent",
74
+ border: "none",
75
+ cursor: "pointer",
76
+ square: "28px",
77
+ "&[disabled]": {
78
+ cursor: "not-allowed"
79
+ },
80
+ "& svg": {
81
+ color: "$text-neutrals-subtle",
82
+ square: "22px"
83
+ },
84
+ "&[data-custom]": {
85
+ width: "100%",
86
+ height: "unset"
87
+ }
88
+ });
89
+
90
+ const Button = React__default.forwardRef((props, forwardRef) => {
91
+ const ref = useRef(null);
92
+ const { buttonProps } = useButton(props, ref);
93
+ const { focusProps } = useFocusRing();
94
+ const { children } = props;
95
+ const refs = mergeRefs([ref, forwardRef]);
96
+ return /* @__PURE__ */ React__default.createElement(StyledButton, {
97
+ ...mergeProps(buttonProps, focusProps),
98
+ ref: refs
99
+ }, children);
100
+ });
101
+ const FieldButton = (props) => {
102
+ const ref = useRef(null);
103
+ const { buttonProps } = useButton(props, ref);
104
+ const { customButton = false, children } = props;
105
+ return /* @__PURE__ */ React__default.createElement(StyledFieldButton, {
106
+ "data-custom": customButton ? "" : void 0,
107
+ ...buttonProps,
108
+ ref
109
+ }, children);
110
+ };
111
+
112
+ const Popover = (props) => {
113
+ const ref = React.useRef(null);
114
+ const { state, children } = props;
115
+ const { dialogProps } = useDialog(props, ref);
116
+ const { popoverProps, underlayProps } = usePopover(
117
+ {
118
+ ...props,
119
+ popoverRef: ref
120
+ },
121
+ state
122
+ );
123
+ return /* @__PURE__ */ React.createElement(Overlay, null, /* @__PURE__ */ React.createElement("div", {
124
+ ...underlayProps
125
+ }), /* @__PURE__ */ React.createElement("div", {
126
+ ...popoverProps,
127
+ ref
128
+ }, /* @__PURE__ */ React.createElement(DismissButton, {
129
+ onDismiss: state.close
130
+ }), /* @__PURE__ */ React.createElement("div", {
131
+ ...dialogProps,
132
+ ref
133
+ }, children), /* @__PURE__ */ React.createElement(DismissButton, {
134
+ onDismiss: state.close
135
+ })));
136
+ };
137
+
138
+ const StyledRangePicker = styled(Primitive.div, {
139
+ display: "inline-block"
140
+ });
141
+ const StyledRangePickerInput$1 = styled(Primitive.div, {
142
+ display: "flex",
143
+ alignItems: "center",
144
+ padding: "$100",
145
+ paddingLeft: "$150",
146
+ border: "1px solid $border-neutrals",
147
+ borderRadius: "$50",
148
+ background: "$background-neutrals",
149
+ color: "$text-neutrals",
150
+ minWidth: "230px",
151
+ "&:hover": {
152
+ border: "1px solid $border-primary-hover",
153
+ cursor: "pointer"
154
+ }
155
+ });
156
+ const StyledRangePickerInputContent$1 = styled(Primitive.div, {
157
+ display: "flex",
158
+ alignItems: "center",
159
+ fontSize: "$200",
160
+ lineHeight: "24px",
161
+ width: "100%"
162
+ });
163
+
164
+ const StyledPredefinedRanges = styled(Primitive.div, {
165
+ display: "flex",
166
+ flexDirection: "column",
167
+ borderRight: "1px solid $border-neutrals",
168
+ padding: "$300 $200 0 $200",
169
+ "& button": {
170
+ background: "transparent",
171
+ border: "none",
172
+ fontSize: "$200",
173
+ padding: "0 0 0 $100",
174
+ textAlign: "left",
175
+ lineHeight: "24px",
176
+ color: "$text-neutrals",
177
+ marginBottom: "$150",
178
+ borderRadius: "$50",
179
+ minWidth: "125px",
180
+ cursor: "pointer",
181
+ "&:hover": {
182
+ backgroundColor: "$background-primary-prominent-hover",
183
+ color: "$text-primary-inverted",
184
+ fontWeight: "600"
185
+ }
186
+ }
187
+ });
188
+
189
+ const PredefinedRanges = React__default.forwardRef(({ range, onClick }, forwardRef) => /* @__PURE__ */ React__default.createElement(StyledPredefinedRanges, {
190
+ ref: forwardRef
191
+ }, range == null ? void 0 : range.map((date, i) => /* @__PURE__ */ React__default.createElement("button", {
192
+ key: i,
193
+ type: "button",
194
+ onClick: () => onClick(date)
195
+ }, date.label))));
196
+
197
+ const StyledBody = styled(Primitive.div, {
198
+ display: "inline-block",
199
+ background: "$background-neutrals"
200
+ });
201
+ const StyledBodyContent = styled(Flex$1, {
202
+ margin: "0 auto",
203
+ boxShadow: "$100",
204
+ background: "$background-neutrals",
205
+ borderRadius: "$100"
206
+ });
207
+ const StyledGridContent = styled(Flex$1, {
208
+ paddingBottom: "$200",
209
+ "& [data-left-calendar]": {
210
+ paddingLeft: "$200",
211
+ paddingRight: "$100"
212
+ },
213
+ "& [data-right-calendar]": {
214
+ paddingLeft: "$100",
215
+ paddingRight: "$200"
216
+ }
217
+ });
218
+ const StyledBodyContentLeft = styled(Primitive.div, {
219
+ paddingLeft: "$200",
220
+ paddingRight: "$100"
221
+ });
222
+ const StyledBodyContentRight = styled(Primitive.div, {
223
+ paddingLeft: "$100",
224
+ paddingRight: "$200"
225
+ });
226
+ const StyledClearContent = styled(Primitive.div, {
227
+ padding: "$200",
228
+ borderTop: "1px solid $border-neutrals"
229
+ });
230
+
231
+ const StyledHeaderTitle = styled(Flex$1, {
232
+ justifyContent: "center",
233
+ flex: "3",
234
+ color: "$text-neutrals"
235
+ });
236
+ const StyledHeader = styled(Flex$1, {
237
+ padding: "0 $200",
238
+ color: "$text-neutrals"
239
+ });
240
+
241
+ const Header = ({
242
+ state,
243
+ prevButtonProps,
244
+ nextButtonProps,
245
+ visibleMonths
246
+ }) => {
247
+ const monthDateFormatter = useDateFormatter({
248
+ month: "long",
249
+ year: "numeric",
250
+ timeZone: state.timeZone
251
+ });
252
+ return /* @__PURE__ */ React__default.createElement(StyledHeader, null, /* @__PURE__ */ React__default.createElement(Button, {
253
+ ...prevButtonProps
254
+ }, /* @__PURE__ */ React__default.createElement(IconChevronLeft, null)), /* @__PURE__ */ React__default.createElement(StyledHeaderTitle, null, /* @__PURE__ */ React__default.createElement("h2", null, monthDateFormatter.format(
255
+ state.visibleRange.start.toDate(state.timeZone)
256
+ ))), visibleMonths !== void 0 && /* @__PURE__ */ React__default.createElement(StyledHeaderTitle, null, /* @__PURE__ */ React__default.createElement("h2", null, monthDateFormatter.format(
257
+ state.visibleRange.start.add({ months: 1 }).toDate(state.timeZone)
258
+ ))), /* @__PURE__ */ React__default.createElement(Button, {
259
+ ...nextButtonProps
260
+ }, /* @__PURE__ */ React__default.createElement(IconChevronRight, null)));
261
+ };
262
+
263
+ const StyledCellContent = styled(Primitive.div, {
264
+ square: "28px",
265
+ display: "flex",
266
+ alignItems: "center",
267
+ justifyContent: "center",
268
+ borderRadius: "$50",
269
+ color: "$text-neutrals",
270
+ "&[data-today]": {
271
+ color: "$text-primary"
272
+ },
273
+ "&[data-weekend]": {
274
+ color: "$text-neutrals-subtle"
275
+ },
276
+ "&[data-selected-middle]": {
277
+ color: "$text-neutrals"
278
+ },
279
+ "&[data-selection]": {
280
+ borderRadius: "$50",
281
+ background: "$background-primary-prominent-selected",
282
+ color: "$text-primary-inverted",
283
+ fontWeight: "600"
284
+ },
285
+ "&[data-disabled]": {
286
+ textDecoration: "line-through",
287
+ color: "$text-neutrals-disabled"
288
+ }
289
+ });
290
+ const StyledCell = styled(Primitive.div, {
291
+ square: "36px",
292
+ cursor: "pointer",
293
+ display: "flex",
294
+ alignItems: "center",
295
+ justifyContent: "center",
296
+ "&:hover": {
297
+ background: "$background-primary-subtle-hover",
298
+ [`& ${StyledCellContent}`]: {
299
+ background: "$background-primary-prominent-hover",
300
+ color: "$text-primary-inverted"
301
+ }
302
+ },
303
+ "&[data-selected]": {
304
+ background: "$background-primary-subtle-hover"
305
+ },
306
+ "&[data-selection-start]": {
307
+ borderBottomLeftRadius: "$lg",
308
+ borderTopLeftRadius: "$lg"
309
+ },
310
+ "&[data-selection-end]": {
311
+ borderBottomRightRadius: "$lg",
312
+ borderTopRightRadius: "$lg"
313
+ },
314
+ "&[data-hidden]": {
315
+ display: "none"
316
+ },
317
+ "&[data-disabled]": {
318
+ cursor: "not-allowed",
319
+ "&:hover": {
320
+ background: "transparent",
321
+ [`& ${StyledCellContent}`]: {
322
+ background: "transparent",
323
+ color: "$text-neutrals-disabled"
324
+ }
325
+ }
326
+ }
327
+ });
328
+
329
+ const Cell = React__default.forwardRef(
330
+ (props, forwardRef) => {
331
+ const { state, date, currentMonth } = props;
332
+ const ref = useRef(null);
333
+ const { cellProps, buttonProps, isSelected, isDisabled, formattedDate } = useCalendarCell({ date }, state, ref);
334
+ const isOutsideMonth = !isSameMonth(currentMonth, date);
335
+ const isSelectionStart = state.highlightedRange !== void 0 && state.highlightedRange !== null ? isSameDay(date, state.highlightedRange.start) : isSelected;
336
+ const isSelectionEnd = state.highlightedRange !== void 0 && state.highlightedRange !== null ? isSameDay(date, state.highlightedRange.end) : isSelected;
337
+ const { locale } = useLocale();
338
+ const dayOfWeek = getDayOfWeek(date, locale);
339
+ const isWeekendDay = isWeekend(date, locale);
340
+ const isRoundedLeft = isSelected && (isSelectionStart || dayOfWeek === 0 || date.day === 1);
341
+ const isRoundedRight = isSelected && (isSelectionEnd || dayOfWeek === 6 || date.day === date.calendar.getDaysInMonth(date));
342
+ const { focusProps } = useFocusRing();
343
+ return /* @__PURE__ */ React__default.createElement("td", {
344
+ ...cellProps
345
+ }, /* @__PURE__ */ React__default.createElement(StyledCell, {
346
+ ...mergeProps(buttonProps, focusProps),
347
+ ref: forwardRef,
348
+ "data-selected": isSelected ? "" : void 0,
349
+ "data-selection-start": isRoundedLeft ? "" : void 0,
350
+ "data-selection-end": isRoundedRight ? "" : void 0,
351
+ "data-disabled": isDisabled ? "" : void 0,
352
+ "data-hidden": isOutsideMonth ? "" : void 0
353
+ }, /* @__PURE__ */ React__default.createElement(StyledCellContent, {
354
+ "data-selected-middle": isSelected && !(isSelectionStart || isSelectionEnd) ? "" : void 0,
355
+ "data-selection": isSelectionStart || isSelectionEnd ? "" : void 0,
356
+ "data-disabled": isDisabled ? "" : void 0,
357
+ "data-today": isToday(date, getLocalTimeZone()) ? "" : void 0,
358
+ "data-weekend": isWeekendDay ? "" : void 0
359
+ }, formattedDate)));
360
+ }
361
+ );
362
+
363
+ const StyledGrid = styled(Primitive.table, {
364
+ borderCollapse: "separate",
365
+ borderSpacing: " 0 $50"
366
+ });
367
+ const StyledDays = styled(Primitive.th, {
368
+ square: "36px",
369
+ color: "$text-neutrals"
370
+ });
371
+
372
+ const Grid = React__default.forwardRef(
373
+ (props, forwardRef) => {
374
+ const { locale } = useLocale();
375
+ const { state, offset = {} } = props;
376
+ const startDate = state.visibleRange.start.add(offset);
377
+ const { gridProps, headerProps, weekDays } = useCalendarGrid(
378
+ props,
379
+ state
380
+ );
381
+ const weeksInMonth = getWeeksInMonth(startDate, locale);
382
+ return /* @__PURE__ */ React__default.createElement(StyledGrid, {
383
+ ref: forwardRef,
384
+ ...gridProps,
385
+ cellPadding: "0"
386
+ }, /* @__PURE__ */ React__default.createElement("thead", {
387
+ ...headerProps
388
+ }, /* @__PURE__ */ React__default.createElement("tr", null, weekDays.map((day, i) => /* @__PURE__ */ React__default.createElement(StyledDays, {
389
+ key: i
390
+ }, /* @__PURE__ */ React__default.createElement("div", null, day))))), /* @__PURE__ */ React__default.createElement("tbody", null, Array.from(Array(weeksInMonth).keys()).map((weekIndex) => /* @__PURE__ */ React__default.createElement("tr", {
391
+ key: weekIndex
392
+ }, state.getDatesInWeek(weekIndex, startDate).map(
393
+ (date, i) => date !== null ? /* @__PURE__ */ React__default.createElement(Cell, {
394
+ key: i,
395
+ state,
396
+ date,
397
+ currentMonth: startDate
398
+ }) : /* @__PURE__ */ React__default.createElement("td", {
399
+ key: i
400
+ })
401
+ )))));
402
+ }
403
+ );
404
+
405
+ const RangePicker = React__default.forwardRef((props, forwardRef) => {
406
+ const {
407
+ predefinedRanges,
408
+ minDate,
409
+ maxDate,
410
+ visibleMonths,
411
+ clearString,
412
+ children,
413
+ defaultOpen,
414
+ onClear
415
+ } = props;
416
+ const state = useDateRangePickerState(
417
+ props
418
+ );
419
+ const ref = useRef(null);
420
+ const { locale } = useLocale();
421
+ const { groupProps, startFieldProps, endFieldProps, buttonProps } = useDateRangePicker(
422
+ {
423
+ ...props,
424
+ isOpen: defaultOpen
425
+ },
426
+ state,
427
+ ref
428
+ );
429
+ const change = (value) => {
430
+ state.setValue(value);
431
+ state.close();
432
+ };
433
+ const rangeState = useRangeCalendarState({
434
+ ...props,
435
+ visibleDuration: visibleMonths,
436
+ minValue: minDate,
437
+ maxValue: maxDate,
438
+ autoFocus: true,
439
+ onFocusChange: focus,
440
+ onChange: change,
441
+ locale,
442
+ createCalendar
443
+ });
444
+ const { calendarProps, prevButtonProps, nextButtonProps } = useRangeCalendar(
445
+ props,
446
+ rangeState,
447
+ ref
448
+ );
449
+ const rangeClick = useCallback(
450
+ (selectedRange) => {
451
+ if (selectedRange.range !== void 0) {
452
+ state.setValue(selectedRange.range);
453
+ rangeState.setValue(selectedRange.range);
454
+ }
455
+ },
456
+ [rangeState, state]
457
+ );
458
+ const clear = () => {
459
+ state.setValue({ start: null, end: null });
460
+ if (onClear !== void 0) {
461
+ onClear();
462
+ state.close();
463
+ }
464
+ };
465
+ const refs = mergeRefs([ref, forwardRef]);
466
+ return /* @__PURE__ */ React__default.createElement(StyledRangePicker, {
467
+ ref: refs
468
+ }, children === void 0 && /* @__PURE__ */ React__default.createElement(StyledRangePickerInput$1, {
469
+ ...groupProps,
470
+ ref
471
+ }, /* @__PURE__ */ React__default.createElement(StyledRangePickerInputContent$1, null, /* @__PURE__ */ React__default.createElement(TextField, {
472
+ ...startFieldProps
473
+ }), /* @__PURE__ */ React__default.createElement("span", {
474
+ "aria-hidden": "true"
475
+ }, "\u2013"), /* @__PURE__ */ React__default.createElement(TextField, {
476
+ ...endFieldProps
477
+ }), /* @__PURE__ */ React__default.createElement(Flex, {
478
+ css: { marginLeft: "auto" }
479
+ }, /* @__PURE__ */ React__default.createElement(FieldButton, {
480
+ ...buttonProps
481
+ }, /* @__PURE__ */ React__default.createElement(IconCalendarBlank, null))))), children !== null && /* @__PURE__ */ React__default.createElement("div", {
482
+ ...groupProps,
483
+ ref
484
+ }, /* @__PURE__ */ React__default.createElement(FieldButton, {
485
+ ...buttonProps,
486
+ customButton: true
487
+ }, children)), state.isOpen && /* @__PURE__ */ React__default.createElement(Popover, {
488
+ triggerRef: ref,
489
+ state,
490
+ placement: "bottom start"
491
+ }, /* @__PURE__ */ React__default.createElement(StyledBody, {
492
+ ref: refs
493
+ }, /* @__PURE__ */ React__default.createElement(StyledBodyContent, null, predefinedRanges !== void 0 && /* @__PURE__ */ React__default.createElement(PredefinedRanges, {
494
+ range: predefinedRanges,
495
+ onClick: rangeClick
496
+ }), /* @__PURE__ */ React__default.createElement(Flex, {
497
+ direction: "column",
498
+ ...calendarProps
499
+ }, /* @__PURE__ */ React__default.createElement(Header, {
500
+ state: rangeState,
501
+ prevButtonProps,
502
+ nextButtonProps,
503
+ visibleMonths
504
+ }), /* @__PURE__ */ React__default.createElement(StyledGridContent, null, /* @__PURE__ */ React__default.createElement(StyledBodyContentLeft, null, /* @__PURE__ */ React__default.createElement(Grid, {
505
+ state: rangeState
506
+ })), visibleMonths !== void 0 && /* @__PURE__ */ React__default.createElement(StyledBodyContentRight, null, /* @__PURE__ */ React__default.createElement(Grid, {
507
+ onChange: change,
508
+ state: rangeState,
509
+ offset: { months: 1 }
510
+ }))), onClear !== void 0 && /* @__PURE__ */ React__default.createElement(StyledClearContent, null, /* @__PURE__ */ React__default.createElement(Button$1, {
511
+ size: "medium",
512
+ type: "button",
513
+ onClick: clear,
514
+ disabled: rangeState.value === null
515
+ }, clearString)))))));
516
+ });
517
+
518
+ const StyledRangePickerInput = styled(Primitive.div, {
519
+ display: "flex",
520
+ alignItems: "center",
521
+ padding: "$100",
522
+ paddingLeft: "$150",
523
+ border: "1px solid $border-neutrals",
524
+ borderRadius: "$50",
525
+ background: "$background-neutrals",
526
+ color: "$text-neutrals",
527
+ minWidth: "230px",
528
+ "&:hover": {
529
+ border: "1px solid $border-primary-hover",
530
+ cursor: "pointer"
531
+ }
532
+ });
533
+ const StyledRangePickerInputContent = styled(Primitive.div, {
534
+ display: "flex",
535
+ alignItems: "center",
536
+ fontSize: "$200",
537
+ lineHeight: "24px",
538
+ width: "100%"
539
+ });
540
+ const StyledDatePicker = styled(Primitive.div, {
541
+ display: "inline-block"
542
+ });
543
+
544
+ const DatePickerBody = React__default.forwardRef((props, forwardRef) => {
545
+ const {
546
+ predefinedRanges,
547
+ visibleMonths,
548
+ onClear,
549
+ minDate,
550
+ maxDate,
551
+ clearString
552
+ } = props;
553
+ const { locale } = useLocale();
554
+ const state = useCalendarState({
555
+ ...props,
556
+ visibleDuration: visibleMonths,
557
+ minValue: minDate,
558
+ maxValue: maxDate,
559
+ locale,
560
+ createCalendar
561
+ });
562
+ const ref = useRef(null);
563
+ const { calendarProps, prevButtonProps, nextButtonProps } = useCalendar(
564
+ props,
565
+ state
566
+ );
567
+ const dateClick = useCallback(
568
+ (selectedRange) => {
569
+ if (selectedRange.date !== void 0)
570
+ state.setValue(selectedRange.date);
571
+ },
572
+ [state]
573
+ );
574
+ const refs = mergeRefs([ref, forwardRef]);
575
+ return /* @__PURE__ */ React__default.createElement(StyledBody, {
576
+ ref: refs
577
+ }, /* @__PURE__ */ React__default.createElement(StyledBodyContent, {
578
+ ...calendarProps
579
+ }, predefinedRanges !== void 0 && /* @__PURE__ */ React__default.createElement(PredefinedRanges, {
580
+ range: predefinedRanges,
581
+ onClick: dateClick
582
+ }), /* @__PURE__ */ React__default.createElement(Flex$1, {
583
+ direction: "column"
584
+ }, /* @__PURE__ */ React__default.createElement(Header, {
585
+ state,
586
+ prevButtonProps,
587
+ nextButtonProps,
588
+ visibleMonths
589
+ }), /* @__PURE__ */ React__default.createElement(StyledGridContent, null, /* @__PURE__ */ React__default.createElement(StyledBodyContentLeft, null, /* @__PURE__ */ React__default.createElement(Grid, {
590
+ state
591
+ })), visibleMonths !== void 0 && /* @__PURE__ */ React__default.createElement(StyledBodyContentRight, null, /* @__PURE__ */ React__default.createElement(Grid, {
592
+ state,
593
+ offset: { months: 1 }
594
+ }))), onClear !== void 0 && /* @__PURE__ */ React__default.createElement(StyledClearContent, null, /* @__PURE__ */ React__default.createElement(Button$1, {
595
+ size: "medium",
596
+ onClick: onClear,
597
+ disabled: state.value === null
598
+ }, clearString)))));
599
+ });
600
+
601
+ const DatePicker = React__default.forwardRef((props, forwardRef) => {
602
+ const {
603
+ picker,
604
+ predefinedRanges,
605
+ visibleMonths,
606
+ defaultValue,
607
+ minDate,
608
+ maxDate,
609
+ children,
610
+ clearString,
611
+ defaultOpen,
612
+ onClear
613
+ } = props;
614
+ const ref = useRef(null);
615
+ const refs = mergeRefs$1([ref, forwardRef]);
616
+ const state = useDatePickerState(props);
617
+ const { groupProps, fieldProps, buttonProps, calendarProps } = useDatePicker(
618
+ { ...props, isOpen: defaultOpen },
619
+ state,
620
+ ref
621
+ );
622
+ const clearState = () => {
623
+ state.setValue(null);
624
+ if (onClear !== void 0) {
625
+ onClear();
626
+ }
627
+ };
628
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, picker === "single" ? /* @__PURE__ */ React__default.createElement(StyledDatePicker, {
629
+ ref: refs
630
+ }, children === void 0 && /* @__PURE__ */ React__default.createElement(StyledRangePickerInput, {
631
+ ...groupProps,
632
+ ref
633
+ }, /* @__PURE__ */ React__default.createElement(StyledRangePickerInputContent, null, /* @__PURE__ */ React__default.createElement(TextField, {
634
+ ...fieldProps
635
+ }), /* @__PURE__ */ React__default.createElement(Flex, {
636
+ css: { marginLeft: "auto" }
637
+ }, /* @__PURE__ */ React__default.createElement(FieldButton, {
638
+ ...buttonProps
639
+ }, /* @__PURE__ */ React__default.createElement(IconCalendarBlank, null))))), children !== void 0 && /* @__PURE__ */ React__default.createElement("div", {
640
+ ...groupProps,
641
+ ref
642
+ }, /* @__PURE__ */ React__default.createElement(FieldButton, {
643
+ ...buttonProps,
644
+ customButton: true
645
+ }, children)), state.isOpen && /* @__PURE__ */ React__default.createElement(Popover, {
646
+ triggerRef: ref,
647
+ state,
648
+ placement: "bottom start"
649
+ }, /* @__PURE__ */ React__default.createElement(DatePickerBody, {
650
+ ...calendarProps,
651
+ defaultValue,
652
+ predefinedRanges,
653
+ visibleMonths,
654
+ onClear: clearState,
655
+ minDate,
656
+ maxDate,
657
+ clearString
658
+ }))) : /* @__PURE__ */ React__default.createElement(DatePickerBody, {
659
+ ...calendarProps,
660
+ defaultValue,
661
+ predefinedRanges,
662
+ visibleMonths,
663
+ onClear: onClear !== void 0 ? clearState : void 0,
664
+ minDate,
665
+ maxDate,
666
+ clearString: onClear !== void 0 ? clearString : void 0
667
+ }));
668
+ });
669
+
670
+ const StyledCalendar = styled(Primitive$1.div, {});
671
+ const Calendar = React__default.forwardRef(({ picker, defaultValue, ...props }, forwardRef) => /* @__PURE__ */ React__default.createElement(StyledCalendar, {
672
+ ref: forwardRef
673
+ }, picker === "range" ? /* @__PURE__ */ React__default.createElement(RangePicker, {
674
+ defaultValue,
675
+ ...props
676
+ }) : /* @__PURE__ */ React__default.createElement(DatePicker, {
677
+ defaultValue,
678
+ ...props,
679
+ picker
680
+ })));
681
+
682
+ export { Calendar };
683
+ //# sourceMappingURL=module.js.map