@duskmoon-dev/components 0.3.3 → 0.4.1
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 +142 -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 +1195 -368
- package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
- package/dist/components/dm-query/index.js +943 -188
- package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
- package/dist/components/dm-search/index.js +929 -163
- package/dist/components/dm-table/index.js +1013 -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/json-schema-form/JsonSchemaForm.d.ts +19 -0
- package/dist/components/json-schema-form/JsonSchemaWidget.d.ts +14 -0
- package/dist/components/json-schema-form/index.d.ts +8 -0
- package/dist/components/json-schema-form/index.js +7661 -0
- package/dist/components/json-schema-form/json-form-widgets.d.ts +26 -0
- package/dist/components/json-schema-form/json-schema-form.d.ts +50 -0
- 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/select/index.js +12 -0
- 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 +3343 -1633
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +1359 -865
- package/package.json +31 -5
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/fab/Fab.tsx
|
|
4
|
+
import { createContext, forwardRef, useContext, useId } 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/fab.ts
|
|
32
|
+
var fabClass = "fab";
|
|
33
|
+
var fabTriggerClass = "fab-trigger";
|
|
34
|
+
var fabActionsClass = "fab-actions";
|
|
35
|
+
var fabActionClass = "fab-action";
|
|
36
|
+
var fabLabelClass = "fab-label";
|
|
37
|
+
function getFabClasses({
|
|
38
|
+
contained,
|
|
39
|
+
start,
|
|
40
|
+
speedDial,
|
|
41
|
+
className
|
|
42
|
+
}) {
|
|
43
|
+
return cn(fabClass, contained && "fab-contained", start && "fab-start", speedDial && "fab-speed-dial", className);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/components/button/Button.tsx
|
|
47
|
+
import React from "react";
|
|
48
|
+
import { createPortal } from "react-dom";
|
|
49
|
+
|
|
50
|
+
// src/classes/button.ts
|
|
51
|
+
var buttonBaseClass = "btn";
|
|
52
|
+
var buttonColorClasses = {
|
|
53
|
+
primary: "btn-primary",
|
|
54
|
+
secondary: "btn-secondary",
|
|
55
|
+
tertiary: "btn-tertiary",
|
|
56
|
+
accent: "btn-accent",
|
|
57
|
+
neutral: "btn-neutral",
|
|
58
|
+
base: "btn-base",
|
|
59
|
+
info: "btn-info",
|
|
60
|
+
success: "btn-success",
|
|
61
|
+
warning: "btn-warning",
|
|
62
|
+
error: "btn-error"
|
|
63
|
+
};
|
|
64
|
+
var buttonAppearanceClasses = {
|
|
65
|
+
filled: "",
|
|
66
|
+
outline: "btn-outline",
|
|
67
|
+
tonal: "btn-tonal",
|
|
68
|
+
ghost: "btn-ghost",
|
|
69
|
+
text: "btn-text"
|
|
70
|
+
};
|
|
71
|
+
var buttonShapeClasses = {
|
|
72
|
+
rect: "",
|
|
73
|
+
circle: "btn-circle btn-icon",
|
|
74
|
+
square: "btn-square"
|
|
75
|
+
};
|
|
76
|
+
var buttonSizeClasses = {
|
|
77
|
+
xs: "btn-xs",
|
|
78
|
+
sm: "btn-sm",
|
|
79
|
+
md: "btn-md",
|
|
80
|
+
lg: "btn-lg"
|
|
81
|
+
};
|
|
82
|
+
var buttonBlockClass = "btn-block";
|
|
83
|
+
var buttonIsLoadingClass = "btn-loading";
|
|
84
|
+
function getButtonClasses({
|
|
85
|
+
color = "primary",
|
|
86
|
+
appearance = "filled",
|
|
87
|
+
shape = "rect",
|
|
88
|
+
size = "md",
|
|
89
|
+
block,
|
|
90
|
+
isLoading,
|
|
91
|
+
className
|
|
92
|
+
}) {
|
|
93
|
+
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);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/components/button/Button.tsx
|
|
97
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
98
|
+
function isPromiseLike(value) {
|
|
99
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
100
|
+
}
|
|
101
|
+
function Button({
|
|
102
|
+
color = "primary",
|
|
103
|
+
appearance = "filled",
|
|
104
|
+
shape = "rect",
|
|
105
|
+
size = "md",
|
|
106
|
+
block,
|
|
107
|
+
isLoading,
|
|
108
|
+
leftIcon,
|
|
109
|
+
rightIcon,
|
|
110
|
+
className,
|
|
111
|
+
children,
|
|
112
|
+
disabled,
|
|
113
|
+
ref,
|
|
114
|
+
confirm,
|
|
115
|
+
onClick,
|
|
116
|
+
...props
|
|
117
|
+
}) {
|
|
118
|
+
const buttonRef = React.useRef(null);
|
|
119
|
+
const popoverRef = React.useRef(null);
|
|
120
|
+
const cancelRef = React.useRef(null);
|
|
121
|
+
const approvalRef = React.useRef("idle");
|
|
122
|
+
const pendingRef = React.useRef(false);
|
|
123
|
+
const actionRef = React.useRef(0);
|
|
124
|
+
const operationRef = React.useRef(0);
|
|
125
|
+
const mountedRef = React.useRef(false);
|
|
126
|
+
const [portalTarget, setPortalTarget] = React.useState(null);
|
|
127
|
+
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
|
128
|
+
const [confirmError, setConfirmError] = React.useState(false);
|
|
129
|
+
const generatedId = React.useId().replace(/:/g, "");
|
|
130
|
+
const popoverId = `button-confirm-${generatedId}`;
|
|
131
|
+
const titleId = `${popoverId}-title`;
|
|
132
|
+
const descriptionId = `${popoverId}-description`;
|
|
133
|
+
const anchor = `--${popoverId}-anchor`;
|
|
134
|
+
const hasConfirm = Boolean(confirm);
|
|
135
|
+
const confirmation = confirm && typeof confirm === "object" ? confirm : undefined;
|
|
136
|
+
const title = confirmation ? confirmation.title : "Confirm action";
|
|
137
|
+
const hasTitle = title !== undefined && title !== null && title !== false && title !== "";
|
|
138
|
+
const content = confirmation?.component ?? confirmation?.message ?? confirmation?.description;
|
|
139
|
+
const hasContent = content !== undefined && content !== null && content !== false && content !== "";
|
|
140
|
+
const mergedRef = React.useCallback((node) => {
|
|
141
|
+
buttonRef.current = node;
|
|
142
|
+
if (!node) {
|
|
143
|
+
if (typeof ref === "function")
|
|
144
|
+
ref(null);
|
|
145
|
+
else if (ref)
|
|
146
|
+
ref.current = null;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const cleanup = typeof ref === "function" ? ref(node) : undefined;
|
|
150
|
+
if (ref && typeof ref !== "function")
|
|
151
|
+
ref.current = node;
|
|
152
|
+
return () => {
|
|
153
|
+
buttonRef.current = null;
|
|
154
|
+
if (typeof cleanup === "function")
|
|
155
|
+
cleanup();
|
|
156
|
+
else if (typeof ref === "function")
|
|
157
|
+
ref(null);
|
|
158
|
+
else if (ref)
|
|
159
|
+
ref.current = null;
|
|
160
|
+
};
|
|
161
|
+
}, [ref]);
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
mountedRef.current = true;
|
|
164
|
+
return () => {
|
|
165
|
+
mountedRef.current = false;
|
|
166
|
+
operationRef.current += 1;
|
|
167
|
+
};
|
|
168
|
+
}, []);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
operationRef.current += 1;
|
|
171
|
+
approvalRef.current = "idle";
|
|
172
|
+
setConfirmError(false);
|
|
173
|
+
setPortalTarget(hasConfirm ? document.body : null);
|
|
174
|
+
}, [hasConfirm]);
|
|
175
|
+
function closePopover() {
|
|
176
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
177
|
+
popoverRef.current.hidePopover();
|
|
178
|
+
}
|
|
179
|
+
buttonRef.current?.focus();
|
|
180
|
+
}
|
|
181
|
+
function handleClick(event) {
|
|
182
|
+
if (!confirm) {
|
|
183
|
+
onClick?.(event);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (approvalRef.current === "native") {
|
|
187
|
+
approvalRef.current = "idle";
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (approvalRef.current === "action") {
|
|
191
|
+
approvalRef.current = "idle";
|
|
192
|
+
let result;
|
|
193
|
+
try {
|
|
194
|
+
result = onClick?.(event);
|
|
195
|
+
} catch {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
pendingRef.current = false;
|
|
198
|
+
setConfirmError(true);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!isPromiseLike(result)) {
|
|
202
|
+
pendingRef.current = false;
|
|
203
|
+
closePopover();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const userPreventedDefault = event.defaultPrevented;
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
setConfirmLoading(true);
|
|
209
|
+
const action = actionRef.current;
|
|
210
|
+
const operation = operationRef.current;
|
|
211
|
+
Promise.resolve(result).then(() => {
|
|
212
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
213
|
+
return;
|
|
214
|
+
pendingRef.current = false;
|
|
215
|
+
setConfirmLoading(false);
|
|
216
|
+
if (operation !== operationRef.current)
|
|
217
|
+
return;
|
|
218
|
+
closePopover();
|
|
219
|
+
if (!userPreventedDefault && !buttonRef.current?.disabled) {
|
|
220
|
+
approvalRef.current = "native";
|
|
221
|
+
buttonRef.current?.click();
|
|
222
|
+
approvalRef.current = "idle";
|
|
223
|
+
}
|
|
224
|
+
}, () => {
|
|
225
|
+
if (!mountedRef.current || action !== actionRef.current)
|
|
226
|
+
return;
|
|
227
|
+
pendingRef.current = false;
|
|
228
|
+
setConfirmLoading(false);
|
|
229
|
+
if (operation !== operationRef.current)
|
|
230
|
+
return;
|
|
231
|
+
setConfirmError(true);
|
|
232
|
+
cancelRef.current?.focus();
|
|
233
|
+
});
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
if (disabled || isLoading || pendingRef.current)
|
|
238
|
+
return;
|
|
239
|
+
if (popoverRef.current?.matches(":popover-open")) {
|
|
240
|
+
closePopover();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
setConfirmError(false);
|
|
244
|
+
popoverRef.current?.showPopover();
|
|
245
|
+
cancelRef.current?.focus();
|
|
246
|
+
}
|
|
247
|
+
function handleConfirm(event) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
event.stopPropagation();
|
|
250
|
+
const trigger = buttonRef.current;
|
|
251
|
+
if (disabled || isLoading || pendingRef.current || !trigger || trigger.disabled || !event.currentTarget.matches(":popover-open"))
|
|
252
|
+
return;
|
|
253
|
+
setConfirmError(false);
|
|
254
|
+
pendingRef.current = true;
|
|
255
|
+
actionRef.current += 1;
|
|
256
|
+
approvalRef.current = "action";
|
|
257
|
+
trigger.click();
|
|
258
|
+
if (approvalRef.current === "action") {
|
|
259
|
+
approvalRef.current = "idle";
|
|
260
|
+
pendingRef.current = false;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const classes = getButtonClasses({
|
|
264
|
+
color,
|
|
265
|
+
appearance,
|
|
266
|
+
shape,
|
|
267
|
+
size,
|
|
268
|
+
block,
|
|
269
|
+
isLoading,
|
|
270
|
+
className
|
|
271
|
+
});
|
|
272
|
+
const confirmClasses = getButtonClasses({
|
|
273
|
+
color,
|
|
274
|
+
size: "sm",
|
|
275
|
+
isLoading: confirmLoading
|
|
276
|
+
});
|
|
277
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
278
|
+
children: [
|
|
279
|
+
/* @__PURE__ */ jsxs("button", {
|
|
280
|
+
ref: confirm ? mergedRef : ref,
|
|
281
|
+
className: classes,
|
|
282
|
+
disabled: disabled || isLoading,
|
|
283
|
+
"aria-busy": isLoading,
|
|
284
|
+
"aria-disabled": disabled || isLoading,
|
|
285
|
+
...props,
|
|
286
|
+
style: confirm ? { ...props.style, anchorName: anchor } : props.style,
|
|
287
|
+
"aria-haspopup": confirm ? "dialog" : props["aria-haspopup"],
|
|
288
|
+
"aria-controls": confirm ? popoverId : props["aria-controls"],
|
|
289
|
+
onClick: confirm ? handleClick : onClick,
|
|
290
|
+
children: [
|
|
291
|
+
isLoading && /* @__PURE__ */ jsx("span", {
|
|
292
|
+
className: "btn-spinner"
|
|
293
|
+
}),
|
|
294
|
+
!isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
|
|
295
|
+
className: "btn-icon-left",
|
|
296
|
+
children: leftIcon
|
|
297
|
+
}),
|
|
298
|
+
/* @__PURE__ */ jsx("span", {
|
|
299
|
+
className: "btn-content",
|
|
300
|
+
children
|
|
301
|
+
}),
|
|
302
|
+
!isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
|
|
303
|
+
className: "btn-icon-right",
|
|
304
|
+
children: rightIcon
|
|
305
|
+
})
|
|
306
|
+
]
|
|
307
|
+
}),
|
|
308
|
+
confirm && portalTarget && createPortal(/* @__PURE__ */ jsxs("form", {
|
|
309
|
+
id: popoverId,
|
|
310
|
+
ref: popoverRef,
|
|
311
|
+
popover: "auto",
|
|
312
|
+
role: "dialog",
|
|
313
|
+
"aria-labelledby": hasTitle ? titleId : undefined,
|
|
314
|
+
"aria-label": hasTitle ? undefined : "Confirm action",
|
|
315
|
+
"aria-describedby": hasContent ? descriptionId : undefined,
|
|
316
|
+
className: "popover popover-confirm popover-bottom",
|
|
317
|
+
style: { positionAnchor: anchor },
|
|
318
|
+
onSubmit: handleConfirm,
|
|
319
|
+
onClick: (event) => event.stopPropagation(),
|
|
320
|
+
onToggle: (event) => {
|
|
321
|
+
if (!event.currentTarget.matches(":popover-open")) {
|
|
322
|
+
operationRef.current += 1;
|
|
323
|
+
if (event.currentTarget.contains(document.activeElement) || document.activeElement === document.body) {
|
|
324
|
+
buttonRef.current?.focus();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
children: [
|
|
329
|
+
hasTitle && /* @__PURE__ */ jsx("div", {
|
|
330
|
+
className: "popover-header",
|
|
331
|
+
children: /* @__PURE__ */ jsx("h3", {
|
|
332
|
+
id: titleId,
|
|
333
|
+
className: "popover-title",
|
|
334
|
+
children: title
|
|
335
|
+
})
|
|
336
|
+
}),
|
|
337
|
+
hasContent && /* @__PURE__ */ jsx("div", {
|
|
338
|
+
id: descriptionId,
|
|
339
|
+
className: "popover-body",
|
|
340
|
+
children: content
|
|
341
|
+
}),
|
|
342
|
+
confirmError && /* @__PURE__ */ jsx("div", {
|
|
343
|
+
role: "alert",
|
|
344
|
+
className: "popover-body",
|
|
345
|
+
children: "The action failed. Please try again."
|
|
346
|
+
}),
|
|
347
|
+
/* @__PURE__ */ jsxs("div", {
|
|
348
|
+
className: "popover-footer",
|
|
349
|
+
children: [
|
|
350
|
+
/* @__PURE__ */ jsx("button", {
|
|
351
|
+
ref: cancelRef,
|
|
352
|
+
type: "button",
|
|
353
|
+
className: "btn btn-text btn-sm",
|
|
354
|
+
popoverTarget: popoverId,
|
|
355
|
+
popoverTargetAction: "hide",
|
|
356
|
+
disabled: confirmLoading,
|
|
357
|
+
children: confirmation?.cancelText ?? "Cancel"
|
|
358
|
+
}),
|
|
359
|
+
/* @__PURE__ */ jsx("button", {
|
|
360
|
+
type: "submit",
|
|
361
|
+
className: confirmClasses,
|
|
362
|
+
disabled: disabled || isLoading || confirmLoading,
|
|
363
|
+
"aria-busy": confirmLoading,
|
|
364
|
+
children: confirmation?.confirmText ?? "Confirm"
|
|
365
|
+
})
|
|
366
|
+
]
|
|
367
|
+
})
|
|
368
|
+
]
|
|
369
|
+
}), portalTarget)
|
|
370
|
+
]
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
// src/components/fab/Fab.tsx
|
|
374
|
+
import { jsx as jsx2, jsxs as jsxs2, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
375
|
+
var FabContext = createContext(null);
|
|
376
|
+
function useFabContext() {
|
|
377
|
+
const context = useContext(FabContext);
|
|
378
|
+
if (!context)
|
|
379
|
+
throw new Error("Fab subcomponents must be inside Fab");
|
|
380
|
+
return context;
|
|
381
|
+
}
|
|
382
|
+
var Trigger = forwardRef(({ extended, className, type = "button", ...props }, ref) => {
|
|
383
|
+
const { actionsId, speedDial } = useFabContext();
|
|
384
|
+
return /* @__PURE__ */ jsx2(Button, {
|
|
385
|
+
...props,
|
|
386
|
+
ref,
|
|
387
|
+
type,
|
|
388
|
+
popoverTarget: speedDial ? actionsId : undefined,
|
|
389
|
+
className: cn(fabTriggerClass, extended && "fab-extended", className)
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
Trigger.displayName = "Fab.Trigger";
|
|
393
|
+
var Actions = forwardRef(({ className, ...props }, ref) => {
|
|
394
|
+
const { actionsId } = useFabContext();
|
|
395
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
396
|
+
...props,
|
|
397
|
+
ref,
|
|
398
|
+
id: actionsId,
|
|
399
|
+
popover: "auto",
|
|
400
|
+
className: cn(fabActionsClass, className)
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
Actions.displayName = "Fab.Actions";
|
|
404
|
+
var Action = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2("div", {
|
|
405
|
+
...props,
|
|
406
|
+
ref,
|
|
407
|
+
className: cn(fabActionClass, className)
|
|
408
|
+
}));
|
|
409
|
+
Action.displayName = "Fab.Action";
|
|
410
|
+
var Label = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx2("span", {
|
|
411
|
+
...props,
|
|
412
|
+
ref,
|
|
413
|
+
className: cn(fabLabelClass, className)
|
|
414
|
+
}));
|
|
415
|
+
Label.displayName = "Fab.Label";
|
|
416
|
+
var FabRoot = forwardRef(({
|
|
417
|
+
contained,
|
|
418
|
+
start,
|
|
419
|
+
speedDial = false,
|
|
420
|
+
label,
|
|
421
|
+
actions,
|
|
422
|
+
extended,
|
|
423
|
+
buttonProps,
|
|
424
|
+
className,
|
|
425
|
+
children,
|
|
426
|
+
...props
|
|
427
|
+
}, ref) => {
|
|
428
|
+
const actionsId = `fab-actions-${useId().replace(/:/g, "")}`;
|
|
429
|
+
const hasActions = actions != null;
|
|
430
|
+
const resolvedSpeedDial = speedDial || hasActions;
|
|
431
|
+
return /* @__PURE__ */ jsx2(FabContext.Provider, {
|
|
432
|
+
value: { actionsId, speedDial: resolvedSpeedDial },
|
|
433
|
+
children: /* @__PURE__ */ jsx2("div", {
|
|
434
|
+
...props,
|
|
435
|
+
ref,
|
|
436
|
+
className: getFabClasses({
|
|
437
|
+
contained,
|
|
438
|
+
start,
|
|
439
|
+
speedDial: resolvedSpeedDial,
|
|
440
|
+
className
|
|
441
|
+
}),
|
|
442
|
+
children: label != null ? /* @__PURE__ */ jsxs2(Fragment2, {
|
|
443
|
+
children: [
|
|
444
|
+
/* @__PURE__ */ jsx2(Trigger, {
|
|
445
|
+
...buttonProps,
|
|
446
|
+
type: "button",
|
|
447
|
+
"aria-label": label,
|
|
448
|
+
extended,
|
|
449
|
+
className: cn(!extended && "btn-icon", buttonProps?.className),
|
|
450
|
+
children
|
|
451
|
+
}),
|
|
452
|
+
hasActions && /* @__PURE__ */ jsx2(Actions, {
|
|
453
|
+
children: actions
|
|
454
|
+
})
|
|
455
|
+
]
|
|
456
|
+
}) : children
|
|
457
|
+
})
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
FabRoot.displayName = "Fab";
|
|
461
|
+
FabRoot.Trigger = Trigger;
|
|
462
|
+
FabRoot.Actions = Actions;
|
|
463
|
+
FabRoot.Action = Action;
|
|
464
|
+
FabRoot.Label = Label;
|
|
465
|
+
var Fab = FabRoot;
|
|
466
|
+
var FabAction = forwardRef(({ label, children, ...props }, ref) => /* @__PURE__ */ jsxs2(Action, {
|
|
467
|
+
...props,
|
|
468
|
+
ref,
|
|
469
|
+
children: [
|
|
470
|
+
label ? /* @__PURE__ */ jsx2(Label, {
|
|
471
|
+
children: label
|
|
472
|
+
}) : null,
|
|
473
|
+
children
|
|
474
|
+
]
|
|
475
|
+
}));
|
|
476
|
+
FabAction.displayName = "FabAction";
|
|
477
|
+
export {
|
|
478
|
+
Fab,
|
|
479
|
+
FabAction
|
|
480
|
+
};
|
|
@@ -9,6 +9,7 @@ import React, {
|
|
|
9
9
|
useContext,
|
|
10
10
|
useEffect,
|
|
11
11
|
useImperativeHandle,
|
|
12
|
+
useId,
|
|
12
13
|
useLayoutEffect,
|
|
13
14
|
useMemo,
|
|
14
15
|
useRef,
|
|
@@ -308,6 +309,7 @@ var FormItem = forwardRef(({
|
|
|
308
309
|
className,
|
|
309
310
|
extra,
|
|
310
311
|
help,
|
|
312
|
+
htmlFor,
|
|
311
313
|
label,
|
|
312
314
|
name,
|
|
313
315
|
noStyle,
|
|
@@ -318,9 +320,13 @@ var FormItem = forwardRef(({
|
|
|
318
320
|
...props
|
|
319
321
|
}, ref) => {
|
|
320
322
|
const context = useContext(FormContext);
|
|
323
|
+
const generatedId = useId();
|
|
321
324
|
useFormVersion(context?.form);
|
|
322
325
|
const fieldErrors = name && context ? context.getFieldError(name) : [];
|
|
323
326
|
const ruleRequired = required ?? rules.some((rule) => rule.required);
|
|
327
|
+
const child = isValidElement(children) && children.type !== React.Fragment ? children : null;
|
|
328
|
+
const childProps = child?.props;
|
|
329
|
+
const controlId = label && !noStyle && htmlFor === undefined && child ? childProps?.id ?? generatedId : undefined;
|
|
324
330
|
useEffect(() => {
|
|
325
331
|
if (!name || !context) {
|
|
326
332
|
return;
|
|
@@ -328,14 +334,18 @@ var FormItem = forwardRef(({
|
|
|
328
334
|
return context.registerField(name, rules);
|
|
329
335
|
}, [context, name, rules]);
|
|
330
336
|
function renderControl() {
|
|
331
|
-
if (!
|
|
337
|
+
if (!child || !childProps) {
|
|
332
338
|
return children;
|
|
333
339
|
}
|
|
340
|
+
const associationProps = controlId && childProps.id == null ? { id: controlId } : {};
|
|
341
|
+
if (!name || !context) {
|
|
342
|
+
return controlId && childProps.id == null ? React.cloneElement(child, associationProps) : children;
|
|
343
|
+
}
|
|
334
344
|
const key = nameKey(name);
|
|
335
345
|
const value = context.form.getFieldValue(name);
|
|
336
|
-
const childProps = children.props;
|
|
337
346
|
const originalTrigger = childProps[trigger];
|
|
338
|
-
return React.cloneElement(
|
|
347
|
+
return React.cloneElement(child, {
|
|
348
|
+
...associationProps,
|
|
339
349
|
[valuePropName]: valuePropName === "checked" ? Boolean(value) : value ?? "",
|
|
340
350
|
disabled: childProps.disabled ?? context.disabled,
|
|
341
351
|
[trigger]: (...args) => {
|
|
@@ -363,6 +373,7 @@ var FormItem = forwardRef(({
|
|
|
363
373
|
children: [
|
|
364
374
|
label ? /* @__PURE__ */ jsx("label", {
|
|
365
375
|
className: formItemLabelClass,
|
|
376
|
+
htmlFor: htmlFor ?? controlId,
|
|
366
377
|
children: label
|
|
367
378
|
}) : null,
|
|
368
379
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CompiledForm, FormErrors, RenderableSchema, FormValue } from "./json-schema-form";
|
|
3
|
+
export type JsonSchemaFormProps = {
|
|
4
|
+
value?: FormValue;
|
|
5
|
+
defaultValue?: FormValue;
|
|
6
|
+
onChange?: (value: FormValue) => void;
|
|
7
|
+
/** Backend errors keyed by JSON Pointer; clear these in onErrorsChange. */
|
|
8
|
+
errors?: FormErrors;
|
|
9
|
+
onErrorsChange?: (errors: FormErrors) => void;
|
|
10
|
+
onSubmit: (value: FormValue) => void;
|
|
11
|
+
onReset?: () => void;
|
|
12
|
+
} & ({
|
|
13
|
+
compiled: CompiledForm;
|
|
14
|
+
schema?: never;
|
|
15
|
+
} | {
|
|
16
|
+
schema: RenderableSchema;
|
|
17
|
+
compiled?: never;
|
|
18
|
+
});
|
|
19
|
+
export declare function JsonSchemaForm({ compiled: suppliedCompiled, schema, value: controlledValue, defaultValue, onChange, errors: suppliedErrors, onErrorsChange, onSubmit, onReset, }: JsonSchemaFormProps): React.JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { JsonValue, RenderableSchema } from "./json-schema-form";
|
|
3
|
+
export type JsonSchemaWidgetProps = {
|
|
4
|
+
schema: RenderableSchema;
|
|
5
|
+
value: JsonValue | undefined;
|
|
6
|
+
onChange: (value: JsonValue | undefined) => void;
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
path: string;
|
|
10
|
+
describedBy?: string;
|
|
11
|
+
invalid: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const specializedWidgets: Set<string>;
|
|
14
|
+
export declare function JsonSchemaWidget({ schema, value, onChange, id, label, path, describedBy, invalid, }: JsonSchemaWidgetProps): React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { JsonSchemaForm } from "./JsonSchemaForm";
|
|
2
|
+
export type { JsonSchemaFormProps } from "./JsonSchemaForm";
|
|
3
|
+
export { JsonSchemaWidget, specializedWidgets } from "./JsonSchemaWidget";
|
|
4
|
+
export type { JsonSchemaWidgetProps } from "./JsonSchemaWidget";
|
|
5
|
+
export { compileForm } from "./json-schema-form";
|
|
6
|
+
export type { CompiledForm, FormErrors, FormValidationResult, FormValue, JsonValue, RenderableSchema, } from "./json-schema-form";
|
|
7
|
+
export { flattenOptions, inspectWidgets, naturalWidgetValue, optionsFor, widgetConfig, widgetNames, widgetValueError, } from "./json-form-widgets";
|
|
8
|
+
export type { OrientationWidgetConfig, WidgetConfig, WidgetName, WidgetOption, } from "./json-form-widgets";
|