@mdocui/react 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +138 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +137 -41
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -264,39 +264,79 @@ function Chart({ props }) {
|
|
|
264
264
|
const max = values.reduce((a, b) => Math.max(a, b), 1);
|
|
265
265
|
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-chart": true, "data-type": type, style: { padding: "12px 0" }, children: [
|
|
266
266
|
title && /* @__PURE__ */ jsx3("div", { style: { fontWeight: 600, marginBottom: "12px" }, children: title }),
|
|
267
|
-
(type === "bar" || type === "line") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", alignItems: "flex-end", gap: "6px", height: "140px" }, children: values.map((val, i) => /* @__PURE__ */ jsxs2(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
267
|
+
(type === "bar" || type === "line") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", alignItems: "flex-end", gap: "6px", height: "140px" }, children: values.map((val, i) => /* @__PURE__ */ jsxs2(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
style: {
|
|
271
|
+
flex: 1,
|
|
272
|
+
textAlign: "center",
|
|
273
|
+
display: "flex",
|
|
274
|
+
flexDirection: "column",
|
|
275
|
+
justifyContent: "flex-end",
|
|
276
|
+
height: "100%"
|
|
277
|
+
},
|
|
278
|
+
children: [
|
|
279
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", color: "#94a3b8", marginBottom: "4px" }, children: val }),
|
|
280
|
+
/* @__PURE__ */ jsx3(
|
|
281
|
+
"div",
|
|
282
|
+
{
|
|
283
|
+
style: {
|
|
284
|
+
height: `${Math.max(val / max * 100, 4)}%`,
|
|
285
|
+
background: "linear-gradient(180deg, #3b82f6, #2563eb)",
|
|
286
|
+
borderRadius: "4px 4px 0 0",
|
|
287
|
+
minHeight: "4px"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
),
|
|
291
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", marginTop: "6px", color: "#64748b" }, children: labels[i] })
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
labels[i] ?? i
|
|
295
|
+
)) }),
|
|
282
296
|
(type === "pie" || type === "donut") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap" }, children: labels.map((label, i) => {
|
|
283
297
|
const total = values.reduce((a, b) => a + b, 0);
|
|
284
298
|
const pct = total > 0 ? Math.round(values[i] / total * 100) : 0;
|
|
285
|
-
return /* @__PURE__ */ jsxs2(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
299
|
+
return /* @__PURE__ */ jsxs2(
|
|
300
|
+
"div",
|
|
301
|
+
{
|
|
302
|
+
style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "13px" },
|
|
303
|
+
children: [
|
|
304
|
+
/* @__PURE__ */ jsx3(
|
|
305
|
+
"div",
|
|
306
|
+
{
|
|
307
|
+
style: {
|
|
308
|
+
width: 10,
|
|
309
|
+
height: 10,
|
|
310
|
+
borderRadius: "50%",
|
|
311
|
+
background: chartColors[i % chartColors.length]
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
),
|
|
315
|
+
/* @__PURE__ */ jsxs2("span", { children: [
|
|
316
|
+
label,
|
|
317
|
+
": ",
|
|
318
|
+
values[i],
|
|
319
|
+
" (",
|
|
320
|
+
pct,
|
|
321
|
+
"%)"
|
|
322
|
+
] })
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
label
|
|
326
|
+
);
|
|
296
327
|
}) })
|
|
297
328
|
] });
|
|
298
329
|
}
|
|
299
|
-
var chartColors = [
|
|
330
|
+
var chartColors = [
|
|
331
|
+
"#3b82f6",
|
|
332
|
+
"#22c55e",
|
|
333
|
+
"#f59e0b",
|
|
334
|
+
"#ef4444",
|
|
335
|
+
"#8b5cf6",
|
|
336
|
+
"#ec4899",
|
|
337
|
+
"#06b6d4",
|
|
338
|
+
"#f97316"
|
|
339
|
+
];
|
|
300
340
|
function Table({ props }) {
|
|
301
341
|
const headers = Array.isArray(props.headers) ? props.headers : [];
|
|
302
342
|
const rows = Array.isArray(props.rows) ? props.rows : [];
|
|
@@ -345,13 +385,24 @@ function Progress({ props }) {
|
|
|
345
385
|
const max = Number(props.max) || 100;
|
|
346
386
|
const pct = Math.min(100, Math.max(0, value / max * 100));
|
|
347
387
|
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-progress": true, children: [
|
|
348
|
-
label && /* @__PURE__ */ jsxs2(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
388
|
+
label && /* @__PURE__ */ jsxs2(
|
|
389
|
+
"div",
|
|
390
|
+
{
|
|
391
|
+
style: {
|
|
392
|
+
fontSize: "13px",
|
|
393
|
+
marginBottom: "4px",
|
|
394
|
+
display: "flex",
|
|
395
|
+
justifyContent: "space-between"
|
|
396
|
+
},
|
|
397
|
+
children: [
|
|
398
|
+
/* @__PURE__ */ jsx3("span", { children: label }),
|
|
399
|
+
/* @__PURE__ */ jsxs2("span", { style: { color: "#64748b" }, children: [
|
|
400
|
+
Math.round(pct),
|
|
401
|
+
"%"
|
|
402
|
+
] })
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
),
|
|
355
406
|
/* @__PURE__ */ jsx3(
|
|
356
407
|
"div",
|
|
357
408
|
{
|
|
@@ -374,14 +425,17 @@ function Progress({ props }) {
|
|
|
374
425
|
}
|
|
375
426
|
|
|
376
427
|
// src/components/interactive.tsx
|
|
428
|
+
import { useState as useState2 } from "react";
|
|
377
429
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
378
430
|
function Button({ props, onAction, isStreaming }) {
|
|
379
431
|
const action = props.action;
|
|
380
432
|
const label = props.label;
|
|
381
433
|
const variant = props.variant ?? "primary";
|
|
382
434
|
const disabled = props.disabled ?? false;
|
|
435
|
+
const [clicked, setClicked] = useState2(false);
|
|
436
|
+
const isDisabled = isStreaming || disabled || clicked;
|
|
383
437
|
const handleClick = () => {
|
|
384
|
-
if (
|
|
438
|
+
if (isDisabled) return;
|
|
385
439
|
const event = {
|
|
386
440
|
type: "button_click",
|
|
387
441
|
action,
|
|
@@ -389,6 +443,7 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
389
443
|
tagName: "button"
|
|
390
444
|
};
|
|
391
445
|
onAction(event);
|
|
446
|
+
setClicked(true);
|
|
392
447
|
};
|
|
393
448
|
return /* @__PURE__ */ jsx4(
|
|
394
449
|
"button",
|
|
@@ -396,13 +451,13 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
396
451
|
type: "button",
|
|
397
452
|
"data-mdocui-button": true,
|
|
398
453
|
"data-variant": variant,
|
|
399
|
-
disabled:
|
|
454
|
+
disabled: isDisabled,
|
|
400
455
|
onClick: handleClick,
|
|
401
456
|
style: {
|
|
402
457
|
padding: "8px 16px",
|
|
403
458
|
borderRadius: "6px",
|
|
404
|
-
cursor:
|
|
405
|
-
opacity:
|
|
459
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
460
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
406
461
|
border: variant === "outline" ? "1px solid #555" : "none",
|
|
407
462
|
background: variant === "primary" ? "#3b82f6" : variant === "ghost" ? "transparent" : "#27272a",
|
|
408
463
|
color: "#fff"
|
|
@@ -525,9 +580,10 @@ function Checkbox({ props, onAction, isStreaming }) {
|
|
|
525
580
|
function Form({ props, children, onAction, isStreaming }) {
|
|
526
581
|
const formName = props.name;
|
|
527
582
|
const action = props.action ?? `submit:${formName}`;
|
|
583
|
+
const [submitted, setSubmitted] = useState2(false);
|
|
528
584
|
const handleSubmit = (e) => {
|
|
529
585
|
e.preventDefault();
|
|
530
|
-
if (isStreaming) return;
|
|
586
|
+
if (isStreaming || submitted) return;
|
|
531
587
|
const formData = new FormData(e.currentTarget);
|
|
532
588
|
const state = {};
|
|
533
589
|
formData.forEach((value, key) => {
|
|
@@ -541,7 +597,47 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
541
597
|
tagName: "form"
|
|
542
598
|
};
|
|
543
599
|
onAction(event);
|
|
600
|
+
setSubmitted(true);
|
|
544
601
|
};
|
|
602
|
+
if (submitted) {
|
|
603
|
+
return /* @__PURE__ */ jsxs3(
|
|
604
|
+
"div",
|
|
605
|
+
{
|
|
606
|
+
"data-mdocui-form": true,
|
|
607
|
+
"data-name": formName,
|
|
608
|
+
"data-submitted": true,
|
|
609
|
+
style: {
|
|
610
|
+
display: "flex",
|
|
611
|
+
flexDirection: "column",
|
|
612
|
+
gap: "12px",
|
|
613
|
+
opacity: 0.5,
|
|
614
|
+
pointerEvents: "none",
|
|
615
|
+
position: "relative"
|
|
616
|
+
},
|
|
617
|
+
children: [
|
|
618
|
+
children,
|
|
619
|
+
/* @__PURE__ */ jsx4(
|
|
620
|
+
"div",
|
|
621
|
+
{
|
|
622
|
+
style: {
|
|
623
|
+
position: "absolute",
|
|
624
|
+
inset: 0,
|
|
625
|
+
display: "flex",
|
|
626
|
+
alignItems: "center",
|
|
627
|
+
justifyContent: "center",
|
|
628
|
+
background: "rgba(0,0,0,0.3)",
|
|
629
|
+
borderRadius: "8px",
|
|
630
|
+
fontSize: "13px",
|
|
631
|
+
color: "#4ade80",
|
|
632
|
+
fontWeight: 500
|
|
633
|
+
},
|
|
634
|
+
children: "Submitted"
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
);
|
|
640
|
+
}
|
|
545
641
|
return /* @__PURE__ */ jsx4(
|
|
546
642
|
"form",
|
|
547
643
|
{
|
|
@@ -555,7 +651,7 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
555
651
|
}
|
|
556
652
|
|
|
557
653
|
// src/components/layout.tsx
|
|
558
|
-
import React, { useState as
|
|
654
|
+
import React, { useState as useState3 } from "react";
|
|
559
655
|
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
560
656
|
function Stack({ props, children }) {
|
|
561
657
|
const direction = props.direction ?? "vertical";
|
|
@@ -629,7 +725,7 @@ function Accordion({ props, children }) {
|
|
|
629
725
|
function Tabs({ props, children }) {
|
|
630
726
|
const labels = Array.isArray(props.labels) ? props.labels : [];
|
|
631
727
|
const initialActive = props.active ?? 0;
|
|
632
|
-
const [active, setActive] =
|
|
728
|
+
const [active, setActive] = useState3(initialActive);
|
|
633
729
|
const childArray = React.Children.toArray(children);
|
|
634
730
|
return /* @__PURE__ */ jsxs4("div", { "data-mdocui-tabs": true, children: [
|
|
635
731
|
/* @__PURE__ */ jsx5(
|