@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 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)("div", { style: { flex: 1, textAlign: "center", display: "flex", flexDirection: "column", justifyContent: "flex-end", height: "100%" }, children: [
327
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", color: "#94a3b8", marginBottom: "4px" }, children: val }),
328
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
329
- "div",
330
- {
331
- style: {
332
- height: `${Math.max(val / max * 100, 4)}%`,
333
- background: "linear-gradient(180deg, #3b82f6, #2563eb)",
334
- borderRadius: "4px 4px 0 0",
335
- minHeight: "4px"
336
- }
337
- }
338
- ),
339
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", marginTop: "6px", color: "#64748b" }, children: labels[i] })
340
- ] }, labels[i] ?? i)) }),
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)("div", { style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "13px" }, children: [
345
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { width: 10, height: 10, borderRadius: "50%", background: chartColors[i % chartColors.length] } }),
346
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
347
- label,
348
- ": ",
349
- values[i],
350
- " (",
351
- pct,
352
- "%)"
353
- ] })
354
- ] }, label);
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 = ["#3b82f6", "#22c55e", "#f59e0b", "#ef4444", "#8b5cf6", "#ec4899", "#06b6d4", "#f97316"];
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)("div", { style: { fontSize: "13px", marginBottom: "4px", display: "flex", justifyContent: "space-between" }, children: [
408
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: label }),
409
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { color: "#64748b" }, children: [
410
- Math.round(pct),
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 (isStreaming || disabled) return;
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: isStreaming || disabled,
513
+ disabled: isDisabled,
459
514
  onClick: handleClick,
460
515
  style: {
461
516
  padding: "8px 16px",
462
517
  borderRadius: "6px",
463
- cursor: isStreaming || disabled ? "not-allowed" : "pointer",
464
- opacity: isStreaming || disabled ? 0.6 : 1,
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 import_react4 = __toESM(require("react"), 1);
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, import_react4.useState)(initialActive);
692
- const childArray = import_react4.default.Children.toArray(children);
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",