@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.cjs
CHANGED
|
@@ -323,39 +323,79 @@ function Chart({ props }) {
|
|
|
323
323
|
const max = values.reduce((a, b) => Math.max(a, b), 1);
|
|
324
324
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-chart": true, "data-type": type, style: { padding: "12px 0" }, children: [
|
|
325
325
|
title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontWeight: 600, marginBottom: "12px" }, children: title }),
|
|
326
|
-
(type === "bar" || type === "line") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", alignItems: "flex-end", gap: "6px", height: "140px" }, children: values.map((val, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
326
|
+
(type === "bar" || type === "line") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", alignItems: "flex-end", gap: "6px", height: "140px" }, children: values.map((val, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
327
|
+
"div",
|
|
328
|
+
{
|
|
329
|
+
style: {
|
|
330
|
+
flex: 1,
|
|
331
|
+
textAlign: "center",
|
|
332
|
+
display: "flex",
|
|
333
|
+
flexDirection: "column",
|
|
334
|
+
justifyContent: "flex-end",
|
|
335
|
+
height: "100%"
|
|
336
|
+
},
|
|
337
|
+
children: [
|
|
338
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", color: "#94a3b8", marginBottom: "4px" }, children: val }),
|
|
339
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
340
|
+
"div",
|
|
341
|
+
{
|
|
342
|
+
style: {
|
|
343
|
+
height: `${Math.max(val / max * 100, 4)}%`,
|
|
344
|
+
background: "linear-gradient(180deg, #3b82f6, #2563eb)",
|
|
345
|
+
borderRadius: "4px 4px 0 0",
|
|
346
|
+
minHeight: "4px"
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
),
|
|
350
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", marginTop: "6px", color: "#64748b" }, children: labels[i] })
|
|
351
|
+
]
|
|
352
|
+
},
|
|
353
|
+
labels[i] ?? i
|
|
354
|
+
)) }),
|
|
341
355
|
(type === "pie" || type === "donut") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap" }, children: labels.map((label, i) => {
|
|
342
356
|
const total = values.reduce((a, b) => a + b, 0);
|
|
343
357
|
const pct = total > 0 ? Math.round(values[i] / total * 100) : 0;
|
|
344
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
358
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
359
|
+
"div",
|
|
360
|
+
{
|
|
361
|
+
style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "13px" },
|
|
362
|
+
children: [
|
|
363
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
364
|
+
"div",
|
|
365
|
+
{
|
|
366
|
+
style: {
|
|
367
|
+
width: 10,
|
|
368
|
+
height: 10,
|
|
369
|
+
borderRadius: "50%",
|
|
370
|
+
background: chartColors[i % chartColors.length]
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
),
|
|
374
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
|
|
375
|
+
label,
|
|
376
|
+
": ",
|
|
377
|
+
values[i],
|
|
378
|
+
" (",
|
|
379
|
+
pct,
|
|
380
|
+
"%)"
|
|
381
|
+
] })
|
|
382
|
+
]
|
|
383
|
+
},
|
|
384
|
+
label
|
|
385
|
+
);
|
|
355
386
|
}) })
|
|
356
387
|
] });
|
|
357
388
|
}
|
|
358
|
-
var chartColors = [
|
|
389
|
+
var chartColors = [
|
|
390
|
+
"#3b82f6",
|
|
391
|
+
"#22c55e",
|
|
392
|
+
"#f59e0b",
|
|
393
|
+
"#ef4444",
|
|
394
|
+
"#8b5cf6",
|
|
395
|
+
"#ec4899",
|
|
396
|
+
"#06b6d4",
|
|
397
|
+
"#f97316"
|
|
398
|
+
];
|
|
359
399
|
function Table({ props }) {
|
|
360
400
|
const headers = Array.isArray(props.headers) ? props.headers : [];
|
|
361
401
|
const rows = Array.isArray(props.rows) ? props.rows : [];
|
|
@@ -404,13 +444,24 @@ function Progress({ props }) {
|
|
|
404
444
|
const max = Number(props.max) || 100;
|
|
405
445
|
const pct = Math.min(100, Math.max(0, value / max * 100));
|
|
406
446
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-progress": true, children: [
|
|
407
|
-
label && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
447
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
448
|
+
"div",
|
|
449
|
+
{
|
|
450
|
+
style: {
|
|
451
|
+
fontSize: "13px",
|
|
452
|
+
marginBottom: "4px",
|
|
453
|
+
display: "flex",
|
|
454
|
+
justifyContent: "space-between"
|
|
455
|
+
},
|
|
456
|
+
children: [
|
|
457
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: label }),
|
|
458
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { color: "#64748b" }, children: [
|
|
459
|
+
Math.round(pct),
|
|
460
|
+
"%"
|
|
461
|
+
] })
|
|
462
|
+
]
|
|
463
|
+
}
|
|
464
|
+
),
|
|
414
465
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
415
466
|
"div",
|
|
416
467
|
{
|
|
@@ -433,14 +484,17 @@ function Progress({ props }) {
|
|
|
433
484
|
}
|
|
434
485
|
|
|
435
486
|
// src/components/interactive.tsx
|
|
487
|
+
var import_react4 = require("react");
|
|
436
488
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
437
489
|
function Button({ props, onAction, isStreaming }) {
|
|
438
490
|
const action = props.action;
|
|
439
491
|
const label = props.label;
|
|
440
492
|
const variant = props.variant ?? "primary";
|
|
441
493
|
const disabled = props.disabled ?? false;
|
|
494
|
+
const [clicked, setClicked] = (0, import_react4.useState)(false);
|
|
495
|
+
const isDisabled = isStreaming || disabled || clicked;
|
|
442
496
|
const handleClick = () => {
|
|
443
|
-
if (
|
|
497
|
+
if (isDisabled) return;
|
|
444
498
|
const event = {
|
|
445
499
|
type: "button_click",
|
|
446
500
|
action,
|
|
@@ -448,6 +502,7 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
448
502
|
tagName: "button"
|
|
449
503
|
};
|
|
450
504
|
onAction(event);
|
|
505
|
+
setClicked(true);
|
|
451
506
|
};
|
|
452
507
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
453
508
|
"button",
|
|
@@ -455,13 +510,13 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
455
510
|
type: "button",
|
|
456
511
|
"data-mdocui-button": true,
|
|
457
512
|
"data-variant": variant,
|
|
458
|
-
disabled:
|
|
513
|
+
disabled: isDisabled,
|
|
459
514
|
onClick: handleClick,
|
|
460
515
|
style: {
|
|
461
516
|
padding: "8px 16px",
|
|
462
517
|
borderRadius: "6px",
|
|
463
|
-
cursor:
|
|
464
|
-
opacity:
|
|
518
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
519
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
465
520
|
border: variant === "outline" ? "1px solid #555" : "none",
|
|
466
521
|
background: variant === "primary" ? "#3b82f6" : variant === "ghost" ? "transparent" : "#27272a",
|
|
467
522
|
color: "#fff"
|
|
@@ -584,9 +639,10 @@ function Checkbox({ props, onAction, isStreaming }) {
|
|
|
584
639
|
function Form({ props, children, onAction, isStreaming }) {
|
|
585
640
|
const formName = props.name;
|
|
586
641
|
const action = props.action ?? `submit:${formName}`;
|
|
642
|
+
const [submitted, setSubmitted] = (0, import_react4.useState)(false);
|
|
587
643
|
const handleSubmit = (e) => {
|
|
588
644
|
e.preventDefault();
|
|
589
|
-
if (isStreaming) return;
|
|
645
|
+
if (isStreaming || submitted) return;
|
|
590
646
|
const formData = new FormData(e.currentTarget);
|
|
591
647
|
const state = {};
|
|
592
648
|
formData.forEach((value, key) => {
|
|
@@ -600,7 +656,47 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
600
656
|
tagName: "form"
|
|
601
657
|
};
|
|
602
658
|
onAction(event);
|
|
659
|
+
setSubmitted(true);
|
|
603
660
|
};
|
|
661
|
+
if (submitted) {
|
|
662
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
663
|
+
"div",
|
|
664
|
+
{
|
|
665
|
+
"data-mdocui-form": true,
|
|
666
|
+
"data-name": formName,
|
|
667
|
+
"data-submitted": true,
|
|
668
|
+
style: {
|
|
669
|
+
display: "flex",
|
|
670
|
+
flexDirection: "column",
|
|
671
|
+
gap: "12px",
|
|
672
|
+
opacity: 0.5,
|
|
673
|
+
pointerEvents: "none",
|
|
674
|
+
position: "relative"
|
|
675
|
+
},
|
|
676
|
+
children: [
|
|
677
|
+
children,
|
|
678
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
679
|
+
"div",
|
|
680
|
+
{
|
|
681
|
+
style: {
|
|
682
|
+
position: "absolute",
|
|
683
|
+
inset: 0,
|
|
684
|
+
display: "flex",
|
|
685
|
+
alignItems: "center",
|
|
686
|
+
justifyContent: "center",
|
|
687
|
+
background: "rgba(0,0,0,0.3)",
|
|
688
|
+
borderRadius: "8px",
|
|
689
|
+
fontSize: "13px",
|
|
690
|
+
color: "#4ade80",
|
|
691
|
+
fontWeight: 500
|
|
692
|
+
},
|
|
693
|
+
children: "Submitted"
|
|
694
|
+
}
|
|
695
|
+
)
|
|
696
|
+
]
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
}
|
|
604
700
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
605
701
|
"form",
|
|
606
702
|
{
|
|
@@ -614,7 +710,7 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
614
710
|
}
|
|
615
711
|
|
|
616
712
|
// src/components/layout.tsx
|
|
617
|
-
var
|
|
713
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
618
714
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
619
715
|
function Stack({ props, children }) {
|
|
620
716
|
const direction = props.direction ?? "vertical";
|
|
@@ -688,8 +784,8 @@ function Accordion({ props, children }) {
|
|
|
688
784
|
function Tabs({ props, children }) {
|
|
689
785
|
const labels = Array.isArray(props.labels) ? props.labels : [];
|
|
690
786
|
const initialActive = props.active ?? 0;
|
|
691
|
-
const [active, setActive] = (0,
|
|
692
|
-
const childArray =
|
|
787
|
+
const [active, setActive] = (0, import_react5.useState)(initialActive);
|
|
788
|
+
const childArray = import_react5.default.Children.toArray(children);
|
|
693
789
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-mdocui-tabs": true, children: [
|
|
694
790
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
695
791
|
"div",
|