@db-vincent/components 0.0.0-stage → 0.1.1

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.
Files changed (86) hide show
  1. package/package.json +28 -4
  2. package/src/astro/Accordion.astro +37 -0
  3. package/src/astro/Alert.astro +73 -0
  4. package/src/astro/Avatar.astro +88 -0
  5. package/src/astro/AvatarGroup.astro +63 -0
  6. package/src/astro/Badge.astro +23 -0
  7. package/src/astro/Breadcrumbs.astro +45 -0
  8. package/src/astro/Button.astro +125 -0
  9. package/src/astro/Card.astro +63 -0
  10. package/src/astro/Checkbox.astro +61 -0
  11. package/src/astro/Chip.astro +135 -0
  12. package/src/astro/CodeBlock.astro +17 -0
  13. package/src/astro/Drawer.astro +30 -0
  14. package/src/astro/EmptyState.astro +45 -0
  15. package/src/astro/Example.astro +37 -0
  16. package/src/astro/Grid.astro +56 -0
  17. package/src/astro/GridItem.astro +25 -0
  18. package/src/astro/Icon.astro +52 -0
  19. package/src/astro/Menu.astro +151 -0
  20. package/src/astro/MenuItem.astro +57 -0
  21. package/src/astro/Modal.astro +124 -0
  22. package/src/astro/Navbar.astro +756 -0
  23. package/src/astro/PageHeader.astro +34 -0
  24. package/src/astro/Pagination.astro +212 -0
  25. package/src/astro/Popover.astro +51 -0
  26. package/src/astro/Progress.astro +71 -0
  27. package/src/astro/Radio.astro +58 -0
  28. package/src/astro/RadioGroup.astro +25 -0
  29. package/src/astro/Section.astro +25 -0
  30. package/src/astro/Select.astro +420 -0
  31. package/src/astro/Sidebar.astro +215 -0
  32. package/src/astro/Skeleton.astro +41 -0
  33. package/src/astro/Spinner.astro +20 -0
  34. package/src/astro/Stepper.astro +82 -0
  35. package/src/astro/Switch.astro +78 -0
  36. package/src/astro/Table.astro +268 -0
  37. package/src/astro/Tabs.astro +83 -0
  38. package/src/astro/TextField.astro +305 -0
  39. package/src/astro/ThemeToggle.astro +66 -0
  40. package/src/astro/Toast.astro +181 -0
  41. package/src/astro/Tooltip.astro +54 -0
  42. package/src/astro/TopBar.astro +29 -0
  43. package/src/data/icons.ts +120 -0
  44. package/src/scripts/avatar.ts +33 -0
  45. package/src/scripts/menu.ts +218 -0
  46. package/src/scripts/tabs.ts +127 -0
  47. package/src/scripts/toast.ts +565 -0
  48. package/src/scripts/tooltip.ts +127 -0
  49. package/src/styles/accordion.css +79 -0
  50. package/src/styles/alert.css +108 -0
  51. package/src/styles/avatar.css +131 -0
  52. package/src/styles/badge.css +48 -0
  53. package/src/styles/base.css +205 -0
  54. package/src/styles/breadcrumbs.css +54 -0
  55. package/src/styles/button.css +174 -0
  56. package/src/styles/card.css +112 -0
  57. package/src/styles/chip.css +106 -0
  58. package/src/styles/choice.css +143 -0
  59. package/src/styles/code.css +44 -0
  60. package/src/styles/empty.css +59 -0
  61. package/src/styles/example.css +57 -0
  62. package/src/styles/grid.css +64 -0
  63. package/src/styles/input.css +208 -0
  64. package/src/styles/menu.css +151 -0
  65. package/src/styles/modal.css +285 -0
  66. package/src/styles/motion.css +114 -0
  67. package/src/styles/nav.css +232 -0
  68. package/src/styles/navbar.css +658 -0
  69. package/src/styles/page-header.css +62 -0
  70. package/src/styles/pagination.css +81 -0
  71. package/src/styles/popover.css +134 -0
  72. package/src/styles/progress.css +95 -0
  73. package/src/styles/section.css +38 -0
  74. package/src/styles/select.css +246 -0
  75. package/src/styles/skeleton.css +66 -0
  76. package/src/styles/spinner.css +44 -0
  77. package/src/styles/sr-only.css +14 -0
  78. package/src/styles/stepper.css +169 -0
  79. package/src/styles/switch.css +143 -0
  80. package/src/styles/table.css +177 -0
  81. package/src/styles/tabs.css +120 -0
  82. package/src/styles/theme-toggle.css +31 -0
  83. package/src/styles/toast.css +225 -0
  84. package/src/styles/tooltip.css +63 -0
  85. package/src/styles/topbar.css +32 -0
  86. package/README.md +0 -3
@@ -0,0 +1,124 @@
1
+ ---
2
+ import Icon from "./Icon.astro";
3
+ import Button from "./Button.astro";
4
+ import "../styles/modal.css";
5
+
6
+ /**
7
+ * Modal dialog on native <dialog>. Native showModal() supplies the focus trap,
8
+ * Escape handling and inert background. The trigger is wired with ARIA; focus
9
+ * returns to the trigger on close automatically.
10
+ *
11
+ * `placement` anchors the dialog: "center" (default), or a drawer on the
12
+ * "bottom", "start" or "end" edge. Use the Drawer component for a drawer with
13
+ * its own defaults.
14
+ */
15
+ interface Props {
16
+ id: string;
17
+ title: string;
18
+ description?: string;
19
+ triggerLabel?: string;
20
+ triggerVariant?: "primary" | "secondary" | "ghost" | "danger";
21
+ size?: "sm" | "md" | "lg";
22
+ placement?: "center" | "start" | "end" | "bottom";
23
+ class?: string;
24
+ }
25
+
26
+ const {
27
+ id,
28
+ title,
29
+ description,
30
+ triggerLabel = "Open dialog",
31
+ triggerVariant = "secondary",
32
+ size = "md",
33
+ placement: placementProp,
34
+ class: className,
35
+ } = Astro.props;
36
+
37
+ const placement = placementProp ?? "center";
38
+ const edge = placement !== "center";
39
+
40
+ const titleId = `${id}-title`;
41
+ const descriptionId = description ? `${id}-description` : undefined;
42
+ ---
43
+
44
+ <Button
45
+ variant={triggerVariant}
46
+ type="button"
47
+ data-modal-open={id}
48
+ aria-haspopup="dialog"
49
+ >
50
+ {triggerLabel}
51
+ </Button>
52
+
53
+ <dialog
54
+ class:list={[
55
+ "ds-modal",
56
+ size !== "md" && `ds-modal--${size}`,
57
+ edge && ["ds-modal--drawer", `ds-modal--${placement}`],
58
+ className,
59
+ ]}
60
+ id={id}
61
+ aria-labelledby={titleId}
62
+ aria-describedby={descriptionId}
63
+ >
64
+ <div class="ds-modal__header">
65
+ <div>
66
+ <h2 class="ds-modal__title" id={titleId}>
67
+ {title}
68
+ </h2>
69
+ {description && (
70
+ <p class="ds-modal__description" id={descriptionId}>
71
+ {description}
72
+ </p>
73
+ )}
74
+ </div>
75
+ <form method="dialog">
76
+ <button class="ds-modal__close" type="submit" aria-label="Close dialog">
77
+ <Icon name="x" size={20} />
78
+ </button>
79
+ </form>
80
+ </div>
81
+ <div class="ds-modal__body">
82
+ <slot />
83
+ </div>
84
+ <slot name="footer" />
85
+ </dialog>
86
+
87
+ <script>
88
+ const bind = () => {
89
+ document
90
+ .querySelectorAll<HTMLElement>("[data-modal-open]")
91
+ .forEach((trigger) => {
92
+ if (trigger.dataset.bound) return;
93
+ trigger.dataset.bound = "true";
94
+ const id = trigger.dataset.modalOpen;
95
+ const dialog = id
96
+ ? (document.getElementById(id) as HTMLDialogElement | null)
97
+ : null;
98
+ if (!dialog) return;
99
+ trigger.addEventListener("click", () => {
100
+ dialog.showModal();
101
+ // Land on an explicit [autofocus], else the first footer action
102
+ // (Cancel in a destructive dialog), never on the close icon.
103
+ dialog
104
+ .querySelector<HTMLElement>(
105
+ "[autofocus], .ds-modal__footer button, .ds-modal__footer a",
106
+ )
107
+ ?.focus();
108
+ });
109
+ dialog.addEventListener("click", (event) => {
110
+ if (event.target !== dialog) return;
111
+ const rect = dialog.getBoundingClientRect();
112
+ const inside =
113
+ event.clientX >= rect.left &&
114
+ event.clientX <= rect.right &&
115
+ event.clientY >= rect.top &&
116
+ event.clientY <= rect.bottom;
117
+ if (!inside) dialog.close();
118
+ });
119
+ });
120
+ };
121
+
122
+ bind();
123
+ document.addEventListener("astro:page-load", bind);
124
+ </script>