@starwind-ui/core 1.14.0 → 1.15.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.
- package/package.json +1 -1
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -85
- package/dist/index.js.map +0 -1
- package/dist/src/components/accordion/Accordion.astro +0 -254
- package/dist/src/components/accordion/AccordionContent.astro +0 -33
- package/dist/src/components/accordion/AccordionItem.astro +0 -27
- package/dist/src/components/accordion/AccordionTrigger.astro +0 -32
- package/dist/src/components/accordion/index.ts +0 -15
- package/dist/src/components/alert/Alert.astro +0 -31
- package/dist/src/components/alert/AlertDescription.astro +0 -14
- package/dist/src/components/alert/AlertTitle.astro +0 -16
- package/dist/src/components/alert/index.ts +0 -13
- package/dist/src/components/alert-dialog/AlertDialog.astro +0 -275
- package/dist/src/components/alert-dialog/AlertDialogAction.astro +0 -44
- package/dist/src/components/alert-dialog/AlertDialogCancel.astro +0 -45
- package/dist/src/components/alert-dialog/AlertDialogContent.astro +0 -52
- package/dist/src/components/alert-dialog/AlertDialogDescription.astro +0 -18
- package/dist/src/components/alert-dialog/AlertDialogFooter.astro +0 -16
- package/dist/src/components/alert-dialog/AlertDialogHeader.astro +0 -14
- package/dist/src/components/alert-dialog/AlertDialogTitle.astro +0 -20
- package/dist/src/components/alert-dialog/AlertDialogTrigger.astro +0 -47
- package/dist/src/components/alert-dialog/index.ts +0 -46
- package/dist/src/components/aspect-ratio/AspectRatio.astro +0 -32
- package/dist/src/components/aspect-ratio/index.ts +0 -7
- package/dist/src/components/avatar/Avatar.astro +0 -29
- package/dist/src/components/avatar/AvatarFallback.astro +0 -18
- package/dist/src/components/avatar/AvatarImage.astro +0 -49
- package/dist/src/components/avatar/index.ts +0 -13
- package/dist/src/components/badge/Badge.astro +0 -49
- package/dist/src/components/badge/index.ts +0 -7
- package/dist/src/components/breadcrumb/Breadcrumb.astro +0 -11
- package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +0 -28
- package/dist/src/components/breadcrumb/BreadcrumbItem.astro +0 -14
- package/dist/src/components/breadcrumb/BreadcrumbLink.astro +0 -22
- package/dist/src/components/breadcrumb/BreadcrumbList.astro +0 -16
- package/dist/src/components/breadcrumb/BreadcrumbPage.astro +0 -21
- package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +0 -23
- package/dist/src/components/breadcrumb/index.ts +0 -37
- package/dist/src/components/button/Button.astro +0 -54
- package/dist/src/components/button/index.ts +0 -7
- package/dist/src/components/button-group/ButtonGroup.astro +0 -62
- package/dist/src/components/button-group/ButtonGroupSeparator.astro +0 -27
- package/dist/src/components/button-group/ButtonGroupText.astro +0 -19
- package/dist/src/components/button-group/index.ts +0 -17
- package/dist/src/components/card/Card.astro +0 -14
- package/dist/src/components/card/CardContent.astro +0 -14
- package/dist/src/components/card/CardDescription.astro +0 -14
- package/dist/src/components/card/CardFooter.astro +0 -14
- package/dist/src/components/card/CardHeader.astro +0 -14
- package/dist/src/components/card/CardTitle.astro +0 -14
- package/dist/src/components/card/index.ts +0 -26
- package/dist/src/components/carousel/Carousel.astro +0 -55
- package/dist/src/components/carousel/CarouselContent.astro +0 -26
- package/dist/src/components/carousel/CarouselItem.astro +0 -26
- package/dist/src/components/carousel/CarouselNext.astro +0 -37
- package/dist/src/components/carousel/CarouselPrevious.astro +0 -37
- package/dist/src/components/carousel/carousel-script.ts +0 -191
- package/dist/src/components/carousel/index.ts +0 -32
- package/dist/src/components/checkbox/Checkbox.astro +0 -128
- package/dist/src/components/checkbox/index.ts +0 -7
- package/dist/src/components/dialog/Dialog.astro +0 -355
- package/dist/src/components/dialog/DialogClose.astro +0 -35
- package/dist/src/components/dialog/DialogContent.astro +0 -78
- package/dist/src/components/dialog/DialogDescription.astro +0 -14
- package/dist/src/components/dialog/DialogFooter.astro +0 -14
- package/dist/src/components/dialog/DialogHeader.astro +0 -14
- package/dist/src/components/dialog/DialogTitle.astro +0 -22
- package/dist/src/components/dialog/DialogTrigger.astro +0 -47
- package/dist/src/components/dialog/index.ts +0 -45
- package/dist/src/components/dropdown/Dropdown.astro +0 -377
- package/dist/src/components/dropdown/DropdownContent.astro +0 -81
- package/dist/src/components/dropdown/DropdownItem.astro +0 -48
- package/dist/src/components/dropdown/DropdownLabel.astro +0 -29
- package/dist/src/components/dropdown/DropdownSeparator.astro +0 -21
- package/dist/src/components/dropdown/DropdownTrigger.astro +0 -52
- package/dist/src/components/dropdown/index.ts +0 -33
- package/dist/src/components/dropzone/Dropzone.astro +0 -236
- package/dist/src/components/dropzone/DropzoneFilesList.astro +0 -26
- package/dist/src/components/dropzone/DropzoneLoadingIndicator.astro +0 -10
- package/dist/src/components/dropzone/DropzoneUploadIndicator.astro +0 -10
- package/dist/src/components/dropzone/index.ts +0 -24
- package/dist/src/components/image/Image.astro +0 -24
- package/dist/src/components/image/index.ts +0 -9
- package/dist/src/components/input/Input.astro +0 -25
- package/dist/src/components/input/index.ts +0 -7
- package/dist/src/components/item/Item.astro +0 -52
- package/dist/src/components/item/ItemActions.astro +0 -16
- package/dist/src/components/item/ItemContent.astro +0 -16
- package/dist/src/components/item/ItemDescription.astro +0 -19
- package/dist/src/components/item/ItemFooter.astro +0 -16
- package/dist/src/components/item/ItemGroup.astro +0 -16
- package/dist/src/components/item/ItemHeader.astro +0 -16
- package/dist/src/components/item/ItemMedia.astro +0 -40
- package/dist/src/components/item/ItemSeparator.astro +0 -21
- package/dist/src/components/item/ItemTitle.astro +0 -16
- package/dist/src/components/item/index.ts +0 -50
- package/dist/src/components/kbd/Kbd.astro +0 -21
- package/dist/src/components/kbd/KbdGroup.astro +0 -16
- package/dist/src/components/kbd/index.ts +0 -11
- package/dist/src/components/label/Label.astro +0 -22
- package/dist/src/components/label/index.ts +0 -7
- package/dist/src/components/pagination/Pagination.astro +0 -20
- package/dist/src/components/pagination/PaginationContent.astro +0 -16
- package/dist/src/components/pagination/PaginationEllipsis.astro +0 -35
- package/dist/src/components/pagination/PaginationItem.astro +0 -16
- package/dist/src/components/pagination/PaginationLink.astro +0 -24
- package/dist/src/components/pagination/PaginationNext.astro +0 -30
- package/dist/src/components/pagination/PaginationPrevious.astro +0 -30
- package/dist/src/components/pagination/index.ts +0 -38
- package/dist/src/components/progress/Progress.astro +0 -155
- package/dist/src/components/progress/index.ts +0 -10
- package/dist/src/components/radio-group/RadioGroup.astro +0 -162
- package/dist/src/components/radio-group/RadioGroupItem.astro +0 -129
- package/dist/src/components/radio-group/RadioGroupTypes.ts +0 -6
- package/dist/src/components/radio-group/index.ts +0 -23
- package/dist/src/components/select/Select.astro +0 -751
- package/dist/src/components/select/SelectContent.astro +0 -94
- package/dist/src/components/select/SelectGroup.astro +0 -9
- package/dist/src/components/select/SelectItem.astro +0 -51
- package/dist/src/components/select/SelectLabel.astro +0 -14
- package/dist/src/components/select/SelectSearch.astro +0 -49
- package/dist/src/components/select/SelectSeparator.astro +0 -12
- package/dist/src/components/select/SelectTrigger.astro +0 -54
- package/dist/src/components/select/SelectTypes.ts +0 -13
- package/dist/src/components/select/SelectValue.astro +0 -19
- package/dist/src/components/select/index.ts +0 -49
- package/dist/src/components/separator/Separator.astro +0 -36
- package/dist/src/components/separator/index.ts +0 -7
- package/dist/src/components/sheet/Sheet.astro +0 -13
- package/dist/src/components/sheet/SheetClose.astro +0 -13
- package/dist/src/components/sheet/SheetContent.astro +0 -92
- package/dist/src/components/sheet/SheetDescription.astro +0 -16
- package/dist/src/components/sheet/SheetFooter.astro +0 -16
- package/dist/src/components/sheet/SheetHeader.astro +0 -16
- package/dist/src/components/sheet/SheetTitle.astro +0 -16
- package/dist/src/components/sheet/SheetTrigger.astro +0 -13
- package/dist/src/components/sheet/index.ts +0 -41
- package/dist/src/components/skeleton/Skeleton.astro +0 -14
- package/dist/src/components/skeleton/index.ts +0 -9
- package/dist/src/components/slider/Slider.astro +0 -411
- package/dist/src/components/slider/index.ts +0 -9
- package/dist/src/components/spinner/Spinner.astro +0 -21
- package/dist/src/components/spinner/index.ts +0 -7
- package/dist/src/components/switch/Switch.astro +0 -192
- package/dist/src/components/switch/SwitchTypes.ts +0 -6
- package/dist/src/components/switch/index.ts +0 -12
- package/dist/src/components/table/Table.astro +0 -18
- package/dist/src/components/table/TableBody.astro +0 -16
- package/dist/src/components/table/TableCaption.astro +0 -16
- package/dist/src/components/table/TableCell.astro +0 -16
- package/dist/src/components/table/TableFoot.astro +0 -16
- package/dist/src/components/table/TableHead.astro +0 -16
- package/dist/src/components/table/TableHeader.astro +0 -16
- package/dist/src/components/table/TableRow.astro +0 -16
- package/dist/src/components/table/index.ts +0 -42
- package/dist/src/components/tabs/Tabs.astro +0 -271
- package/dist/src/components/tabs/TabsContent.astro +0 -28
- package/dist/src/components/tabs/TabsList.astro +0 -22
- package/dist/src/components/tabs/TabsTrigger.astro +0 -34
- package/dist/src/components/tabs/index.ts +0 -20
- package/dist/src/components/textarea/Textarea.astro +0 -29
- package/dist/src/components/textarea/index.ts +0 -9
- package/dist/src/components/toast/ToastDescription.astro +0 -21
- package/dist/src/components/toast/ToastItem.astro +0 -54
- package/dist/src/components/toast/ToastTemplate.astro +0 -25
- package/dist/src/components/toast/ToastTitle.astro +0 -57
- package/dist/src/components/toast/Toaster.astro +0 -982
- package/dist/src/components/toast/index.ts +0 -29
- package/dist/src/components/toast/toast-manager.ts +0 -216
- package/dist/src/components/toggle/Toggle.astro +0 -174
- package/dist/src/components/toggle/ToggleTypes.ts +0 -14
- package/dist/src/components/toggle/index.ts +0 -8
- package/dist/src/components/tooltip/Tooltip.astro +0 -239
- package/dist/src/components/tooltip/TooltipContent.astro +0 -114
- package/dist/src/components/tooltip/TooltipTrigger.astro +0 -10
- package/dist/src/components/tooltip/index.ts +0 -16
- package/dist/src/components/video/Video.astro +0 -120
- package/dist/src/components/video/index.ts +0 -9
|
@@ -1,355 +0,0 @@
|
|
|
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-dialog", className]} data-slot="dialog" {...rest}>
|
|
10
|
-
<slot />
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
// Store instances in a WeakMap to avoid memory leaks
|
|
15
|
-
const dialogInstances = new WeakMap<HTMLElement, DialogHandler>();
|
|
16
|
-
let dialogCounter = 0;
|
|
17
|
-
|
|
18
|
-
class DialogHandler {
|
|
19
|
-
private triggers: HTMLButtonElement[] = [];
|
|
20
|
-
private dialog: HTMLDialogElement | null = null;
|
|
21
|
-
private closeButtons: HTMLButtonElement[] = [];
|
|
22
|
-
private backdrop: HTMLElement | null = null;
|
|
23
|
-
private dialogWrapper: HTMLElement;
|
|
24
|
-
private dialogId: string;
|
|
25
|
-
/**
|
|
26
|
-
* The duration of the animation in milliseconds. This is used to calculate the
|
|
27
|
-
* duration of close animation before hiding the dialog and backdrop
|
|
28
|
-
*/
|
|
29
|
-
private animationDuration: number;
|
|
30
|
-
private parentDialog: DialogHandler | null = null;
|
|
31
|
-
private nestedOpenCount: number = 0;
|
|
32
|
-
private isNested: boolean = false;
|
|
33
|
-
|
|
34
|
-
constructor(dialogWrapper: HTMLElement, dialogNumber: number) {
|
|
35
|
-
this.dialogWrapper = dialogWrapper;
|
|
36
|
-
this.dialog = dialogWrapper.querySelector("dialog");
|
|
37
|
-
this.backdrop = dialogWrapper.querySelector(".starwind-dialog-backdrop");
|
|
38
|
-
if (!this.dialog || !this.backdrop) {
|
|
39
|
-
throw new Error("Dialog: dialog or backdrop not found");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// if no ID was provided for the wrapper, generate one
|
|
43
|
-
if (dialogWrapper.id) {
|
|
44
|
-
this.dialogId = dialogWrapper.id;
|
|
45
|
-
} else {
|
|
46
|
-
this.dialogId = `starwind-dialog${dialogNumber}`;
|
|
47
|
-
dialogWrapper.id = this.dialogId;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// animationDuration is set with inline styles through passed prop to DialogContent
|
|
51
|
-
// if no animationDuration, check data-close-duration
|
|
52
|
-
const animationDurationString = this.dialog.style.animationDuration;
|
|
53
|
-
if (animationDurationString.endsWith("ms")) {
|
|
54
|
-
this.animationDuration = parseFloat(animationDurationString);
|
|
55
|
-
} else if (animationDurationString.endsWith("s")) {
|
|
56
|
-
// using something like @playform/compress might optimize to use "s" instead of "ms"
|
|
57
|
-
this.animationDuration = parseFloat(animationDurationString) * 1000;
|
|
58
|
-
} else {
|
|
59
|
-
this.animationDuration = this.dialog.dataset.closeDuration
|
|
60
|
-
? parseFloat(this.dialog.dataset.closeDuration)
|
|
61
|
-
: 200;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Find internal triggers and handle them
|
|
65
|
-
const internalTriggers = dialogWrapper.querySelectorAll(".starwind-dialog-trigger");
|
|
66
|
-
internalTriggers.forEach((triggerElement) => {
|
|
67
|
-
const tempTrigger = triggerElement as HTMLElement;
|
|
68
|
-
let trigger: HTMLButtonElement;
|
|
69
|
-
|
|
70
|
-
if (tempTrigger?.hasAttribute("data-as-child")) {
|
|
71
|
-
trigger = tempTrigger.firstElementChild as HTMLButtonElement;
|
|
72
|
-
} else {
|
|
73
|
-
trigger = tempTrigger as HTMLButtonElement;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (trigger) {
|
|
77
|
-
this.triggers.push(trigger);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Find external triggers that target this dialog
|
|
82
|
-
this.findExternalTriggers();
|
|
83
|
-
|
|
84
|
-
// if closeButtons are set with asChild, swap the wrapper with its first child
|
|
85
|
-
const tempCloseButtons = dialogWrapper.querySelectorAll(
|
|
86
|
-
".starwind-dialog-close",
|
|
87
|
-
) as NodeListOf<HTMLElement>;
|
|
88
|
-
tempCloseButtons.forEach((button: HTMLElement) => {
|
|
89
|
-
if (button.hasAttribute("data-as-child")) {
|
|
90
|
-
const childElement = button.firstElementChild;
|
|
91
|
-
if (childElement) {
|
|
92
|
-
childElement.classList.add("starwind-dialog-close");
|
|
93
|
-
button.parentNode?.replaceChild(childElement, button);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return button;
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Convert NodeList to Array for consistency with triggers
|
|
100
|
-
this.closeButtons = Array.from(
|
|
101
|
-
dialogWrapper.querySelectorAll(".starwind-dialog-close"),
|
|
102
|
-
) as HTMLButtonElement[];
|
|
103
|
-
|
|
104
|
-
// if essential elements are not there, exit
|
|
105
|
-
if (!this.dialog || !this.backdrop) return;
|
|
106
|
-
|
|
107
|
-
this.setupAccessibility(dialogNumber);
|
|
108
|
-
this.setupEvents();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private setupAccessibility(dialogNumber: number): void {
|
|
112
|
-
// get the first heading element in the dialog
|
|
113
|
-
const firstHeading = this.dialog?.querySelector("h1, h2, h3, h4, h5, h6");
|
|
114
|
-
if (firstHeading) {
|
|
115
|
-
// create a unique ID for the heading
|
|
116
|
-
firstHeading.id = `starwind-dialog${dialogNumber}-heading`;
|
|
117
|
-
// set the aria-labelledby attribute to the first heading element
|
|
118
|
-
this.dialog?.setAttribute("aria-labelledby", firstHeading.id);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Find all external triggers that target this dialog
|
|
124
|
-
*/
|
|
125
|
-
private findExternalTriggers(): void {
|
|
126
|
-
const externalTriggers = document.querySelectorAll(
|
|
127
|
-
`.starwind-dialog-trigger[data-dialog-for="${this.dialogId}"]`,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
externalTriggers.forEach((triggerElement) => {
|
|
131
|
-
// Skip if this is an internal trigger we already processed
|
|
132
|
-
const dialogWrapper = triggerElement.closest(".starwind-dialog");
|
|
133
|
-
if (dialogWrapper && dialogWrapper.id === this.dialogId) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let trigger: HTMLButtonElement;
|
|
138
|
-
if (triggerElement.hasAttribute("data-as-child")) {
|
|
139
|
-
trigger = triggerElement.firstElementChild as HTMLButtonElement;
|
|
140
|
-
} else {
|
|
141
|
-
trigger = triggerElement as HTMLButtonElement;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (trigger && !this.triggers.includes(trigger)) {
|
|
145
|
-
this.triggers.push(trigger);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private setupEvents(): void {
|
|
151
|
-
if (!this.dialog) return;
|
|
152
|
-
// Add click listeners to all triggers
|
|
153
|
-
this.triggers.forEach((trigger) => {
|
|
154
|
-
trigger.addEventListener("click", () => {
|
|
155
|
-
this.open();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Add click handlers to all close buttons
|
|
160
|
-
this.closeButtons?.forEach((button) => {
|
|
161
|
-
button.addEventListener("click", () => {
|
|
162
|
-
// Only close if this is the topmost dialog
|
|
163
|
-
const openDialogs = document.querySelectorAll("dialog[open]");
|
|
164
|
-
if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
|
|
165
|
-
this.close();
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Close on click outside
|
|
171
|
-
this.dialog.addEventListener("click", (e) => {
|
|
172
|
-
if (!this.dialog) return;
|
|
173
|
-
const dialogDimensions = this.dialog.getBoundingClientRect();
|
|
174
|
-
const clickedInDialog =
|
|
175
|
-
e.clientX >= dialogDimensions.left &&
|
|
176
|
-
e.clientX <= dialogDimensions.right &&
|
|
177
|
-
e.clientY >= dialogDimensions.top &&
|
|
178
|
-
e.clientY <= dialogDimensions.bottom;
|
|
179
|
-
|
|
180
|
-
if (!clickedInDialog) {
|
|
181
|
-
// Only close if this is the topmost dialog
|
|
182
|
-
const openDialogs = document.querySelectorAll("dialog[open]");
|
|
183
|
-
if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
|
|
184
|
-
this.close();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Handle escape key
|
|
190
|
-
this.dialog.addEventListener("keydown", (e) => {
|
|
191
|
-
if (e.key === "Escape") {
|
|
192
|
-
// prevent default dialog closing behavior so we can add closing animation
|
|
193
|
-
e.preventDefault();
|
|
194
|
-
// Only close if this is the topmost dialog
|
|
195
|
-
const openDialogs = document.querySelectorAll("dialog[open]");
|
|
196
|
-
if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
|
|
197
|
-
this.close();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// Intercept form submissions to handle dialog close
|
|
203
|
-
const forms = this.dialog.querySelectorAll("form");
|
|
204
|
-
forms.forEach((form) => {
|
|
205
|
-
form.addEventListener("submit", (e) => {
|
|
206
|
-
/**
|
|
207
|
-
* Default form.method = "dialog" submissions cause the dialog to close
|
|
208
|
-
* Default form.method = "post" submissions do not close the dialog
|
|
209
|
-
* Here we intercept the form submission and manage the dialog closing if method = "dialog"
|
|
210
|
-
* so we can add closing animation
|
|
211
|
-
* Normal form event listeners for "submit" will still get the form data
|
|
212
|
-
*/
|
|
213
|
-
if (form.method === "dialog") {
|
|
214
|
-
e.preventDefault();
|
|
215
|
-
// Only close if this is the topmost dialog
|
|
216
|
-
const openDialogs = document.querySelectorAll("dialog[open]");
|
|
217
|
-
if (openDialogs.length > 0 && openDialogs[openDialogs.length - 1] === this.dialog) {
|
|
218
|
-
this.close();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private open(): void {
|
|
226
|
-
if (!this.dialog || !this.backdrop) return;
|
|
227
|
-
|
|
228
|
-
// Reset nested count when opening (in case it wasn't properly reset)
|
|
229
|
-
this.nestedOpenCount = 0;
|
|
230
|
-
this.updateNestedState();
|
|
231
|
-
|
|
232
|
-
this.dialog.showModal();
|
|
233
|
-
document.body.classList.add("overflow-hidden");
|
|
234
|
-
|
|
235
|
-
// For nested dialogs, hide the backdrop and notify parent
|
|
236
|
-
if (this.isNested && this.parentDialog) {
|
|
237
|
-
this.backdrop.classList.add("hidden");
|
|
238
|
-
this.parentDialog.onNestedDialogOpen();
|
|
239
|
-
} else {
|
|
240
|
-
this.backdrop.classList.remove("hidden");
|
|
241
|
-
this.backdrop.dataset.state = "open";
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.dialog.dataset.state = "open";
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private close(): void {
|
|
248
|
-
if (!this.dialog || !this.backdrop) return;
|
|
249
|
-
|
|
250
|
-
this.dialog.dataset.state = "closed";
|
|
251
|
-
|
|
252
|
-
// Notify parent dialog that nested dialog is closing
|
|
253
|
-
if (this.isNested && this.parentDialog) {
|
|
254
|
-
this.parentDialog.onNestedDialogClose();
|
|
255
|
-
} else {
|
|
256
|
-
this.backdrop.dataset.state = "closed";
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Wait for animation to finish before hiding backdrop
|
|
260
|
-
setTimeout(() => {
|
|
261
|
-
if (!this.isNested) {
|
|
262
|
-
this.backdrop?.classList.add("hidden");
|
|
263
|
-
}
|
|
264
|
-
this.dialog?.close();
|
|
265
|
-
const stillOpen = document.querySelectorAll("dialog[open]").length;
|
|
266
|
-
if (stillOpen === 0) {
|
|
267
|
-
document.body.classList.remove("overflow-hidden");
|
|
268
|
-
}
|
|
269
|
-
}, this.animationDuration);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Called by child dialogs when they open
|
|
274
|
-
*/
|
|
275
|
-
public onNestedDialogOpen(): void {
|
|
276
|
-
this.nestedOpenCount++;
|
|
277
|
-
this.updateNestedState();
|
|
278
|
-
// Propagate up the chain to grandparent dialogs
|
|
279
|
-
if (this.parentDialog) {
|
|
280
|
-
this.parentDialog.onNestedDialogOpen();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Called by child dialogs when they close
|
|
286
|
-
*/
|
|
287
|
-
public onNestedDialogClose(): void {
|
|
288
|
-
this.nestedOpenCount = Math.max(0, this.nestedOpenCount - 1);
|
|
289
|
-
this.updateNestedState();
|
|
290
|
-
// Propagate up the chain to grandparent dialogs
|
|
291
|
-
if (this.parentDialog) {
|
|
292
|
-
this.parentDialog.onNestedDialogClose();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Updates the nested dialog state attributes
|
|
298
|
-
*/
|
|
299
|
-
private updateNestedState(): void {
|
|
300
|
-
if (!this.dialog) return;
|
|
301
|
-
|
|
302
|
-
if (this.nestedOpenCount > 0) {
|
|
303
|
-
this.dialog.setAttribute("data-nested-dialog-open", "");
|
|
304
|
-
this.dialog.style.setProperty("--nested-dialogs", String(this.nestedOpenCount));
|
|
305
|
-
} else {
|
|
306
|
-
this.dialog.removeAttribute("data-nested-dialog-open");
|
|
307
|
-
this.dialog.style.removeProperty("--nested-dialogs");
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Links this dialog to its parent dialog (called after all dialogs are initialized)
|
|
313
|
-
*/
|
|
314
|
-
public linkParentDialog(): void {
|
|
315
|
-
const parentDialogWrapper = this.dialogWrapper.parentElement?.closest(".starwind-dialog");
|
|
316
|
-
if (parentDialogWrapper) {
|
|
317
|
-
this.isNested = true;
|
|
318
|
-
const parentInstance = dialogInstances.get(parentDialogWrapper as HTMLElement);
|
|
319
|
-
if (parentInstance) {
|
|
320
|
-
this.parentDialog = parentInstance;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Initialize all dialogs
|
|
327
|
-
const setupDialogs = () => {
|
|
328
|
-
// First pass: create all dialog instances
|
|
329
|
-
document.querySelectorAll(".starwind-dialog").forEach((dialogWrapper) => {
|
|
330
|
-
const wrapper = dialogWrapper as HTMLElement;
|
|
331
|
-
if (!dialogInstances.has(wrapper)) {
|
|
332
|
-
dialogInstances.set(wrapper, new DialogHandler(wrapper, dialogCounter++));
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// Second pass: link parent dialogs (now that all instances exist)
|
|
337
|
-
document.querySelectorAll(".starwind-dialog").forEach((dialogWrapper) => {
|
|
338
|
-
const wrapper = dialogWrapper as HTMLElement;
|
|
339
|
-
const instance = dialogInstances.get(wrapper);
|
|
340
|
-
if (instance) {
|
|
341
|
-
instance.linkParentDialog();
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
setupDialogs();
|
|
347
|
-
document.addEventListener("astro:after-swap", setupDialogs);
|
|
348
|
-
document.addEventListener("starwind:init", setupDialogs);
|
|
349
|
-
</script>
|
|
350
|
-
|
|
351
|
-
<style>
|
|
352
|
-
.overflow-hidden {
|
|
353
|
-
overflow: hidden;
|
|
354
|
-
}
|
|
355
|
-
</style>
|
|
@@ -1,35 +0,0 @@
|
|
|
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 instead of a button
|
|
7
|
-
*/
|
|
8
|
-
asChild?: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const { class: className, asChild = false, ...rest } = Astro.props;
|
|
12
|
-
|
|
13
|
-
// Get the first child element if asChild is true
|
|
14
|
-
let hasChildren = false;
|
|
15
|
-
if (Astro.slots.has("default")) {
|
|
16
|
-
hasChildren = true;
|
|
17
|
-
}
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
asChild && hasChildren ? (
|
|
22
|
-
<div class="starwind-dialog-close" data-slot="dialog-close" data-as-child>
|
|
23
|
-
<slot />
|
|
24
|
-
</div>
|
|
25
|
-
) : (
|
|
26
|
-
<button
|
|
27
|
-
type="button"
|
|
28
|
-
class:list={["starwind-dialog-close", className]}
|
|
29
|
-
data-slot="dialog-close"
|
|
30
|
-
{...rest}
|
|
31
|
-
>
|
|
32
|
-
<slot>Demo close button</slot>
|
|
33
|
-
</button>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import X from "@tabler/icons/outline/x.svg";
|
|
3
|
-
import type { HTMLAttributes } from "astro/types";
|
|
4
|
-
import { tv } from "tailwind-variants";
|
|
5
|
-
|
|
6
|
-
type Props = HTMLAttributes<"dialog"> & {
|
|
7
|
-
/**
|
|
8
|
-
* Open and close animation duration in milliseconds
|
|
9
|
-
*/
|
|
10
|
-
animationDuration?: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const dialogBackdrop = tv({
|
|
14
|
-
base: [
|
|
15
|
-
"starwind-dialog-backdrop fixed inset-0 top-0 left-0 z-50 hidden h-screen w-screen bg-black/80",
|
|
16
|
-
"data-[state=open]:animate-in fade-in",
|
|
17
|
-
"data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards fade-out",
|
|
18
|
-
],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const dialogContent = tv({
|
|
22
|
-
base: [
|
|
23
|
-
"starwind-dialog-content",
|
|
24
|
-
"fixed top-16 left-[50%] z-50 translate-x-[-50%] sm:top-[50%] sm:translate-y-[-50%]",
|
|
25
|
-
"bg-background w-full max-w-md rounded-lg border p-8 shadow-lg",
|
|
26
|
-
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards transition-[translate,scale,opacity]",
|
|
27
|
-
"fade-in zoom-in-95 slide-in-from-bottom-2",
|
|
28
|
-
"fade-out zoom-out-95 slide-out-to-bottom-2",
|
|
29
|
-
"data-[state=open]:data-[nested-dialog-open]:-translate-y-[calc(50%-var(--nested-offset)*var(--nested-dialogs,1))]",
|
|
30
|
-
"data-[state=open]:data-[nested-dialog-open]:scale-[calc(1-var(--nested-scale)*var(--nested-dialogs,1))]",
|
|
31
|
-
"max-sm:data-[state=open]:data-[nested-dialog-open]:translate-y-[calc(var(--nested-offset)*var(--nested-dialogs,1))]",
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const dialogCloseButton = tv({
|
|
36
|
-
base: [
|
|
37
|
-
"starwind-dialog-close text-muted-foreground",
|
|
38
|
-
"absolute top-5.5 right-5.5 rounded-sm [&>svg]:opacity-70 hover:[&>svg]:opacity-100",
|
|
39
|
-
"focus-visible:ring-outline/50 transition-[color,box-shadow] outline-none focus-visible:ring-3",
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const { class: className, animationDuration = 200, ...rest } = Astro.props;
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
<!-- dialog overlay -->
|
|
47
|
-
<slot name="backdrop">
|
|
48
|
-
<div
|
|
49
|
-
class={dialogBackdrop()}
|
|
50
|
-
data-state="closed"
|
|
51
|
-
data-slot="dialog-backdrop"
|
|
52
|
-
style={{ animationDuration: `${animationDuration}ms` }}
|
|
53
|
-
>
|
|
54
|
-
</div>
|
|
55
|
-
</slot>
|
|
56
|
-
|
|
57
|
-
<dialog
|
|
58
|
-
class={dialogContent({ class: className })}
|
|
59
|
-
data-state="closed"
|
|
60
|
-
data-slot="dialog-content"
|
|
61
|
-
{...rest}
|
|
62
|
-
style={{ animationDuration: `${animationDuration}ms` }}
|
|
63
|
-
>
|
|
64
|
-
<slot />
|
|
65
|
-
<button type="button" class={dialogCloseButton()} data-dialog-close aria-label="Close dialog">
|
|
66
|
-
<slot name="icon">
|
|
67
|
-
<X class="size-5 transition-opacity" />
|
|
68
|
-
</slot>
|
|
69
|
-
<span class="sr-only">Close</span>
|
|
70
|
-
</button>
|
|
71
|
-
</dialog>
|
|
72
|
-
|
|
73
|
-
<style>
|
|
74
|
-
.starwind-dialog-content {
|
|
75
|
-
--nested-offset: 1rem;
|
|
76
|
-
--nested-scale: 0.05;
|
|
77
|
-
}
|
|
78
|
-
</style>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"p">;
|
|
6
|
-
|
|
7
|
-
export const dialogDescription = tv({ base: "text-muted-foreground" });
|
|
8
|
-
|
|
9
|
-
const { class: className, ...rest } = Astro.props;
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
<p class={dialogDescription({ class: className })} data-slot="dialog-description" {...rest}>
|
|
13
|
-
<slot />
|
|
14
|
-
</p>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const dialogFooter = tv({ base: "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end" });
|
|
8
|
-
|
|
9
|
-
const { class: className, ...rest } = Astro.props;
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
<div class={dialogFooter({ class: className })} data-slot="dialog-footer" {...rest}>
|
|
13
|
-
<slot />
|
|
14
|
-
</div>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const dialogHeader = tv({ base: "flex flex-col space-y-2 text-center sm:text-left" });
|
|
8
|
-
|
|
9
|
-
const { class: className, ...rest } = Astro.props;
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
<div class={dialogHeader({ class: className })} data-slot="dialog-header" {...rest}>
|
|
13
|
-
<slot />
|
|
14
|
-
</div>
|
|
@@ -1,22 +0,0 @@
|
|
|
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 dialogTitle = tv({
|
|
14
|
-
base: "font-heading text-xl leading-none font-semibold tracking-tight",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const { class: className, ...rest } = Astro.props;
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
<h2 class={dialogTitle({ class: className })} data-slot="dialog-title" {...rest}>
|
|
21
|
-
<slot />
|
|
22
|
-
</h2>
|
|
@@ -1,47 +0,0 @@
|
|
|
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-dialog-trigger", className]}
|
|
29
|
-
data-slot="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-dialog-trigger", className]}
|
|
40
|
-
data-slot="dialog-trigger"
|
|
41
|
-
data-dialog-for={dialogFor}
|
|
42
|
-
{...rest}
|
|
43
|
-
>
|
|
44
|
-
<slot />
|
|
45
|
-
</button>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Dialog from "./Dialog.astro";
|
|
2
|
-
import DialogClose from "./DialogClose.astro";
|
|
3
|
-
import DialogContent, {
|
|
4
|
-
dialogBackdrop,
|
|
5
|
-
dialogCloseButton,
|
|
6
|
-
dialogContent,
|
|
7
|
-
} from "./DialogContent.astro";
|
|
8
|
-
import DialogDescription, { dialogDescription } from "./DialogDescription.astro";
|
|
9
|
-
import DialogFooter, { dialogFooter } from "./DialogFooter.astro";
|
|
10
|
-
import DialogHeader, { dialogHeader } from "./DialogHeader.astro";
|
|
11
|
-
import DialogTitle, { dialogTitle } from "./DialogTitle.astro";
|
|
12
|
-
import DialogTrigger from "./DialogTrigger.astro";
|
|
13
|
-
|
|
14
|
-
const DialogVariants = {
|
|
15
|
-
dialogBackdrop,
|
|
16
|
-
dialogContent,
|
|
17
|
-
dialogCloseButton,
|
|
18
|
-
dialogDescription,
|
|
19
|
-
dialogFooter,
|
|
20
|
-
dialogHeader,
|
|
21
|
-
dialogTitle,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
Dialog,
|
|
26
|
-
DialogClose,
|
|
27
|
-
DialogContent,
|
|
28
|
-
DialogDescription,
|
|
29
|
-
DialogFooter,
|
|
30
|
-
DialogHeader,
|
|
31
|
-
DialogTitle,
|
|
32
|
-
DialogTrigger,
|
|
33
|
-
DialogVariants,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default {
|
|
37
|
-
Root: Dialog,
|
|
38
|
-
Trigger: DialogTrigger,
|
|
39
|
-
Content: DialogContent,
|
|
40
|
-
Header: DialogHeader,
|
|
41
|
-
Footer: DialogFooter,
|
|
42
|
-
Title: DialogTitle,
|
|
43
|
-
Description: DialogDescription,
|
|
44
|
-
Close: DialogClose,
|
|
45
|
-
};
|