@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.js CHANGED
@@ -116,10 +116,10 @@ import { ComponentRegistry } from "@mdocui/core";
116
116
  // src/components/content.tsx
117
117
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
118
118
  var calloutColors = {
119
- info: { bg: "#eff6ff", border: "#3b82f6" },
120
- warning: { bg: "#fffbeb", border: "#f59e0b" },
121
- error: { bg: "#fef2f2", border: "#ef4444" },
122
- success: { bg: "#f0fdf4", border: "#22c55e" }
119
+ info: { bg: "rgba(59,130,246,0.1)", border: "#3b82f6" },
120
+ warning: { bg: "rgba(245,158,11,0.1)", border: "#f59e0b" },
121
+ error: { bg: "rgba(239,68,68,0.1)", border: "#ef4444" },
122
+ success: { bg: "rgba(34,197,94,0.1)", border: "#22c55e" }
123
123
  };
124
124
  function Callout({ props, children }) {
125
125
  const type = props.type ?? "info";
@@ -145,11 +145,11 @@ function Callout({ props, children }) {
145
145
  );
146
146
  }
147
147
  var badgeColors = {
148
- default: { bg: "#f1f5f9", color: "#475569" },
149
- success: { bg: "#dcfce7", color: "#166534" },
150
- warning: { bg: "#fef3c7", color: "#92400e" },
151
- error: { bg: "#fee2e2", color: "#991b1b" },
152
- info: { bg: "#dbeafe", color: "#1e40af" }
148
+ default: { bg: "rgba(148,163,184,0.15)", color: "#94a3b8" },
149
+ success: { bg: "rgba(34,197,94,0.15)", color: "#4ade80" },
150
+ warning: { bg: "rgba(245,158,11,0.15)", color: "#fbbf24" },
151
+ error: { bg: "rgba(239,68,68,0.15)", color: "#f87171" },
152
+ info: { bg: "rgba(59,130,246,0.15)", color: "#60a5fa" }
153
153
  };
154
154
  function Badge({ props }) {
155
155
  const label = props.label;
@@ -248,7 +248,7 @@ function Link({ props, onAction, isStreaming }) {
248
248
  "data-mdocui-link": true,
249
249
  href: url ?? "#",
250
250
  onClick: handleClick,
251
- style: { color: "#3b82f6", textDecoration: "underline", cursor: "pointer" },
251
+ style: { color: "#60a5fa", textDecoration: "underline", cursor: "pointer" },
252
252
  children: label
253
253
  }
254
254
  );
@@ -258,36 +258,88 @@ function Link({ props, onAction, isStreaming }) {
258
258
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
259
259
  function Chart({ props }) {
260
260
  const type = props.type;
261
- const labels = props.labels ?? [];
262
- const values = props.values ?? [];
261
+ const labels = Array.isArray(props.labels) ? props.labels : [];
262
+ const values = Array.isArray(props.values) ? props.values.map(Number) : [];
263
263
  const title = props.title;
264
264
  const max = values.reduce((a, b) => Math.max(a, b), 1);
265
- return /* @__PURE__ */ jsxs2("div", { "data-mdocui-chart": true, "data-type": type, children: [
266
- title && /* @__PURE__ */ jsx3("div", { style: { fontWeight: 600, marginBottom: "8px" }, children: title }),
267
- (type === "bar" || type === "line") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", alignItems: "flex-end", gap: "4px", height: "120px" }, children: values.map((val, i) => /* @__PURE__ */ jsxs2("div", { style: { flex: 1, textAlign: "center" }, children: [
268
- /* @__PURE__ */ jsx3(
265
+ return /* @__PURE__ */ jsxs2("div", { "data-mdocui-chart": true, "data-type": type, style: { padding: "12px 0" }, children: [
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
+ "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
+ )) }),
296
+ (type === "pie" || type === "donut") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap" }, children: labels.map((label, i) => {
297
+ const total = values.reduce((a, b) => a + b, 0);
298
+ const pct = total > 0 ? Math.round(values[i] / total * 100) : 0;
299
+ return /* @__PURE__ */ jsxs2(
269
300
  "div",
270
301
  {
271
- style: {
272
- height: `${val / max * 100}%`,
273
- background: "#3b82f6",
274
- borderRadius: "4px 4px 0 0",
275
- minHeight: "2px"
276
- }
277
- }
278
- ),
279
- /* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", marginTop: "4px", color: "#64748b" }, children: labels[i] })
280
- ] }, labels[i] ?? i)) }),
281
- (type === "pie" || type === "donut") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: labels.map((label, i) => /* @__PURE__ */ jsxs2("span", { style: { fontSize: "13px" }, children: [
282
- label,
283
- ": ",
284
- values[i]
285
- ] }, label)) })
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
+ );
327
+ }) })
286
328
  ] });
287
329
  }
330
+ var chartColors = [
331
+ "#3b82f6",
332
+ "#22c55e",
333
+ "#f59e0b",
334
+ "#ef4444",
335
+ "#8b5cf6",
336
+ "#ec4899",
337
+ "#06b6d4",
338
+ "#f97316"
339
+ ];
288
340
  function Table({ props }) {
289
- const headers = props.headers ?? [];
290
- const rows = props.rows ?? [];
341
+ const headers = Array.isArray(props.headers) ? props.headers : [];
342
+ const rows = Array.isArray(props.rows) ? props.rows : [];
291
343
  const caption = props.caption;
292
344
  return /* @__PURE__ */ jsxs2("table", { "data-mdocui-table": true, style: { width: "100%", borderCollapse: "collapse" }, children: [
293
345
  caption && /* @__PURE__ */ jsx3("caption", { style: { textAlign: "left", fontWeight: 600, marginBottom: "8px" }, children: caption }),
@@ -297,17 +349,22 @@ function Table({ props }) {
297
349
  style: {
298
350
  textAlign: "left",
299
351
  padding: "8px",
300
- borderBottom: "2px solid #e2e8f0",
301
- fontWeight: 600
352
+ borderBottom: "2px solid #333",
353
+ fontWeight: 600,
354
+ color: "#94a3b8",
355
+ fontSize: "13px"
302
356
  },
303
357
  children: h
304
358
  },
305
359
  h
306
360
  )) }) }),
307
- /* @__PURE__ */ jsx3("tbody", { children: rows.map((row) => /* @__PURE__ */ jsx3("tr", { children: row.map((cell, _ci) => {
308
- const cellKey = `${row[0]}-${cell}`;
309
- return /* @__PURE__ */ jsx3("td", { style: { padding: "8px", borderBottom: "1px solid #f1f5f9" }, children: cell }, cellKey);
310
- }) }, row.join(" "))) })
361
+ /* @__PURE__ */ jsx3("tbody", { children: rows.map((row) => {
362
+ const cells = Array.isArray(row) ? row : [String(row)];
363
+ return /* @__PURE__ */ jsx3("tr", { children: cells.map((cell) => {
364
+ const cellKey = `${cells[0]}-${cell}`;
365
+ return /* @__PURE__ */ jsx3("td", { style: { padding: "8px", borderBottom: "1px solid #222" }, children: cell }, cellKey);
366
+ }) }, cells.join(" "));
367
+ }) })
311
368
  ] });
312
369
  }
313
370
  function Stat({ props }) {
@@ -315,24 +372,41 @@ function Stat({ props }) {
315
372
  const value = props.value;
316
373
  const change = props.change;
317
374
  const trend = props.trend ?? "neutral";
318
- const trendColor = trend === "up" ? "#16a34a" : trend === "down" ? "#dc2626" : "#64748b";
319
- return /* @__PURE__ */ jsxs2("div", { "data-mdocui-stat": true, children: [
375
+ const trendColor = trend === "up" ? "#4ade80" : trend === "down" ? "#f87171" : "#64748b";
376
+ return /* @__PURE__ */ jsxs2("div", { "data-mdocui-stat": true, style: { padding: "8px 0" }, children: [
320
377
  /* @__PURE__ */ jsx3("div", { style: { fontSize: "13px", color: "#64748b" }, children: label }),
321
378
  /* @__PURE__ */ jsx3("div", { style: { fontSize: "24px", fontWeight: 700 }, children: value }),
322
379
  change && /* @__PURE__ */ jsx3("div", { style: { fontSize: "13px", color: trendColor }, children: change })
323
380
  ] });
324
381
  }
325
382
  function Progress({ props }) {
326
- const value = props.value;
383
+ const value = Number(props.value) || 0;
327
384
  const label = props.label;
328
- const max = props.max ?? 100;
385
+ const max = Number(props.max) || 100;
329
386
  const pct = Math.min(100, Math.max(0, value / max * 100));
330
387
  return /* @__PURE__ */ jsxs2("div", { "data-mdocui-progress": true, children: [
331
- label && /* @__PURE__ */ jsx3("div", { style: { fontSize: "13px", marginBottom: "4px" }, children: label }),
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
+ ),
332
406
  /* @__PURE__ */ jsx3(
333
407
  "div",
334
408
  {
335
- style: { height: "8px", background: "#e2e8f0", borderRadius: "4px", overflow: "hidden" },
409
+ style: { height: "8px", background: "#27272a", borderRadius: "4px", overflow: "hidden" },
336
410
  children: /* @__PURE__ */ jsx3(
337
411
  "div",
338
412
  {
@@ -351,14 +425,17 @@ function Progress({ props }) {
351
425
  }
352
426
 
353
427
  // src/components/interactive.tsx
428
+ import { useState as useState2 } from "react";
354
429
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
355
430
  function Button({ props, onAction, isStreaming }) {
356
431
  const action = props.action;
357
432
  const label = props.label;
358
433
  const variant = props.variant ?? "primary";
359
434
  const disabled = props.disabled ?? false;
435
+ const [clicked, setClicked] = useState2(false);
436
+ const isDisabled = isStreaming || disabled || clicked;
360
437
  const handleClick = () => {
361
- if (isStreaming || disabled) return;
438
+ if (isDisabled) return;
362
439
  const event = {
363
440
  type: "button_click",
364
441
  action,
@@ -366,6 +443,7 @@ function Button({ props, onAction, isStreaming }) {
366
443
  tagName: "button"
367
444
  };
368
445
  onAction(event);
446
+ setClicked(true);
369
447
  };
370
448
  return /* @__PURE__ */ jsx4(
371
449
  "button",
@@ -373,16 +451,16 @@ function Button({ props, onAction, isStreaming }) {
373
451
  type: "button",
374
452
  "data-mdocui-button": true,
375
453
  "data-variant": variant,
376
- disabled: isStreaming || disabled,
454
+ disabled: isDisabled,
377
455
  onClick: handleClick,
378
456
  style: {
379
457
  padding: "8px 16px",
380
458
  borderRadius: "6px",
381
- cursor: isStreaming || disabled ? "not-allowed" : "pointer",
382
- opacity: isStreaming || disabled ? 0.6 : 1,
383
- border: variant === "outline" ? "1px solid currentColor" : "none",
384
- background: variant === "primary" ? "#0f172a" : variant === "ghost" ? "transparent" : "#e2e8f0",
385
- color: variant === "primary" ? "#fff" : "inherit"
459
+ cursor: isDisabled ? "not-allowed" : "pointer",
460
+ opacity: isDisabled ? 0.5 : 1,
461
+ border: variant === "outline" ? "1px solid #555" : "none",
462
+ background: variant === "primary" ? "#3b82f6" : variant === "ghost" ? "transparent" : "#27272a",
463
+ color: "#fff"
386
464
  },
387
465
  children: label
388
466
  }
@@ -423,7 +501,9 @@ function Input({ props }) {
423
501
  style: {
424
502
  width: "100%",
425
503
  padding: "8px 12px",
426
- border: "1px solid #e2e8f0",
504
+ border: "1px solid #333",
505
+ background: "#18181b",
506
+ color: "inherit",
427
507
  borderRadius: "6px",
428
508
  boxSizing: "border-box"
429
509
  }
@@ -434,7 +514,7 @@ function Input({ props }) {
434
514
  function Select({ props, onAction, isStreaming }) {
435
515
  const name = props.name;
436
516
  const label = props.label;
437
- const options = props.options ?? [];
517
+ const options = Array.isArray(props.options) ? props.options : [];
438
518
  const placeholder = props.placeholder;
439
519
  const required = props.required ?? false;
440
520
  const id = `mdocui-${name}`;
@@ -459,7 +539,9 @@ function Select({ props, onAction, isStreaming }) {
459
539
  style: {
460
540
  width: "100%",
461
541
  padding: "8px 12px",
462
- border: "1px solid #e2e8f0",
542
+ border: "1px solid #333",
543
+ background: "#18181b",
544
+ color: "inherit",
463
545
  borderRadius: "6px"
464
546
  },
465
547
  children: [
@@ -498,9 +580,10 @@ function Checkbox({ props, onAction, isStreaming }) {
498
580
  function Form({ props, children, onAction, isStreaming }) {
499
581
  const formName = props.name;
500
582
  const action = props.action ?? `submit:${formName}`;
583
+ const [submitted, setSubmitted] = useState2(false);
501
584
  const handleSubmit = (e) => {
502
585
  e.preventDefault();
503
- if (isStreaming) return;
586
+ if (isStreaming || submitted) return;
504
587
  const formData = new FormData(e.currentTarget);
505
588
  const state = {};
506
589
  formData.forEach((value, key) => {
@@ -514,7 +597,47 @@ function Form({ props, children, onAction, isStreaming }) {
514
597
  tagName: "form"
515
598
  };
516
599
  onAction(event);
600
+ setSubmitted(true);
517
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
+ }
518
641
  return /* @__PURE__ */ jsx4(
519
642
  "form",
520
643
  {
@@ -528,7 +651,7 @@ function Form({ props, children, onAction, isStreaming }) {
528
651
  }
529
652
 
530
653
  // src/components/layout.tsx
531
- import React, { useState as useState2 } from "react";
654
+ import React, { useState as useState3 } from "react";
532
655
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
533
656
  function Stack({ props, children }) {
534
657
  const direction = props.direction ?? "vertical";
@@ -574,7 +697,7 @@ function Card({ props, children }) {
574
697
  {
575
698
  "data-mdocui-card": true,
576
699
  "data-variant": props.variant ?? "default",
577
- style: { border: "1px solid #e2e8f0", borderRadius: "8px", padding: "16px" },
700
+ style: { border: "1px solid #27272a", borderRadius: "8px", padding: "16px" },
578
701
  children: [
579
702
  title && /* @__PURE__ */ jsx5("div", { "data-mdocui-card-title": true, style: { fontWeight: 600, marginBottom: "8px" }, children: title }),
580
703
  /* @__PURE__ */ jsx5("div", { "data-mdocui-card-body": true, children })
@@ -587,7 +710,7 @@ function Divider(_) {
587
710
  "hr",
588
711
  {
589
712
  "data-mdocui-divider": true,
590
- style: { border: "none", borderTop: "1px solid #e2e8f0", margin: "8px 0" }
713
+ style: { border: "none", borderTop: "1px solid #27272a", margin: "8px 0" }
591
714
  }
592
715
  );
593
716
  }
@@ -600,16 +723,16 @@ function Accordion({ props, children }) {
600
723
  ] });
601
724
  }
602
725
  function Tabs({ props, children }) {
603
- const labels = props.labels ?? [];
726
+ const labels = Array.isArray(props.labels) ? props.labels : [];
604
727
  const initialActive = props.active ?? 0;
605
- const [active, setActive] = useState2(initialActive);
728
+ const [active, setActive] = useState3(initialActive);
606
729
  const childArray = React.Children.toArray(children);
607
730
  return /* @__PURE__ */ jsxs4("div", { "data-mdocui-tabs": true, children: [
608
731
  /* @__PURE__ */ jsx5(
609
732
  "div",
610
733
  {
611
734
  role: "tablist",
612
- style: { display: "flex", gap: "4px", borderBottom: "1px solid #e2e8f0" },
735
+ style: { display: "flex", gap: "4px", borderBottom: "1px solid #27272a" },
613
736
  children: labels.map((label, i) => /* @__PURE__ */ jsx5(
614
737
  "button",
615
738
  {