@starwind-ui/core 1.15.1 → 1.15.2

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 (216) hide show
  1. package/dist/index.d.ts +28 -0
  2. package/dist/index.js +108 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/src/components/accordion/Accordion.astro +254 -0
  5. package/dist/src/components/accordion/AccordionContent.astro +33 -0
  6. package/dist/src/components/accordion/AccordionItem.astro +27 -0
  7. package/dist/src/components/accordion/AccordionTrigger.astro +32 -0
  8. package/dist/src/components/accordion/index.ts +15 -0
  9. package/dist/src/components/alert/Alert.astro +31 -0
  10. package/dist/src/components/alert/AlertDescription.astro +14 -0
  11. package/dist/src/components/alert/AlertTitle.astro +16 -0
  12. package/dist/src/components/alert/index.ts +13 -0
  13. package/dist/src/components/alert-dialog/AlertDialog.astro +275 -0
  14. package/dist/src/components/alert-dialog/AlertDialogAction.astro +44 -0
  15. package/dist/src/components/alert-dialog/AlertDialogCancel.astro +45 -0
  16. package/dist/src/components/alert-dialog/AlertDialogContent.astro +52 -0
  17. package/dist/src/components/alert-dialog/AlertDialogDescription.astro +18 -0
  18. package/dist/src/components/alert-dialog/AlertDialogFooter.astro +16 -0
  19. package/dist/src/components/alert-dialog/AlertDialogHeader.astro +14 -0
  20. package/dist/src/components/alert-dialog/AlertDialogTitle.astro +20 -0
  21. package/dist/src/components/alert-dialog/AlertDialogTrigger.astro +47 -0
  22. package/dist/src/components/alert-dialog/index.ts +46 -0
  23. package/dist/src/components/aspect-ratio/AspectRatio.astro +32 -0
  24. package/dist/src/components/aspect-ratio/index.ts +7 -0
  25. package/dist/src/components/avatar/Avatar.astro +29 -0
  26. package/dist/src/components/avatar/AvatarFallback.astro +18 -0
  27. package/dist/src/components/avatar/AvatarImage.astro +49 -0
  28. package/dist/src/components/avatar/index.ts +13 -0
  29. package/dist/src/components/badge/Badge.astro +55 -0
  30. package/dist/src/components/badge/index.ts +7 -0
  31. package/dist/src/components/breadcrumb/Breadcrumb.astro +11 -0
  32. package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +28 -0
  33. package/dist/src/components/breadcrumb/BreadcrumbItem.astro +14 -0
  34. package/dist/src/components/breadcrumb/BreadcrumbLink.astro +22 -0
  35. package/dist/src/components/breadcrumb/BreadcrumbList.astro +16 -0
  36. package/dist/src/components/breadcrumb/BreadcrumbPage.astro +21 -0
  37. package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +23 -0
  38. package/dist/src/components/breadcrumb/index.ts +37 -0
  39. package/dist/src/components/button/Button.astro +55 -0
  40. package/dist/src/components/button/index.ts +7 -0
  41. package/dist/src/components/button-group/ButtonGroup.astro +62 -0
  42. package/dist/src/components/button-group/ButtonGroupSeparator.astro +27 -0
  43. package/dist/src/components/button-group/ButtonGroupText.astro +19 -0
  44. package/dist/src/components/button-group/index.ts +17 -0
  45. package/dist/src/components/card/Card.astro +14 -0
  46. package/dist/src/components/card/CardContent.astro +14 -0
  47. package/dist/src/components/card/CardDescription.astro +14 -0
  48. package/dist/src/components/card/CardFooter.astro +14 -0
  49. package/dist/src/components/card/CardHeader.astro +14 -0
  50. package/dist/src/components/card/CardTitle.astro +14 -0
  51. package/dist/src/components/card/index.ts +26 -0
  52. package/dist/src/components/carousel/Carousel.astro +55 -0
  53. package/dist/src/components/carousel/CarouselContent.astro +26 -0
  54. package/dist/src/components/carousel/CarouselItem.astro +26 -0
  55. package/dist/src/components/carousel/CarouselNext.astro +37 -0
  56. package/dist/src/components/carousel/CarouselPrevious.astro +37 -0
  57. package/dist/src/components/carousel/carousel-script.ts +191 -0
  58. package/dist/src/components/carousel/index.ts +32 -0
  59. package/dist/src/components/checkbox/Checkbox.astro +128 -0
  60. package/dist/src/components/checkbox/index.ts +7 -0
  61. package/dist/src/components/collapsible/Collapsible.astro +161 -0
  62. package/dist/src/components/collapsible/CollapsibleContent.astro +22 -0
  63. package/dist/src/components/collapsible/CollapsibleTrigger.astro +44 -0
  64. package/dist/src/components/collapsible/index.ts +13 -0
  65. package/dist/src/components/dialog/Dialog.astro +389 -0
  66. package/dist/src/components/dialog/DialogClose.astro +35 -0
  67. package/dist/src/components/dialog/DialogContent.astro +78 -0
  68. package/dist/src/components/dialog/DialogDescription.astro +14 -0
  69. package/dist/src/components/dialog/DialogFooter.astro +14 -0
  70. package/dist/src/components/dialog/DialogHeader.astro +14 -0
  71. package/dist/src/components/dialog/DialogTitle.astro +22 -0
  72. package/dist/src/components/dialog/DialogTrigger.astro +47 -0
  73. package/dist/src/components/dialog/index.ts +45 -0
  74. package/dist/src/components/dropdown/Dropdown.astro +377 -0
  75. package/dist/src/components/dropdown/DropdownContent.astro +81 -0
  76. package/dist/src/components/dropdown/DropdownItem.astro +48 -0
  77. package/dist/src/components/dropdown/DropdownLabel.astro +29 -0
  78. package/dist/src/components/dropdown/DropdownSeparator.astro +21 -0
  79. package/dist/src/components/dropdown/DropdownTrigger.astro +52 -0
  80. package/dist/src/components/dropdown/index.ts +33 -0
  81. package/dist/src/components/dropzone/Dropzone.astro +236 -0
  82. package/dist/src/components/dropzone/DropzoneFilesList.astro +26 -0
  83. package/dist/src/components/dropzone/DropzoneLoadingIndicator.astro +10 -0
  84. package/dist/src/components/dropzone/DropzoneUploadIndicator.astro +10 -0
  85. package/dist/src/components/dropzone/index.ts +24 -0
  86. package/dist/src/components/image/Image.astro +24 -0
  87. package/dist/src/components/image/index.ts +9 -0
  88. package/dist/src/components/input/Input.astro +25 -0
  89. package/dist/src/components/input/index.ts +7 -0
  90. package/dist/src/components/input-otp/InputOtp.astro +352 -0
  91. package/dist/src/components/input-otp/InputOtpGroup.astro +16 -0
  92. package/dist/src/components/input-otp/InputOtpSeparator.astro +25 -0
  93. package/dist/src/components/input-otp/InputOtpSlot.astro +48 -0
  94. package/dist/src/components/input-otp/InputOtpTypes.ts +6 -0
  95. package/dist/src/components/input-otp/index.ts +33 -0
  96. package/dist/src/components/item/Item.astro +52 -0
  97. package/dist/src/components/item/ItemActions.astro +16 -0
  98. package/dist/src/components/item/ItemContent.astro +16 -0
  99. package/dist/src/components/item/ItemDescription.astro +19 -0
  100. package/dist/src/components/item/ItemFooter.astro +16 -0
  101. package/dist/src/components/item/ItemGroup.astro +16 -0
  102. package/dist/src/components/item/ItemHeader.astro +16 -0
  103. package/dist/src/components/item/ItemMedia.astro +40 -0
  104. package/dist/src/components/item/ItemSeparator.astro +21 -0
  105. package/dist/src/components/item/ItemTitle.astro +16 -0
  106. package/dist/src/components/item/index.ts +50 -0
  107. package/dist/src/components/kbd/Kbd.astro +21 -0
  108. package/dist/src/components/kbd/KbdGroup.astro +16 -0
  109. package/dist/src/components/kbd/index.ts +11 -0
  110. package/dist/src/components/label/Label.astro +22 -0
  111. package/dist/src/components/label/index.ts +7 -0
  112. package/dist/src/components/pagination/Pagination.astro +20 -0
  113. package/dist/src/components/pagination/PaginationContent.astro +16 -0
  114. package/dist/src/components/pagination/PaginationEllipsis.astro +35 -0
  115. package/dist/src/components/pagination/PaginationItem.astro +16 -0
  116. package/dist/src/components/pagination/PaginationLink.astro +24 -0
  117. package/dist/src/components/pagination/PaginationNext.astro +30 -0
  118. package/dist/src/components/pagination/PaginationPrevious.astro +30 -0
  119. package/dist/src/components/pagination/index.ts +38 -0
  120. package/dist/src/components/progress/Progress.astro +155 -0
  121. package/dist/src/components/progress/index.ts +10 -0
  122. package/dist/src/components/prose/Prose.astro +617 -0
  123. package/dist/src/components/prose/index.ts +9 -0
  124. package/dist/src/components/radio-group/RadioGroup.astro +162 -0
  125. package/dist/src/components/radio-group/RadioGroupItem.astro +129 -0
  126. package/dist/src/components/radio-group/RadioGroupTypes.ts +6 -0
  127. package/dist/src/components/radio-group/index.ts +23 -0
  128. package/dist/src/components/select/Select.astro +752 -0
  129. package/dist/src/components/select/SelectContent.astro +94 -0
  130. package/dist/src/components/select/SelectGroup.astro +9 -0
  131. package/dist/src/components/select/SelectItem.astro +51 -0
  132. package/dist/src/components/select/SelectLabel.astro +14 -0
  133. package/dist/src/components/select/SelectSearch.astro +49 -0
  134. package/dist/src/components/select/SelectSeparator.astro +12 -0
  135. package/dist/src/components/select/SelectTrigger.astro +54 -0
  136. package/dist/src/components/select/SelectTypes.ts +13 -0
  137. package/dist/src/components/select/SelectValue.astro +19 -0
  138. package/dist/src/components/select/index.ts +49 -0
  139. package/dist/src/components/separator/Separator.astro +36 -0
  140. package/dist/src/components/separator/index.ts +7 -0
  141. package/dist/src/components/sheet/Sheet.astro +13 -0
  142. package/dist/src/components/sheet/SheetClose.astro +13 -0
  143. package/dist/src/components/sheet/SheetContent.astro +92 -0
  144. package/dist/src/components/sheet/SheetDescription.astro +16 -0
  145. package/dist/src/components/sheet/SheetFooter.astro +16 -0
  146. package/dist/src/components/sheet/SheetHeader.astro +16 -0
  147. package/dist/src/components/sheet/SheetTitle.astro +16 -0
  148. package/dist/src/components/sheet/SheetTrigger.astro +13 -0
  149. package/dist/src/components/sheet/index.ts +41 -0
  150. package/dist/src/components/sidebar/Sidebar.astro +213 -0
  151. package/dist/src/components/sidebar/SidebarContent.astro +24 -0
  152. package/dist/src/components/sidebar/SidebarFooter.astro +21 -0
  153. package/dist/src/components/sidebar/SidebarGroup.astro +21 -0
  154. package/dist/src/components/sidebar/SidebarGroupContent.astro +21 -0
  155. package/dist/src/components/sidebar/SidebarGroupLabel.astro +52 -0
  156. package/dist/src/components/sidebar/SidebarHeader.astro +21 -0
  157. package/dist/src/components/sidebar/SidebarInput.astro +22 -0
  158. package/dist/src/components/sidebar/SidebarInset.astro +21 -0
  159. package/dist/src/components/sidebar/SidebarMenu.astro +21 -0
  160. package/dist/src/components/sidebar/SidebarMenuAction.astro +59 -0
  161. package/dist/src/components/sidebar/SidebarMenuBadge.astro +30 -0
  162. package/dist/src/components/sidebar/SidebarMenuButton.astro +129 -0
  163. package/dist/src/components/sidebar/SidebarMenuItem.astro +21 -0
  164. package/dist/src/components/sidebar/SidebarMenuSkeleton.astro +40 -0
  165. package/dist/src/components/sidebar/SidebarMenuSub.astro +24 -0
  166. package/dist/src/components/sidebar/SidebarMenuSubButton.astro +49 -0
  167. package/dist/src/components/sidebar/SidebarMenuSubItem.astro +16 -0
  168. package/dist/src/components/sidebar/SidebarProvider.astro +213 -0
  169. package/dist/src/components/sidebar/SidebarRail.astro +71 -0
  170. package/dist/src/components/sidebar/SidebarSeparator.astro +22 -0
  171. package/dist/src/components/sidebar/SidebarTrigger.astro +66 -0
  172. package/dist/src/components/sidebar/index.ts +103 -0
  173. package/dist/src/components/skeleton/Skeleton.astro +14 -0
  174. package/dist/src/components/skeleton/index.ts +9 -0
  175. package/dist/src/components/slider/Slider.astro +411 -0
  176. package/dist/src/components/slider/index.ts +9 -0
  177. package/dist/src/components/spinner/Spinner.astro +21 -0
  178. package/dist/src/components/spinner/index.ts +7 -0
  179. package/dist/src/components/switch/Switch.astro +192 -0
  180. package/dist/src/components/switch/SwitchTypes.ts +6 -0
  181. package/dist/src/components/switch/index.ts +12 -0
  182. package/dist/src/components/table/Table.astro +18 -0
  183. package/dist/src/components/table/TableBody.astro +16 -0
  184. package/dist/src/components/table/TableCaption.astro +16 -0
  185. package/dist/src/components/table/TableCell.astro +16 -0
  186. package/dist/src/components/table/TableFoot.astro +16 -0
  187. package/dist/src/components/table/TableHead.astro +16 -0
  188. package/dist/src/components/table/TableHeader.astro +16 -0
  189. package/dist/src/components/table/TableRow.astro +16 -0
  190. package/dist/src/components/table/index.ts +42 -0
  191. package/dist/src/components/tabs/Tabs.astro +271 -0
  192. package/dist/src/components/tabs/TabsContent.astro +28 -0
  193. package/dist/src/components/tabs/TabsList.astro +22 -0
  194. package/dist/src/components/tabs/TabsTrigger.astro +34 -0
  195. package/dist/src/components/tabs/index.ts +20 -0
  196. package/dist/src/components/textarea/Textarea.astro +29 -0
  197. package/dist/src/components/textarea/index.ts +9 -0
  198. package/dist/src/components/theme-toggle/ThemeToggle.astro +208 -0
  199. package/dist/src/components/theme-toggle/index.ts +7 -0
  200. package/dist/src/components/toast/ToastDescription.astro +21 -0
  201. package/dist/src/components/toast/ToastItem.astro +54 -0
  202. package/dist/src/components/toast/ToastTemplate.astro +25 -0
  203. package/dist/src/components/toast/ToastTitle.astro +57 -0
  204. package/dist/src/components/toast/Toaster.astro +982 -0
  205. package/dist/src/components/toast/index.ts +29 -0
  206. package/dist/src/components/toast/toast-manager.ts +216 -0
  207. package/dist/src/components/toggle/Toggle.astro +174 -0
  208. package/dist/src/components/toggle/ToggleTypes.ts +14 -0
  209. package/dist/src/components/toggle/index.ts +8 -0
  210. package/dist/src/components/tooltip/Tooltip.astro +282 -0
  211. package/dist/src/components/tooltip/TooltipContent.astro +89 -0
  212. package/dist/src/components/tooltip/TooltipTrigger.astro +10 -0
  213. package/dist/src/components/tooltip/index.ts +16 -0
  214. package/dist/src/components/video/Video.astro +120 -0
  215. package/dist/src/components/video/index.ts +9 -0
  216. package/package.json +1 -1
@@ -0,0 +1,275 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ type Props = HTMLAttributes<"div">;
5
+
6
+ const { class: className, ...rest } = Astro.props;
7
+ ---
8
+
9
+ <div class:list={["starwind-alert-dialog", className]} data-slot="alert-dialog" {...rest}>
10
+ <slot />
11
+ </div>
12
+
13
+ <script>
14
+ class AlertDialogHandler {
15
+ private triggers: HTMLButtonElement[] = [];
16
+ private dialog: HTMLDialogElement | null = null;
17
+ private closeButtons: HTMLButtonElement[] = [];
18
+ private actionButtons: HTMLButtonElement[] = [];
19
+ private backdrop: HTMLElement | null = null;
20
+ private dialogId: string;
21
+ /**
22
+ * The duration of the animation in milliseconds. This is used to calculate the
23
+ * duration of close animation before hiding the dialog and backdrop
24
+ */
25
+ private animationDuration: number;
26
+
27
+ constructor(dialogWrapper: HTMLElement, dialogNumber: number) {
28
+ this.dialog = dialogWrapper.querySelector("dialog");
29
+ this.backdrop = dialogWrapper.querySelector(".starwind-alert-dialog-backdrop");
30
+ if (!this.dialog || !this.backdrop) {
31
+ throw new Error("AlertDialog: dialog or backdrop not found");
32
+ }
33
+
34
+ // if no ID was provided for the wrapper, generate one
35
+ if (dialogWrapper.id) {
36
+ this.dialogId = dialogWrapper.id;
37
+ } else {
38
+ this.dialogId = `starwind-alert-dialog${dialogNumber}`;
39
+ dialogWrapper.id = this.dialogId;
40
+ }
41
+
42
+ // animationDuration is set with inline styles through passed prop to DialogContent
43
+ const animationDurationString = this.dialog.style.animationDuration;
44
+ if (animationDurationString.endsWith("ms")) {
45
+ this.animationDuration = parseFloat(animationDurationString);
46
+ } else if (animationDurationString.endsWith("s")) {
47
+ // using something like @playform/compress might optimize to use "s" instead of "ms"
48
+ this.animationDuration = parseFloat(animationDurationString) * 1000;
49
+ } else {
50
+ this.animationDuration = 200;
51
+ }
52
+
53
+ // Find internal triggers and handle them
54
+ const internalTriggers = dialogWrapper.querySelectorAll(".starwind-alert-dialog-trigger");
55
+ internalTriggers.forEach((triggerElement) => {
56
+ const tempTrigger = triggerElement as HTMLElement;
57
+ let trigger: HTMLButtonElement;
58
+
59
+ if (tempTrigger?.hasAttribute("data-as-child")) {
60
+ trigger = tempTrigger.firstElementChild as HTMLButtonElement;
61
+ } else {
62
+ trigger = tempTrigger as HTMLButtonElement;
63
+ }
64
+
65
+ if (trigger) {
66
+ this.triggers.push(trigger);
67
+ }
68
+ });
69
+
70
+ // Find external triggers that target this dialog
71
+ this.findExternalTriggers();
72
+
73
+ // if closeButtons are set with asChild, swap the wrapper with its first child
74
+ const tempCloseButtons = dialogWrapper.querySelectorAll(
75
+ ".starwind-alert-dialog-close",
76
+ ) as NodeListOf<HTMLElement>;
77
+ tempCloseButtons.forEach((button: HTMLElement) => {
78
+ if (button.hasAttribute("data-as-child")) {
79
+ const childElement = button.firstElementChild;
80
+ if (childElement) {
81
+ childElement.classList.add("starwind-alert-dialog-close");
82
+ button.parentNode?.replaceChild(childElement, button);
83
+ }
84
+ }
85
+ return button;
86
+ });
87
+
88
+ // Convert NodeList to Array for consistency with triggers
89
+ this.closeButtons = Array.from(
90
+ dialogWrapper.querySelectorAll(".starwind-alert-dialog-close"),
91
+ ) as HTMLButtonElement[];
92
+
93
+ // if actionButtons are set with asChild, swap the wrapper with its first child
94
+ const tempActionButtons = dialogWrapper.querySelectorAll(
95
+ ".starwind-alert-dialog-action",
96
+ ) as NodeListOf<HTMLElement>;
97
+ tempActionButtons.forEach((button: HTMLElement) => {
98
+ if (button.hasAttribute("data-as-child")) {
99
+ const childElement = button.firstElementChild;
100
+ if (childElement) {
101
+ childElement.classList.add("starwind-alert-dialog-action");
102
+ button.parentNode?.replaceChild(childElement, button);
103
+ }
104
+ }
105
+ return button;
106
+ });
107
+
108
+ // Convert NodeList to Array for consistency with triggers
109
+ this.actionButtons = Array.from(
110
+ dialogWrapper.querySelectorAll(".starwind-alert-dialog-action"),
111
+ ) as HTMLButtonElement[];
112
+
113
+ // if essential elements are not there, exit
114
+ if (!this.dialog || !this.backdrop) return;
115
+
116
+ this.setupAccessibility(dialogNumber);
117
+ this.setupEvents();
118
+ }
119
+
120
+ private setupAccessibility(dialogNumber: number): void {
121
+ // get the first heading element in the dialog
122
+ const firstHeading = this.dialog?.querySelector("h1, h2, h3, h4, h5, h6");
123
+ if (firstHeading) {
124
+ // create a unique ID for the heading
125
+ firstHeading.id = `starwind-alert-dialog${dialogNumber}-heading`;
126
+ // set the aria-labelledby attribute to the first heading element
127
+ this.dialog?.setAttribute("aria-labelledby", firstHeading.id);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Find all external triggers that target this dialog
133
+ */
134
+ private findExternalTriggers(): void {
135
+ const externalTriggers = document.querySelectorAll(
136
+ `.starwind-alert-dialog-trigger[data-dialog-for="${this.dialogId}"]`,
137
+ );
138
+
139
+ externalTriggers.forEach((triggerElement) => {
140
+ // Skip if this is an internal trigger we already processed
141
+ const dialogWrapper = triggerElement.closest(".starwind-alert-dialog");
142
+ if (dialogWrapper && dialogWrapper.id === this.dialogId) {
143
+ return;
144
+ }
145
+
146
+ let trigger: HTMLButtonElement;
147
+ if (triggerElement.hasAttribute("data-as-child")) {
148
+ trigger = triggerElement.firstElementChild as HTMLButtonElement;
149
+ } else {
150
+ trigger = triggerElement as HTMLButtonElement;
151
+ }
152
+
153
+ if (trigger && !this.triggers.includes(trigger)) {
154
+ this.triggers.push(trigger);
155
+ }
156
+ });
157
+ }
158
+
159
+ private setupEvents(): void {
160
+ if (!this.dialog) return;
161
+ // Add click listeners to all triggers
162
+ this.triggers.forEach((trigger) => {
163
+ trigger.addEventListener("click", () => {
164
+ this.open();
165
+ });
166
+ });
167
+
168
+ // Add click handlers to all close buttons
169
+ this.closeButtons.forEach((button) => {
170
+ button.addEventListener("click", () => {
171
+ // Only close if this is the topmost dialog
172
+ const openDialogs = document.querySelectorAll("dialog[open]");
173
+ if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
174
+ this.close();
175
+ }
176
+ });
177
+ });
178
+
179
+ // Add click handlers to all action buttons
180
+ this.actionButtons.forEach((button) => {
181
+ button.addEventListener("click", () => {
182
+ // Only close if this is the topmost dialog
183
+ const openDialogs = document.querySelectorAll("dialog[open]");
184
+ if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
185
+ this.close();
186
+ }
187
+ });
188
+ });
189
+
190
+ // Handle escape key
191
+ this.dialog.addEventListener("keydown", (e) => {
192
+ if (e.key === "Escape") {
193
+ // prevent default dialog closing behavior so we can add closing animation
194
+ e.preventDefault();
195
+ // Only close if this is the topmost dialog
196
+ const openDialogs = document.querySelectorAll("dialog[open]");
197
+ if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
198
+ this.close();
199
+ }
200
+ }
201
+ });
202
+
203
+ // Intercept form submissions to handle dialog close
204
+ const forms = this.dialog.querySelectorAll("form");
205
+ forms.forEach((form) => {
206
+ form.addEventListener("submit", (e) => {
207
+ /**
208
+ * Default form.method = "dialog" submissions cause the dialog to close
209
+ * Default form.method = "post" submissions do not close the dialog
210
+ * Here we intercept the form submission and manage the dialog closing if method = "dialog"
211
+ * so we can add closing animation
212
+ * Normal form event listeners for "submit" will still get the form data
213
+ */
214
+ if (form.method === "dialog") {
215
+ e.preventDefault();
216
+ // Only close if this is the topmost dialog
217
+ const openDialogs = document.querySelectorAll("dialog[open]");
218
+ if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
219
+ this.close();
220
+ }
221
+ }
222
+ });
223
+ });
224
+ }
225
+
226
+ private open(): void {
227
+ if (!this.dialog || !this.backdrop) return;
228
+ this.dialog.showModal();
229
+ document.body.classList.add("overflow-hidden");
230
+ this.backdrop.classList.remove("hidden");
231
+ this.backdrop.dataset.state = "open";
232
+ this.dialog.dataset.state = "open";
233
+ }
234
+
235
+ private close(): void {
236
+ if (!this.dialog || !this.backdrop) return;
237
+ this.dialog.dataset.state = "closed";
238
+ this.backdrop.dataset.state = "closed";
239
+
240
+ // Wait for animation to finish before hiding backdrop
241
+ setTimeout(() => {
242
+ this.backdrop?.classList.add("hidden");
243
+ this.dialog?.close();
244
+ const stillOpen = document.querySelectorAll("dialog[open]").length;
245
+ if (stillOpen === 0) {
246
+ document.body.classList.remove("overflow-hidden");
247
+ }
248
+ }, this.animationDuration);
249
+ }
250
+ }
251
+
252
+ // Store instances in a WeakMap to avoid memory leaks
253
+ const alertDialogInstances = new WeakMap<HTMLElement, AlertDialogHandler>();
254
+ let alertDialogCounter = 0;
255
+
256
+ // Initialize all dialogs
257
+ const setupAlertDialogs = () => {
258
+ document.querySelectorAll(".starwind-alert-dialog").forEach((dialogWrapper) => {
259
+ const wrapper = dialogWrapper as HTMLElement;
260
+ if (!alertDialogInstances.has(wrapper)) {
261
+ alertDialogInstances.set(wrapper, new AlertDialogHandler(wrapper, alertDialogCounter++));
262
+ }
263
+ });
264
+ };
265
+
266
+ setupAlertDialogs();
267
+ document.addEventListener("astro:after-swap", setupAlertDialogs);
268
+ document.addEventListener("starwind:init", setupAlertDialogs);
269
+ </script>
270
+
271
+ <style>
272
+ .overflow-hidden {
273
+ overflow: hidden;
274
+ }
275
+ </style>
@@ -0,0 +1,44 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ import { ButtonVariants } from "@/components/starwind/button";
5
+
6
+ type Props = HTMLAttributes<"button"> & {
7
+ /**
8
+ * When true, the component will render its child element instead of a button
9
+ */
10
+ asChild?: boolean;
11
+ };
12
+
13
+ const { class: className, asChild = false, ...rest } = Astro.props;
14
+
15
+ // Get the first child element if asChild is true
16
+ let hasChildren = false;
17
+ if (Astro.slots.has("default")) {
18
+ hasChildren = true;
19
+ }
20
+ ---
21
+
22
+ {
23
+ asChild && hasChildren ? (
24
+ <div
25
+ class:list={["starwind-alert-dialog-action", className]}
26
+ data-slot="alert-dialog-action"
27
+ data-as-child
28
+ >
29
+ <slot />
30
+ </div>
31
+ ) : (
32
+ <button
33
+ type="button"
34
+ class={ButtonVariants.button({
35
+ variant: "default",
36
+ class: `starwind-alert-dialog-action ${className || ""}`,
37
+ })}
38
+ data-slot="alert-dialog-action"
39
+ {...rest}
40
+ >
41
+ <slot />
42
+ </button>
43
+ )
44
+ }
@@ -0,0 +1,45 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ import { ButtonVariants } from "@/components/starwind/button";
6
+
7
+ type Props = HTMLAttributes<"button"> & {
8
+ /**
9
+ * When true, the component will render its child element instead of a button
10
+ */
11
+ asChild?: boolean;
12
+ };
13
+
14
+ const { class: className, asChild = false, ...rest } = Astro.props;
15
+
16
+ // Get the first child element if asChild is true
17
+ let hasChildren = false;
18
+ if (Astro.slots.has("default")) {
19
+ hasChildren = true;
20
+ }
21
+ ---
22
+
23
+ {
24
+ asChild && hasChildren ? (
25
+ <div
26
+ class:list={["starwind-alert-dialog-close", className]}
27
+ data-slot="alert-dialog-cancel"
28
+ data-as-child
29
+ >
30
+ <slot />
31
+ </div>
32
+ ) : (
33
+ <button
34
+ type="button"
35
+ class={ButtonVariants.button({
36
+ variant: "outline",
37
+ class: `starwind-alert-dialog-close ${className || ""}`,
38
+ })}
39
+ data-slot="alert-dialog-cancel"
40
+ {...rest}
41
+ >
42
+ <slot />
43
+ </button>
44
+ )
45
+ }
@@ -0,0 +1,52 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props = HTMLAttributes<"dialog"> & {
6
+ /**
7
+ * Open and close animation duration in milliseconds
8
+ */
9
+ animationDuration?: number;
10
+ };
11
+
12
+ export const alertDialogBackdrop = tv({
13
+ base: [
14
+ "starwind-alert-dialog-backdrop fixed inset-0 z-50 hidden bg-black/50",
15
+ "data-[state=open]:animate-in fade-in",
16
+ "data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards fade-out",
17
+ ],
18
+ });
19
+
20
+ export const alertDialogContent = tv({
21
+ base: [
22
+ "bg-background space-y-4 rounded-lg border p-6 shadow-lg sm:max-w-lg",
23
+ "fixed top-[50%] left-[50%] z-50 w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%]",
24
+ "data-[state=open]:animate-in fade-in zoom-in-95 will-change-transform",
25
+ "data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards fade-out zoom-out-95",
26
+ ],
27
+ });
28
+
29
+ const { class: className, animationDuration = 200, ...rest } = Astro.props;
30
+ ---
31
+
32
+ <!-- dialog overlay -->
33
+ <slot name="backdrop">
34
+ <div
35
+ class={alertDialogBackdrop()}
36
+ data-state="closed"
37
+ data-slot="alert-dialog-backdrop"
38
+ style={{ animationDuration: `${animationDuration}ms` }}
39
+ >
40
+ </div>
41
+ </slot>
42
+
43
+ <dialog
44
+ class={alertDialogContent({ class: className })}
45
+ data-state="closed"
46
+ data-slot="alert-dialog-content"
47
+ role="alertdialog"
48
+ {...rest}
49
+ style={{ animationDuration: `${animationDuration}ms` }}
50
+ >
51
+ <slot />
52
+ </dialog>
@@ -0,0 +1,18 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props = HTMLAttributes<"p">;
6
+
7
+ export const alertDialogDescription = tv({ base: "text-muted-foreground" });
8
+
9
+ const { class: className, ...rest } = Astro.props;
10
+ ---
11
+
12
+ <p
13
+ class={alertDialogDescription({ class: className })}
14
+ data-slot="alert-dialog-description"
15
+ {...rest}
16
+ >
17
+ <slot />
18
+ </p>
@@ -0,0 +1,16 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props = HTMLAttributes<"div">;
6
+
7
+ export const alertDialogFooter = tv({
8
+ base: "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
9
+ });
10
+
11
+ const { class: className, ...rest } = Astro.props;
12
+ ---
13
+
14
+ <div class={alertDialogFooter({ class: className })} data-slot="alert-dialog-footer" {...rest}>
15
+ <slot />
16
+ </div>
@@ -0,0 +1,14 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props = HTMLAttributes<"div">;
6
+
7
+ export const alertDialogHeader = tv({ base: "flex flex-col gap-2 text-center sm:text-left" });
8
+
9
+ const { class: className, ...rest } = Astro.props;
10
+ ---
11
+
12
+ <div class={alertDialogHeader({ class: className })} data-slot="alert-dialog-header" {...rest}>
13
+ <slot />
14
+ </div>
@@ -0,0 +1,20 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props = Omit<HTMLAttributes<"h2">, "id"> & {
6
+ /**
7
+ * The content to be rendered inside the dialog title
8
+ */
9
+
10
+ children: any;
11
+ };
12
+
13
+ export const alertDialogTitle = tv({ base: "font-heading text-xl font-semibold" });
14
+
15
+ const { class: className, ...rest } = Astro.props;
16
+ ---
17
+
18
+ <h2 class={alertDialogTitle({ class: className })} data-slot="alert-dialog-title" {...rest}>
19
+ <slot />
20
+ </h2>
@@ -0,0 +1,47 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ type Props = HTMLAttributes<"button"> & {
5
+ /**
6
+ * When true, the component will render its child element with a simple wrapper instead of a button component
7
+ */
8
+ asChild?: boolean;
9
+ /**
10
+ * Optional ID of the dialog to trigger. If not provided and the trigger is inside a Dialog component,
11
+ * it will automatically target that dialog. Required when used outside a Dialog component.
12
+ */
13
+ for?: string;
14
+ };
15
+
16
+ const { class: className, asChild = false, for: dialogFor, ...rest } = Astro.props;
17
+
18
+ // Get the first child element if asChild is true
19
+ let hasChildren = false;
20
+ if (Astro.slots.has("default")) {
21
+ hasChildren = true;
22
+ }
23
+ ---
24
+
25
+ {
26
+ asChild && hasChildren ? (
27
+ <div
28
+ class:list={["starwind-alert-dialog-trigger", className]}
29
+ data-slot="alert-dialog-trigger"
30
+ data-as-child
31
+ data-dialog-for={dialogFor}
32
+ >
33
+ <slot />
34
+ </div>
35
+ ) : (
36
+ <button
37
+ type="button"
38
+ aria-haspopup="dialog"
39
+ class:list={["starwind-alert-dialog-trigger", className]}
40
+ data-slot="alert-dialog-trigger"
41
+ data-dialog-for={dialogFor}
42
+ {...rest}
43
+ >
44
+ <slot />
45
+ </button>
46
+ )
47
+ }
@@ -0,0 +1,46 @@
1
+ import AlertDialog from "./AlertDialog.astro";
2
+ import AlertDialogAction from "./AlertDialogAction.astro";
3
+ import AlertDialogCancel from "./AlertDialogCancel.astro";
4
+ import AlertDialogContent, {
5
+ alertDialogBackdrop,
6
+ alertDialogContent,
7
+ } from "./AlertDialogContent.astro";
8
+ import AlertDialogDescription, { alertDialogDescription } from "./AlertDialogDescription.astro";
9
+ import AlertDialogFooter, { alertDialogFooter } from "./AlertDialogFooter.astro";
10
+ import AlertDialogHeader, { alertDialogHeader } from "./AlertDialogHeader.astro";
11
+ import AlertDialogTitle, { alertDialogTitle } from "./AlertDialogTitle.astro";
12
+ import AlertDialogTrigger from "./AlertDialogTrigger.astro";
13
+
14
+ const AlertDialogVariants = {
15
+ alertDialogBackdrop,
16
+ alertDialogContent,
17
+ alertDialogDescription,
18
+ alertDialogFooter,
19
+ alertDialogHeader,
20
+ alertDialogTitle,
21
+ };
22
+
23
+ export {
24
+ AlertDialog,
25
+ AlertDialogAction,
26
+ AlertDialogCancel,
27
+ AlertDialogContent,
28
+ AlertDialogDescription,
29
+ AlertDialogFooter,
30
+ AlertDialogHeader,
31
+ AlertDialogTitle,
32
+ AlertDialogTrigger,
33
+ AlertDialogVariants,
34
+ };
35
+
36
+ export default {
37
+ Root: AlertDialog,
38
+ Trigger: AlertDialogTrigger,
39
+ Content: AlertDialogContent,
40
+ Header: AlertDialogHeader,
41
+ Footer: AlertDialogFooter,
42
+ Title: AlertDialogTitle,
43
+ Description: AlertDialogDescription,
44
+ Action: AlertDialogAction,
45
+ Cancel: AlertDialogCancel,
46
+ };
@@ -0,0 +1,32 @@
1
+ ---
2
+ import type { HTMLTag, Polymorphic } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & {
6
+ /**
7
+ * The aspect ratio of the container (e.g., 16/9, 4/3, 1)
8
+ * @default 1
9
+ */
10
+ ratio?: number;
11
+ };
12
+
13
+ export const aspectRatioWrapper = tv({
14
+ base: "relative w-full",
15
+ });
16
+
17
+ export const aspectRatio = tv({
18
+ base: "absolute inset-0",
19
+ });
20
+
21
+ const { ratio = 1, class: className, as: Tag = "div", ...rest } = Astro.props;
22
+ ---
23
+
24
+ <div
25
+ class={aspectRatioWrapper()}
26
+ style={`padding-bottom: ${100 / ratio}%`}
27
+ data-slot="aspect-ratio-wrapper"
28
+ >
29
+ <Tag class={aspectRatio({ class: className })} data-slot="aspect-ratio" {...rest}>
30
+ <slot />
31
+ </Tag>
32
+ </div>
@@ -0,0 +1,7 @@
1
+ import AspectRatio, { aspectRatio, aspectRatioWrapper } from "./AspectRatio.astro";
2
+
3
+ const AspectRatioVariants = { aspectRatio, aspectRatioWrapper };
4
+
5
+ export { AspectRatio, AspectRatioVariants };
6
+
7
+ export default AspectRatio;
@@ -0,0 +1,29 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv, type VariantProps } from "tailwind-variants";
4
+
5
+ interface Props extends HTMLAttributes<"div">, VariantProps<typeof avatar> {}
6
+
7
+ export const avatar = tv({
8
+ base: "text-foreground bg-muted relative overflow-hidden rounded-full border-2",
9
+ variants: {
10
+ variant: {
11
+ default: "border-border",
12
+ primary: "border-primary",
13
+ secondary: "border-secondary",
14
+ info: "border-info",
15
+ success: "border-success",
16
+ warning: "border-warning",
17
+ error: "border-error",
18
+ },
19
+ size: { sm: "h-8 w-8 text-xs", md: "h-10 w-10 text-sm", lg: "h-12 w-12 text-base" },
20
+ },
21
+ defaultVariants: { variant: "default", size: "md" },
22
+ });
23
+
24
+ const { variant, size, class: className, ...rest } = Astro.props;
25
+ ---
26
+
27
+ <figure class={avatar({ variant, size, class: className })} data-slot="avatar" {...rest}>
28
+ <slot />
29
+ </figure>
@@ -0,0 +1,18 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { tv } from "tailwind-variants";
4
+
5
+ export const avatarFallback = tv({
6
+ base: "absolute inset-0.5 flex items-center justify-center rounded-full font-medium",
7
+ });
8
+
9
+ interface Props extends HTMLAttributes<"div"> {
10
+ class?: string;
11
+ }
12
+
13
+ const { class: className, ...rest } = Astro.props;
14
+ ---
15
+
16
+ <div class={avatarFallback({ class: className })} data-slot="avatar-fallback" {...rest}>
17
+ <slot />
18
+ </div>