@duskmoon-dev/components 0.3.1 → 0.4.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/README.md +61 -2
- package/dist/{chunk-r9wkv7xd.js → chunk-fwjzvsrx.js} +3 -3
- package/dist/classes/chat.d.ts +43 -0
- package/dist/classes/console-page.d.ts +16 -0
- package/dist/classes/dropdown.d.ts +5 -5
- package/dist/classes/fab.d.ts +11 -0
- package/dist/classes/index.d.ts +6 -0
- package/dist/classes/index.js +1443 -1210
- package/dist/classes/megamenu.d.ts +10 -0
- package/dist/classes/otp-input.d.ts +12 -0
- package/dist/classes/popover.d.ts +1 -3
- package/dist/classes/swap.d.ts +12 -0
- package/dist/classes/tree-select.d.ts +6 -6
- package/dist/components/anchor/index.js +2 -2
- package/dist/components/app/index.js +211 -151
- package/dist/components/avatar/Avatar.types.d.ts +1 -1
- package/dist/components/avatar/index.js +2 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/Button.d.ts +1 -1
- package/dist/components/button/Button.types.d.ts +8 -0
- package/dist/components/button/index.js +253 -24
- package/dist/components/calendar/index.js +44 -19
- package/dist/components/cascader/index.js +2 -2
- package/dist/components/chat/Chat.d.ts +22 -0
- package/dist/components/chat/Chat.types.d.ts +73 -0
- package/dist/components/chat/index.d.ts +2 -0
- package/dist/components/chat/index.js +309 -0
- package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
- package/dist/components/color-picker/index.js +210 -13
- package/dist/components/config-provider/index.js +2 -2
- package/dist/components/console-page/ConsolePage.d.ts +2 -0
- package/dist/components/console-page/ConsolePage.types.d.ts +29 -0
- package/dist/components/console-page/index.d.ts +2 -0
- package/dist/components/console-page/index.js +205 -0
- package/dist/components/date-picker/DatePicker.types.d.ts +1 -0
- package/dist/components/date-picker/index.js +537 -35
- package/dist/components/date-picker/usePickerDropdown.d.ts +17 -0
- package/dist/components/dm-breadcrumb/index.js +18 -18
- package/dist/components/dm-date-picker/index.js +635 -133
- package/dist/components/dm-drawer/index.js +269 -40
- package/dist/components/dm-layout/index.js +575 -208
- package/dist/components/dm-menu/index.js +399 -32
- package/dist/components/dm-message/index.js +18 -18
- package/dist/components/dm-page-header/index.js +537 -247
- package/dist/components/dm-pagination/index.js +39 -39
- package/dist/components/dm-pro-table/index.js +2374 -1559
- package/dist/components/dm-provider/index.js +94 -94
- package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
- package/dist/components/dm-query/index.js +955 -210
- package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
- package/dist/components/dm-search/index.js +937 -183
- package/dist/components/dm-splitter/index.js +32 -32
- package/dist/components/dm-status/index.js +25 -25
- package/dist/components/dm-table/index.js +1430 -676
- package/dist/components/dm-tabs/index.js +34 -34
- package/dist/components/dm-toolbar/index.js +423 -133
- package/dist/components/dm-tree/index.js +92 -92
- package/dist/components/dm-truncate/index.js +145 -65
- package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
- package/dist/components/dropdown/index.js +467 -177
- package/dist/components/fab/Fab.d.ts +4 -0
- package/dist/components/fab/Fab.types.d.ts +25 -0
- package/dist/components/fab/index.d.ts +2 -0
- package/dist/components/fab/index.js +480 -0
- package/dist/components/form/Form.types.d.ts +1 -0
- package/dist/components/form/index.js +16 -5
- package/dist/components/grid/index.js +2 -2
- package/dist/components/input/index.js +4 -4
- package/dist/components/markdown/index.js +1 -1
- package/dist/components/megamenu/Megamenu.d.ts +2 -0
- package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
- package/dist/components/megamenu/index.d.ts +2 -0
- package/dist/components/megamenu/index.js +214 -0
- package/dist/components/message/index.js +5 -5
- package/dist/components/modal/index.js +128 -68
- package/dist/components/notification/index.js +2 -2
- package/dist/components/otp-input/OtpInput.d.ts +2 -0
- package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
- package/dist/components/otp-input/index.d.ts +2 -0
- package/dist/components/otp-input/index.js +112 -0
- package/dist/components/popconfirm/index.js +297 -68
- package/dist/components/popover/index.js +24 -4
- package/dist/components/skeleton/index.js +5 -5
- package/dist/components/spin/index.js +2 -2
- package/dist/components/steps/index.js +2 -2
- package/dist/components/swap/Swap.d.ts +3 -0
- package/dist/components/swap/Swap.types.d.ts +22 -0
- package/dist/components/swap/index.d.ts +2 -0
- package/dist/components/swap/index.js +109 -0
- package/dist/components/table/index.js +2 -2
- package/dist/components/tabs/index.js +2 -2
- package/dist/components/tag/index.js +2 -2
- package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
- package/dist/components/time-picker/index.js +167 -29
- package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
- package/dist/components/tooltip/index.js +107 -27
- package/dist/components/tour/index.js +315 -86
- package/dist/components/tree-select/index.js +8 -8
- package/dist/components/typography/index.js +4 -4
- package/dist/components/upload/Upload.types.d.ts +1 -0
- package/dist/components/upload/index.js +7 -5
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4023 -2134
- package/dist/infrastructure.js +11 -11
- package/dist/styles.css +13677 -9811
- package/dist/theme/index.js +3 -3
- package/dist/utils/index.js +5 -5
- package/package.json +30 -6
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
// src/components/dm-search/DmSearch.tsx
|
|
4
|
+
import {
|
|
5
|
+
forwardRef as forwardRef5,
|
|
6
|
+
useEffect as useEffect2,
|
|
7
|
+
useImperativeHandle as useImperativeHandle3,
|
|
8
|
+
useMemo as useMemo4,
|
|
9
|
+
useState as useState6
|
|
10
|
+
} from "react";
|
|
11
|
+
|
|
3
12
|
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
4
13
|
function r(e) {
|
|
5
14
|
var t, f, n = "";
|
|
@@ -25,6 +34,26 @@ function clsx() {
|
|
|
25
34
|
function cn(...inputs) {
|
|
26
35
|
return clsx(inputs);
|
|
27
36
|
}
|
|
37
|
+
// src/classes/dm-search.ts
|
|
38
|
+
var dmSearchBaseClass = "dm-search";
|
|
39
|
+
var dmSearchCompactClass = "dm-search-compact";
|
|
40
|
+
var dmSearchCollapsedClass = "dm-search-collapsed";
|
|
41
|
+
var dmSearchFieldsClass = "dm-search-fields";
|
|
42
|
+
var dmSearchFieldClass = "dm-search-field";
|
|
43
|
+
var dmSearchActionsClass = "dm-search-actions";
|
|
44
|
+
var dmSearchFastFilterClass = "dm-search-fast-filter";
|
|
45
|
+
function getDmSearchClasses({
|
|
46
|
+
compact,
|
|
47
|
+
collapsed,
|
|
48
|
+
className
|
|
49
|
+
}) {
|
|
50
|
+
return cn(dmSearchBaseClass, compact && dmSearchCompactClass, collapsed && dmSearchCollapsedClass, className);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/components/button/Button.tsx
|
|
54
|
+
import React from "react";
|
|
55
|
+
import { createPortal } from "react-dom";
|
|
56
|
+
|
|
28
57
|
// src/classes/button.ts
|
|
29
58
|
var buttonBaseClass = "btn";
|
|
30
59
|
var buttonColorClasses = {
|
|
@@ -48,7 +77,7 @@ var buttonAppearanceClasses = {
|
|
|
48
77
|
};
|
|
49
78
|
var buttonShapeClasses = {
|
|
50
79
|
rect: "",
|
|
51
|
-
circle: "btn-circle",
|
|
80
|
+
circle: "btn-circle btn-icon",
|
|
52
81
|
square: "btn-square"
|
|
53
82
|
};
|
|
54
83
|
var buttonSizeClasses = {
|
|
@@ -68,11 +97,14 @@ function getButtonClasses({
|
|
|
68
97
|
isLoading,
|
|
69
98
|
className
|
|
70
99
|
}) {
|
|
71
|
-
return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
|
|
100
|
+
return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], shape === "circle" && size === "xs" && "btn-icon-sm", shape === "circle" && size === "sm" && "btn-icon-sm", shape === "circle" && size === "lg" && "btn-icon-lg", block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
|
|
72
101
|
}
|
|
73
102
|
|
|
74
103
|
// src/components/button/Button.tsx
|
|
75
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
104
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
105
|
+
function isPromiseLike(value) {
|
|
106
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
107
|
+
}
|
|
76
108
|
function Button({
|
|
77
109
|
color = "primary",
|
|
78
110
|
appearance = "filled",
|
|
@@ -86,8 +118,155 @@ function Button({
|
|
|
86
118
|
children,
|
|
87
119
|
disabled,
|
|
88
120
|
ref,
|
|
121
|
+
confirm,
|
|
122
|
+
onClick,
|
|
89
123
|
...props
|
|
90
124
|
}) {
|
|
125
|
+
const buttonRef = React.useRef(null);
|
|
126
|
+
const popoverRef = React.useRef(null);
|
|
127
|
+
const cancelRef = React.useRef(null);
|
|
128
|
+
const approvalRef = React.useRef("idle");
|
|
129
|
+
const pendingRef = React.useRef(false);
|
|
130
|
+
const actionRef = React.useRef(0);
|
|
131
|
+
const operationRef = React.useRef(0);
|
|
132
|
+
const mountedRef = React.useRef(false);
|
|
133
|
+
const [portalTarget, setPortalTarget] = React.useState(null);
|
|
134
|
+
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
|
135
|
+
const [confirmError, setConfirmError] = React.useState(false);
|
|
136
|
+
const generatedId = React.useId().replace(/:/g, "");
|
|
137
|
+
const popoverId = `button-confirm-${generatedId}`;
|
|
138
|
+
const titleId = `${popoverId}-title`;
|
|
139
|
+
const descriptionId = `${popoverId}-description`;
|
|
140
|
+
const anchor = `--${popoverId}-anchor`;
|
|
141
|
+
const hasConfirm = Boolean(confirm);
|
|
142
|
+
const confirmation = confirm && typeof confirm === "object" ? confirm : undefined;
|
|
143
|
+
const title = confirmation ? confirmation.title : "Confirm action";
|
|
144
|
+
const hasTitle = title !== undefined && title !== null && title !== false && title !== "";
|
|
145
|
+
const content = confirmation?.component ?? confirmation?.message ?? confirmation?.description;
|
|
146
|
+
const hasContent = content !== undefined && content !== null && content !== false && content !== "";
|
|
147
|
+
const mergedRef = React.useCallback((node) => {
|
|
148
|
+
buttonRef.current = node;
|
|
149
|
+
if (!node) {
|
|
150
|
+
if (typeof ref === "function")
|
|
151
|
+
ref(null);
|
|
152
|
+
else if (ref)
|
|
153
|
+
ref.current = null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const cleanup = typeof ref === "function" ? ref(node) : undefined;
|
|
157
|
+
if (ref && typeof ref !== "function")
|
|
158
|
+
ref.current = node;
|
|
159
|
+
return () => {
|
|
160
|
+
buttonRef.current = null;
|
|
161
|
+
if (typeof cleanup === "function")
|
|
162
|
+
cleanup();
|
|
163
|
+
else if (typeof ref === "function")
|
|
164
|
+
ref(null);
|
|
165
|
+
else if (ref)
|
|
166
|
+
ref.current = null;
|
|
167
|
+
};
|
|
168
|
+
}, [ref]);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
mountedRef.current = true;
|
|
171
|
+
return () => {
|
|
172
|
+
mountedRef.current = false;
|
|
173
|
+
operationRef.current += 1;
|
|
174
|
+
};
|
|
175
|
+
}, []);
|
|
176
|
+
React.useEffect(() => {
|
|
177
|
+
operationRef.current += 1;
|
|
178
|
+
approvalRef.current = "idle";
|
|
179
|
+
setConfirmError(false);
|
|
180
|
+
setPortalTarget(hasConfirm ? document.body : null);
|
|
181
|
+
}, [hasConfirm]);
|
|
182
|
+
function closePopover() {
|
|
183
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
184
|
+
popoverRef.current.hidePopover();
|
|
185
|
+
}
|
|
186
|
+
buttonRef.current?.focus();
|
|
187
|
+
}
|
|
188
|
+
function handleClick(event) {
|
|
189
|
+
if (!confirm) {
|
|
190
|
+
onClick?.(event);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (approvalRef.current === "native") {
|
|
194
|
+
approvalRef.current = "idle";
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (approvalRef.current === "action") {
|
|
198
|
+
approvalRef.current = "idle";
|
|
199
|
+
let result;
|
|
200
|
+
try {
|
|
201
|
+
result = onClick?.(event);
|
|
202
|
+
} catch {
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
pendingRef.current = false;
|
|
205
|
+
setConfirmError(true);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!isPromiseLike(result)) {
|
|
209
|
+
pendingRef.current = false;
|
|
210
|
+
closePopover();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const userPreventedDefault = event.defaultPrevented;
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
setConfirmLoading(true);
|
|
216
|
+
const action = actionRef.current;
|
|
217
|
+
const operation = operationRef.current;
|
|
218
|
+
Promise.resolve(result).then(() => {
|
|
219
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
220
|
+
return;
|
|
221
|
+
pendingRef.current = false;
|
|
222
|
+
setConfirmLoading(false);
|
|
223
|
+
if (operation !== operationRef.current)
|
|
224
|
+
return;
|
|
225
|
+
closePopover();
|
|
226
|
+
if (!userPreventedDefault && !buttonRef.current?.disabled) {
|
|
227
|
+
approvalRef.current = "native";
|
|
228
|
+
buttonRef.current?.click();
|
|
229
|
+
approvalRef.current = "idle";
|
|
230
|
+
}
|
|
231
|
+
}, () => {
|
|
232
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
233
|
+
return;
|
|
234
|
+
pendingRef.current = false;
|
|
235
|
+
setConfirmLoading(false);
|
|
236
|
+
if (operation !== operationRef.current)
|
|
237
|
+
return;
|
|
238
|
+
setConfirmError(true);
|
|
239
|
+
cancelRef.current?.focus();
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
event.preventDefault();
|
|
244
|
+
if (disabled || isLoading || pendingRef.current)
|
|
245
|
+
return;
|
|
246
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
247
|
+
closePopover();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setConfirmError(false);
|
|
251
|
+
popoverRef.current?.showPopover();
|
|
252
|
+
cancelRef.current?.focus();
|
|
253
|
+
}
|
|
254
|
+
function handleConfirm(event) {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
event.stopPropagation();
|
|
257
|
+
const trigger = buttonRef.current;
|
|
258
|
+
if (disabled || isLoading || pendingRef.current || !trigger || trigger.disabled || !event.currentTarget.matches(":popover-open"))
|
|
259
|
+
return;
|
|
260
|
+
setConfirmError(false);
|
|
261
|
+
pendingRef.current = true;
|
|
262
|
+
actionRef.current += 1;
|
|
263
|
+
approvalRef.current = "action";
|
|
264
|
+
trigger.click();
|
|
265
|
+
if (approvalRef.current === "action") {
|
|
266
|
+
approvalRef.current = "idle";
|
|
267
|
+
pendingRef.current = false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
91
270
|
const classes = getButtonClasses({
|
|
92
271
|
color,
|
|
93
272
|
appearance,
|
|
@@ -97,34 +276,526 @@ function Button({
|
|
|
97
276
|
isLoading,
|
|
98
277
|
className
|
|
99
278
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
...props,
|
|
279
|
+
const confirmClasses = getButtonClasses({
|
|
280
|
+
color,
|
|
281
|
+
size: "sm",
|
|
282
|
+
isLoading: confirmLoading
|
|
283
|
+
});
|
|
284
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
107
285
|
children: [
|
|
108
|
-
|
|
109
|
-
|
|
286
|
+
/* @__PURE__ */ jsxs("button", {
|
|
287
|
+
ref: confirm ? mergedRef : ref,
|
|
288
|
+
className: classes,
|
|
289
|
+
disabled: disabled || isLoading,
|
|
290
|
+
"aria-busy": isLoading,
|
|
291
|
+
"aria-disabled": disabled || isLoading,
|
|
292
|
+
...props,
|
|
293
|
+
style: confirm ? { ...props.style, anchorName: anchor } : props.style,
|
|
294
|
+
"aria-haspopup": confirm ? "dialog" : props["aria-haspopup"],
|
|
295
|
+
"aria-controls": confirm ? popoverId : props["aria-controls"],
|
|
296
|
+
onClick: confirm ? handleClick : onClick,
|
|
297
|
+
children: [
|
|
298
|
+
isLoading && /* @__PURE__ */ jsx("span", {
|
|
299
|
+
className: "btn-spinner"
|
|
300
|
+
}),
|
|
301
|
+
!isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
|
|
302
|
+
className: "btn-icon-left",
|
|
303
|
+
children: leftIcon
|
|
304
|
+
}),
|
|
305
|
+
/* @__PURE__ */ jsx("span", {
|
|
306
|
+
className: "btn-content",
|
|
307
|
+
children
|
|
308
|
+
}),
|
|
309
|
+
!isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
|
|
310
|
+
className: "btn-icon-right",
|
|
311
|
+
children: rightIcon
|
|
312
|
+
})
|
|
313
|
+
]
|
|
110
314
|
}),
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
315
|
+
confirm && portalTarget && createPortal(/* @__PURE__ */ jsxs("form", {
|
|
316
|
+
id: popoverId,
|
|
317
|
+
ref: popoverRef,
|
|
318
|
+
popover: "auto",
|
|
319
|
+
role: "dialog",
|
|
320
|
+
"aria-labelledby": hasTitle ? titleId : undefined,
|
|
321
|
+
"aria-label": hasTitle ? undefined : "Confirm action",
|
|
322
|
+
"aria-describedby": hasContent ? descriptionId : undefined,
|
|
323
|
+
className: "popover popover-confirm popover-bottom",
|
|
324
|
+
style: { positionAnchor: anchor },
|
|
325
|
+
onSubmit: handleConfirm,
|
|
326
|
+
onClick: (event) => event.stopPropagation(),
|
|
327
|
+
onToggle: (event) => {
|
|
328
|
+
if (!event.currentTarget.matches(":popover-open")) {
|
|
329
|
+
operationRef.current += 1;
|
|
330
|
+
if (event.currentTarget.contains(document.activeElement) || document.activeElement === document.body) {
|
|
331
|
+
buttonRef.current?.focus();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
children: [
|
|
336
|
+
hasTitle && /* @__PURE__ */ jsx("div", {
|
|
337
|
+
className: "popover-header",
|
|
338
|
+
children: /* @__PURE__ */ jsx("h3", {
|
|
339
|
+
id: titleId,
|
|
340
|
+
className: "popover-title",
|
|
341
|
+
children: title
|
|
342
|
+
})
|
|
343
|
+
}),
|
|
344
|
+
hasContent && /* @__PURE__ */ jsx("div", {
|
|
345
|
+
id: descriptionId,
|
|
346
|
+
className: "popover-body",
|
|
347
|
+
children: content
|
|
348
|
+
}),
|
|
349
|
+
confirmError && /* @__PURE__ */ jsx("div", {
|
|
350
|
+
role: "alert",
|
|
351
|
+
className: "popover-body",
|
|
352
|
+
children: "The action failed. Please try again."
|
|
353
|
+
}),
|
|
354
|
+
/* @__PURE__ */ jsxs("div", {
|
|
355
|
+
className: "popover-footer",
|
|
356
|
+
children: [
|
|
357
|
+
/* @__PURE__ */ jsx("button", {
|
|
358
|
+
ref: cancelRef,
|
|
359
|
+
type: "button",
|
|
360
|
+
className: "btn btn-text btn-sm",
|
|
361
|
+
popoverTarget: popoverId,
|
|
362
|
+
popoverTargetAction: "hide",
|
|
363
|
+
disabled: confirmLoading,
|
|
364
|
+
children: confirmation?.cancelText ?? "Cancel"
|
|
365
|
+
}),
|
|
366
|
+
/* @__PURE__ */ jsx("button", {
|
|
367
|
+
type: "submit",
|
|
368
|
+
className: confirmClasses,
|
|
369
|
+
disabled: disabled || isLoading || confirmLoading,
|
|
370
|
+
"aria-busy": confirmLoading,
|
|
371
|
+
children: confirmation?.confirmText ?? "Confirm"
|
|
372
|
+
})
|
|
373
|
+
]
|
|
374
|
+
})
|
|
375
|
+
]
|
|
376
|
+
}), portalTarget)
|
|
377
|
+
]
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
// src/components/date-picker/DatePicker.tsx
|
|
381
|
+
import { forwardRef as forwardRef2, useMemo as useMemo2, useState as useState3 } from "react";
|
|
382
|
+
|
|
383
|
+
// src/components/calendar/Calendar.tsx
|
|
384
|
+
import { forwardRef, useMemo, useState } from "react";
|
|
385
|
+
|
|
386
|
+
// src/classes/calendar.ts
|
|
387
|
+
var calendarBaseClass = "datepicker calendar";
|
|
388
|
+
var calendarHeaderClass = "calendar-header";
|
|
389
|
+
var calendarTitleClass = "calendar-title";
|
|
390
|
+
var calendarControlsClass = "calendar-controls";
|
|
391
|
+
var calendarNavClass = "calendar-nav";
|
|
392
|
+
var calendarModeClass = "calendar-mode";
|
|
393
|
+
var calendarWeekdaysClass = "calendar-weekdays";
|
|
394
|
+
var calendarWeekdayClass = "calendar-weekday";
|
|
395
|
+
var calendarBodyClass = "calendar-body";
|
|
396
|
+
var calendarDateGridClass = "calendar-date-grid";
|
|
397
|
+
var calendarMonthGridClass = "calendar-month-grid";
|
|
398
|
+
var calendarCellContentClass = "calendar-cell-content";
|
|
399
|
+
function getCalendarClasses({
|
|
400
|
+
fullscreen = true,
|
|
401
|
+
mode = "month",
|
|
402
|
+
className
|
|
403
|
+
}) {
|
|
404
|
+
return cn(calendarBaseClass, fullscreen ? "calendar-fullscreen" : "calendar-card", mode === "year" && "calendar-year-mode", className);
|
|
405
|
+
}
|
|
406
|
+
function getCalendarCellClasses({
|
|
407
|
+
selected,
|
|
408
|
+
today,
|
|
409
|
+
outside,
|
|
410
|
+
disabled,
|
|
411
|
+
className
|
|
412
|
+
}) {
|
|
413
|
+
return cn("calendar-cell", selected && "calendar-cell-selected", today && "calendar-cell-today", outside && "calendar-cell-outside", disabled && "calendar-cell-disabled", className);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/components/calendar/Calendar.tsx
|
|
417
|
+
import { jsx as jsx2, jsxs as jsxs2, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
418
|
+
var WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
419
|
+
var MONTHS = [
|
|
420
|
+
"Jan",
|
|
421
|
+
"Feb",
|
|
422
|
+
"Mar",
|
|
423
|
+
"Apr",
|
|
424
|
+
"May",
|
|
425
|
+
"Jun",
|
|
426
|
+
"Jul",
|
|
427
|
+
"Aug",
|
|
428
|
+
"Sep",
|
|
429
|
+
"Oct",
|
|
430
|
+
"Nov",
|
|
431
|
+
"Dec"
|
|
432
|
+
];
|
|
433
|
+
function pad(value) {
|
|
434
|
+
return String(value).padStart(2, "0");
|
|
435
|
+
}
|
|
436
|
+
function formatDate(date) {
|
|
437
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
438
|
+
}
|
|
439
|
+
function formatMonth(date) {
|
|
440
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-01`;
|
|
441
|
+
}
|
|
442
|
+
function parseDate(value) {
|
|
443
|
+
if (value instanceof Date && !Number.isNaN(value.getTime())) {
|
|
444
|
+
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
|
|
445
|
+
}
|
|
446
|
+
if (typeof value === "string" && value.length > 0) {
|
|
447
|
+
const [year, month = "1", day = "1"] = value.split("-");
|
|
448
|
+
const parsed = new Date(Number(year), Number(month) - 1, Number(day));
|
|
449
|
+
if (!Number.isNaN(parsed.getTime())) {
|
|
450
|
+
return parsed;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const today = new Date;
|
|
454
|
+
return new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
455
|
+
}
|
|
456
|
+
function addMonths(date, amount) {
|
|
457
|
+
return new Date(date.getFullYear(), date.getMonth() + amount, 1);
|
|
458
|
+
}
|
|
459
|
+
function addYears(date, amount) {
|
|
460
|
+
return new Date(date.getFullYear() + amount, date.getMonth(), 1);
|
|
461
|
+
}
|
|
462
|
+
function startOfCalendarGrid(panelDate) {
|
|
463
|
+
const firstOfMonth = new Date(panelDate.getFullYear(), panelDate.getMonth(), 1);
|
|
464
|
+
const start = new Date(firstOfMonth);
|
|
465
|
+
start.setDate(firstOfMonth.getDate() - firstOfMonth.getDay());
|
|
466
|
+
return start;
|
|
467
|
+
}
|
|
468
|
+
function buildDateGrid(panelDate) {
|
|
469
|
+
const start = startOfCalendarGrid(panelDate);
|
|
470
|
+
return Array.from({ length: 42 }, (_, index) => {
|
|
471
|
+
const date = new Date(start);
|
|
472
|
+
date.setDate(start.getDate() + index);
|
|
473
|
+
return date;
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
function isSameMonth(left, right) {
|
|
477
|
+
return left.getFullYear() === right.getFullYear() && left.getMonth() === right.getMonth();
|
|
478
|
+
}
|
|
479
|
+
function isOutsideRange(date, validRange) {
|
|
480
|
+
if (!validRange) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const current = formatDate(date);
|
|
484
|
+
const start = formatDate(parseDate(validRange[0]));
|
|
485
|
+
const end = formatDate(parseDate(validRange[1]));
|
|
486
|
+
return current < start || current > end;
|
|
487
|
+
}
|
|
488
|
+
function Header({
|
|
489
|
+
panelDate,
|
|
490
|
+
mode,
|
|
491
|
+
setPanelDate,
|
|
492
|
+
setMode
|
|
493
|
+
}) {
|
|
494
|
+
const title = mode === "year" ? String(panelDate.getFullYear()) : `${MONTHS[panelDate.getMonth()]} ${panelDate.getFullYear()}`;
|
|
495
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
496
|
+
className: calendarHeaderClass,
|
|
497
|
+
children: [
|
|
498
|
+
/* @__PURE__ */ jsx2("button", {
|
|
499
|
+
type: "button",
|
|
500
|
+
className: calendarNavClass,
|
|
501
|
+
"aria-label": "Previous panel",
|
|
502
|
+
onClick: () => setPanelDate(mode === "year" ? addYears(panelDate, -1) : addMonths(panelDate, -1), mode),
|
|
503
|
+
children: /* @__PURE__ */ jsx2("svg", {
|
|
504
|
+
"aria-hidden": "true",
|
|
505
|
+
focusable: "false",
|
|
506
|
+
width: "16",
|
|
507
|
+
height: "16",
|
|
508
|
+
viewBox: "0 0 24 24",
|
|
509
|
+
fill: "none",
|
|
510
|
+
stroke: "currentColor",
|
|
511
|
+
strokeWidth: "2",
|
|
512
|
+
strokeLinecap: "round",
|
|
513
|
+
strokeLinejoin: "round",
|
|
514
|
+
children: /* @__PURE__ */ jsx2("path", {
|
|
515
|
+
d: "m15 18-6-6 6-6"
|
|
516
|
+
})
|
|
517
|
+
})
|
|
114
518
|
}),
|
|
115
|
-
/* @__PURE__ */
|
|
116
|
-
className:
|
|
117
|
-
children
|
|
519
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
520
|
+
className: calendarControlsClass,
|
|
521
|
+
children: [
|
|
522
|
+
/* @__PURE__ */ jsx2("div", {
|
|
523
|
+
className: calendarTitleClass,
|
|
524
|
+
children: title
|
|
525
|
+
}),
|
|
526
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
527
|
+
className: calendarModeClass,
|
|
528
|
+
children: [
|
|
529
|
+
/* @__PURE__ */ jsx2("button", {
|
|
530
|
+
type: "button",
|
|
531
|
+
"aria-pressed": mode === "month",
|
|
532
|
+
onClick: () => setMode("month"),
|
|
533
|
+
children: "Month"
|
|
534
|
+
}),
|
|
535
|
+
/* @__PURE__ */ jsx2("button", {
|
|
536
|
+
type: "button",
|
|
537
|
+
"aria-pressed": mode === "year",
|
|
538
|
+
onClick: () => setMode("year"),
|
|
539
|
+
children: "Year"
|
|
540
|
+
})
|
|
541
|
+
]
|
|
542
|
+
})
|
|
543
|
+
]
|
|
118
544
|
}),
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
545
|
+
/* @__PURE__ */ jsx2("button", {
|
|
546
|
+
type: "button",
|
|
547
|
+
className: calendarNavClass,
|
|
548
|
+
"aria-label": "Next panel",
|
|
549
|
+
onClick: () => setPanelDate(mode === "year" ? addYears(panelDate, 1) : addMonths(panelDate, 1), mode),
|
|
550
|
+
children: /* @__PURE__ */ jsx2("svg", {
|
|
551
|
+
"aria-hidden": "true",
|
|
552
|
+
focusable: "false",
|
|
553
|
+
width: "16",
|
|
554
|
+
height: "16",
|
|
555
|
+
viewBox: "0 0 24 24",
|
|
556
|
+
fill: "none",
|
|
557
|
+
stroke: "currentColor",
|
|
558
|
+
strokeWidth: "2",
|
|
559
|
+
strokeLinecap: "round",
|
|
560
|
+
strokeLinejoin: "round",
|
|
561
|
+
children: /* @__PURE__ */ jsx2("path", {
|
|
562
|
+
d: "m9 18 6-6-6-6"
|
|
563
|
+
})
|
|
564
|
+
})
|
|
122
565
|
})
|
|
123
566
|
]
|
|
124
567
|
});
|
|
125
568
|
}
|
|
126
|
-
|
|
127
|
-
|
|
569
|
+
var Calendar = forwardRef(({
|
|
570
|
+
className,
|
|
571
|
+
value,
|
|
572
|
+
defaultValue,
|
|
573
|
+
mode,
|
|
574
|
+
defaultMode = "month",
|
|
575
|
+
fullscreen = true,
|
|
576
|
+
validRange,
|
|
577
|
+
disabledDate,
|
|
578
|
+
dateCellRender,
|
|
579
|
+
dateFullCellRender,
|
|
580
|
+
monthCellRender,
|
|
581
|
+
monthFullCellRender,
|
|
582
|
+
cellRender,
|
|
583
|
+
fullCellRender,
|
|
584
|
+
headerRender,
|
|
585
|
+
onChange,
|
|
586
|
+
onSelect,
|
|
587
|
+
onPanelChange,
|
|
588
|
+
...props
|
|
589
|
+
}, ref) => {
|
|
590
|
+
const selectedDate = parseDate(value ?? defaultValue);
|
|
591
|
+
const [innerValue, setInnerValue] = useState(() => formatDate(selectedDate));
|
|
592
|
+
const [panelDate, setInnerPanelDate] = useState(selectedDate);
|
|
593
|
+
const [innerMode, setInnerMode] = useState(mode ?? defaultMode);
|
|
594
|
+
const currentMode = mode ?? innerMode;
|
|
595
|
+
const currentValue = value === undefined ? innerValue : formatDate(parseDate(value));
|
|
596
|
+
const today = useMemo(() => formatDate(new Date), []);
|
|
597
|
+
const dateGrid = useMemo(() => buildDateGrid(panelDate), [panelDate]);
|
|
598
|
+
function emitPanelChange(nextDate, nextMode = currentMode) {
|
|
599
|
+
setInnerPanelDate(nextDate);
|
|
600
|
+
onPanelChange?.(formatDate(nextDate), nextMode);
|
|
601
|
+
}
|
|
602
|
+
function setCalendarMode(nextMode) {
|
|
603
|
+
if (mode === undefined) {
|
|
604
|
+
setInnerMode(nextMode);
|
|
605
|
+
}
|
|
606
|
+
onPanelChange?.(formatDate(panelDate), nextMode);
|
|
607
|
+
}
|
|
608
|
+
function commitValue(nextDate, source) {
|
|
609
|
+
const nextValue = source === "month" ? formatMonth(nextDate) : formatDate(nextDate);
|
|
610
|
+
if (disabledDate?.(nextValue) || isOutsideRange(nextDate, validRange)) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (value === undefined) {
|
|
614
|
+
setInnerValue(nextValue);
|
|
615
|
+
}
|
|
616
|
+
setInnerPanelDate(nextDate);
|
|
617
|
+
onSelect?.(nextValue, { source });
|
|
618
|
+
onChange?.(nextValue);
|
|
619
|
+
}
|
|
620
|
+
function renderDateCell(date) {
|
|
621
|
+
const dateValue = formatDate(date);
|
|
622
|
+
const originNode = /* @__PURE__ */ jsxs2("div", {
|
|
623
|
+
className: calendarCellContentClass,
|
|
624
|
+
children: [
|
|
625
|
+
/* @__PURE__ */ jsx2("span", {
|
|
626
|
+
children: date.getDate()
|
|
627
|
+
}),
|
|
628
|
+
dateCellRender?.(dateValue)
|
|
629
|
+
]
|
|
630
|
+
});
|
|
631
|
+
const info = {
|
|
632
|
+
originNode,
|
|
633
|
+
today,
|
|
634
|
+
type: "month"
|
|
635
|
+
};
|
|
636
|
+
const content = fullCellRender?.(dateValue, info) ?? dateFullCellRender?.(dateValue) ?? cellRender?.(dateValue, info) ?? originNode;
|
|
637
|
+
const disabled = disabledDate?.(dateValue) || isOutsideRange(date, validRange);
|
|
638
|
+
return /* @__PURE__ */ jsx2("button", {
|
|
639
|
+
type: "button",
|
|
640
|
+
"aria-label": dateValue,
|
|
641
|
+
disabled,
|
|
642
|
+
className: getCalendarCellClasses({
|
|
643
|
+
selected: dateValue === currentValue,
|
|
644
|
+
today: dateValue === today,
|
|
645
|
+
outside: !isSameMonth(date, panelDate),
|
|
646
|
+
disabled
|
|
647
|
+
}),
|
|
648
|
+
onClick: () => commitValue(date, "date"),
|
|
649
|
+
children: content
|
|
650
|
+
}, dateValue);
|
|
651
|
+
}
|
|
652
|
+
function renderMonthCell(month) {
|
|
653
|
+
const date = new Date(panelDate.getFullYear(), month, 1);
|
|
654
|
+
const dateValue = formatMonth(date);
|
|
655
|
+
const originNode = /* @__PURE__ */ jsxs2("div", {
|
|
656
|
+
className: calendarCellContentClass,
|
|
657
|
+
children: [
|
|
658
|
+
/* @__PURE__ */ jsx2("span", {
|
|
659
|
+
children: MONTHS[month]
|
|
660
|
+
}),
|
|
661
|
+
monthCellRender?.(dateValue)
|
|
662
|
+
]
|
|
663
|
+
});
|
|
664
|
+
const info = {
|
|
665
|
+
originNode,
|
|
666
|
+
today,
|
|
667
|
+
type: "year"
|
|
668
|
+
};
|
|
669
|
+
const content = fullCellRender?.(dateValue, info) ?? monthFullCellRender?.(dateValue) ?? cellRender?.(dateValue, info) ?? originNode;
|
|
670
|
+
const disabled = disabledDate?.(dateValue) || isOutsideRange(date, validRange);
|
|
671
|
+
return /* @__PURE__ */ jsx2("button", {
|
|
672
|
+
type: "button",
|
|
673
|
+
"aria-label": dateValue,
|
|
674
|
+
disabled,
|
|
675
|
+
className: getCalendarCellClasses({
|
|
676
|
+
selected: dateValue === formatMonth(parseDate(currentValue)),
|
|
677
|
+
today: dateValue === formatMonth(new Date),
|
|
678
|
+
disabled
|
|
679
|
+
}),
|
|
680
|
+
onClick: () => commitValue(date, "month"),
|
|
681
|
+
children: content
|
|
682
|
+
}, dateValue);
|
|
683
|
+
}
|
|
684
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
685
|
+
...props,
|
|
686
|
+
ref,
|
|
687
|
+
className: getCalendarClasses({
|
|
688
|
+
fullscreen,
|
|
689
|
+
mode: currentMode,
|
|
690
|
+
className
|
|
691
|
+
}),
|
|
692
|
+
children: [
|
|
693
|
+
headerRender ? headerRender({
|
|
694
|
+
value: formatDate(panelDate),
|
|
695
|
+
type: currentMode,
|
|
696
|
+
onChange: (nextValue) => emitPanelChange(parseDate(nextValue)),
|
|
697
|
+
onTypeChange: setCalendarMode
|
|
698
|
+
}) : /* @__PURE__ */ jsx2(Header, {
|
|
699
|
+
panelDate,
|
|
700
|
+
mode: currentMode,
|
|
701
|
+
setPanelDate: emitPanelChange,
|
|
702
|
+
setMode: setCalendarMode
|
|
703
|
+
}),
|
|
704
|
+
/* @__PURE__ */ jsx2("div", {
|
|
705
|
+
className: calendarBodyClass,
|
|
706
|
+
children: currentMode === "month" ? /* @__PURE__ */ jsxs2(Fragment2, {
|
|
707
|
+
children: [
|
|
708
|
+
/* @__PURE__ */ jsx2("div", {
|
|
709
|
+
className: calendarWeekdaysClass,
|
|
710
|
+
"aria-hidden": "true",
|
|
711
|
+
children: WEEKDAYS.map((weekday) => /* @__PURE__ */ jsx2("span", {
|
|
712
|
+
className: calendarWeekdayClass,
|
|
713
|
+
children: weekday
|
|
714
|
+
}, weekday))
|
|
715
|
+
}),
|
|
716
|
+
/* @__PURE__ */ jsx2("div", {
|
|
717
|
+
className: calendarDateGridClass,
|
|
718
|
+
children: dateGrid.map(renderDateCell)
|
|
719
|
+
})
|
|
720
|
+
]
|
|
721
|
+
}) : /* @__PURE__ */ jsx2("div", {
|
|
722
|
+
className: calendarMonthGridClass,
|
|
723
|
+
children: MONTHS.map((_, month) => renderMonthCell(month))
|
|
724
|
+
})
|
|
725
|
+
})
|
|
726
|
+
]
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
Calendar.displayName = "Calendar";
|
|
730
|
+
// src/components/date-picker/usePickerDropdown.ts
|
|
731
|
+
import { useEffect, useId, useImperativeHandle, useRef, useState as useState2 } from "react";
|
|
732
|
+
function usePickerDropdown({
|
|
733
|
+
open,
|
|
734
|
+
defaultOpen,
|
|
735
|
+
disabled,
|
|
736
|
+
onOpenChange,
|
|
737
|
+
ref
|
|
738
|
+
}) {
|
|
739
|
+
const rootRef = useRef(null);
|
|
740
|
+
const inputRef = useRef(null);
|
|
741
|
+
const skipFocus = useRef(false);
|
|
742
|
+
const panelId = useId();
|
|
743
|
+
const [innerOpen, setInnerOpen] = useState2(Boolean(defaultOpen));
|
|
744
|
+
const visible = !disabled && (open ?? innerOpen);
|
|
745
|
+
useImperativeHandle(ref, () => rootRef.current, []);
|
|
746
|
+
function setVisible(next) {
|
|
747
|
+
if (disabled || next === visible)
|
|
748
|
+
return;
|
|
749
|
+
if (open === undefined)
|
|
750
|
+
setInnerOpen(next);
|
|
751
|
+
onOpenChange?.(next);
|
|
752
|
+
}
|
|
753
|
+
function closeAndFocus() {
|
|
754
|
+
skipFocus.current = true;
|
|
755
|
+
inputRef.current?.focus();
|
|
756
|
+
skipFocus.current = false;
|
|
757
|
+
setVisible(false);
|
|
758
|
+
}
|
|
759
|
+
useEffect(() => {
|
|
760
|
+
function handleOutside(event) {
|
|
761
|
+
if (visible && !rootRef.current?.contains(event.target))
|
|
762
|
+
setVisible(false);
|
|
763
|
+
}
|
|
764
|
+
function handleKeyDown(event) {
|
|
765
|
+
if (event.defaultPrevented || !rootRef.current?.contains(event.target))
|
|
766
|
+
return;
|
|
767
|
+
if (event.key === "Escape" && visible) {
|
|
768
|
+
event.preventDefault();
|
|
769
|
+
closeAndFocus();
|
|
770
|
+
} else if (event.key === "ArrowDown" && event.target === inputRef.current) {
|
|
771
|
+
event.preventDefault();
|
|
772
|
+
setVisible(true);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
document.addEventListener("pointerdown", handleOutside);
|
|
776
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
777
|
+
return () => {
|
|
778
|
+
document.removeEventListener("pointerdown", handleOutside);
|
|
779
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
780
|
+
};
|
|
781
|
+
});
|
|
782
|
+
return {
|
|
783
|
+
rootRef,
|
|
784
|
+
inputRef,
|
|
785
|
+
panelId,
|
|
786
|
+
visible,
|
|
787
|
+
setVisible,
|
|
788
|
+
closeAndFocus,
|
|
789
|
+
onInputFocus: () => {
|
|
790
|
+
if (!skipFocus.current)
|
|
791
|
+
setVisible(true);
|
|
792
|
+
},
|
|
793
|
+
onRootBlur: (event) => {
|
|
794
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
795
|
+
setVisible(false);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
128
799
|
|
|
129
800
|
// src/classes/date-picker.ts
|
|
130
801
|
var datePickerBaseClass = "datepicker";
|
|
@@ -173,7 +844,7 @@ function getDatePickerDropdownClasses({
|
|
|
173
844
|
}
|
|
174
845
|
|
|
175
846
|
// src/components/date-picker/DatePicker.tsx
|
|
176
|
-
import { jsx as
|
|
847
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
177
848
|
function todayValue(picker) {
|
|
178
849
|
const today = new Date;
|
|
179
850
|
const year = today.getFullYear();
|
|
@@ -212,9 +883,10 @@ function placeholderForPicker(picker) {
|
|
|
212
883
|
function normalizeDateValue(value) {
|
|
213
884
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
214
885
|
}
|
|
215
|
-
var DatePickerRoot =
|
|
886
|
+
var DatePickerRoot = forwardRef2(({
|
|
216
887
|
allowClear,
|
|
217
888
|
className,
|
|
889
|
+
inputProps,
|
|
218
890
|
defaultOpen,
|
|
219
891
|
defaultValue,
|
|
220
892
|
disabled,
|
|
@@ -233,19 +905,19 @@ var DatePickerRoot = forwardRef(({
|
|
|
233
905
|
value,
|
|
234
906
|
...props
|
|
235
907
|
}, ref) => {
|
|
908
|
+
const [calendarMode, setCalendarMode] = useState3("month");
|
|
236
909
|
const isValueControlled = value !== undefined;
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
|
|
910
|
+
const [innerValue, setInnerValue] = useState3(() => normalizeDateValue(defaultValue));
|
|
911
|
+
const dropdown = usePickerDropdown({
|
|
912
|
+
open,
|
|
913
|
+
defaultOpen,
|
|
914
|
+
disabled,
|
|
915
|
+
onOpenChange,
|
|
916
|
+
ref
|
|
917
|
+
});
|
|
240
918
|
const currentValue = isValueControlled ? normalizeDateValue(value) : innerValue;
|
|
241
|
-
const visible
|
|
919
|
+
const { visible, setVisible } = dropdown;
|
|
242
920
|
const inputType = inputTypeForPicker(picker);
|
|
243
|
-
function setVisible(nextOpen) {
|
|
244
|
-
if (!isOpenControlled) {
|
|
245
|
-
setInnerOpen(nextOpen);
|
|
246
|
-
}
|
|
247
|
-
onOpenChange?.(nextOpen);
|
|
248
|
-
}
|
|
249
921
|
function emitChange(nextValue) {
|
|
250
922
|
if (nextValue && disabledDate?.(nextValue)) {
|
|
251
923
|
return;
|
|
@@ -255,10 +927,17 @@ var DatePickerRoot = forwardRef(({
|
|
|
255
927
|
}
|
|
256
928
|
onChange?.(nextValue, nextValue ?? "");
|
|
257
929
|
}
|
|
258
|
-
|
|
259
|
-
|
|
930
|
+
function selectValue(nextValue) {
|
|
931
|
+
if (disabledDate?.(nextValue))
|
|
932
|
+
return;
|
|
933
|
+
emitChange(nextValue);
|
|
934
|
+
dropdown.closeAndFocus();
|
|
935
|
+
}
|
|
936
|
+
const presetItems = useMemo2(() => presets ?? [], [presets]);
|
|
937
|
+
return /* @__PURE__ */ jsxs3("div", {
|
|
260
938
|
...props,
|
|
261
|
-
ref,
|
|
939
|
+
ref: dropdown.rootRef,
|
|
940
|
+
onBlur: dropdown.onRootBlur,
|
|
262
941
|
className: getDatePickerClasses({
|
|
263
942
|
size,
|
|
264
943
|
status,
|
|
@@ -268,7 +947,11 @@ var DatePickerRoot = forwardRef(({
|
|
|
268
947
|
className
|
|
269
948
|
}),
|
|
270
949
|
children: [
|
|
271
|
-
/* @__PURE__ */
|
|
950
|
+
/* @__PURE__ */ jsx3("input", {
|
|
951
|
+
...inputProps,
|
|
952
|
+
ref: dropdown.inputRef,
|
|
953
|
+
"aria-haspopup": "dialog",
|
|
954
|
+
"aria-controls": visible ? dropdown.panelId : undefined,
|
|
272
955
|
className: datePickerInputClass,
|
|
273
956
|
disabled,
|
|
274
957
|
type: inputType,
|
|
@@ -276,15 +959,15 @@ var DatePickerRoot = forwardRef(({
|
|
|
276
959
|
placeholder: placeholder ?? placeholderForPicker(picker),
|
|
277
960
|
onFocus: (event) => {
|
|
278
961
|
onFocus?.(event);
|
|
279
|
-
|
|
962
|
+
dropdown.onInputFocus();
|
|
280
963
|
},
|
|
281
964
|
onBlur: (event) => {
|
|
282
965
|
onBlur?.(event);
|
|
283
|
-
setVisible(false);
|
|
284
966
|
},
|
|
967
|
+
onClick: () => setVisible(true),
|
|
285
968
|
onChange: (event) => emitChange(event.currentTarget.value || undefined)
|
|
286
969
|
}),
|
|
287
|
-
allowClear && currentValue && !disabled ? /* @__PURE__ */
|
|
970
|
+
allowClear && currentValue && !disabled ? /* @__PURE__ */ jsx3("button", {
|
|
288
971
|
type: "button",
|
|
289
972
|
className: datePickerClearClass,
|
|
290
973
|
"aria-label": "Clear date",
|
|
@@ -292,26 +975,95 @@ var DatePickerRoot = forwardRef(({
|
|
|
292
975
|
onClick: () => emitChange(undefined),
|
|
293
976
|
children: "x"
|
|
294
977
|
}) : null,
|
|
295
|
-
/* @__PURE__ */
|
|
978
|
+
/* @__PURE__ */ jsx3("button", {
|
|
979
|
+
type: "button",
|
|
296
980
|
className: datePickerIconClass,
|
|
297
|
-
"aria-
|
|
981
|
+
"aria-label": "Open date picker",
|
|
982
|
+
"aria-haspopup": "dialog",
|
|
983
|
+
"aria-expanded": visible,
|
|
984
|
+
"aria-controls": visible ? dropdown.panelId : undefined,
|
|
985
|
+
disabled,
|
|
986
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
987
|
+
onClick: () => setVisible(!visible),
|
|
988
|
+
children: /* @__PURE__ */ jsxs3("svg", {
|
|
989
|
+
"aria-hidden": "true",
|
|
990
|
+
focusable: "false",
|
|
991
|
+
width: "18",
|
|
992
|
+
height: "18",
|
|
993
|
+
viewBox: "0 0 24 24",
|
|
994
|
+
fill: "none",
|
|
995
|
+
stroke: "currentColor",
|
|
996
|
+
strokeWidth: "1.75",
|
|
997
|
+
strokeLinecap: "round",
|
|
998
|
+
strokeLinejoin: "round",
|
|
999
|
+
children: [
|
|
1000
|
+
/* @__PURE__ */ jsx3("rect", {
|
|
1001
|
+
x: "3",
|
|
1002
|
+
y: "5",
|
|
1003
|
+
width: "18",
|
|
1004
|
+
height: "16",
|
|
1005
|
+
rx: "2"
|
|
1006
|
+
}),
|
|
1007
|
+
/* @__PURE__ */ jsx3("path", {
|
|
1008
|
+
d: "M8 3v4M16 3v4M3 10h18"
|
|
1009
|
+
})
|
|
1010
|
+
]
|
|
1011
|
+
})
|
|
298
1012
|
}),
|
|
299
|
-
|
|
1013
|
+
visible ? /* @__PURE__ */ jsxs3("div", {
|
|
1014
|
+
id: dropdown.panelId,
|
|
1015
|
+
role: "dialog",
|
|
1016
|
+
"aria-label": "Choose date",
|
|
300
1017
|
className: getDatePickerDropdownClasses({ open: visible }),
|
|
301
1018
|
children: [
|
|
302
|
-
|
|
1019
|
+
picker === "date" || picker === "month" ? /* @__PURE__ */ jsx3(Calendar, {
|
|
1020
|
+
fullscreen: false,
|
|
1021
|
+
value: currentValue,
|
|
1022
|
+
mode: picker === "month" ? "year" : calendarMode,
|
|
1023
|
+
onPanelChange: (_, mode) => {
|
|
1024
|
+
if (picker === "date")
|
|
1025
|
+
setCalendarMode(mode);
|
|
1026
|
+
},
|
|
1027
|
+
disabledDate: (date) => {
|
|
1028
|
+
if (!disabledDate)
|
|
1029
|
+
return false;
|
|
1030
|
+
if (picker === "month")
|
|
1031
|
+
return disabledDate(date.slice(0, 7));
|
|
1032
|
+
if (calendarMode === "year") {
|
|
1033
|
+
const [year, month] = date.split("-").map(Number);
|
|
1034
|
+
const days = new Date(year, month, 0).getDate();
|
|
1035
|
+
return Array.from({ length: days }, (_, index) => `${date.slice(0, 7)}-${String(index + 1).padStart(2, "0")}`).every((day) => disabledDate(day));
|
|
1036
|
+
}
|
|
1037
|
+
return disabledDate(date);
|
|
1038
|
+
},
|
|
1039
|
+
onSelect: (date, info) => {
|
|
1040
|
+
if (picker === "date" && info.source === "month") {
|
|
1041
|
+
setCalendarMode("month");
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
selectValue(picker === "month" ? date.slice(0, 7) : date);
|
|
1045
|
+
}
|
|
1046
|
+
}) : /* @__PURE__ */ jsx3("input", {
|
|
1047
|
+
type: inputType,
|
|
1048
|
+
"aria-label": placeholderForPicker(picker),
|
|
1049
|
+
value: currentValue ?? "",
|
|
1050
|
+
onChange: (event) => selectValue(event.currentTarget.value)
|
|
1051
|
+
}),
|
|
1052
|
+
presetItems.map((preset, index) => /* @__PURE__ */ jsx3("button", {
|
|
303
1053
|
type: "button",
|
|
304
1054
|
className: datePickerPresetClass,
|
|
305
1055
|
onMouseDown: (event) => event.preventDefault(),
|
|
306
|
-
|
|
1056
|
+
disabled: Boolean(disabledDate?.(preset.value)),
|
|
1057
|
+
onClick: () => selectValue(preset.value),
|
|
307
1058
|
children: preset.label
|
|
308
1059
|
}, index)),
|
|
309
|
-
showNow ? /* @__PURE__ */
|
|
1060
|
+
showNow ? /* @__PURE__ */ jsx3("div", {
|
|
310
1061
|
className: datePickerFooterClass,
|
|
311
|
-
children: /* @__PURE__ */
|
|
1062
|
+
children: /* @__PURE__ */ jsx3("button", {
|
|
312
1063
|
type: "button",
|
|
313
1064
|
onMouseDown: (event) => event.preventDefault(),
|
|
314
|
-
|
|
1065
|
+
disabled: Boolean(disabledDate?.(todayValue(picker))),
|
|
1066
|
+
onClick: () => selectValue(todayValue(picker)),
|
|
315
1067
|
children: "Now"
|
|
316
1068
|
})
|
|
317
1069
|
}) : null
|
|
@@ -321,9 +1073,10 @@ var DatePickerRoot = forwardRef(({
|
|
|
321
1073
|
});
|
|
322
1074
|
});
|
|
323
1075
|
DatePickerRoot.displayName = "DatePicker";
|
|
324
|
-
var RangePicker =
|
|
1076
|
+
var RangePicker = forwardRef2(({
|
|
325
1077
|
allowClear,
|
|
326
1078
|
className,
|
|
1079
|
+
inputProps,
|
|
327
1080
|
defaultValue,
|
|
328
1081
|
disabled,
|
|
329
1082
|
disabledDate,
|
|
@@ -337,7 +1090,7 @@ var RangePicker = forwardRef(({
|
|
|
337
1090
|
...props
|
|
338
1091
|
}, ref) => {
|
|
339
1092
|
const isControlled = value !== undefined;
|
|
340
|
-
const [innerValue, setInnerValue] =
|
|
1093
|
+
const [innerValue, setInnerValue] = useState3(defaultValue ?? [undefined, undefined]);
|
|
341
1094
|
const currentValue = isControlled ? value : innerValue;
|
|
342
1095
|
const inputType = inputTypeForPicker(picker);
|
|
343
1096
|
function emitChange(nextValue) {
|
|
@@ -352,7 +1105,7 @@ var RangePicker = forwardRef(({
|
|
|
352
1105
|
function updateIndex(index, nextItem) {
|
|
353
1106
|
emitChange(index === 0 ? [nextItem, currentValue?.[1]] : [currentValue?.[0], nextItem]);
|
|
354
1107
|
}
|
|
355
|
-
return /* @__PURE__ */
|
|
1108
|
+
return /* @__PURE__ */ jsxs3("div", {
|
|
356
1109
|
...props,
|
|
357
1110
|
ref,
|
|
358
1111
|
className: getDatePickerClasses({
|
|
@@ -364,7 +1117,8 @@ var RangePicker = forwardRef(({
|
|
|
364
1117
|
className
|
|
365
1118
|
}),
|
|
366
1119
|
children: [
|
|
367
|
-
/* @__PURE__ */
|
|
1120
|
+
/* @__PURE__ */ jsx3("input", {
|
|
1121
|
+
...inputProps,
|
|
368
1122
|
className: datePickerInputClass,
|
|
369
1123
|
disabled,
|
|
370
1124
|
type: inputType,
|
|
@@ -372,11 +1126,13 @@ var RangePicker = forwardRef(({
|
|
|
372
1126
|
placeholder: Array.isArray(placeholder) ? placeholder[0] : "Start date",
|
|
373
1127
|
onChange: (event) => updateIndex(0, event.currentTarget.value || undefined)
|
|
374
1128
|
}),
|
|
375
|
-
/* @__PURE__ */
|
|
1129
|
+
/* @__PURE__ */ jsx3("span", {
|
|
376
1130
|
className: datePickerSeparatorClass,
|
|
377
1131
|
children: separator
|
|
378
1132
|
}),
|
|
379
|
-
/* @__PURE__ */
|
|
1133
|
+
/* @__PURE__ */ jsx3("input", {
|
|
1134
|
+
...inputProps,
|
|
1135
|
+
id: inputProps?.id ? `${inputProps.id}-end` : undefined,
|
|
380
1136
|
className: datePickerInputClass,
|
|
381
1137
|
disabled,
|
|
382
1138
|
type: inputType,
|
|
@@ -384,7 +1140,7 @@ var RangePicker = forwardRef(({
|
|
|
384
1140
|
placeholder: Array.isArray(placeholder) ? placeholder[1] : "End date",
|
|
385
1141
|
onChange: (event) => updateIndex(1, event.currentTarget.value || undefined)
|
|
386
1142
|
}),
|
|
387
|
-
allowClear && (currentValue?.[0] || currentValue?.[1]) && !disabled ? /* @__PURE__ */
|
|
1143
|
+
allowClear && (currentValue?.[0] || currentValue?.[1]) && !disabled ? /* @__PURE__ */ jsx3("button", {
|
|
388
1144
|
type: "button",
|
|
389
1145
|
className: datePickerClearClass,
|
|
390
1146
|
"aria-label": "Clear date range",
|
|
@@ -396,7 +1152,7 @@ var RangePicker = forwardRef(({
|
|
|
396
1152
|
});
|
|
397
1153
|
RangePicker.displayName = "DatePicker.RangePicker";
|
|
398
1154
|
function withPicker(picker, displayName) {
|
|
399
|
-
const Picker =
|
|
1155
|
+
const Picker = forwardRef2((props, ref) => /* @__PURE__ */ jsx3(DatePickerRoot, {
|
|
400
1156
|
...props,
|
|
401
1157
|
ref,
|
|
402
1158
|
picker
|
|
@@ -413,10 +1169,10 @@ var DatePicker = Object.assign(DatePickerRoot, {
|
|
|
413
1169
|
});
|
|
414
1170
|
// src/components/input/Input.tsx
|
|
415
1171
|
import {
|
|
416
|
-
forwardRef as
|
|
417
|
-
useImperativeHandle,
|
|
418
|
-
useRef,
|
|
419
|
-
useState as
|
|
1172
|
+
forwardRef as forwardRef3,
|
|
1173
|
+
useImperativeHandle as useImperativeHandle2,
|
|
1174
|
+
useRef as useRef2,
|
|
1175
|
+
useState as useState4
|
|
420
1176
|
} from "react";
|
|
421
1177
|
|
|
422
1178
|
// src/classes/input.ts
|
|
@@ -505,14 +1261,14 @@ function getTextAreaCountClasses({ exceeded }) {
|
|
|
505
1261
|
}
|
|
506
1262
|
|
|
507
1263
|
// src/components/input/Input.tsx
|
|
508
|
-
import { jsx as
|
|
1264
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
509
1265
|
function toTextValue(value) {
|
|
510
1266
|
if (Array.isArray(value)) {
|
|
511
1267
|
return value.join(",");
|
|
512
1268
|
}
|
|
513
1269
|
return value == null ? "" : String(value);
|
|
514
1270
|
}
|
|
515
|
-
var InputRoot =
|
|
1271
|
+
var InputRoot = forwardRef3(({
|
|
516
1272
|
allowClear,
|
|
517
1273
|
className,
|
|
518
1274
|
defaultValue,
|
|
@@ -527,12 +1283,12 @@ var InputRoot = forwardRef2(({
|
|
|
527
1283
|
variant = "outlined",
|
|
528
1284
|
...props
|
|
529
1285
|
}, ref) => {
|
|
530
|
-
const inputRef =
|
|
531
|
-
const [internalValue, setInternalValue] =
|
|
1286
|
+
const inputRef = useRef2(null);
|
|
1287
|
+
const [internalValue, setInternalValue] = useState4(() => toTextValue(defaultValue));
|
|
532
1288
|
const isControlled = value !== undefined;
|
|
533
1289
|
const currentValue = isControlled ? toTextValue(value) : internalValue;
|
|
534
1290
|
const hasAffix = prefix != null || suffix != null || allowClear;
|
|
535
|
-
|
|
1291
|
+
useImperativeHandle2(ref, () => inputRef.current);
|
|
536
1292
|
function handleChange(event) {
|
|
537
1293
|
if (!isControlled) {
|
|
538
1294
|
setInternalValue(event.currentTarget.value);
|
|
@@ -555,7 +1311,7 @@ var InputRoot = forwardRef2(({
|
|
|
555
1311
|
});
|
|
556
1312
|
input.focus();
|
|
557
1313
|
}
|
|
558
|
-
const control = /* @__PURE__ */
|
|
1314
|
+
const control = /* @__PURE__ */ jsx4("input", {
|
|
559
1315
|
...props,
|
|
560
1316
|
ref: inputRef,
|
|
561
1317
|
type,
|
|
@@ -568,22 +1324,22 @@ var InputRoot = forwardRef2(({
|
|
|
568
1324
|
return control;
|
|
569
1325
|
}
|
|
570
1326
|
const showClear = allowClear && !disabled && currentValue.length > 0;
|
|
571
|
-
return /* @__PURE__ */
|
|
1327
|
+
return /* @__PURE__ */ jsxs4("span", {
|
|
572
1328
|
className: getInputWrapperClasses({ affixed: hasAffix }),
|
|
573
1329
|
children: [
|
|
574
|
-
prefix != null ? /* @__PURE__ */
|
|
1330
|
+
prefix != null ? /* @__PURE__ */ jsx4("span", {
|
|
575
1331
|
className: inputPrefixClass,
|
|
576
1332
|
children: prefix
|
|
577
1333
|
}) : null,
|
|
578
1334
|
control,
|
|
579
|
-
showClear ? /* @__PURE__ */
|
|
1335
|
+
showClear ? /* @__PURE__ */ jsx4("button", {
|
|
580
1336
|
type: "button",
|
|
581
1337
|
className: inputClearClass,
|
|
582
1338
|
"aria-label": "Clear input",
|
|
583
1339
|
onClick: handleClear,
|
|
584
1340
|
children: "x"
|
|
585
1341
|
}) : null,
|
|
586
|
-
suffix != null ? /* @__PURE__ */
|
|
1342
|
+
suffix != null ? /* @__PURE__ */ jsx4("span", {
|
|
587
1343
|
className: inputSuffixClass,
|
|
588
1344
|
children: suffix
|
|
589
1345
|
}) : null
|
|
@@ -591,7 +1347,7 @@ var InputRoot = forwardRef2(({
|
|
|
591
1347
|
});
|
|
592
1348
|
});
|
|
593
1349
|
InputRoot.displayName = "Input";
|
|
594
|
-
var Search =
|
|
1350
|
+
var Search = forwardRef3(({
|
|
595
1351
|
className,
|
|
596
1352
|
disabled,
|
|
597
1353
|
enterButton,
|
|
@@ -600,8 +1356,8 @@ var Search = forwardRef2(({
|
|
|
600
1356
|
onSearch,
|
|
601
1357
|
...props
|
|
602
1358
|
}, ref) => {
|
|
603
|
-
const inputRef =
|
|
604
|
-
|
|
1359
|
+
const inputRef = useRef2(null);
|
|
1360
|
+
useImperativeHandle2(ref, () => inputRef.current);
|
|
605
1361
|
function emitSearch(event) {
|
|
606
1362
|
onSearch?.(inputRef.current?.value ?? "", event);
|
|
607
1363
|
}
|
|
@@ -612,16 +1368,16 @@ var Search = forwardRef2(({
|
|
|
612
1368
|
}
|
|
613
1369
|
}
|
|
614
1370
|
const buttonContent = enterButton === true ? "Search" : enterButton ?? "Search";
|
|
615
|
-
return /* @__PURE__ */
|
|
1371
|
+
return /* @__PURE__ */ jsxs4("span", {
|
|
616
1372
|
className: getSearchWrapperClasses({ className }),
|
|
617
1373
|
children: [
|
|
618
|
-
/* @__PURE__ */
|
|
1374
|
+
/* @__PURE__ */ jsx4(InputRoot, {
|
|
619
1375
|
...props,
|
|
620
1376
|
ref: inputRef,
|
|
621
1377
|
disabled,
|
|
622
1378
|
onKeyDown: handleKeyDown
|
|
623
1379
|
}),
|
|
624
|
-
enterButton || loading ? /* @__PURE__ */
|
|
1380
|
+
enterButton || loading ? /* @__PURE__ */ jsx4("button", {
|
|
625
1381
|
type: "button",
|
|
626
1382
|
className: inputSearchButtonClass,
|
|
627
1383
|
disabled: disabled || loading,
|
|
@@ -633,10 +1389,10 @@ var Search = forwardRef2(({
|
|
|
633
1389
|
});
|
|
634
1390
|
});
|
|
635
1391
|
Search.displayName = "Input.Search";
|
|
636
|
-
var Password =
|
|
637
|
-
const [visible, setVisible] =
|
|
1392
|
+
var Password = forwardRef3(({ className, disabled, visibilityToggle = true, ...props }, ref) => {
|
|
1393
|
+
const [visible, setVisible] = useState4(false);
|
|
638
1394
|
const type = visible ? "text" : "password";
|
|
639
|
-
const toggle = visibilityToggle ? /* @__PURE__ */
|
|
1395
|
+
const toggle = visibilityToggle ? /* @__PURE__ */ jsx4("button", {
|
|
640
1396
|
type: "button",
|
|
641
1397
|
className: inputPasswordToggleClass,
|
|
642
1398
|
disabled,
|
|
@@ -646,9 +1402,9 @@ var Password = forwardRef2(({ className, disabled, visibilityToggle = true, ...p
|
|
|
646
1402
|
},
|
|
647
1403
|
children: visible ? "Hide" : "Show"
|
|
648
1404
|
}) : undefined;
|
|
649
|
-
return /* @__PURE__ */
|
|
1405
|
+
return /* @__PURE__ */ jsx4("span", {
|
|
650
1406
|
className: getPasswordWrapperClasses({ className }),
|
|
651
|
-
children: /* @__PURE__ */
|
|
1407
|
+
children: /* @__PURE__ */ jsx4(InputRoot, {
|
|
652
1408
|
...props,
|
|
653
1409
|
ref,
|
|
654
1410
|
disabled,
|
|
@@ -658,7 +1414,7 @@ var Password = forwardRef2(({ className, disabled, visibilityToggle = true, ...p
|
|
|
658
1414
|
});
|
|
659
1415
|
});
|
|
660
1416
|
Password.displayName = "Input.Password";
|
|
661
|
-
var TextArea =
|
|
1417
|
+
var TextArea = forwardRef3(({
|
|
662
1418
|
autoSize,
|
|
663
1419
|
className,
|
|
664
1420
|
defaultValue,
|
|
@@ -672,7 +1428,7 @@ var TextArea = forwardRef2(({
|
|
|
672
1428
|
variant = "outlined",
|
|
673
1429
|
...props
|
|
674
1430
|
}, ref) => {
|
|
675
|
-
const [internalValue, setInternalValue] =
|
|
1431
|
+
const [internalValue, setInternalValue] = useState4(() => toTextValue(defaultValue));
|
|
676
1432
|
const isControlled = value !== undefined;
|
|
677
1433
|
const currentValue = isControlled ? toTextValue(value) : internalValue;
|
|
678
1434
|
const count = currentValue.length;
|
|
@@ -683,7 +1439,7 @@ var TextArea = forwardRef2(({
|
|
|
683
1439
|
}
|
|
684
1440
|
onChange?.(event);
|
|
685
1441
|
}
|
|
686
|
-
const control = /* @__PURE__ */
|
|
1442
|
+
const control = /* @__PURE__ */ jsx4("textarea", {
|
|
687
1443
|
...props,
|
|
688
1444
|
ref,
|
|
689
1445
|
className: getTextAreaClasses({
|
|
@@ -701,11 +1457,11 @@ var TextArea = forwardRef2(({
|
|
|
701
1457
|
if (!showCount) {
|
|
702
1458
|
return control;
|
|
703
1459
|
}
|
|
704
|
-
return /* @__PURE__ */
|
|
1460
|
+
return /* @__PURE__ */ jsxs4("span", {
|
|
705
1461
|
className: textAreaWrapperClass,
|
|
706
1462
|
children: [
|
|
707
1463
|
control,
|
|
708
|
-
/* @__PURE__ */
|
|
1464
|
+
/* @__PURE__ */ jsxs4("span", {
|
|
709
1465
|
className: getTextAreaCountClasses({ exceeded }),
|
|
710
1466
|
children: [
|
|
711
1467
|
count,
|
|
@@ -716,7 +1472,7 @@ var TextArea = forwardRef2(({
|
|
|
716
1472
|
});
|
|
717
1473
|
});
|
|
718
1474
|
TextArea.displayName = "Input.TextArea";
|
|
719
|
-
var Group =
|
|
1475
|
+
var Group = forwardRef3(({ className, children, ...props }, ref) => /* @__PURE__ */ jsx4("div", {
|
|
720
1476
|
...props,
|
|
721
1477
|
ref,
|
|
722
1478
|
className: cn(inputGroupClass, className),
|
|
@@ -730,7 +1486,7 @@ var Input = Object.assign(InputRoot, {
|
|
|
730
1486
|
Group
|
|
731
1487
|
});
|
|
732
1488
|
// src/components/select/Select.tsx
|
|
733
|
-
import
|
|
1489
|
+
import React5, { forwardRef as forwardRef4, useMemo as useMemo3, useState as useState5 } from "react";
|
|
734
1490
|
|
|
735
1491
|
// src/classes/select.ts
|
|
736
1492
|
var selectContainerClass = "select-container";
|
|
@@ -786,7 +1542,7 @@ function getSelectOptionClasses({
|
|
|
786
1542
|
}
|
|
787
1543
|
|
|
788
1544
|
// src/components/select/Select.tsx
|
|
789
|
-
import { jsx as
|
|
1545
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
790
1546
|
function isGroup(option) {
|
|
791
1547
|
return "options" in option;
|
|
792
1548
|
}
|
|
@@ -811,8 +1567,8 @@ function normalizeMultiValue(value) {
|
|
|
811
1567
|
}
|
|
812
1568
|
function optionsFromChildren(children) {
|
|
813
1569
|
const result = [];
|
|
814
|
-
|
|
815
|
-
if (!
|
|
1570
|
+
React5.Children.forEach(children, (child) => {
|
|
1571
|
+
if (!React5.isValidElement(child)) {
|
|
816
1572
|
return;
|
|
817
1573
|
}
|
|
818
1574
|
if (child.type === Option) {
|
|
@@ -862,19 +1618,19 @@ function filterOptions(options, searchValue, filterOption) {
|
|
|
862
1618
|
function renderValue(option) {
|
|
863
1619
|
return option ? optionLabel(option) : null;
|
|
864
1620
|
}
|
|
865
|
-
var Option =
|
|
1621
|
+
var Option = forwardRef4(({ children, ...props }, ref) => /* @__PURE__ */ jsx5("div", {
|
|
866
1622
|
...props,
|
|
867
1623
|
ref,
|
|
868
1624
|
children
|
|
869
1625
|
}));
|
|
870
1626
|
Option.displayName = "Select.Option";
|
|
871
|
-
var OptGroup =
|
|
1627
|
+
var OptGroup = forwardRef4(({ children, ...props }, ref) => /* @__PURE__ */ jsx5("div", {
|
|
872
1628
|
...props,
|
|
873
1629
|
ref,
|
|
874
1630
|
children
|
|
875
1631
|
}));
|
|
876
1632
|
OptGroup.displayName = "Select.OptGroup";
|
|
877
|
-
var SelectRoot =
|
|
1633
|
+
var SelectRoot = forwardRef4(({
|
|
878
1634
|
allowClear,
|
|
879
1635
|
children,
|
|
880
1636
|
className,
|
|
@@ -893,11 +1649,11 @@ var SelectRoot = forwardRef3(({
|
|
|
893
1649
|
...props
|
|
894
1650
|
}, ref) => {
|
|
895
1651
|
const multiple = mode === "multiple" || mode === "tags";
|
|
896
|
-
const sourceOptions =
|
|
897
|
-
const flatOptions =
|
|
898
|
-
const [open, setOpen] =
|
|
899
|
-
const [searchValue, setSearchValue] =
|
|
900
|
-
const [internalValue, setInternalValue] =
|
|
1652
|
+
const sourceOptions = useMemo3(() => options ?? optionsFromChildren(children), [children, options]);
|
|
1653
|
+
const flatOptions = useMemo3(() => flattenOptions(sourceOptions), [sourceOptions]);
|
|
1654
|
+
const [open, setOpen] = useState5(false);
|
|
1655
|
+
const [searchValue, setSearchValue] = useState5("");
|
|
1656
|
+
const [internalValue, setInternalValue] = useState5(multiple ? normalizeMultiValue(defaultValue) : normalizeSingleValue(defaultValue));
|
|
901
1657
|
const controlled = value !== undefined;
|
|
902
1658
|
const currentValue = controlled ? value : internalValue;
|
|
903
1659
|
const selectedValues = multiple ? normalizeMultiValue(currentValue) : normalizeSingleValue(currentValue) === undefined ? [] : [normalizeSingleValue(currentValue)];
|
|
@@ -954,7 +1710,7 @@ var SelectRoot = forwardRef3(({
|
|
|
954
1710
|
}
|
|
955
1711
|
function renderOption(option) {
|
|
956
1712
|
const selected = selectedKeys.has(valueKey(option.value));
|
|
957
|
-
return /* @__PURE__ */
|
|
1713
|
+
return /* @__PURE__ */ jsx5("button", {
|
|
958
1714
|
type: "button",
|
|
959
1715
|
role: "option",
|
|
960
1716
|
"aria-selected": selected,
|
|
@@ -973,11 +1729,11 @@ var SelectRoot = forwardRef3(({
|
|
|
973
1729
|
if (!isGroup(option)) {
|
|
974
1730
|
return renderOption(option);
|
|
975
1731
|
}
|
|
976
|
-
return /* @__PURE__ */
|
|
1732
|
+
return /* @__PURE__ */ jsxs5("div", {
|
|
977
1733
|
className: cn(selectGroupClass, option.className),
|
|
978
1734
|
role: "group",
|
|
979
1735
|
children: [
|
|
980
|
-
/* @__PURE__ */
|
|
1736
|
+
/* @__PURE__ */ jsx5("div", {
|
|
981
1737
|
className: selectGroupLabelClass,
|
|
982
1738
|
children: option.label
|
|
983
1739
|
}),
|
|
@@ -986,11 +1742,11 @@ var SelectRoot = forwardRef3(({
|
|
|
986
1742
|
}, `group-${index}`);
|
|
987
1743
|
});
|
|
988
1744
|
}
|
|
989
|
-
const selection = multiple ? selectedOptions.map((option) => /* @__PURE__ */
|
|
1745
|
+
const selection = multiple ? selectedOptions.map((option) => /* @__PURE__ */ jsx5("span", {
|
|
990
1746
|
className: selectTagClass,
|
|
991
1747
|
children: renderValue(option)
|
|
992
1748
|
}, valueKey(option.value))) : renderValue(selectedOptions[0]);
|
|
993
|
-
return /* @__PURE__ */
|
|
1749
|
+
return /* @__PURE__ */ jsxs5("div", {
|
|
994
1750
|
...props,
|
|
995
1751
|
ref,
|
|
996
1752
|
className: getSelectContainerClasses({
|
|
@@ -1001,7 +1757,7 @@ var SelectRoot = forwardRef3(({
|
|
|
1001
1757
|
className
|
|
1002
1758
|
}),
|
|
1003
1759
|
children: [
|
|
1004
|
-
/* @__PURE__ */
|
|
1760
|
+
/* @__PURE__ */ jsxs5("button", {
|
|
1005
1761
|
type: "button",
|
|
1006
1762
|
className: getSelectClasses({ size, status, disabled }),
|
|
1007
1763
|
disabled: disabled || loading,
|
|
@@ -1009,33 +1765,33 @@ var SelectRoot = forwardRef3(({
|
|
|
1009
1765
|
"aria-expanded": open,
|
|
1010
1766
|
onClick: () => setOpen((current) => !current),
|
|
1011
1767
|
children: [
|
|
1012
|
-
/* @__PURE__ */
|
|
1768
|
+
/* @__PURE__ */ jsx5("span", {
|
|
1013
1769
|
className: selectSelectionClass,
|
|
1014
|
-
children: hasValue ? selection : /* @__PURE__ */
|
|
1770
|
+
children: hasValue ? selection : /* @__PURE__ */ jsx5("span", {
|
|
1015
1771
|
className: selectPlaceholderClass,
|
|
1016
1772
|
children: placeholder
|
|
1017
1773
|
})
|
|
1018
1774
|
}),
|
|
1019
|
-
/* @__PURE__ */
|
|
1775
|
+
/* @__PURE__ */ jsx5("span", {
|
|
1020
1776
|
className: selectIconClass,
|
|
1021
1777
|
"aria-hidden": "true",
|
|
1022
1778
|
children: "v"
|
|
1023
1779
|
})
|
|
1024
1780
|
]
|
|
1025
1781
|
}),
|
|
1026
|
-
allowClear && hasValue && !disabled && !loading ? /* @__PURE__ */
|
|
1782
|
+
allowClear && hasValue && !disabled && !loading ? /* @__PURE__ */ jsx5("button", {
|
|
1027
1783
|
type: "button",
|
|
1028
1784
|
className: selectClearClass,
|
|
1029
1785
|
"aria-label": "Clear selection",
|
|
1030
1786
|
onClick: clearValue,
|
|
1031
1787
|
children: "x"
|
|
1032
1788
|
}) : null,
|
|
1033
|
-
open ? /* @__PURE__ */
|
|
1789
|
+
open ? /* @__PURE__ */ jsxs5("div", {
|
|
1034
1790
|
className: selectDropdownClass,
|
|
1035
1791
|
role: "listbox",
|
|
1036
1792
|
"aria-multiselectable": multiple || undefined,
|
|
1037
1793
|
children: [
|
|
1038
|
-
searchable ? /* @__PURE__ */
|
|
1794
|
+
searchable ? /* @__PURE__ */ jsx5("input", {
|
|
1039
1795
|
className: selectSearchClass,
|
|
1040
1796
|
value: searchValue,
|
|
1041
1797
|
placeholder: typeof placeholder === "string" ? placeholder : undefined,
|
|
@@ -1047,7 +1803,7 @@ var SelectRoot = forwardRef3(({
|
|
|
1047
1803
|
}
|
|
1048
1804
|
}
|
|
1049
1805
|
}) : null,
|
|
1050
|
-
visibleOptions.length > 0 ? renderOptions(visibleOptions) : /* @__PURE__ */
|
|
1806
|
+
visibleOptions.length > 0 ? renderOptions(visibleOptions) : /* @__PURE__ */ jsx5("div", {
|
|
1051
1807
|
className: selectEmptyClass,
|
|
1052
1808
|
children: "No data"
|
|
1053
1809
|
})
|
|
@@ -1061,32 +1817,7 @@ var Select = SelectRoot;
|
|
|
1061
1817
|
Select.Option = Option;
|
|
1062
1818
|
Select.OptGroup = OptGroup;
|
|
1063
1819
|
// src/components/dm-search/DmSearch.tsx
|
|
1064
|
-
import {
|
|
1065
|
-
forwardRef as forwardRef4,
|
|
1066
|
-
useEffect,
|
|
1067
|
-
useImperativeHandle as useImperativeHandle2,
|
|
1068
|
-
useMemo as useMemo3,
|
|
1069
|
-
useState as useState4
|
|
1070
|
-
} from "react";
|
|
1071
|
-
|
|
1072
|
-
// src/classes/dm-search.ts
|
|
1073
|
-
var dmSearchBaseClass = "dm-search";
|
|
1074
|
-
var dmSearchCompactClass = "dm-search-compact";
|
|
1075
|
-
var dmSearchCollapsedClass = "dm-search-collapsed";
|
|
1076
|
-
var dmSearchFieldsClass = "dm-search-fields";
|
|
1077
|
-
var dmSearchFieldClass = "dm-search-field";
|
|
1078
|
-
var dmSearchActionsClass = "dm-search-actions";
|
|
1079
|
-
var dmSearchFastFilterClass = "dm-search-fast-filter";
|
|
1080
|
-
function getDmSearchClasses({
|
|
1081
|
-
compact,
|
|
1082
|
-
collapsed,
|
|
1083
|
-
className
|
|
1084
|
-
}) {
|
|
1085
|
-
return cn(dmSearchBaseClass, compact && dmSearchCompactClass, collapsed && dmSearchCollapsedClass, className);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
// src/components/dm-search/DmSearch.tsx
|
|
1089
|
-
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1820
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1090
1821
|
function initialValues(items, searchParams, useSearchParams = true) {
|
|
1091
1822
|
return items.reduce((acc, item) => {
|
|
1092
1823
|
const defaultValue = item.search.extraProps?.value ?? item.search.formProps?.initialValue;
|
|
@@ -1110,7 +1841,7 @@ function renderField({
|
|
|
1110
1841
|
return item.search.render?.(value, setValue, item) ?? null;
|
|
1111
1842
|
}
|
|
1112
1843
|
if (item.search.type === "select") {
|
|
1113
|
-
return /* @__PURE__ */
|
|
1844
|
+
return /* @__PURE__ */ jsx6(Select, {
|
|
1114
1845
|
...extraProps,
|
|
1115
1846
|
disabled: Boolean(loading || extraProps.disabled),
|
|
1116
1847
|
value,
|
|
@@ -1119,25 +1850,25 @@ function renderField({
|
|
|
1119
1850
|
});
|
|
1120
1851
|
}
|
|
1121
1852
|
if (item.search.type === "dateRange") {
|
|
1122
|
-
return /* @__PURE__ */
|
|
1853
|
+
return /* @__PURE__ */ jsx6(DatePicker.RangePicker, {
|
|
1123
1854
|
...extraProps,
|
|
1124
1855
|
value,
|
|
1125
1856
|
onChange: (nextValue) => setValue(nextValue)
|
|
1126
1857
|
});
|
|
1127
1858
|
}
|
|
1128
1859
|
if (item.search.type === "date") {
|
|
1129
|
-
return /* @__PURE__ */
|
|
1860
|
+
return /* @__PURE__ */ jsx6(DatePicker, {
|
|
1130
1861
|
...extraProps,
|
|
1131
1862
|
value,
|
|
1132
1863
|
onChange: (nextValue) => setValue(nextValue)
|
|
1133
1864
|
});
|
|
1134
1865
|
}
|
|
1135
1866
|
if (item.search.type === "radio" || item.search.type === "checkbox") {
|
|
1136
|
-
return /* @__PURE__ */
|
|
1867
|
+
return /* @__PURE__ */ jsx6("div", {
|
|
1137
1868
|
role: item.search.type === "radio" ? "radiogroup" : "group",
|
|
1138
|
-
children: optionList(extraProps).map((option) => /* @__PURE__ */
|
|
1869
|
+
children: optionList(extraProps).map((option) => /* @__PURE__ */ jsxs6("label", {
|
|
1139
1870
|
children: [
|
|
1140
|
-
/* @__PURE__ */
|
|
1871
|
+
/* @__PURE__ */ jsx6("input", {
|
|
1141
1872
|
type: item.search.type,
|
|
1142
1873
|
disabled: loading,
|
|
1143
1874
|
checked: item.search.type === "checkbox" ? Array.isArray(value) && value.includes(option.value) : value === option.value,
|
|
@@ -1155,7 +1886,7 @@ function renderField({
|
|
|
1155
1886
|
}, String(option.value)))
|
|
1156
1887
|
});
|
|
1157
1888
|
}
|
|
1158
|
-
return /* @__PURE__ */
|
|
1889
|
+
return /* @__PURE__ */ jsx6(Input, {
|
|
1159
1890
|
...extraProps,
|
|
1160
1891
|
type: item.search.type === "input-number" ? "number" : "text",
|
|
1161
1892
|
disabled: Boolean(loading || extraProps.disabled),
|
|
@@ -1169,8 +1900,11 @@ function renderField({
|
|
|
1169
1900
|
}
|
|
1170
1901
|
});
|
|
1171
1902
|
}
|
|
1172
|
-
var DmSearch =
|
|
1903
|
+
var DmSearch = forwardRef5(({
|
|
1173
1904
|
items = [],
|
|
1905
|
+
values: controlledValues,
|
|
1906
|
+
onValuesChange,
|
|
1907
|
+
onReset,
|
|
1174
1908
|
onSearch,
|
|
1175
1909
|
extra,
|
|
1176
1910
|
fastFilterItem,
|
|
@@ -1179,27 +1913,37 @@ var DmSearch = forwardRef4(({
|
|
|
1179
1913
|
compact = false,
|
|
1180
1914
|
searchParams,
|
|
1181
1915
|
loading = false,
|
|
1916
|
+
noValidate,
|
|
1182
1917
|
enableDefaultPlaceHolder = false,
|
|
1183
1918
|
className
|
|
1184
1919
|
}, ref) => {
|
|
1185
|
-
const allItems =
|
|
1186
|
-
const [collapsed, setCollapsed] =
|
|
1187
|
-
const [
|
|
1920
|
+
const allItems = useMemo4(() => fastFilterItem ? [fastFilterItem, ...items] : items, [fastFilterItem, items]);
|
|
1921
|
+
const [collapsed, setCollapsed] = useState6(defaultCollapsed);
|
|
1922
|
+
const [internalValues, setValues] = useState6(() => initialValues(allItems, searchParams));
|
|
1923
|
+
const controlled = controlledValues !== undefined;
|
|
1924
|
+
const values = controlled ? controlledValues : internalValues;
|
|
1188
1925
|
const visibleItems = collapsed ? allItems.slice(0, 1) : allItems;
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1926
|
+
useEffect2(() => {
|
|
1927
|
+
if (!controlled)
|
|
1928
|
+
setValues(initialValues(allItems, searchParams));
|
|
1929
|
+
}, [allItems, searchParams, controlled]);
|
|
1192
1930
|
function reset(useSearchParams = false) {
|
|
1193
1931
|
const nextValues = initialValues(allItems, searchParams, useSearchParams);
|
|
1194
|
-
|
|
1932
|
+
if (!controlled)
|
|
1933
|
+
setValues(nextValues);
|
|
1934
|
+
if (onReset)
|
|
1935
|
+
onReset(nextValues);
|
|
1936
|
+
else if (controlled)
|
|
1937
|
+
onValuesChange?.(nextValues);
|
|
1195
1938
|
return nextValues;
|
|
1196
1939
|
}
|
|
1197
|
-
|
|
1940
|
+
useImperativeHandle3(ref, () => ({
|
|
1198
1941
|
onReset: () => {
|
|
1199
1942
|
reset(false);
|
|
1200
1943
|
}
|
|
1201
1944
|
}));
|
|
1202
|
-
return /* @__PURE__ */
|
|
1945
|
+
return /* @__PURE__ */ jsxs6("form", {
|
|
1946
|
+
noValidate,
|
|
1203
1947
|
id: "searchForm",
|
|
1204
1948
|
className: getDmSearchClasses({ compact, collapsed, className }),
|
|
1205
1949
|
onSubmit: (event) => {
|
|
@@ -1207,53 +1951,63 @@ var DmSearch = forwardRef4(({
|
|
|
1207
1951
|
onSearch?.(values);
|
|
1208
1952
|
},
|
|
1209
1953
|
children: [
|
|
1210
|
-
fastFilterItem ? /* @__PURE__ */
|
|
1954
|
+
fastFilterItem ? /* @__PURE__ */ jsx6("div", {
|
|
1211
1955
|
className: dmSearchFastFilterClass,
|
|
1212
1956
|
children: fastFilterItem.title
|
|
1213
1957
|
}) : null,
|
|
1214
|
-
/* @__PURE__ */
|
|
1958
|
+
/* @__PURE__ */ jsx6("div", {
|
|
1215
1959
|
className: dmSearchFieldsClass,
|
|
1216
|
-
children: visibleItems.map((item) =>
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1960
|
+
children: visibleItems.map((item) => {
|
|
1961
|
+
const Field = item.search.type === "custom" ? "div" : "label";
|
|
1962
|
+
return /* @__PURE__ */ jsxs6(Field, {
|
|
1963
|
+
className: dmSearchFieldClass,
|
|
1964
|
+
children: [
|
|
1965
|
+
compact ? null : /* @__PURE__ */ jsx6("span", {
|
|
1966
|
+
children: item.title
|
|
1967
|
+
}),
|
|
1968
|
+
renderField({
|
|
1969
|
+
item,
|
|
1970
|
+
value: values[item.dataIndex],
|
|
1971
|
+
loading,
|
|
1972
|
+
enableDefaultPlaceHolder,
|
|
1973
|
+
setValue: (value) => {
|
|
1974
|
+
const nextValues = { ...values, [item.dataIndex]: value };
|
|
1975
|
+
if (!controlled)
|
|
1976
|
+
setValues(nextValues);
|
|
1977
|
+
onValuesChange?.(nextValues);
|
|
1978
|
+
}
|
|
1979
|
+
})
|
|
1980
|
+
]
|
|
1981
|
+
}, item.key);
|
|
1982
|
+
})
|
|
1234
1983
|
}),
|
|
1235
|
-
/* @__PURE__ */
|
|
1984
|
+
/* @__PURE__ */ jsxs6("div", {
|
|
1236
1985
|
className: dmSearchActionsClass,
|
|
1237
1986
|
children: [
|
|
1238
|
-
/* @__PURE__ */
|
|
1987
|
+
/* @__PURE__ */ jsx6(Button, {
|
|
1239
1988
|
type: "submit",
|
|
1240
1989
|
isLoading: loading,
|
|
1241
1990
|
children: "Search"
|
|
1242
1991
|
}),
|
|
1243
|
-
/* @__PURE__ */
|
|
1992
|
+
/* @__PURE__ */ jsx6(Button, {
|
|
1244
1993
|
type: "button",
|
|
1245
1994
|
color: "secondary",
|
|
1246
1995
|
appearance: "outline",
|
|
1247
|
-
onClick: () =>
|
|
1996
|
+
onClick: () => {
|
|
1997
|
+
const nextValues = reset(false);
|
|
1998
|
+
if (!onReset)
|
|
1999
|
+
onSearch?.(nextValues);
|
|
2000
|
+
},
|
|
1248
2001
|
children: "Reset"
|
|
1249
2002
|
}),
|
|
1250
|
-
!hideCollapseBtn && allItems.length > 1 ? /* @__PURE__ */
|
|
2003
|
+
!hideCollapseBtn && allItems.length > 1 ? /* @__PURE__ */ jsx6(Button, {
|
|
1251
2004
|
type: "button",
|
|
1252
2005
|
color: "secondary",
|
|
1253
2006
|
appearance: "text",
|
|
1254
2007
|
onClick: () => {
|
|
1255
2008
|
setCollapsed((current) => !current);
|
|
1256
|
-
|
|
2009
|
+
if (!controlled)
|
|
2010
|
+
setValues(initialValues(allItems, searchParams));
|
|
1257
2011
|
},
|
|
1258
2012
|
children: collapsed ? "Expand" : "Collapse"
|
|
1259
2013
|
}) : null,
|