@mdocui/react 0.1.2 → 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
@@ -175,10 +175,10 @@ var import_core3 = require("@mdocui/core");
175
175
  // src/components/content.tsx
176
176
  var import_jsx_runtime2 = require("react/jsx-runtime");
177
177
  var calloutColors = {
178
- info: { bg: "#eff6ff", border: "#3b82f6" },
179
- warning: { bg: "#fffbeb", border: "#f59e0b" },
180
- error: { bg: "#fef2f2", border: "#ef4444" },
181
- success: { bg: "#f0fdf4", border: "#22c55e" }
178
+ info: { bg: "rgba(59,130,246,0.1)", border: "#3b82f6" },
179
+ warning: { bg: "rgba(245,158,11,0.1)", border: "#f59e0b" },
180
+ error: { bg: "rgba(239,68,68,0.1)", border: "#ef4444" },
181
+ success: { bg: "rgba(34,197,94,0.1)", border: "#22c55e" }
182
182
  };
183
183
  function Callout({ props, children }) {
184
184
  const type = props.type ?? "info";
@@ -204,11 +204,11 @@ function Callout({ props, children }) {
204
204
  );
205
205
  }
206
206
  var badgeColors = {
207
- default: { bg: "#f1f5f9", color: "#475569" },
208
- success: { bg: "#dcfce7", color: "#166534" },
209
- warning: { bg: "#fef3c7", color: "#92400e" },
210
- error: { bg: "#fee2e2", color: "#991b1b" },
211
- info: { bg: "#dbeafe", color: "#1e40af" }
207
+ default: { bg: "rgba(148,163,184,0.15)", color: "#94a3b8" },
208
+ success: { bg: "rgba(34,197,94,0.15)", color: "#4ade80" },
209
+ warning: { bg: "rgba(245,158,11,0.15)", color: "#fbbf24" },
210
+ error: { bg: "rgba(239,68,68,0.15)", color: "#f87171" },
211
+ info: { bg: "rgba(59,130,246,0.15)", color: "#60a5fa" }
212
212
  };
213
213
  function Badge({ props }) {
214
214
  const label = props.label;
@@ -307,7 +307,7 @@ function Link({ props, onAction, isStreaming }) {
307
307
  "data-mdocui-link": true,
308
308
  href: url ?? "#",
309
309
  onClick: handleClick,
310
- style: { color: "#3b82f6", textDecoration: "underline", cursor: "pointer" },
310
+ style: { color: "#60a5fa", textDecoration: "underline", cursor: "pointer" },
311
311
  children: label
312
312
  }
313
313
  );
@@ -317,36 +317,88 @@ function Link({ props, onAction, isStreaming }) {
317
317
  var import_jsx_runtime3 = require("react/jsx-runtime");
318
318
  function Chart({ props }) {
319
319
  const type = props.type;
320
- const labels = props.labels ?? [];
321
- const values = props.values ?? [];
320
+ const labels = Array.isArray(props.labels) ? props.labels : [];
321
+ const values = Array.isArray(props.values) ? props.values.map(Number) : [];
322
322
  const title = props.title;
323
323
  const max = values.reduce((a, b) => Math.max(a, b), 1);
324
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-chart": true, "data-type": type, children: [
325
- title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontWeight: 600, marginBottom: "8px" }, children: title }),
326
- (type === "bar" || type === "line") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", alignItems: "flex-end", gap: "4px", height: "120px" }, children: values.map((val, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, textAlign: "center" }, children: [
327
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
324
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-chart": true, "data-type": type, style: { padding: "12px 0" }, children: [
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
+ "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
+ )) }),
355
+ (type === "pie" || type === "donut") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap" }, children: labels.map((label, i) => {
356
+ const total = values.reduce((a, b) => a + b, 0);
357
+ const pct = total > 0 ? Math.round(values[i] / total * 100) : 0;
358
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
328
359
  "div",
329
360
  {
330
- style: {
331
- height: `${val / max * 100}%`,
332
- background: "#3b82f6",
333
- borderRadius: "4px 4px 0 0",
334
- minHeight: "2px"
335
- }
336
- }
337
- ),
338
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", marginTop: "4px", color: "#64748b" }, children: labels[i] })
339
- ] }, labels[i] ?? i)) }),
340
- (type === "pie" || type === "donut") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: labels.map((label, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "13px" }, children: [
341
- label,
342
- ": ",
343
- values[i]
344
- ] }, label)) })
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
+ );
386
+ }) })
345
387
  ] });
346
388
  }
389
+ var chartColors = [
390
+ "#3b82f6",
391
+ "#22c55e",
392
+ "#f59e0b",
393
+ "#ef4444",
394
+ "#8b5cf6",
395
+ "#ec4899",
396
+ "#06b6d4",
397
+ "#f97316"
398
+ ];
347
399
  function Table({ props }) {
348
- const headers = props.headers ?? [];
349
- const rows = props.rows ?? [];
400
+ const headers = Array.isArray(props.headers) ? props.headers : [];
401
+ const rows = Array.isArray(props.rows) ? props.rows : [];
350
402
  const caption = props.caption;
351
403
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { "data-mdocui-table": true, style: { width: "100%", borderCollapse: "collapse" }, children: [
352
404
  caption && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("caption", { style: { textAlign: "left", fontWeight: 600, marginBottom: "8px" }, children: caption }),
@@ -356,17 +408,22 @@ function Table({ props }) {
356
408
  style: {
357
409
  textAlign: "left",
358
410
  padding: "8px",
359
- borderBottom: "2px solid #e2e8f0",
360
- fontWeight: 600
411
+ borderBottom: "2px solid #333",
412
+ fontWeight: 600,
413
+ color: "#94a3b8",
414
+ fontSize: "13px"
361
415
  },
362
416
  children: h
363
417
  },
364
418
  h
365
419
  )) }) }),
366
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tr", { children: row.map((cell, _ci) => {
367
- const cellKey = `${row[0]}-${cell}`;
368
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { style: { padding: "8px", borderBottom: "1px solid #f1f5f9" }, children: cell }, cellKey);
369
- }) }, row.join(" "))) })
420
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: rows.map((row) => {
421
+ const cells = Array.isArray(row) ? row : [String(row)];
422
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tr", { children: cells.map((cell) => {
423
+ const cellKey = `${cells[0]}-${cell}`;
424
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { style: { padding: "8px", borderBottom: "1px solid #222" }, children: cell }, cellKey);
425
+ }) }, cells.join(" "));
426
+ }) })
370
427
  ] });
371
428
  }
372
429
  function Stat({ props }) {
@@ -374,24 +431,41 @@ function Stat({ props }) {
374
431
  const value = props.value;
375
432
  const change = props.change;
376
433
  const trend = props.trend ?? "neutral";
377
- const trendColor = trend === "up" ? "#16a34a" : trend === "down" ? "#dc2626" : "#64748b";
378
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-stat": true, children: [
434
+ const trendColor = trend === "up" ? "#4ade80" : trend === "down" ? "#f87171" : "#64748b";
435
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-stat": true, style: { padding: "8px 0" }, children: [
379
436
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "13px", color: "#64748b" }, children: label }),
380
437
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "24px", fontWeight: 700 }, children: value }),
381
438
  change && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "13px", color: trendColor }, children: change })
382
439
  ] });
383
440
  }
384
441
  function Progress({ props }) {
385
- const value = props.value;
442
+ const value = Number(props.value) || 0;
386
443
  const label = props.label;
387
- const max = props.max ?? 100;
444
+ const max = Number(props.max) || 100;
388
445
  const pct = Math.min(100, Math.max(0, value / max * 100));
389
446
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-mdocui-progress": true, children: [
390
- label && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "13px", marginBottom: "4px" }, children: label }),
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
+ ),
391
465
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
392
466
  "div",
393
467
  {
394
- style: { height: "8px", background: "#e2e8f0", borderRadius: "4px", overflow: "hidden" },
468
+ style: { height: "8px", background: "#27272a", borderRadius: "4px", overflow: "hidden" },
395
469
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
396
470
  "div",
397
471
  {
@@ -410,14 +484,17 @@ function Progress({ props }) {
410
484
  }
411
485
 
412
486
  // src/components/interactive.tsx
487
+ var import_react4 = require("react");
413
488
  var import_jsx_runtime4 = require("react/jsx-runtime");
414
489
  function Button({ props, onAction, isStreaming }) {
415
490
  const action = props.action;
416
491
  const label = props.label;
417
492
  const variant = props.variant ?? "primary";
418
493
  const disabled = props.disabled ?? false;
494
+ const [clicked, setClicked] = (0, import_react4.useState)(false);
495
+ const isDisabled = isStreaming || disabled || clicked;
419
496
  const handleClick = () => {
420
- if (isStreaming || disabled) return;
497
+ if (isDisabled) return;
421
498
  const event = {
422
499
  type: "button_click",
423
500
  action,
@@ -425,6 +502,7 @@ function Button({ props, onAction, isStreaming }) {
425
502
  tagName: "button"
426
503
  };
427
504
  onAction(event);
505
+ setClicked(true);
428
506
  };
429
507
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
430
508
  "button",
@@ -432,16 +510,16 @@ function Button({ props, onAction, isStreaming }) {
432
510
  type: "button",
433
511
  "data-mdocui-button": true,
434
512
  "data-variant": variant,
435
- disabled: isStreaming || disabled,
513
+ disabled: isDisabled,
436
514
  onClick: handleClick,
437
515
  style: {
438
516
  padding: "8px 16px",
439
517
  borderRadius: "6px",
440
- cursor: isStreaming || disabled ? "not-allowed" : "pointer",
441
- opacity: isStreaming || disabled ? 0.6 : 1,
442
- border: variant === "outline" ? "1px solid currentColor" : "none",
443
- background: variant === "primary" ? "#0f172a" : variant === "ghost" ? "transparent" : "#e2e8f0",
444
- color: variant === "primary" ? "#fff" : "inherit"
518
+ cursor: isDisabled ? "not-allowed" : "pointer",
519
+ opacity: isDisabled ? 0.5 : 1,
520
+ border: variant === "outline" ? "1px solid #555" : "none",
521
+ background: variant === "primary" ? "#3b82f6" : variant === "ghost" ? "transparent" : "#27272a",
522
+ color: "#fff"
445
523
  },
446
524
  children: label
447
525
  }
@@ -482,7 +560,9 @@ function Input({ props }) {
482
560
  style: {
483
561
  width: "100%",
484
562
  padding: "8px 12px",
485
- border: "1px solid #e2e8f0",
563
+ border: "1px solid #333",
564
+ background: "#18181b",
565
+ color: "inherit",
486
566
  borderRadius: "6px",
487
567
  boxSizing: "border-box"
488
568
  }
@@ -493,7 +573,7 @@ function Input({ props }) {
493
573
  function Select({ props, onAction, isStreaming }) {
494
574
  const name = props.name;
495
575
  const label = props.label;
496
- const options = props.options ?? [];
576
+ const options = Array.isArray(props.options) ? props.options : [];
497
577
  const placeholder = props.placeholder;
498
578
  const required = props.required ?? false;
499
579
  const id = `mdocui-${name}`;
@@ -518,7 +598,9 @@ function Select({ props, onAction, isStreaming }) {
518
598
  style: {
519
599
  width: "100%",
520
600
  padding: "8px 12px",
521
- border: "1px solid #e2e8f0",
601
+ border: "1px solid #333",
602
+ background: "#18181b",
603
+ color: "inherit",
522
604
  borderRadius: "6px"
523
605
  },
524
606
  children: [
@@ -557,9 +639,10 @@ function Checkbox({ props, onAction, isStreaming }) {
557
639
  function Form({ props, children, onAction, isStreaming }) {
558
640
  const formName = props.name;
559
641
  const action = props.action ?? `submit:${formName}`;
642
+ const [submitted, setSubmitted] = (0, import_react4.useState)(false);
560
643
  const handleSubmit = (e) => {
561
644
  e.preventDefault();
562
- if (isStreaming) return;
645
+ if (isStreaming || submitted) return;
563
646
  const formData = new FormData(e.currentTarget);
564
647
  const state = {};
565
648
  formData.forEach((value, key) => {
@@ -573,7 +656,47 @@ function Form({ props, children, onAction, isStreaming }) {
573
656
  tagName: "form"
574
657
  };
575
658
  onAction(event);
659
+ setSubmitted(true);
576
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
+ }
577
700
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
578
701
  "form",
579
702
  {
@@ -587,7 +710,7 @@ function Form({ props, children, onAction, isStreaming }) {
587
710
  }
588
711
 
589
712
  // src/components/layout.tsx
590
- var import_react4 = __toESM(require("react"), 1);
713
+ var import_react5 = __toESM(require("react"), 1);
591
714
  var import_jsx_runtime5 = require("react/jsx-runtime");
592
715
  function Stack({ props, children }) {
593
716
  const direction = props.direction ?? "vertical";
@@ -633,7 +756,7 @@ function Card({ props, children }) {
633
756
  {
634
757
  "data-mdocui-card": true,
635
758
  "data-variant": props.variant ?? "default",
636
- style: { border: "1px solid #e2e8f0", borderRadius: "8px", padding: "16px" },
759
+ style: { border: "1px solid #27272a", borderRadius: "8px", padding: "16px" },
637
760
  children: [
638
761
  title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-mdocui-card-title": true, style: { fontWeight: 600, marginBottom: "8px" }, children: title }),
639
762
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-mdocui-card-body": true, children })
@@ -646,7 +769,7 @@ function Divider(_) {
646
769
  "hr",
647
770
  {
648
771
  "data-mdocui-divider": true,
649
- style: { border: "none", borderTop: "1px solid #e2e8f0", margin: "8px 0" }
772
+ style: { border: "none", borderTop: "1px solid #27272a", margin: "8px 0" }
650
773
  }
651
774
  );
652
775
  }
@@ -659,16 +782,16 @@ function Accordion({ props, children }) {
659
782
  ] });
660
783
  }
661
784
  function Tabs({ props, children }) {
662
- const labels = props.labels ?? [];
785
+ const labels = Array.isArray(props.labels) ? props.labels : [];
663
786
  const initialActive = props.active ?? 0;
664
- const [active, setActive] = (0, import_react4.useState)(initialActive);
665
- 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);
666
789
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-mdocui-tabs": true, children: [
667
790
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
668
791
  "div",
669
792
  {
670
793
  role: "tablist",
671
- style: { display: "flex", gap: "4px", borderBottom: "1px solid #e2e8f0" },
794
+ style: { display: "flex", gap: "4px", borderBottom: "1px solid #27272a" },
672
795
  children: labels.map((label, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
673
796
  "button",
674
797
  {