@mirohq/design-system-calendar 0.4.7 → 1.1.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/main.js +592 -574
- package/dist/main.js.map +1 -1
- package/dist/module.js +598 -580
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +287 -44
- package/package.json +19 -11
package/dist/module.js
CHANGED
|
@@ -1,146 +1,287 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { useDateRangePickerState, useRangeCalendarState, useCalendarState, useDatePickerState } from 'react-stately';
|
|
9
|
-
import { Flex } from '@mirohq/design-system-flex';
|
|
10
|
-
import { Button as Button$1 } from '@mirohq/design-system-button';
|
|
11
|
-
import { FloatingLabel } from '@mirohq/design-system-base-form';
|
|
12
|
-
import { IconChevronLeft, IconChevronRight, IconCross, IconCalendarBlank } from '@mirohq/design-system-icons';
|
|
2
|
+
import React, { createContext, useState, useMemo, useCallback, useContext, useRef, useEffect } from 'react';
|
|
3
|
+
import { useDateFormatter, useCalendarCell, useFocusRing, mergeProps, useLocale, useCalendarGrid, useCalendar, useRangeCalendar, I18nProvider } from 'react-aria';
|
|
4
|
+
import * as RadixPopover from '@radix-ui/react-popover';
|
|
5
|
+
import { Trigger as Trigger$1, Content as Content$1 } from '@radix-ui/react-popover';
|
|
6
|
+
import { useFormFieldContext, FloatingLabel } from '@mirohq/design-system-base-form';
|
|
7
|
+
import { IconCross, IconCalendarBlank, IconChevronLeft, IconChevronRight } from '@mirohq/design-system-icons';
|
|
13
8
|
import { useNewDesignLanguage } from '@mirohq/design-system-experiments';
|
|
9
|
+
import { stringAttrValue, booleanify } from '@mirohq/design-system-utils';
|
|
10
|
+
import { Primitive } from '@mirohq/design-system-primitive';
|
|
11
|
+
import { styled, theme } from '@mirohq/design-system-stitches';
|
|
14
12
|
import { textFieldStyles, actionButtonStyles } from '@mirohq/design-system-base-text-field';
|
|
15
|
-
import { focus
|
|
16
|
-
import { Tooltip } from '@mirohq/design-system-tooltip';
|
|
13
|
+
import { focus } from '@mirohq/design-system-styles';
|
|
17
14
|
import { BaseButton } from '@mirohq/design-system-base-button';
|
|
15
|
+
import { Tooltip } from '@mirohq/design-system-tooltip';
|
|
16
|
+
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
17
|
+
import { useCalendarState, useRangeCalendarState } from 'react-stately';
|
|
18
|
+
import { isSameMonth, isSameDay, isToday, getLocalTimeZone, getWeeksInMonth, createCalendar } from '@internationalized/date';
|
|
19
|
+
import { Flex } from '@mirohq/design-system-flex';
|
|
20
|
+
import { Heading } from '@mirohq/design-system-typography';
|
|
21
|
+
import { IconButton } from '@mirohq/design-system-icon-button';
|
|
22
|
+
import { Button } from '@mirohq/design-system-button';
|
|
18
23
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const StyledPlaceholder = styled(Primitive.span, {
|
|
25
|
+
...textFieldStyles.base.placeholder.old,
|
|
26
|
+
padding: "0 $50"
|
|
27
|
+
});
|
|
28
|
+
const StyledValue$1 = styled(Primitive.span, {
|
|
29
|
+
padding: "0 $50"
|
|
30
|
+
});
|
|
31
|
+
const StyledIconContainer = styled(Primitive.span, {
|
|
32
|
+
display: "flex",
|
|
33
|
+
justifyContent: "center",
|
|
34
|
+
padding: "6px",
|
|
35
|
+
color: "$text-neutrals-subtle"
|
|
36
|
+
});
|
|
37
|
+
const StyledTrigger = styled(BaseButton, {
|
|
38
|
+
display: "inline-flex",
|
|
39
|
+
gap: "$50",
|
|
40
|
+
justifyContent: "space-between",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
height: "$10",
|
|
43
|
+
padding: "0 $100",
|
|
44
|
+
minWidth: "230px",
|
|
45
|
+
...textFieldStyles.variants.idle,
|
|
46
|
+
_hover: textFieldStyles.variants.hovered,
|
|
47
|
+
'&:disabled, &[aria-disabled="true"]': {
|
|
48
|
+
...textFieldStyles.variants.disabled,
|
|
49
|
+
color: "$text-neutrals-disabled"
|
|
50
|
+
},
|
|
51
|
+
variants: {
|
|
52
|
+
v1: {
|
|
53
|
+
true: {
|
|
54
|
+
...textFieldStyles.v1.idle,
|
|
55
|
+
...focus.css(textFieldStyles.v1.focused)
|
|
56
|
+
},
|
|
57
|
+
false: {
|
|
58
|
+
...focus.css(textFieldStyles.variants.focused)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
withClearButton: {
|
|
62
|
+
true: {
|
|
63
|
+
paddingRight: "calc($100 + $400)"
|
|
64
|
+
// initial left padding + clear button width + gap
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const StyledCustomTrigger = styled(BaseButton, {
|
|
70
|
+
width: "100%",
|
|
71
|
+
height: "unset",
|
|
72
|
+
padding: "0",
|
|
73
|
+
backgroundColor: "$transparent",
|
|
74
|
+
border: "none",
|
|
75
|
+
cursor: "pointer"
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const StyledClearAction = styled(BaseButton, {
|
|
79
|
+
position: "absolute",
|
|
80
|
+
top: 0,
|
|
81
|
+
bottom: 0,
|
|
82
|
+
right: "calc($100 + 1px)",
|
|
83
|
+
// to compensate border width
|
|
84
|
+
margin: "auto",
|
|
85
|
+
...actionButtonStyles,
|
|
86
|
+
'&:disabled, &[aria-disabled="true"]': {
|
|
87
|
+
color: "$icon-neutrals-disabled"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const ClearAction = React.forwardRef(({ "aria-label": ariaLabel, label, ...restProps }, forwardRef) => /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
92
|
+
/* @__PURE__ */ jsx(Tooltip.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
93
|
+
StyledClearAction,
|
|
24
94
|
{
|
|
25
|
-
...
|
|
26
|
-
|
|
95
|
+
...restProps,
|
|
96
|
+
ref: forwardRef,
|
|
97
|
+
"aria-label": ariaLabel != null ? ariaLabel : label,
|
|
98
|
+
children: /* @__PURE__ */ jsx(IconCross, {})
|
|
99
|
+
}
|
|
100
|
+
) }),
|
|
101
|
+
/* @__PURE__ */ jsx(Tooltip.Content, { children: label })
|
|
102
|
+
] }));
|
|
103
|
+
|
|
104
|
+
const CalendarContext = createContext({});
|
|
105
|
+
const CalendarProvider = ({
|
|
106
|
+
children,
|
|
107
|
+
visibleMonths = 1,
|
|
108
|
+
value: valueProp,
|
|
109
|
+
defaultValue: defaultValueProp,
|
|
110
|
+
onValueChange,
|
|
111
|
+
open: openProp,
|
|
112
|
+
defaultOpen: defaultOpenProp,
|
|
113
|
+
onOpen,
|
|
114
|
+
onClose,
|
|
115
|
+
...restProps
|
|
116
|
+
}) => {
|
|
117
|
+
var _a;
|
|
118
|
+
const [immediateSave, setImmediateSave] = useState(false);
|
|
119
|
+
const [internalCalendarValue, setInternalCalendarValue] = useState(valueProp != null ? valueProp : defaultValueProp);
|
|
120
|
+
const visibleDuration = useMemo(
|
|
121
|
+
() => ({
|
|
122
|
+
months: visibleMonths
|
|
123
|
+
}),
|
|
124
|
+
[visibleMonths]
|
|
125
|
+
);
|
|
126
|
+
const [value, setValue] = useControllableState({
|
|
127
|
+
prop: valueProp,
|
|
128
|
+
defaultProp: defaultValueProp,
|
|
129
|
+
onChange: onValueChange
|
|
130
|
+
});
|
|
131
|
+
const [open = false, setOpen] = useControllableState({
|
|
132
|
+
prop: openProp,
|
|
133
|
+
defaultProp: defaultOpenProp,
|
|
134
|
+
onChange: (state) => {
|
|
135
|
+
if (state) {
|
|
136
|
+
onOpen == null ? void 0 : onOpen();
|
|
137
|
+
} else {
|
|
138
|
+
onClose == null ? void 0 : onClose();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const onCalendarDateClick = useCallback(
|
|
143
|
+
(value2) => {
|
|
144
|
+
if (immediateSave) {
|
|
145
|
+
setInternalCalendarValue(value2);
|
|
146
|
+
} else {
|
|
147
|
+
setValue(value2);
|
|
148
|
+
setOpen(false);
|
|
149
|
+
}
|
|
27
150
|
},
|
|
28
|
-
|
|
151
|
+
[setValue, setOpen, immediateSave, setInternalCalendarValue]
|
|
152
|
+
);
|
|
153
|
+
const onSaveClick = () => {
|
|
154
|
+
setValue(internalCalendarValue);
|
|
155
|
+
setOpen(false);
|
|
156
|
+
};
|
|
157
|
+
return /* @__PURE__ */ jsx(
|
|
158
|
+
CalendarContext.Provider,
|
|
159
|
+
{
|
|
160
|
+
value: {
|
|
161
|
+
...restProps,
|
|
162
|
+
visibleDuration,
|
|
163
|
+
value,
|
|
164
|
+
setValue,
|
|
165
|
+
open,
|
|
166
|
+
setOpen,
|
|
167
|
+
onCalendarDateClick,
|
|
168
|
+
setImmediateSave,
|
|
169
|
+
onSaveClick,
|
|
170
|
+
// value should not be undefined otherwise react-aria calendar will complain in console
|
|
171
|
+
calendarValue: (_a = immediateSave ? internalCalendarValue : value) != null ? _a : null
|
|
172
|
+
},
|
|
173
|
+
children
|
|
174
|
+
}
|
|
29
175
|
);
|
|
30
|
-
return /* @__PURE__ */ jsxs(Overlay, { children: [
|
|
31
|
-
/* @__PURE__ */ jsx("div", { ...underlayProps }),
|
|
32
|
-
/* @__PURE__ */ jsxs("div", { ...popoverProps, ref, children: [
|
|
33
|
-
/* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close }),
|
|
34
|
-
/* @__PURE__ */ jsx("div", { ...dialogProps, ref, children }),
|
|
35
|
-
/* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close })
|
|
36
|
-
] })
|
|
37
|
-
] });
|
|
38
176
|
};
|
|
177
|
+
const useCalendarContext = () => useContext(CalendarContext);
|
|
39
178
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
color: "$text-neutrals",
|
|
58
|
-
marginBottom: "$150",
|
|
59
|
-
borderRadius: "$50",
|
|
60
|
-
minWidth: "125px",
|
|
61
|
-
cursor: "pointer",
|
|
62
|
-
"&:hover": {
|
|
63
|
-
backgroundColor: "$background-primary-prominent-hover",
|
|
64
|
-
color: "$text-primary-inverted",
|
|
65
|
-
fontWeight: "600"
|
|
179
|
+
const Trigger = React.forwardRef(
|
|
180
|
+
({
|
|
181
|
+
id,
|
|
182
|
+
"aria-describedby": ariaDescribedBy,
|
|
183
|
+
placeholder,
|
|
184
|
+
asChild = false,
|
|
185
|
+
clearable = true,
|
|
186
|
+
clearLabel,
|
|
187
|
+
onClear,
|
|
188
|
+
children,
|
|
189
|
+
...restProps
|
|
190
|
+
}, forwardRef) => {
|
|
191
|
+
const [v1] = useNewDesignLanguage();
|
|
192
|
+
const { value, setValue, disabled, ariaDisabled } = useCalendarContext();
|
|
193
|
+
const { formElementId, ariaDescribedBy: formFieldContextDescribedBy } = useFormFieldContext();
|
|
194
|
+
if (asChild) {
|
|
195
|
+
return /* @__PURE__ */ jsx(Trigger$1, { ref: forwardRef, asChild: true, children: /* @__PURE__ */ jsx(StyledCustomTrigger, { asChild: true, ...restProps, children }) });
|
|
66
196
|
}
|
|
197
|
+
const onClearHandler = () => {
|
|
198
|
+
setValue(void 0);
|
|
199
|
+
if (onClear !== void 0) {
|
|
200
|
+
onClear();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const clearButtonVisible = clearable && value != null && clearLabel !== void 0;
|
|
204
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
205
|
+
/* @__PURE__ */ jsx(Trigger$1, { ref: forwardRef, asChild: true, children: /* @__PURE__ */ jsxs(
|
|
206
|
+
StyledTrigger,
|
|
207
|
+
{
|
|
208
|
+
id: id != null ? id : formElementId,
|
|
209
|
+
"aria-describedby": stringAttrValue(
|
|
210
|
+
ariaDescribedBy,
|
|
211
|
+
formFieldContextDescribedBy
|
|
212
|
+
),
|
|
213
|
+
v1,
|
|
214
|
+
withClearButton: clearButtonVisible,
|
|
215
|
+
disabled,
|
|
216
|
+
"aria-disabled": ariaDisabled,
|
|
217
|
+
...restProps,
|
|
218
|
+
children: [
|
|
219
|
+
value != null ? /* @__PURE__ */ jsx(StyledValue$1, { children }) : /* @__PURE__ */ jsx(StyledPlaceholder, { children: placeholder }),
|
|
220
|
+
!clearButtonVisible && /* @__PURE__ */ jsx(StyledIconContainer, { children: /* @__PURE__ */ jsx(IconCalendarBlank, { weight: "thin", size: "small" }) })
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
) }),
|
|
224
|
+
clearButtonVisible && /* @__PURE__ */ jsx(
|
|
225
|
+
ClearAction,
|
|
226
|
+
{
|
|
227
|
+
label: clearLabel,
|
|
228
|
+
onPress: onClearHandler,
|
|
229
|
+
disabled: disabled != null ? disabled : booleanify(ariaDisabled)
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
] });
|
|
67
233
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const PredefinedRanges = React__default.forwardRef(({ range, onClick }, forwardRef) => /* @__PURE__ */ jsx(StyledPredefinedRanges, { ref: forwardRef, children: range == null ? void 0 : range.map((date, i) => /* @__PURE__ */ jsx(
|
|
71
|
-
Button$1,
|
|
72
|
-
{
|
|
73
|
-
variant: "ghost",
|
|
74
|
-
size: "medium",
|
|
75
|
-
type: "button",
|
|
76
|
-
onClick: () => onClick(date),
|
|
77
|
-
children: date.label
|
|
78
|
-
},
|
|
79
|
-
i
|
|
80
|
-
)) }));
|
|
234
|
+
);
|
|
81
235
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
background: "$background-neutrals"
|
|
85
|
-
});
|
|
86
|
-
const StyledBodyContent = styled(Flex, {
|
|
87
|
-
margin: "0 auto",
|
|
88
|
-
boxShadow: "$100",
|
|
236
|
+
const StyledContent = styled(Content$1, {
|
|
237
|
+
zIndex: "$calendar",
|
|
89
238
|
background: "$background-neutrals",
|
|
90
|
-
borderRadius: "$100"
|
|
239
|
+
borderRadius: "$100",
|
|
240
|
+
boxShadow: "$100"
|
|
91
241
|
});
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
"& [data-left-calendar]": {
|
|
95
|
-
paddingLeft: "$200",
|
|
96
|
-
paddingRight: "$100"
|
|
97
|
-
},
|
|
98
|
-
"& [data-right-calendar]": {
|
|
99
|
-
paddingLeft: "$100",
|
|
100
|
-
paddingRight: "$200"
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
const StyledBodyContentLeft = styled(Primitive.div, {
|
|
104
|
-
paddingLeft: "$200",
|
|
105
|
-
paddingRight: "$100"
|
|
242
|
+
const StyledCalendarBody = styled(Flex, {
|
|
243
|
+
padding: "$200"
|
|
106
244
|
});
|
|
245
|
+
const StyledGridContent = styled(Flex, {});
|
|
246
|
+
const StyledBodyContentLeft = styled(Primitive.div, {});
|
|
107
247
|
const StyledBodyContentRight = styled(Primitive.div, {
|
|
108
|
-
paddingLeft: "$
|
|
109
|
-
paddingRight: "$200"
|
|
248
|
+
paddingLeft: "$200"
|
|
110
249
|
});
|
|
111
250
|
const StyledClearContent = styled(Primitive.div, {
|
|
251
|
+
display: "flex",
|
|
252
|
+
gap: "$100",
|
|
112
253
|
padding: "$200",
|
|
113
254
|
borderTop: "1px solid $border-neutrals"
|
|
114
255
|
});
|
|
115
256
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
cursor: "pointer",
|
|
121
|
-
color: "$text-neutrals",
|
|
122
|
-
"&[disabled]": {
|
|
123
|
-
cursor: "not-allowed"
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const Button = React__default.forwardRef((props, forwardRef) => {
|
|
128
|
-
const { buttonProps } = useButton(props, forwardRef);
|
|
129
|
-
const { focusProps } = useFocusRing();
|
|
130
|
-
const { children } = props;
|
|
131
|
-
return /* @__PURE__ */ jsx(StyledButton, { ...mergeProps(buttonProps, focusProps), ref: forwardRef, children });
|
|
257
|
+
const StyledHeaderTitle = styled(Heading, {
|
|
258
|
+
margin: 0,
|
|
259
|
+
flex: "2",
|
|
260
|
+
textAlign: "center"
|
|
132
261
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
color: "$text-neutrals"
|
|
262
|
+
const StyledHeaderPlaceholder = styled("div", {
|
|
263
|
+
height: "$8",
|
|
264
|
+
// to compensate icon buttons' width and space between 2 calendars
|
|
265
|
+
width: "calc($8 * 2 + $space$200)"
|
|
138
266
|
});
|
|
139
267
|
const StyledHeader = styled(Flex, {
|
|
140
|
-
|
|
141
|
-
|
|
268
|
+
color: "$text-neutrals",
|
|
269
|
+
height: "$8",
|
|
270
|
+
alignItems: "center",
|
|
271
|
+
justifyContent: "space-between"
|
|
142
272
|
});
|
|
143
273
|
|
|
274
|
+
const HeaderButton = React.forwardRef(({ isDisabled, children, ...restProps }, forwardRef) => /* @__PURE__ */ jsx(
|
|
275
|
+
IconButton,
|
|
276
|
+
{
|
|
277
|
+
...restProps,
|
|
278
|
+
size: "medium",
|
|
279
|
+
disabled: isDisabled,
|
|
280
|
+
ref: forwardRef,
|
|
281
|
+
children
|
|
282
|
+
}
|
|
283
|
+
));
|
|
284
|
+
|
|
144
285
|
const Header = ({
|
|
145
286
|
state,
|
|
146
287
|
prevButtonProps,
|
|
@@ -153,133 +294,139 @@ const Header = ({
|
|
|
153
294
|
timeZone: state.timeZone
|
|
154
295
|
});
|
|
155
296
|
return /* @__PURE__ */ jsxs(StyledHeader, { children: [
|
|
156
|
-
/* @__PURE__ */ jsx(
|
|
157
|
-
/* @__PURE__ */ jsx(StyledHeaderTitle, {
|
|
297
|
+
/* @__PURE__ */ jsx(HeaderButton, { ...prevButtonProps, children: /* @__PURE__ */ jsx(IconChevronLeft, {}) }),
|
|
298
|
+
/* @__PURE__ */ jsx(StyledHeaderTitle, { level: 2, styledAs: "h3", children: monthDateFormatter.format(
|
|
158
299
|
state.visibleRange.start.toDate(state.timeZone)
|
|
159
|
-
) })
|
|
160
|
-
visibleMonths
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
300
|
+
) }),
|
|
301
|
+
visibleMonths === 2 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
302
|
+
/* @__PURE__ */ jsx(StyledHeaderPlaceholder, {}),
|
|
303
|
+
/* @__PURE__ */ jsx(StyledHeaderTitle, { level: 2, styledAs: "h3", children: monthDateFormatter.format(
|
|
304
|
+
state.visibleRange.start.add({ months: 1 }).toDate(state.timeZone)
|
|
305
|
+
) })
|
|
306
|
+
] }),
|
|
307
|
+
/* @__PURE__ */ jsx(HeaderButton, { ...nextButtonProps, children: /* @__PURE__ */ jsx(IconChevronRight, {}) })
|
|
164
308
|
] });
|
|
165
309
|
};
|
|
166
310
|
|
|
311
|
+
const StyledCell = styled(Primitive.td, {
|
|
312
|
+
square: "$10",
|
|
313
|
+
marginTop: "$50",
|
|
314
|
+
position: "relative"
|
|
315
|
+
});
|
|
167
316
|
const StyledCellContent = styled(Primitive.div, {
|
|
168
|
-
|
|
317
|
+
cursor: "pointer",
|
|
318
|
+
square: "$10",
|
|
169
319
|
display: "flex",
|
|
170
320
|
alignItems: "center",
|
|
171
321
|
justifyContent: "center",
|
|
172
322
|
borderRadius: "$50",
|
|
173
323
|
color: "$text-neutrals",
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
"&[data-selection]": {
|
|
184
|
-
borderRadius: "$50",
|
|
185
|
-
background: "$background-primary-prominent-selected",
|
|
186
|
-
color: "$text-primary-inverted",
|
|
187
|
-
fontWeight: "600"
|
|
188
|
-
},
|
|
189
|
-
"&[data-disabled]": {
|
|
324
|
+
...focus.css({
|
|
325
|
+
top: "0",
|
|
326
|
+
left: "0",
|
|
327
|
+
position: "absolute",
|
|
328
|
+
zIndex: "1",
|
|
329
|
+
boxShadow: "$focus-v1",
|
|
330
|
+
outline: "1px solid transparent"
|
|
331
|
+
}),
|
|
332
|
+
'&[aria-disabled="true"]': {
|
|
190
333
|
textDecoration: "line-through",
|
|
191
|
-
color: "$text-neutrals-disabled"
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
const StyledCell = styled(Primitive.div, {
|
|
195
|
-
square: "36px",
|
|
196
|
-
cursor: "pointer",
|
|
197
|
-
display: "flex",
|
|
198
|
-
alignItems: "center",
|
|
199
|
-
justifyContent: "center",
|
|
200
|
-
"&:hover": {
|
|
201
|
-
background: "$background-primary-subtle-hover",
|
|
202
|
-
["& ".concat(StyledCellContent)]: {
|
|
203
|
-
background: "$background-primary-prominent-hover",
|
|
204
|
-
color: "$text-primary-inverted"
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
"&[data-selected]": {
|
|
208
|
-
background: "$background-primary-subtle-hover"
|
|
334
|
+
color: "$text-neutrals-disabled",
|
|
335
|
+
cursor: "default"
|
|
209
336
|
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
borderBottomRightRadius: "$lg",
|
|
216
|
-
borderTopRightRadius: "$lg"
|
|
217
|
-
},
|
|
218
|
-
"&[data-hidden]": {
|
|
219
|
-
display: "none"
|
|
337
|
+
'&:not([aria-disabled="true"])': {
|
|
338
|
+
_hover: {
|
|
339
|
+
backgroundColor: "$background-neutrals-subtle-hover",
|
|
340
|
+
color: "$text-neutrals"
|
|
341
|
+
}
|
|
220
342
|
},
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
343
|
+
variants: {
|
|
344
|
+
today: {
|
|
345
|
+
true: {
|
|
346
|
+
backgroundColor: "$background-neutrals-subtle-hover",
|
|
347
|
+
color: "$text-neutrals"
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
selected: {
|
|
351
|
+
true: {
|
|
352
|
+
backgroundColor: "$background-primary-prominent-selected",
|
|
353
|
+
color: "$text-neutrals-inverted",
|
|
354
|
+
'&:not([aria-disabled="true"])': {
|
|
355
|
+
_hover: {
|
|
356
|
+
backgroundColor: "$background-primary-prominent-hover",
|
|
357
|
+
color: "$text-neutrals-inverted"
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
range: {
|
|
363
|
+
middle: {
|
|
364
|
+
backgroundColor: "$background-primary-subtle-selected",
|
|
365
|
+
color: "$text-neutrals",
|
|
366
|
+
borderRadius: 0,
|
|
367
|
+
'&:not([aria-disabled="true"])': {
|
|
368
|
+
_hover: {
|
|
369
|
+
backgroundColor: "$background-primary-subtle-hover"
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
start: {
|
|
374
|
+
borderTopRightRadius: 0,
|
|
375
|
+
borderBottomRightRadius: 0
|
|
376
|
+
},
|
|
377
|
+
end: {
|
|
378
|
+
borderTopLeftRadius: 0,
|
|
379
|
+
borderBottomLeftRadius: 0
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
hidden: {
|
|
383
|
+
true: {
|
|
384
|
+
display: "none"
|
|
228
385
|
}
|
|
229
386
|
}
|
|
230
387
|
}
|
|
231
388
|
});
|
|
232
389
|
|
|
233
|
-
const Cell =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
"data-selected-middle": isSelected && !(isSelectionStart || isSelectionEnd) ? "" : void 0,
|
|
261
|
-
"data-selection": isSelectionStart || isSelectionEnd ? "" : void 0,
|
|
262
|
-
"data-disabled": isDisabled ? "" : void 0,
|
|
263
|
-
"data-today": isToday(date, getLocalTimeZone()) ? "" : void 0,
|
|
264
|
-
"data-weekend": isWeekendDay ? "" : void 0,
|
|
265
|
-
children: formattedDate
|
|
266
|
-
}
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
) });
|
|
270
|
-
}
|
|
271
|
-
);
|
|
390
|
+
const Cell = (props) => {
|
|
391
|
+
const { state, date, currentMonth } = props;
|
|
392
|
+
const ref = useRef(null);
|
|
393
|
+
const { cellProps, buttonProps, isSelected, formattedDate } = useCalendarCell(
|
|
394
|
+
{ date },
|
|
395
|
+
state,
|
|
396
|
+
ref
|
|
397
|
+
);
|
|
398
|
+
const isOutsideMonth = !isSameMonth(currentMonth, date);
|
|
399
|
+
const isSelectionStart = state.highlightedRange !== void 0 && state.highlightedRange !== null ? isSameDay(date, state.highlightedRange.start) : isSelected;
|
|
400
|
+
const isSelectionEnd = state.highlightedRange !== void 0 && state.highlightedRange !== null ? isSameDay(date, state.highlightedRange.end) : isSelected;
|
|
401
|
+
const { focusProps } = useFocusRing();
|
|
402
|
+
const isRange = isSelected && (!isSelectionStart || !isSelectionEnd);
|
|
403
|
+
const rangeVariant = isRange ? isSelectionStart ? "start" : isSelectionEnd ? "end" : "middle" : void 0;
|
|
404
|
+
return /* @__PURE__ */ jsx(StyledCell, { ...cellProps, children: /* @__PURE__ */ jsx(
|
|
405
|
+
StyledCellContent,
|
|
406
|
+
{
|
|
407
|
+
...mergeProps(buttonProps, focusProps),
|
|
408
|
+
ref,
|
|
409
|
+
selected: isSelected && (isSelectionStart || isSelectionEnd),
|
|
410
|
+
today: isToday(date, getLocalTimeZone()),
|
|
411
|
+
range: rangeVariant,
|
|
412
|
+
hidden: isOutsideMonth,
|
|
413
|
+
children: formattedDate
|
|
414
|
+
}
|
|
415
|
+
) });
|
|
416
|
+
};
|
|
272
417
|
|
|
273
418
|
const StyledGrid = styled(Primitive.table, {
|
|
274
419
|
borderCollapse: "separate",
|
|
275
420
|
borderSpacing: " 0 $50"
|
|
276
421
|
});
|
|
277
422
|
const StyledDays = styled(Primitive.th, {
|
|
278
|
-
|
|
279
|
-
color: "$text-neutrals"
|
|
423
|
+
height: "$10",
|
|
424
|
+
color: "$text-neutrals-subtle",
|
|
425
|
+
fontWeight: "$regular",
|
|
426
|
+
paddingTop: "$50"
|
|
280
427
|
});
|
|
281
428
|
|
|
282
|
-
const Grid =
|
|
429
|
+
const Grid = React.forwardRef(
|
|
283
430
|
(props, forwardRef) => {
|
|
284
431
|
const { locale } = useLocale();
|
|
285
432
|
const { state, offset = {} } = props;
|
|
@@ -306,411 +453,282 @@ const Grid = React__default.forwardRef(
|
|
|
306
453
|
}
|
|
307
454
|
);
|
|
308
455
|
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
variants: {
|
|
335
|
-
v1: {
|
|
336
|
-
true: {
|
|
337
|
-
...textFieldStyles.v1.idle,
|
|
338
|
-
...focus$1.css(textFieldStyles.v1.focused)
|
|
339
|
-
},
|
|
340
|
-
false: {
|
|
341
|
-
...focus$1.css(textFieldStyles.variants.focused)
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
withClearButton: {
|
|
345
|
-
true: {
|
|
346
|
-
paddingRight: "calc($100 + $400)"
|
|
347
|
-
// initial left padding + clear button width + gap
|
|
456
|
+
const CONTENT_OFFSET = parseInt(theme.space[50]);
|
|
457
|
+
const SharedContent = React.forwardRef(
|
|
458
|
+
({ calendarProps, prevButtonProps, nextButtonProps, state }, forwardRef) => {
|
|
459
|
+
const { visibleDuration } = useCalendarContext();
|
|
460
|
+
return /* @__PURE__ */ jsxs(
|
|
461
|
+
StyledCalendarBody,
|
|
462
|
+
{
|
|
463
|
+
direction: "column",
|
|
464
|
+
...calendarProps,
|
|
465
|
+
ref: forwardRef,
|
|
466
|
+
children: [
|
|
467
|
+
/* @__PURE__ */ jsx(
|
|
468
|
+
Header,
|
|
469
|
+
{
|
|
470
|
+
state,
|
|
471
|
+
prevButtonProps,
|
|
472
|
+
nextButtonProps,
|
|
473
|
+
visibleMonths: visibleDuration.months
|
|
474
|
+
}
|
|
475
|
+
),
|
|
476
|
+
/* @__PURE__ */ jsxs(StyledGridContent, { children: [
|
|
477
|
+
/* @__PURE__ */ jsx(StyledBodyContentLeft, { children: /* @__PURE__ */ jsx(Grid, { state }) }),
|
|
478
|
+
visibleDuration.months === 2 && /* @__PURE__ */ jsx(StyledBodyContentRight, { children: /* @__PURE__ */ jsx(Grid, { state, offset: { months: 1 } }) })
|
|
479
|
+
] })
|
|
480
|
+
]
|
|
348
481
|
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
const StyledCustomTrigger = styled(Primitive.button, {
|
|
353
|
-
width: "100%",
|
|
354
|
-
height: "unset",
|
|
355
|
-
padding: "0",
|
|
356
|
-
backgroundColor: "$transparent",
|
|
357
|
-
border: "none",
|
|
358
|
-
cursor: "pointer"
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
const StyledClearButton = styled(BaseButton, {
|
|
362
|
-
position: "absolute",
|
|
363
|
-
top: 0,
|
|
364
|
-
bottom: 0,
|
|
365
|
-
right: "calc($100 + 1px)",
|
|
366
|
-
// to compensate border width
|
|
367
|
-
margin: "auto",
|
|
368
|
-
...actionButtonStyles
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
const ClearButton = React__default.forwardRef(({ "aria-label": ariaLabel, label, ...restProps }, forwardRef) => /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
372
|
-
/* @__PURE__ */ jsx(Tooltip.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
373
|
-
StyledClearButton,
|
|
374
|
-
{
|
|
375
|
-
...restProps,
|
|
376
|
-
ref: forwardRef,
|
|
377
|
-
"aria-label": ariaLabel != null ? ariaLabel : label,
|
|
378
|
-
children: /* @__PURE__ */ jsx(IconCross, {})
|
|
379
|
-
}
|
|
380
|
-
) }),
|
|
381
|
-
/* @__PURE__ */ jsx(Tooltip.Content, { children: label })
|
|
382
|
-
] }));
|
|
383
|
-
|
|
384
|
-
function dateToString(value) {
|
|
385
|
-
if (value == null) {
|
|
386
|
-
return void 0;
|
|
387
|
-
}
|
|
388
|
-
if ("start" in value) {
|
|
389
|
-
if (value.start == null || value.end == null) {
|
|
390
|
-
return void 0;
|
|
391
|
-
}
|
|
392
|
-
return "".concat(value.start, " - ").concat(value.end);
|
|
393
|
-
}
|
|
394
|
-
return value.toString();
|
|
395
|
-
}
|
|
396
|
-
const Trigger = React__default.forwardRef(
|
|
397
|
-
({
|
|
398
|
-
placeholder,
|
|
399
|
-
displayValue,
|
|
400
|
-
stateValue,
|
|
401
|
-
asChild = false,
|
|
402
|
-
clearable = true,
|
|
403
|
-
clearActionLabel,
|
|
404
|
-
onClear,
|
|
405
|
-
...restProps
|
|
406
|
-
}, forwardRef) => {
|
|
407
|
-
const [v1] = useNewDesignLanguage();
|
|
408
|
-
const { buttonProps } = useButton(
|
|
409
|
-
restProps,
|
|
410
|
-
forwardRef
|
|
411
482
|
);
|
|
412
|
-
const { children } = restProps;
|
|
413
|
-
if (asChild) {
|
|
414
|
-
return /* @__PURE__ */ jsx(StyledCustomTrigger, { ...buttonProps, children });
|
|
415
|
-
}
|
|
416
|
-
const valueToDisplay = displayValue != null ? displayValue : dateToString(stateValue);
|
|
417
|
-
const clearButtonVisible = clearable && clearActionLabel !== void 0 && valueToDisplay != null;
|
|
418
|
-
return /* @__PURE__ */ jsxs(StyledTriggerContainer, { children: [
|
|
419
|
-
/* @__PURE__ */ jsxs(
|
|
420
|
-
StyledTrigger,
|
|
421
|
-
{
|
|
422
|
-
"data-custom": "",
|
|
423
|
-
...buttonProps,
|
|
424
|
-
v1,
|
|
425
|
-
ref: forwardRef,
|
|
426
|
-
withClearButton: clearButtonVisible,
|
|
427
|
-
children: [
|
|
428
|
-
valueToDisplay != null ? /* @__PURE__ */ jsx(StyledValue, { children: valueToDisplay }) : /* @__PURE__ */ jsx(StyledPlaceholder, { children: placeholder }),
|
|
429
|
-
!clearButtonVisible && /* @__PURE__ */ jsx(IconCalendarBlank, { weight: "thin" })
|
|
430
|
-
]
|
|
431
|
-
}
|
|
432
|
-
),
|
|
433
|
-
clearButtonVisible && /* @__PURE__ */ jsx(ClearButton, { label: clearActionLabel, onPress: onClear })
|
|
434
|
-
] });
|
|
435
483
|
}
|
|
436
484
|
);
|
|
437
|
-
|
|
438
|
-
const
|
|
485
|
+
const DatePickerContent = () => {
|
|
486
|
+
const { locale } = useLocale();
|
|
439
487
|
const {
|
|
440
|
-
|
|
488
|
+
calendarValue,
|
|
489
|
+
visibleDuration,
|
|
441
490
|
minDate,
|
|
442
491
|
maxDate,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
492
|
+
onCalendarDateClick
|
|
493
|
+
} = useCalendarContext();
|
|
494
|
+
const state = useCalendarState({
|
|
495
|
+
value: calendarValue,
|
|
496
|
+
visibleDuration,
|
|
497
|
+
minValue: minDate,
|
|
498
|
+
maxValue: maxDate,
|
|
499
|
+
autoFocus: true,
|
|
500
|
+
onChange: onCalendarDateClick,
|
|
501
|
+
locale,
|
|
502
|
+
createCalendar
|
|
503
|
+
});
|
|
504
|
+
const { calendarProps, prevButtonProps, nextButtonProps } = useCalendar(
|
|
505
|
+
{},
|
|
506
|
+
state
|
|
454
507
|
);
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const { groupProps, labelProps, buttonProps } = useDateRangePicker(
|
|
508
|
+
return /* @__PURE__ */ jsx(
|
|
509
|
+
SharedContent,
|
|
458
510
|
{
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
ref
|
|
511
|
+
calendarProps,
|
|
512
|
+
prevButtonProps,
|
|
513
|
+
nextButtonProps,
|
|
514
|
+
state
|
|
515
|
+
}
|
|
465
516
|
);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
517
|
+
};
|
|
518
|
+
const RangePickerContent = () => {
|
|
519
|
+
const { locale } = useLocale();
|
|
520
|
+
const {
|
|
521
|
+
calendarValue,
|
|
522
|
+
visibleDuration,
|
|
523
|
+
minDate,
|
|
524
|
+
maxDate,
|
|
525
|
+
onCalendarDateClick
|
|
526
|
+
} = useCalendarContext();
|
|
527
|
+
const ref = useRef(null);
|
|
528
|
+
const state = useRangeCalendarState({
|
|
529
|
+
value: calendarValue,
|
|
530
|
+
visibleDuration,
|
|
473
531
|
minValue: minDate,
|
|
474
532
|
maxValue: maxDate,
|
|
475
533
|
autoFocus: true,
|
|
476
|
-
|
|
477
|
-
onChange: change,
|
|
534
|
+
onChange: onCalendarDateClick,
|
|
478
535
|
locale,
|
|
479
536
|
createCalendar
|
|
480
537
|
});
|
|
481
538
|
const { calendarProps, prevButtonProps, nextButtonProps } = useRangeCalendar(
|
|
482
|
-
|
|
483
|
-
|
|
539
|
+
{},
|
|
540
|
+
state,
|
|
484
541
|
ref
|
|
485
542
|
);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
543
|
+
return /* @__PURE__ */ jsx(
|
|
544
|
+
SharedContent,
|
|
545
|
+
{
|
|
546
|
+
ref,
|
|
547
|
+
calendarProps,
|
|
548
|
+
prevButtonProps,
|
|
549
|
+
nextButtonProps,
|
|
550
|
+
state
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
};
|
|
554
|
+
const Content = React.forwardRef(
|
|
555
|
+
({
|
|
556
|
+
side = "bottom",
|
|
557
|
+
sideOffset = CONTENT_OFFSET,
|
|
558
|
+
align = "start",
|
|
559
|
+
alignOffset = 0,
|
|
560
|
+
collisionPadding = 0,
|
|
561
|
+
avoidCollisions = true,
|
|
562
|
+
sticky = "partial",
|
|
563
|
+
hideWhenDetached = true,
|
|
564
|
+
children,
|
|
565
|
+
...restProps
|
|
566
|
+
}, forwardRef) => {
|
|
567
|
+
const { picker, open } = useCalendarContext();
|
|
568
|
+
if (!open) {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
return /* @__PURE__ */ jsx(
|
|
572
|
+
StyledContent,
|
|
573
|
+
{
|
|
574
|
+
...restProps,
|
|
575
|
+
ref: forwardRef,
|
|
576
|
+
side,
|
|
577
|
+
sideOffset,
|
|
578
|
+
align,
|
|
579
|
+
alignOffset,
|
|
580
|
+
collisionPadding,
|
|
581
|
+
avoidCollisions,
|
|
582
|
+
sticky,
|
|
583
|
+
hideWhenDetached,
|
|
584
|
+
children: /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
|
|
585
|
+
picker === "single" ? /* @__PURE__ */ jsx(DatePickerContent, {}) : /* @__PURE__ */ jsx(RangePickerContent, {}),
|
|
586
|
+
children != null && /* @__PURE__ */ jsx(StyledClearContent, { children })
|
|
587
|
+
] })
|
|
491
588
|
}
|
|
492
|
-
|
|
493
|
-
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
const StyledValue = styled(Primitive.span, {});
|
|
594
|
+
|
|
595
|
+
const DEFAULT_FORMAT = {
|
|
596
|
+
day: "2-digit",
|
|
597
|
+
month: "short",
|
|
598
|
+
year: "numeric"
|
|
599
|
+
};
|
|
600
|
+
function formatDate(date, formatter, timeZone) {
|
|
601
|
+
return formatter.format(date.toDate(timeZone));
|
|
602
|
+
}
|
|
603
|
+
function formatValue(value, formatter, timeZone) {
|
|
604
|
+
if (value == null) {
|
|
605
|
+
return void 0;
|
|
606
|
+
}
|
|
607
|
+
if ("start" in value) {
|
|
608
|
+
if (value.start == null || value.end == null) {
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
return "".concat(formatDate(value.start, formatter, timeZone), " - ").concat(formatDate(
|
|
612
|
+
value.end,
|
|
613
|
+
formatter,
|
|
614
|
+
timeZone
|
|
615
|
+
));
|
|
616
|
+
}
|
|
617
|
+
return formatDate(value, formatter, timeZone);
|
|
618
|
+
}
|
|
619
|
+
const Value = React.forwardRef(({ format = DEFAULT_FORMAT, ...restProps }, forwardRef) => {
|
|
620
|
+
const { value } = useCalendarContext();
|
|
621
|
+
const timeZone = useMemo(getLocalTimeZone, [format]);
|
|
622
|
+
const formatWithTimeZone = useMemo(
|
|
623
|
+
() => ({ ...format, timeZone }),
|
|
624
|
+
[format, timeZone]
|
|
494
625
|
);
|
|
626
|
+
const dateFormatter = useDateFormatter(formatWithTimeZone);
|
|
627
|
+
const valueToDisplay = formatValue(value, dateFormatter, timeZone);
|
|
628
|
+
return /* @__PURE__ */ jsx(StyledValue, { ref: forwardRef, ...restProps, children: valueToDisplay });
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
const ClearButton = React.forwardRef(({ onClear, children, ...restProps }, forwardRef) => {
|
|
632
|
+
const { value, setValue } = useCalendarContext();
|
|
495
633
|
const onClearHandler = () => {
|
|
496
|
-
|
|
634
|
+
setValue(void 0);
|
|
497
635
|
if (onClear !== void 0) {
|
|
498
636
|
onClear();
|
|
499
|
-
state.close();
|
|
500
637
|
}
|
|
501
638
|
};
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
clearable: clearableTrigger,
|
|
515
|
-
clearActionLabel: clearableTrigger ? clearButtonText : void 0,
|
|
516
|
-
onClear: clearableTrigger ? onClearHandler : void 0
|
|
517
|
-
}
|
|
518
|
-
)
|
|
519
|
-
] }),
|
|
520
|
-
children !== void 0 && /* @__PURE__ */ jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsx(Trigger, { ...buttonProps, asChild: true, children }) }),
|
|
521
|
-
state.isOpen && /* @__PURE__ */ jsx(Popover, { triggerRef: ref, state, placement: "bottom start", children: /* @__PURE__ */ jsx(StyledBody, { ref: forwardRef, children: /* @__PURE__ */ jsxs(StyledBodyContent, { children: [
|
|
522
|
-
predefinedRanges !== void 0 && /* @__PURE__ */ jsx(
|
|
523
|
-
PredefinedRanges,
|
|
524
|
-
{
|
|
525
|
-
range: predefinedRanges,
|
|
526
|
-
onClick: rangeClick
|
|
527
|
-
}
|
|
528
|
-
),
|
|
529
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", ...calendarProps, children: [
|
|
530
|
-
/* @__PURE__ */ jsx(
|
|
531
|
-
Header,
|
|
532
|
-
{
|
|
533
|
-
state: rangeState,
|
|
534
|
-
prevButtonProps,
|
|
535
|
-
nextButtonProps,
|
|
536
|
-
visibleMonths
|
|
537
|
-
}
|
|
538
|
-
),
|
|
539
|
-
/* @__PURE__ */ jsxs(StyledGridContent, { children: [
|
|
540
|
-
/* @__PURE__ */ jsx(StyledBodyContentLeft, { children: /* @__PURE__ */ jsx(Grid, { state: rangeState }) }),
|
|
541
|
-
visibleMonths !== void 0 && /* @__PURE__ */ jsx(StyledBodyContentRight, { children: /* @__PURE__ */ jsx(
|
|
542
|
-
Grid,
|
|
543
|
-
{
|
|
544
|
-
onChange: change,
|
|
545
|
-
state: rangeState,
|
|
546
|
-
offset: { months: 1 }
|
|
547
|
-
}
|
|
548
|
-
) })
|
|
549
|
-
] }),
|
|
550
|
-
onClear !== void 0 && /* @__PURE__ */ jsx(StyledClearContent, { children: /* @__PURE__ */ jsx(
|
|
551
|
-
Button$1,
|
|
552
|
-
{
|
|
553
|
-
size: "medium",
|
|
554
|
-
type: "button",
|
|
555
|
-
onClick: onClearHandler,
|
|
556
|
-
disabled: rangeState.value === null,
|
|
557
|
-
children: clearButtonText
|
|
558
|
-
}
|
|
559
|
-
) })
|
|
560
|
-
] })
|
|
561
|
-
] }) }) })
|
|
562
|
-
] });
|
|
639
|
+
return /* @__PURE__ */ jsx(
|
|
640
|
+
Button,
|
|
641
|
+
{
|
|
642
|
+
...restProps,
|
|
643
|
+
ref: forwardRef,
|
|
644
|
+
variant: "ghost",
|
|
645
|
+
size: "medium",
|
|
646
|
+
onClick: onClearHandler,
|
|
647
|
+
disabled: value === null,
|
|
648
|
+
children
|
|
649
|
+
}
|
|
650
|
+
);
|
|
563
651
|
});
|
|
564
652
|
|
|
565
|
-
const
|
|
566
|
-
const {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const dateClick = useCallback(
|
|
588
|
-
(selectedRange) => {
|
|
589
|
-
if (selectedRange.date !== void 0)
|
|
590
|
-
state.setValue(selectedRange.date);
|
|
591
|
-
},
|
|
592
|
-
[state]
|
|
653
|
+
const SaveButton = React.forwardRef(({ onSave, children, ...restProps }, forwardRef) => {
|
|
654
|
+
const { setImmediateSave, onSaveClick } = useCalendarContext();
|
|
655
|
+
useEffect(() => {
|
|
656
|
+
setImmediateSave(true);
|
|
657
|
+
return () => setImmediateSave(false);
|
|
658
|
+
}, [setImmediateSave]);
|
|
659
|
+
const onSaveHandler = () => {
|
|
660
|
+
onSaveClick();
|
|
661
|
+
if (onSave !== void 0) {
|
|
662
|
+
onSave();
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
return /* @__PURE__ */ jsx(
|
|
666
|
+
Button,
|
|
667
|
+
{
|
|
668
|
+
ref: forwardRef,
|
|
669
|
+
...restProps,
|
|
670
|
+
variant: "primary",
|
|
671
|
+
size: "medium",
|
|
672
|
+
onClick: onSaveHandler,
|
|
673
|
+
children
|
|
674
|
+
}
|
|
593
675
|
);
|
|
594
|
-
return /* @__PURE__ */ jsx(StyledBody, { ref: forwardRef, children: /* @__PURE__ */ jsxs(StyledBodyContent, { ...calendarProps, children: [
|
|
595
|
-
predefinedRanges !== void 0 && /* @__PURE__ */ jsx(PredefinedRanges, { range: predefinedRanges, onClick: dateClick }),
|
|
596
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
|
|
597
|
-
/* @__PURE__ */ jsx(
|
|
598
|
-
Header,
|
|
599
|
-
{
|
|
600
|
-
state,
|
|
601
|
-
prevButtonProps,
|
|
602
|
-
nextButtonProps,
|
|
603
|
-
visibleMonths
|
|
604
|
-
}
|
|
605
|
-
),
|
|
606
|
-
/* @__PURE__ */ jsxs(StyledGridContent, { children: [
|
|
607
|
-
/* @__PURE__ */ jsx(StyledBodyContentLeft, { children: /* @__PURE__ */ jsx(Grid, { state }) }),
|
|
608
|
-
visibleMonths !== void 0 && /* @__PURE__ */ jsx(StyledBodyContentRight, { children: /* @__PURE__ */ jsx(Grid, { state, offset: { months: 1 } }) })
|
|
609
|
-
] }),
|
|
610
|
-
onClear !== void 0 && /* @__PURE__ */ jsx(StyledClearContent, { children: /* @__PURE__ */ jsx(
|
|
611
|
-
Button$1,
|
|
612
|
-
{
|
|
613
|
-
size: "medium",
|
|
614
|
-
onClick: onClear,
|
|
615
|
-
disabled: state.value === null,
|
|
616
|
-
children: clearButtonText
|
|
617
|
-
}
|
|
618
|
-
) })
|
|
619
|
-
] })
|
|
620
|
-
] }) });
|
|
621
676
|
});
|
|
622
677
|
|
|
623
|
-
const
|
|
624
|
-
|
|
678
|
+
const StyledCalendar = styled(Primitive.div, {
|
|
679
|
+
position: "relative"
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
const Root = React.forwardRef(({ children, ...restProps }, forwardRef) => {
|
|
683
|
+
const { open, setOpen } = useCalendarContext();
|
|
684
|
+
const { label, isFloatingLabel } = useFormFieldContext();
|
|
685
|
+
return /* @__PURE__ */ jsx(RadixPopover.Root, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(StyledCalendar, { ref: forwardRef, ...restProps, children: [
|
|
686
|
+
label !== null && isFloatingLabel && /* @__PURE__ */ jsx(FloatingLabel, { floating: true, size: "medium", children: label }),
|
|
687
|
+
children
|
|
688
|
+
] }) });
|
|
689
|
+
});
|
|
690
|
+
const Calendar = React.forwardRef(
|
|
691
|
+
({
|
|
625
692
|
picker,
|
|
626
|
-
predefinedRanges,
|
|
627
|
-
visibleMonths,
|
|
628
693
|
defaultValue,
|
|
694
|
+
value,
|
|
695
|
+
onValueChange,
|
|
696
|
+
defaultOpen,
|
|
697
|
+
open,
|
|
698
|
+
onClose,
|
|
699
|
+
onOpen,
|
|
700
|
+
locale,
|
|
701
|
+
visibleMonths,
|
|
629
702
|
minDate,
|
|
630
703
|
maxDate,
|
|
704
|
+
disabled,
|
|
705
|
+
"aria-disabled": ariaDisabled,
|
|
631
706
|
children,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
placeholder,
|
|
637
|
-
displayValue
|
|
638
|
-
} = props;
|
|
639
|
-
const ref = useRef(null);
|
|
640
|
-
const state = useDatePickerState(props);
|
|
641
|
-
const { groupProps, buttonProps, calendarProps, labelProps } = useDatePicker(
|
|
642
|
-
{
|
|
643
|
-
...props,
|
|
644
|
-
isOpen: defaultOpen,
|
|
645
|
-
label
|
|
646
|
-
},
|
|
647
|
-
state,
|
|
648
|
-
ref
|
|
649
|
-
);
|
|
650
|
-
const onClearHandler = () => {
|
|
651
|
-
state.setValue(null);
|
|
652
|
-
if (onClear !== void 0) {
|
|
653
|
-
onClear();
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
const clearableTrigger = clearButtonText !== void 0 && onClear !== void 0;
|
|
657
|
-
return /* @__PURE__ */ jsx(Fragment, { children: picker === "single" ? /* @__PURE__ */ jsxs(StyledPicker, { ref: forwardRef, children: [
|
|
658
|
-
children === void 0 && /* @__PURE__ */ jsxs(StyledGroup, { ...groupProps, ref, children: [
|
|
659
|
-
label !== void 0 && // todo refactoring: use Form Field context
|
|
660
|
-
/* @__PURE__ */ jsx(FloatingLabel, { floating: true, ...labelProps, children: label }),
|
|
661
|
-
/* @__PURE__ */ jsx(
|
|
662
|
-
Trigger,
|
|
663
|
-
{
|
|
664
|
-
...buttonProps,
|
|
665
|
-
placeholder,
|
|
666
|
-
displayValue,
|
|
667
|
-
stateValue: state.value,
|
|
668
|
-
clearable: clearableTrigger,
|
|
669
|
-
clearActionLabel: clearableTrigger ? clearButtonText : void 0,
|
|
670
|
-
onClear: clearableTrigger ? onClearHandler : void 0
|
|
671
|
-
}
|
|
672
|
-
)
|
|
673
|
-
] }),
|
|
674
|
-
children !== void 0 && /* @__PURE__ */ jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsx(Trigger, { ...buttonProps, asChild: true, children }) }),
|
|
675
|
-
state.isOpen && /* @__PURE__ */ jsx(Popover, { triggerRef: ref, state, placement: "bottom start", children: /* @__PURE__ */ jsx(
|
|
676
|
-
DatePickerBody,
|
|
677
|
-
{
|
|
678
|
-
...calendarProps,
|
|
679
|
-
defaultValue,
|
|
680
|
-
predefinedRanges,
|
|
681
|
-
visibleMonths,
|
|
682
|
-
onClear: onClear !== void 0 ? onClearHandler : void 0,
|
|
683
|
-
minDate,
|
|
684
|
-
maxDate,
|
|
685
|
-
clearButtonText: onClear !== void 0 ? clearButtonText : void 0,
|
|
686
|
-
ref: forwardRef
|
|
687
|
-
}
|
|
688
|
-
) })
|
|
689
|
-
] }) : /* @__PURE__ */ jsx(
|
|
690
|
-
DatePickerBody,
|
|
691
|
-
{
|
|
692
|
-
...calendarProps,
|
|
693
|
-
ref: forwardRef,
|
|
707
|
+
...props
|
|
708
|
+
}, forwardRef) => {
|
|
709
|
+
const providerProps = {
|
|
710
|
+
picker,
|
|
694
711
|
defaultValue,
|
|
695
|
-
|
|
712
|
+
value,
|
|
713
|
+
onValueChange,
|
|
696
714
|
visibleMonths,
|
|
697
|
-
onClear: onClear !== void 0 ? onClearHandler : void 0,
|
|
698
715
|
minDate,
|
|
699
716
|
maxDate,
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
{
|
|
709
|
-
defaultValue,
|
|
710
|
-
...props,
|
|
711
|
-
picker
|
|
717
|
+
defaultOpen,
|
|
718
|
+
open,
|
|
719
|
+
onClose,
|
|
720
|
+
onOpen,
|
|
721
|
+
disabled,
|
|
722
|
+
ariaDisabled
|
|
723
|
+
};
|
|
724
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale, children: /* @__PURE__ */ jsx(CalendarProvider, { ...providerProps, children: /* @__PURE__ */ jsx(Root, { ...props, ref: forwardRef, children }) }) });
|
|
712
725
|
}
|
|
713
|
-
)
|
|
726
|
+
);
|
|
727
|
+
Calendar.Trigger = Trigger;
|
|
728
|
+
Calendar.Content = Content;
|
|
729
|
+
Calendar.Value = Value;
|
|
730
|
+
Calendar.ClearButton = ClearButton;
|
|
731
|
+
Calendar.SaveButton = SaveButton;
|
|
714
732
|
|
|
715
733
|
export { Calendar };
|
|
716
734
|
//# sourceMappingURL=module.js.map
|