@duskmoon-dev/components 0.3.3 → 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/classes/chat.d.ts +9 -1
- 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 +5 -0
- package/dist/classes/index.js +180 -34
- 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/app/index.js +128 -68
- 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/chat/Chat.d.ts +9 -1
- package/dist/components/chat/Chat.types.d.ts +26 -0
- package/dist/components/chat/index.js +92 -3
- package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
- package/dist/components/color-picker/index.js +206 -9
- 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-date-picker/index.js +545 -43
- package/dist/components/dm-drawer/index.js +253 -24
- package/dist/components/dm-layout/index.js +391 -24
- package/dist/components/dm-menu/index.js +380 -13
- package/dist/components/dm-page-header/index.js +404 -114
- package/dist/components/dm-pro-table/index.js +1183 -368
- package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
- package/dist/components/dm-query/index.js +931 -188
- package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
- package/dist/components/dm-search/index.js +917 -163
- package/dist/components/dm-table/index.js +1001 -247
- package/dist/components/dm-toolbar/index.js +400 -110
- package/dist/components/dm-truncate/index.js +115 -35
- package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
- package/dist/components/dropdown/index.js +400 -110
- 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 +14 -3
- 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/modal/index.js +128 -68
- 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 +255 -26
- package/dist/components/popover/index.js +24 -4
- 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/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 +253 -24
- package/dist/components/tree-select/index.js +8 -8
- package/dist/components/upload/Upload.types.d.ts +1 -0
- package/dist/components/upload/index.js +2 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3330 -1632
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +1190 -906
- package/package.json +23 -3
|
@@ -67,6 +67,10 @@ function getPopconfirmClasses({
|
|
|
67
67
|
return cn(popconfirmBaseClass, popconfirmPlacementClasses[placement], open && popconfirmOpenClass, !arrow && popconfirmNoArrowClass, className);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/components/button/Button.tsx
|
|
71
|
+
import React from "react";
|
|
72
|
+
import { createPortal } from "react-dom";
|
|
73
|
+
|
|
70
74
|
// src/classes/button.ts
|
|
71
75
|
var buttonBaseClass = "btn";
|
|
72
76
|
var buttonColorClasses = {
|
|
@@ -90,7 +94,7 @@ var buttonAppearanceClasses = {
|
|
|
90
94
|
};
|
|
91
95
|
var buttonShapeClasses = {
|
|
92
96
|
rect: "",
|
|
93
|
-
circle: "btn-circle",
|
|
97
|
+
circle: "btn-circle btn-icon",
|
|
94
98
|
square: "btn-square"
|
|
95
99
|
};
|
|
96
100
|
var buttonSizeClasses = {
|
|
@@ -110,11 +114,14 @@ function getButtonClasses({
|
|
|
110
114
|
isLoading,
|
|
111
115
|
className
|
|
112
116
|
}) {
|
|
113
|
-
return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
|
|
117
|
+
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);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
// src/components/button/Button.tsx
|
|
117
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
121
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
122
|
+
function isPromiseLike(value) {
|
|
123
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
124
|
+
}
|
|
118
125
|
function Button({
|
|
119
126
|
color = "primary",
|
|
120
127
|
appearance = "filled",
|
|
@@ -128,8 +135,155 @@ function Button({
|
|
|
128
135
|
children,
|
|
129
136
|
disabled,
|
|
130
137
|
ref,
|
|
138
|
+
confirm,
|
|
139
|
+
onClick,
|
|
131
140
|
...props
|
|
132
141
|
}) {
|
|
142
|
+
const buttonRef = React.useRef(null);
|
|
143
|
+
const popoverRef = React.useRef(null);
|
|
144
|
+
const cancelRef = React.useRef(null);
|
|
145
|
+
const approvalRef = React.useRef("idle");
|
|
146
|
+
const pendingRef = React.useRef(false);
|
|
147
|
+
const actionRef = React.useRef(0);
|
|
148
|
+
const operationRef = React.useRef(0);
|
|
149
|
+
const mountedRef = React.useRef(false);
|
|
150
|
+
const [portalTarget, setPortalTarget] = React.useState(null);
|
|
151
|
+
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
|
152
|
+
const [confirmError, setConfirmError] = React.useState(false);
|
|
153
|
+
const generatedId = React.useId().replace(/:/g, "");
|
|
154
|
+
const popoverId = `button-confirm-${generatedId}`;
|
|
155
|
+
const titleId = `${popoverId}-title`;
|
|
156
|
+
const descriptionId = `${popoverId}-description`;
|
|
157
|
+
const anchor = `--${popoverId}-anchor`;
|
|
158
|
+
const hasConfirm = Boolean(confirm);
|
|
159
|
+
const confirmation = confirm && typeof confirm === "object" ? confirm : undefined;
|
|
160
|
+
const title = confirmation ? confirmation.title : "Confirm action";
|
|
161
|
+
const hasTitle = title !== undefined && title !== null && title !== false && title !== "";
|
|
162
|
+
const content = confirmation?.component ?? confirmation?.message ?? confirmation?.description;
|
|
163
|
+
const hasContent = content !== undefined && content !== null && content !== false && content !== "";
|
|
164
|
+
const mergedRef = React.useCallback((node) => {
|
|
165
|
+
buttonRef.current = node;
|
|
166
|
+
if (!node) {
|
|
167
|
+
if (typeof ref === "function")
|
|
168
|
+
ref(null);
|
|
169
|
+
else if (ref)
|
|
170
|
+
ref.current = null;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const cleanup = typeof ref === "function" ? ref(node) : undefined;
|
|
174
|
+
if (ref && typeof ref !== "function")
|
|
175
|
+
ref.current = node;
|
|
176
|
+
return () => {
|
|
177
|
+
buttonRef.current = null;
|
|
178
|
+
if (typeof cleanup === "function")
|
|
179
|
+
cleanup();
|
|
180
|
+
else if (typeof ref === "function")
|
|
181
|
+
ref(null);
|
|
182
|
+
else if (ref)
|
|
183
|
+
ref.current = null;
|
|
184
|
+
};
|
|
185
|
+
}, [ref]);
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
mountedRef.current = true;
|
|
188
|
+
return () => {
|
|
189
|
+
mountedRef.current = false;
|
|
190
|
+
operationRef.current += 1;
|
|
191
|
+
};
|
|
192
|
+
}, []);
|
|
193
|
+
React.useEffect(() => {
|
|
194
|
+
operationRef.current += 1;
|
|
195
|
+
approvalRef.current = "idle";
|
|
196
|
+
setConfirmError(false);
|
|
197
|
+
setPortalTarget(hasConfirm ? document.body : null);
|
|
198
|
+
}, [hasConfirm]);
|
|
199
|
+
function closePopover() {
|
|
200
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
201
|
+
popoverRef.current.hidePopover();
|
|
202
|
+
}
|
|
203
|
+
buttonRef.current?.focus();
|
|
204
|
+
}
|
|
205
|
+
function handleClick(event) {
|
|
206
|
+
if (!confirm) {
|
|
207
|
+
onClick?.(event);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (approvalRef.current === "native") {
|
|
211
|
+
approvalRef.current = "idle";
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (approvalRef.current === "action") {
|
|
215
|
+
approvalRef.current = "idle";
|
|
216
|
+
let result;
|
|
217
|
+
try {
|
|
218
|
+
result = onClick?.(event);
|
|
219
|
+
} catch {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
pendingRef.current = false;
|
|
222
|
+
setConfirmError(true);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (!isPromiseLike(result)) {
|
|
226
|
+
pendingRef.current = false;
|
|
227
|
+
closePopover();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const userPreventedDefault = event.defaultPrevented;
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
setConfirmLoading(true);
|
|
233
|
+
const action = actionRef.current;
|
|
234
|
+
const operation = operationRef.current;
|
|
235
|
+
Promise.resolve(result).then(() => {
|
|
236
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
237
|
+
return;
|
|
238
|
+
pendingRef.current = false;
|
|
239
|
+
setConfirmLoading(false);
|
|
240
|
+
if (operation !== operationRef.current)
|
|
241
|
+
return;
|
|
242
|
+
closePopover();
|
|
243
|
+
if (!userPreventedDefault && !buttonRef.current?.disabled) {
|
|
244
|
+
approvalRef.current = "native";
|
|
245
|
+
buttonRef.current?.click();
|
|
246
|
+
approvalRef.current = "idle";
|
|
247
|
+
}
|
|
248
|
+
}, () => {
|
|
249
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
250
|
+
return;
|
|
251
|
+
pendingRef.current = false;
|
|
252
|
+
setConfirmLoading(false);
|
|
253
|
+
if (operation !== operationRef.current)
|
|
254
|
+
return;
|
|
255
|
+
setConfirmError(true);
|
|
256
|
+
cancelRef.current?.focus();
|
|
257
|
+
});
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
if (disabled || isLoading || pendingRef.current)
|
|
262
|
+
return;
|
|
263
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
264
|
+
closePopover();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
setConfirmError(false);
|
|
268
|
+
popoverRef.current?.showPopover();
|
|
269
|
+
cancelRef.current?.focus();
|
|
270
|
+
}
|
|
271
|
+
function handleConfirm(event) {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
event.stopPropagation();
|
|
274
|
+
const trigger = buttonRef.current;
|
|
275
|
+
if (disabled || isLoading || pendingRef.current || !trigger || trigger.disabled || !event.currentTarget.matches(":popover-open"))
|
|
276
|
+
return;
|
|
277
|
+
setConfirmError(false);
|
|
278
|
+
pendingRef.current = true;
|
|
279
|
+
actionRef.current += 1;
|
|
280
|
+
approvalRef.current = "action";
|
|
281
|
+
trigger.click();
|
|
282
|
+
if (approvalRef.current === "action") {
|
|
283
|
+
approvalRef.current = "idle";
|
|
284
|
+
pendingRef.current = false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
133
287
|
const classes = getButtonClasses({
|
|
134
288
|
color,
|
|
135
289
|
appearance,
|
|
@@ -139,29 +293,104 @@ function Button({
|
|
|
139
293
|
isLoading,
|
|
140
294
|
className
|
|
141
295
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
...props,
|
|
296
|
+
const confirmClasses = getButtonClasses({
|
|
297
|
+
color,
|
|
298
|
+
size: "sm",
|
|
299
|
+
isLoading: confirmLoading
|
|
300
|
+
});
|
|
301
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
149
302
|
children: [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
303
|
+
/* @__PURE__ */ jsxs("button", {
|
|
304
|
+
ref: confirm ? mergedRef : ref,
|
|
305
|
+
className: classes,
|
|
306
|
+
disabled: disabled || isLoading,
|
|
307
|
+
"aria-busy": isLoading,
|
|
308
|
+
"aria-disabled": disabled || isLoading,
|
|
309
|
+
...props,
|
|
310
|
+
style: confirm ? { ...props.style, anchorName: anchor } : props.style,
|
|
311
|
+
"aria-haspopup": confirm ? "dialog" : props["aria-haspopup"],
|
|
312
|
+
"aria-controls": confirm ? popoverId : props["aria-controls"],
|
|
313
|
+
onClick: confirm ? handleClick : onClick,
|
|
314
|
+
children: [
|
|
315
|
+
isLoading && /* @__PURE__ */ jsx("span", {
|
|
316
|
+
className: "btn-spinner"
|
|
317
|
+
}),
|
|
318
|
+
!isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
|
|
319
|
+
className: "btn-icon-left",
|
|
320
|
+
children: leftIcon
|
|
321
|
+
}),
|
|
322
|
+
/* @__PURE__ */ jsx("span", {
|
|
323
|
+
className: "btn-content",
|
|
324
|
+
children
|
|
325
|
+
}),
|
|
326
|
+
!isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
|
|
327
|
+
className: "btn-icon-right",
|
|
328
|
+
children: rightIcon
|
|
329
|
+
})
|
|
330
|
+
]
|
|
160
331
|
}),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
332
|
+
confirm && portalTarget && createPortal(/* @__PURE__ */ jsxs("form", {
|
|
333
|
+
id: popoverId,
|
|
334
|
+
ref: popoverRef,
|
|
335
|
+
popover: "auto",
|
|
336
|
+
role: "dialog",
|
|
337
|
+
"aria-labelledby": hasTitle ? titleId : undefined,
|
|
338
|
+
"aria-label": hasTitle ? undefined : "Confirm action",
|
|
339
|
+
"aria-describedby": hasContent ? descriptionId : undefined,
|
|
340
|
+
className: "popover popover-confirm popover-bottom",
|
|
341
|
+
style: { positionAnchor: anchor },
|
|
342
|
+
onSubmit: handleConfirm,
|
|
343
|
+
onClick: (event) => event.stopPropagation(),
|
|
344
|
+
onToggle: (event) => {
|
|
345
|
+
if (!event.currentTarget.matches(":popover-open")) {
|
|
346
|
+
operationRef.current += 1;
|
|
347
|
+
if (event.currentTarget.contains(document.activeElement) || document.activeElement === document.body) {
|
|
348
|
+
buttonRef.current?.focus();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
children: [
|
|
353
|
+
hasTitle && /* @__PURE__ */ jsx("div", {
|
|
354
|
+
className: "popover-header",
|
|
355
|
+
children: /* @__PURE__ */ jsx("h3", {
|
|
356
|
+
id: titleId,
|
|
357
|
+
className: "popover-title",
|
|
358
|
+
children: title
|
|
359
|
+
})
|
|
360
|
+
}),
|
|
361
|
+
hasContent && /* @__PURE__ */ jsx("div", {
|
|
362
|
+
id: descriptionId,
|
|
363
|
+
className: "popover-body",
|
|
364
|
+
children: content
|
|
365
|
+
}),
|
|
366
|
+
confirmError && /* @__PURE__ */ jsx("div", {
|
|
367
|
+
role: "alert",
|
|
368
|
+
className: "popover-body",
|
|
369
|
+
children: "The action failed. Please try again."
|
|
370
|
+
}),
|
|
371
|
+
/* @__PURE__ */ jsxs("div", {
|
|
372
|
+
className: "popover-footer",
|
|
373
|
+
children: [
|
|
374
|
+
/* @__PURE__ */ jsx("button", {
|
|
375
|
+
ref: cancelRef,
|
|
376
|
+
type: "button",
|
|
377
|
+
className: "btn btn-text btn-sm",
|
|
378
|
+
popoverTarget: popoverId,
|
|
379
|
+
popoverTargetAction: "hide",
|
|
380
|
+
disabled: confirmLoading,
|
|
381
|
+
children: confirmation?.cancelText ?? "Cancel"
|
|
382
|
+
}),
|
|
383
|
+
/* @__PURE__ */ jsx("button", {
|
|
384
|
+
type: "submit",
|
|
385
|
+
className: confirmClasses,
|
|
386
|
+
disabled: disabled || isLoading || confirmLoading,
|
|
387
|
+
"aria-busy": confirmLoading,
|
|
388
|
+
children: confirmation?.confirmText ?? "Confirm"
|
|
389
|
+
})
|
|
390
|
+
]
|
|
391
|
+
})
|
|
392
|
+
]
|
|
393
|
+
}), portalTarget)
|
|
165
394
|
]
|
|
166
395
|
});
|
|
167
396
|
}
|
|
@@ -173,7 +402,7 @@ function normalizeTriggers(trigger) {
|
|
|
173
402
|
function hasTrigger(triggers, trigger) {
|
|
174
403
|
return normalizeTriggers(triggers).includes(trigger);
|
|
175
404
|
}
|
|
176
|
-
function
|
|
405
|
+
function isPromiseLike2(value) {
|
|
177
406
|
return Boolean(value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function");
|
|
178
407
|
}
|
|
179
408
|
var Popconfirm = forwardRef(({
|
|
@@ -228,7 +457,7 @@ var Popconfirm = forwardRef(({
|
|
|
228
457
|
event.preventDefault();
|
|
229
458
|
event.stopPropagation();
|
|
230
459
|
const result = action?.(event);
|
|
231
|
-
if (!
|
|
460
|
+
if (!isPromiseLike2(result)) {
|
|
232
461
|
close();
|
|
233
462
|
return;
|
|
234
463
|
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
forwardRef,
|
|
7
7
|
isValidElement,
|
|
8
8
|
useId,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
9
11
|
useState
|
|
10
12
|
} from "react";
|
|
11
13
|
|
|
@@ -37,7 +39,6 @@ function cn(...inputs) {
|
|
|
37
39
|
// src/classes/popover.ts
|
|
38
40
|
var popoverWrapperClass = "popover-wrapper";
|
|
39
41
|
var popoverBaseClass = "popover";
|
|
40
|
-
var popoverShowClass = "popover-show";
|
|
41
42
|
var popoverArrowClass = "popover-arrow";
|
|
42
43
|
var popoverNoArrowClass = "popover-no-arrow";
|
|
43
44
|
var popoverPlacementClasses = {
|
|
@@ -48,11 +49,10 @@ var popoverPlacementClasses = {
|
|
|
48
49
|
};
|
|
49
50
|
function getPopoverClasses({
|
|
50
51
|
placement = "top",
|
|
51
|
-
open,
|
|
52
52
|
arrow = true,
|
|
53
53
|
className
|
|
54
54
|
}) {
|
|
55
|
-
return cn(popoverBaseClass, popoverPlacementClasses[placement],
|
|
55
|
+
return cn(popoverBaseClass, popoverPlacementClasses[placement], !arrow && popoverNoArrowClass, className);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/components/popover/Popover.tsx
|
|
@@ -110,7 +110,19 @@ var Popover = forwardRef(({
|
|
|
110
110
|
const [internalOpen, setInternalOpen] = useState(Boolean(defaultOpen));
|
|
111
111
|
const generatedId = useId();
|
|
112
112
|
const tooltipId = id ? `${id}-popover` : generatedId;
|
|
113
|
+
const anchorName = `--dm-popover-${generatedId.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
114
|
+
const popoverRef = useRef(null);
|
|
113
115
|
const visible = isControlled ? open : internalOpen;
|
|
116
|
+
useLayoutEffect(() => {
|
|
117
|
+
const popover = popoverRef.current;
|
|
118
|
+
if (!popover || typeof popover.showPopover !== "function")
|
|
119
|
+
return;
|
|
120
|
+
if (visible && !popover.matches(":popover-open")) {
|
|
121
|
+
popover.showPopover();
|
|
122
|
+
} else if (!visible && popover.matches(":popover-open")) {
|
|
123
|
+
popover.hidePopover();
|
|
124
|
+
}
|
|
125
|
+
}, [visible, destroyTooltipOnHide]);
|
|
114
126
|
function updateOpen(nextOpen) {
|
|
115
127
|
if (!isControlled) {
|
|
116
128
|
setInternalOpen(nextOpen);
|
|
@@ -189,14 +201,22 @@ var Popover = forwardRef(({
|
|
|
189
201
|
...props,
|
|
190
202
|
ref,
|
|
191
203
|
className: popoverWrapperClass,
|
|
204
|
+
style: { ...props.style, anchorName },
|
|
192
205
|
children: [
|
|
193
206
|
triggerNode,
|
|
194
207
|
shouldRenderContent ? /* @__PURE__ */ jsxs("span", {
|
|
208
|
+
ref: popoverRef,
|
|
195
209
|
id: tooltipId,
|
|
210
|
+
popover: "auto",
|
|
196
211
|
role: "tooltip",
|
|
212
|
+
style: { positionAnchor: anchorName },
|
|
213
|
+
onToggle: (event) => {
|
|
214
|
+
const nextOpen = event.newState === "open";
|
|
215
|
+
if (nextOpen !== visible)
|
|
216
|
+
updateOpen(nextOpen);
|
|
217
|
+
},
|
|
197
218
|
className: getPopoverClasses({
|
|
198
219
|
placement,
|
|
199
|
-
open: visible,
|
|
200
220
|
arrow,
|
|
201
221
|
className
|
|
202
222
|
}),
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SwapButtonProps, SwapProps } from "./Swap.types";
|
|
2
|
+
export declare const Swap: import("react").ForwardRefExoticComponent<Omit<SwapProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
3
|
+
export declare const SwapButton: import("react").ForwardRefExoticComponent<Omit<SwapButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChangeEventHandler, ComponentProps, ReactNode } from "react";
|
|
2
|
+
export interface SwapProps extends Omit<ComponentProps<"input">, "checked" | "children" | "className" | "defaultChecked" | "onChange" | "size" | "type"> {
|
|
3
|
+
checked?: boolean;
|
|
4
|
+
defaultChecked?: boolean;
|
|
5
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
6
|
+
/** Decorative, noninteractive content shown while unchecked. */
|
|
7
|
+
off?: ReactNode;
|
|
8
|
+
/** Decorative, noninteractive content shown while checked. */
|
|
9
|
+
on?: ReactNode;
|
|
10
|
+
rotate?: boolean;
|
|
11
|
+
/** Additional class names for the wrapping label. */
|
|
12
|
+
wrapperClassName?: string;
|
|
13
|
+
/** Additional class names for the native checkbox. */
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SwapButtonProps extends Omit<ComponentProps<"button">, "children" | "aria-pressed"> {
|
|
17
|
+
"aria-label": string;
|
|
18
|
+
on: ReactNode;
|
|
19
|
+
off: ReactNode;
|
|
20
|
+
rotate?: boolean;
|
|
21
|
+
pressed: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/swap/Swap.tsx
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
7
|
+
function r(e) {
|
|
8
|
+
var t, f, n = "";
|
|
9
|
+
if (typeof e == "string" || typeof e == "number")
|
|
10
|
+
n += e;
|
|
11
|
+
else if (typeof e == "object")
|
|
12
|
+
if (Array.isArray(e)) {
|
|
13
|
+
var o = e.length;
|
|
14
|
+
for (t = 0;t < o; t++)
|
|
15
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
16
|
+
} else
|
|
17
|
+
for (f in e)
|
|
18
|
+
e[f] && (n && (n += " "), n += f);
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
function clsx() {
|
|
22
|
+
for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
|
|
23
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/utils/cn.ts
|
|
28
|
+
function cn(...inputs) {
|
|
29
|
+
return clsx(inputs);
|
|
30
|
+
}
|
|
31
|
+
// src/classes/swap.ts
|
|
32
|
+
var swapBaseClass = "swap";
|
|
33
|
+
var swapInputClass = "swap-input";
|
|
34
|
+
var swapOffClass = "swap-off";
|
|
35
|
+
var swapOnClass = "swap-on";
|
|
36
|
+
var swapRotateClass = "swap-rotate";
|
|
37
|
+
function getSwapClasses({
|
|
38
|
+
rotate = false,
|
|
39
|
+
wrapperClassName
|
|
40
|
+
}) {
|
|
41
|
+
return cn(swapBaseClass, rotate && swapRotateClass, wrapperClassName);
|
|
42
|
+
}
|
|
43
|
+
function getSwapInputClasses({ className }) {
|
|
44
|
+
return cn(swapInputClass, className);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/components/swap/Swap.tsx
|
|
48
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
49
|
+
var Swap = forwardRef(({
|
|
50
|
+
checked,
|
|
51
|
+
defaultChecked,
|
|
52
|
+
onChange,
|
|
53
|
+
disabled,
|
|
54
|
+
off,
|
|
55
|
+
on,
|
|
56
|
+
rotate = false,
|
|
57
|
+
wrapperClassName,
|
|
58
|
+
className,
|
|
59
|
+
...inputProps
|
|
60
|
+
}, ref) => /* @__PURE__ */ jsxs("label", {
|
|
61
|
+
className: getSwapClasses({ rotate, wrapperClassName }),
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsx("input", {
|
|
64
|
+
...inputProps,
|
|
65
|
+
ref,
|
|
66
|
+
type: "checkbox",
|
|
67
|
+
className: getSwapInputClasses({ className }),
|
|
68
|
+
checked,
|
|
69
|
+
defaultChecked,
|
|
70
|
+
onChange,
|
|
71
|
+
disabled
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ jsx("span", {
|
|
74
|
+
className: swapOffClass,
|
|
75
|
+
"aria-hidden": "true",
|
|
76
|
+
children: off
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ jsx("span", {
|
|
79
|
+
className: swapOnClass,
|
|
80
|
+
"aria-hidden": "true",
|
|
81
|
+
children: on
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
}));
|
|
85
|
+
Swap.displayName = "Swap";
|
|
86
|
+
var SwapButton = forwardRef(({ on, off, rotate, className, pressed, type = "button", ...buttonProps }, ref) => /* @__PURE__ */ jsxs("button", {
|
|
87
|
+
...buttonProps,
|
|
88
|
+
ref,
|
|
89
|
+
type,
|
|
90
|
+
"aria-pressed": pressed,
|
|
91
|
+
className: getSwapClasses({ rotate, wrapperClassName: className }),
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ jsx("span", {
|
|
94
|
+
className: swapOffClass,
|
|
95
|
+
"aria-hidden": "true",
|
|
96
|
+
children: off
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ jsx("span", {
|
|
99
|
+
className: swapOnClass,
|
|
100
|
+
"aria-hidden": "true",
|
|
101
|
+
children: on
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
}));
|
|
105
|
+
SwapButton.displayName = "SwapButton";
|
|
106
|
+
export {
|
|
107
|
+
Swap,
|
|
108
|
+
SwapButton
|
|
109
|
+
};
|
|
@@ -12,6 +12,7 @@ export interface DisabledTimeConfig {
|
|
|
12
12
|
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
|
|
13
13
|
}
|
|
14
14
|
export interface TimePickerProps extends Omit<ComponentProps<"div">, "children" | "defaultValue" | "onBlur" | "onChange" | "onFocus"> {
|
|
15
|
+
inputProps?: ComponentProps<"input">;
|
|
15
16
|
value?: TimePickerValue;
|
|
16
17
|
defaultValue?: TimePickerValue;
|
|
17
18
|
format?: string;
|