@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.
- package/dist/index.d.ts +28 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/src/components/accordion/Accordion.astro +254 -0
- package/dist/src/components/accordion/AccordionContent.astro +33 -0
- package/dist/src/components/accordion/AccordionItem.astro +27 -0
- package/dist/src/components/accordion/AccordionTrigger.astro +32 -0
- package/dist/src/components/accordion/index.ts +15 -0
- package/dist/src/components/alert/Alert.astro +31 -0
- package/dist/src/components/alert/AlertDescription.astro +14 -0
- package/dist/src/components/alert/AlertTitle.astro +16 -0
- package/dist/src/components/alert/index.ts +13 -0
- package/dist/src/components/alert-dialog/AlertDialog.astro +275 -0
- package/dist/src/components/alert-dialog/AlertDialogAction.astro +44 -0
- package/dist/src/components/alert-dialog/AlertDialogCancel.astro +45 -0
- package/dist/src/components/alert-dialog/AlertDialogContent.astro +52 -0
- package/dist/src/components/alert-dialog/AlertDialogDescription.astro +18 -0
- package/dist/src/components/alert-dialog/AlertDialogFooter.astro +16 -0
- package/dist/src/components/alert-dialog/AlertDialogHeader.astro +14 -0
- package/dist/src/components/alert-dialog/AlertDialogTitle.astro +20 -0
- package/dist/src/components/alert-dialog/AlertDialogTrigger.astro +47 -0
- package/dist/src/components/alert-dialog/index.ts +46 -0
- package/dist/src/components/aspect-ratio/AspectRatio.astro +32 -0
- package/dist/src/components/aspect-ratio/index.ts +7 -0
- package/dist/src/components/avatar/Avatar.astro +29 -0
- package/dist/src/components/avatar/AvatarFallback.astro +18 -0
- package/dist/src/components/avatar/AvatarImage.astro +49 -0
- package/dist/src/components/avatar/index.ts +13 -0
- package/dist/src/components/badge/Badge.astro +55 -0
- package/dist/src/components/badge/index.ts +7 -0
- package/dist/src/components/breadcrumb/Breadcrumb.astro +11 -0
- package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +28 -0
- package/dist/src/components/breadcrumb/BreadcrumbItem.astro +14 -0
- package/dist/src/components/breadcrumb/BreadcrumbLink.astro +22 -0
- package/dist/src/components/breadcrumb/BreadcrumbList.astro +16 -0
- package/dist/src/components/breadcrumb/BreadcrumbPage.astro +21 -0
- package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +23 -0
- package/dist/src/components/breadcrumb/index.ts +37 -0
- package/dist/src/components/button/Button.astro +55 -0
- package/dist/src/components/button/index.ts +7 -0
- package/dist/src/components/button-group/ButtonGroup.astro +62 -0
- package/dist/src/components/button-group/ButtonGroupSeparator.astro +27 -0
- package/dist/src/components/button-group/ButtonGroupText.astro +19 -0
- package/dist/src/components/button-group/index.ts +17 -0
- package/dist/src/components/card/Card.astro +14 -0
- package/dist/src/components/card/CardContent.astro +14 -0
- package/dist/src/components/card/CardDescription.astro +14 -0
- package/dist/src/components/card/CardFooter.astro +14 -0
- package/dist/src/components/card/CardHeader.astro +14 -0
- package/dist/src/components/card/CardTitle.astro +14 -0
- package/dist/src/components/card/index.ts +26 -0
- package/dist/src/components/carousel/Carousel.astro +55 -0
- package/dist/src/components/carousel/CarouselContent.astro +26 -0
- package/dist/src/components/carousel/CarouselItem.astro +26 -0
- package/dist/src/components/carousel/CarouselNext.astro +37 -0
- package/dist/src/components/carousel/CarouselPrevious.astro +37 -0
- package/dist/src/components/carousel/carousel-script.ts +191 -0
- package/dist/src/components/carousel/index.ts +32 -0
- package/dist/src/components/checkbox/Checkbox.astro +128 -0
- package/dist/src/components/checkbox/index.ts +7 -0
- package/dist/src/components/collapsible/Collapsible.astro +161 -0
- package/dist/src/components/collapsible/CollapsibleContent.astro +22 -0
- package/dist/src/components/collapsible/CollapsibleTrigger.astro +44 -0
- package/dist/src/components/collapsible/index.ts +13 -0
- package/dist/src/components/dialog/Dialog.astro +389 -0
- package/dist/src/components/dialog/DialogClose.astro +35 -0
- package/dist/src/components/dialog/DialogContent.astro +78 -0
- package/dist/src/components/dialog/DialogDescription.astro +14 -0
- package/dist/src/components/dialog/DialogFooter.astro +14 -0
- package/dist/src/components/dialog/DialogHeader.astro +14 -0
- package/dist/src/components/dialog/DialogTitle.astro +22 -0
- package/dist/src/components/dialog/DialogTrigger.astro +47 -0
- package/dist/src/components/dialog/index.ts +45 -0
- package/dist/src/components/dropdown/Dropdown.astro +377 -0
- package/dist/src/components/dropdown/DropdownContent.astro +81 -0
- package/dist/src/components/dropdown/DropdownItem.astro +48 -0
- package/dist/src/components/dropdown/DropdownLabel.astro +29 -0
- package/dist/src/components/dropdown/DropdownSeparator.astro +21 -0
- package/dist/src/components/dropdown/DropdownTrigger.astro +52 -0
- package/dist/src/components/dropdown/index.ts +33 -0
- package/dist/src/components/dropzone/Dropzone.astro +236 -0
- package/dist/src/components/dropzone/DropzoneFilesList.astro +26 -0
- package/dist/src/components/dropzone/DropzoneLoadingIndicator.astro +10 -0
- package/dist/src/components/dropzone/DropzoneUploadIndicator.astro +10 -0
- package/dist/src/components/dropzone/index.ts +24 -0
- package/dist/src/components/image/Image.astro +24 -0
- package/dist/src/components/image/index.ts +9 -0
- package/dist/src/components/input/Input.astro +25 -0
- package/dist/src/components/input/index.ts +7 -0
- package/dist/src/components/input-otp/InputOtp.astro +352 -0
- package/dist/src/components/input-otp/InputOtpGroup.astro +16 -0
- package/dist/src/components/input-otp/InputOtpSeparator.astro +25 -0
- package/dist/src/components/input-otp/InputOtpSlot.astro +48 -0
- package/dist/src/components/input-otp/InputOtpTypes.ts +6 -0
- package/dist/src/components/input-otp/index.ts +33 -0
- package/dist/src/components/item/Item.astro +52 -0
- package/dist/src/components/item/ItemActions.astro +16 -0
- package/dist/src/components/item/ItemContent.astro +16 -0
- package/dist/src/components/item/ItemDescription.astro +19 -0
- package/dist/src/components/item/ItemFooter.astro +16 -0
- package/dist/src/components/item/ItemGroup.astro +16 -0
- package/dist/src/components/item/ItemHeader.astro +16 -0
- package/dist/src/components/item/ItemMedia.astro +40 -0
- package/dist/src/components/item/ItemSeparator.astro +21 -0
- package/dist/src/components/item/ItemTitle.astro +16 -0
- package/dist/src/components/item/index.ts +50 -0
- package/dist/src/components/kbd/Kbd.astro +21 -0
- package/dist/src/components/kbd/KbdGroup.astro +16 -0
- package/dist/src/components/kbd/index.ts +11 -0
- package/dist/src/components/label/Label.astro +22 -0
- package/dist/src/components/label/index.ts +7 -0
- package/dist/src/components/pagination/Pagination.astro +20 -0
- package/dist/src/components/pagination/PaginationContent.astro +16 -0
- package/dist/src/components/pagination/PaginationEllipsis.astro +35 -0
- package/dist/src/components/pagination/PaginationItem.astro +16 -0
- package/dist/src/components/pagination/PaginationLink.astro +24 -0
- package/dist/src/components/pagination/PaginationNext.astro +30 -0
- package/dist/src/components/pagination/PaginationPrevious.astro +30 -0
- package/dist/src/components/pagination/index.ts +38 -0
- package/dist/src/components/progress/Progress.astro +155 -0
- package/dist/src/components/progress/index.ts +10 -0
- package/dist/src/components/prose/Prose.astro +617 -0
- package/dist/src/components/prose/index.ts +9 -0
- package/dist/src/components/radio-group/RadioGroup.astro +162 -0
- package/dist/src/components/radio-group/RadioGroupItem.astro +129 -0
- package/dist/src/components/radio-group/RadioGroupTypes.ts +6 -0
- package/dist/src/components/radio-group/index.ts +23 -0
- package/dist/src/components/select/Select.astro +752 -0
- package/dist/src/components/select/SelectContent.astro +94 -0
- package/dist/src/components/select/SelectGroup.astro +9 -0
- package/dist/src/components/select/SelectItem.astro +51 -0
- package/dist/src/components/select/SelectLabel.astro +14 -0
- package/dist/src/components/select/SelectSearch.astro +49 -0
- package/dist/src/components/select/SelectSeparator.astro +12 -0
- package/dist/src/components/select/SelectTrigger.astro +54 -0
- package/dist/src/components/select/SelectTypes.ts +13 -0
- package/dist/src/components/select/SelectValue.astro +19 -0
- package/dist/src/components/select/index.ts +49 -0
- package/dist/src/components/separator/Separator.astro +36 -0
- package/dist/src/components/separator/index.ts +7 -0
- package/dist/src/components/sheet/Sheet.astro +13 -0
- package/dist/src/components/sheet/SheetClose.astro +13 -0
- package/dist/src/components/sheet/SheetContent.astro +92 -0
- package/dist/src/components/sheet/SheetDescription.astro +16 -0
- package/dist/src/components/sheet/SheetFooter.astro +16 -0
- package/dist/src/components/sheet/SheetHeader.astro +16 -0
- package/dist/src/components/sheet/SheetTitle.astro +16 -0
- package/dist/src/components/sheet/SheetTrigger.astro +13 -0
- package/dist/src/components/sheet/index.ts +41 -0
- package/dist/src/components/sidebar/Sidebar.astro +213 -0
- package/dist/src/components/sidebar/SidebarContent.astro +24 -0
- package/dist/src/components/sidebar/SidebarFooter.astro +21 -0
- package/dist/src/components/sidebar/SidebarGroup.astro +21 -0
- package/dist/src/components/sidebar/SidebarGroupContent.astro +21 -0
- package/dist/src/components/sidebar/SidebarGroupLabel.astro +52 -0
- package/dist/src/components/sidebar/SidebarHeader.astro +21 -0
- package/dist/src/components/sidebar/SidebarInput.astro +22 -0
- package/dist/src/components/sidebar/SidebarInset.astro +21 -0
- package/dist/src/components/sidebar/SidebarMenu.astro +21 -0
- package/dist/src/components/sidebar/SidebarMenuAction.astro +59 -0
- package/dist/src/components/sidebar/SidebarMenuBadge.astro +30 -0
- package/dist/src/components/sidebar/SidebarMenuButton.astro +129 -0
- package/dist/src/components/sidebar/SidebarMenuItem.astro +21 -0
- package/dist/src/components/sidebar/SidebarMenuSkeleton.astro +40 -0
- package/dist/src/components/sidebar/SidebarMenuSub.astro +24 -0
- package/dist/src/components/sidebar/SidebarMenuSubButton.astro +49 -0
- package/dist/src/components/sidebar/SidebarMenuSubItem.astro +16 -0
- package/dist/src/components/sidebar/SidebarProvider.astro +213 -0
- package/dist/src/components/sidebar/SidebarRail.astro +71 -0
- package/dist/src/components/sidebar/SidebarSeparator.astro +22 -0
- package/dist/src/components/sidebar/SidebarTrigger.astro +66 -0
- package/dist/src/components/sidebar/index.ts +103 -0
- package/dist/src/components/skeleton/Skeleton.astro +14 -0
- package/dist/src/components/skeleton/index.ts +9 -0
- package/dist/src/components/slider/Slider.astro +411 -0
- package/dist/src/components/slider/index.ts +9 -0
- package/dist/src/components/spinner/Spinner.astro +21 -0
- package/dist/src/components/spinner/index.ts +7 -0
- package/dist/src/components/switch/Switch.astro +192 -0
- package/dist/src/components/switch/SwitchTypes.ts +6 -0
- package/dist/src/components/switch/index.ts +12 -0
- package/dist/src/components/table/Table.astro +18 -0
- package/dist/src/components/table/TableBody.astro +16 -0
- package/dist/src/components/table/TableCaption.astro +16 -0
- package/dist/src/components/table/TableCell.astro +16 -0
- package/dist/src/components/table/TableFoot.astro +16 -0
- package/dist/src/components/table/TableHead.astro +16 -0
- package/dist/src/components/table/TableHeader.astro +16 -0
- package/dist/src/components/table/TableRow.astro +16 -0
- package/dist/src/components/table/index.ts +42 -0
- package/dist/src/components/tabs/Tabs.astro +271 -0
- package/dist/src/components/tabs/TabsContent.astro +28 -0
- package/dist/src/components/tabs/TabsList.astro +22 -0
- package/dist/src/components/tabs/TabsTrigger.astro +34 -0
- package/dist/src/components/tabs/index.ts +20 -0
- package/dist/src/components/textarea/Textarea.astro +29 -0
- package/dist/src/components/textarea/index.ts +9 -0
- package/dist/src/components/theme-toggle/ThemeToggle.astro +208 -0
- package/dist/src/components/theme-toggle/index.ts +7 -0
- package/dist/src/components/toast/ToastDescription.astro +21 -0
- package/dist/src/components/toast/ToastItem.astro +54 -0
- package/dist/src/components/toast/ToastTemplate.astro +25 -0
- package/dist/src/components/toast/ToastTitle.astro +57 -0
- package/dist/src/components/toast/Toaster.astro +982 -0
- package/dist/src/components/toast/index.ts +29 -0
- package/dist/src/components/toast/toast-manager.ts +216 -0
- package/dist/src/components/toggle/Toggle.astro +174 -0
- package/dist/src/components/toggle/ToggleTypes.ts +14 -0
- package/dist/src/components/toggle/index.ts +8 -0
- package/dist/src/components/tooltip/Tooltip.astro +282 -0
- package/dist/src/components/tooltip/TooltipContent.astro +89 -0
- package/dist/src/components/tooltip/TooltipTrigger.astro +10 -0
- package/dist/src/components/tooltip/index.ts +16 -0
- package/dist/src/components/video/Video.astro +120 -0
- package/dist/src/components/video/index.ts +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
---
|
|
2
|
+
// put the following script in the <head> of each page of your site
|
|
3
|
+
// this ensures it is run early to eliminate any flashes of incorrect color theme
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
<script is:inline>
|
|
7
|
+
function initTheme() {
|
|
8
|
+
const colorTheme = localStorage.getItem("colorTheme");
|
|
9
|
+
if (!colorTheme) {
|
|
10
|
+
// if no color theme yet, use the users preferences
|
|
11
|
+
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
12
|
+
document.documentElement.classList.add("dark");
|
|
13
|
+
localStorage.setItem("colorTheme", "dark");
|
|
14
|
+
} else {
|
|
15
|
+
document.documentElement.classList.remove("dark");
|
|
16
|
+
localStorage.setItem("colorTheme", "light");
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
// assign the theme based on the value in local storage
|
|
20
|
+
if (colorTheme === "dark") {
|
|
21
|
+
document.documentElement.classList.add("dark");
|
|
22
|
+
} else if (colorTheme === "light") {
|
|
23
|
+
document.documentElement.classList.remove("dark");
|
|
24
|
+
} else if (colorTheme === "system") {
|
|
25
|
+
// use system preference
|
|
26
|
+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
27
|
+
document.documentElement.classList.toggle("dark", prefersDark);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// runs on initial page load
|
|
33
|
+
initTheme();
|
|
34
|
+
|
|
35
|
+
// runs on view transitions navigation
|
|
36
|
+
document.addEventListener("astro:after-swap", initTheme);
|
|
37
|
+
</script>
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import Moon from "@tabler/icons/outline/moon.svg";
|
|
41
|
+
import Sun from "@tabler/icons/outline/sun.svg";
|
|
42
|
+
import { tv, type VariantProps } from "tailwind-variants";
|
|
43
|
+
|
|
44
|
+
import { Toggle, ToggleVariants } from "@/components/starwind/toggle";
|
|
45
|
+
|
|
46
|
+
export const themeToggle = tv({
|
|
47
|
+
base: [
|
|
48
|
+
"starwind-theme-toggle",
|
|
49
|
+
"group hover:border-muted-foreground hover:bg-transparent data-[state=on]:bg-transparent",
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
type Props = VariantProps<typeof ToggleVariants.toggle> & {
|
|
54
|
+
/**
|
|
55
|
+
* The ARIA label for the toggle
|
|
56
|
+
*/
|
|
57
|
+
ariaLabel?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Additional classes for the toggle
|
|
60
|
+
*/
|
|
61
|
+
class?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const {
|
|
65
|
+
class: className = "",
|
|
66
|
+
variant = "outline",
|
|
67
|
+
size = "md",
|
|
68
|
+
ariaLabel = "Toggle theme",
|
|
69
|
+
...rest
|
|
70
|
+
} = Astro.props as Props;
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
<Toggle
|
|
74
|
+
class={themeToggle({ class: className })}
|
|
75
|
+
variant={variant}
|
|
76
|
+
size={size}
|
|
77
|
+
aria-label={ariaLabel}
|
|
78
|
+
data-slot="theme-toggle"
|
|
79
|
+
{...rest}
|
|
80
|
+
>
|
|
81
|
+
<slot>
|
|
82
|
+
<span class="size-5" data-theme-icon-wrapper>
|
|
83
|
+
<slot name="light-icon">
|
|
84
|
+
<Sun class="hidden size-5 group-data-[state=off]:data-ready:block" data-theme-icon />
|
|
85
|
+
</slot>
|
|
86
|
+
<slot name="dark-icon">
|
|
87
|
+
<Moon class="hidden size-5 group-data-[state=on]:data-ready:block" data-theme-icon />
|
|
88
|
+
</slot>
|
|
89
|
+
</span>
|
|
90
|
+
</slot>
|
|
91
|
+
</Toggle>
|
|
92
|
+
|
|
93
|
+
<script>
|
|
94
|
+
import type { ToggleChangeEvent } from "@/components/starwind/toggle";
|
|
95
|
+
|
|
96
|
+
class ThemeToggleHandler {
|
|
97
|
+
private toggle: HTMLButtonElement;
|
|
98
|
+
private isInitializing = true;
|
|
99
|
+
|
|
100
|
+
constructor(toggle: HTMLButtonElement) {
|
|
101
|
+
this.toggle = toggle;
|
|
102
|
+
|
|
103
|
+
this.initializeState();
|
|
104
|
+
this.setupEventListeners();
|
|
105
|
+
|
|
106
|
+
// Mark initialization complete after a microtask
|
|
107
|
+
queueMicrotask(() => {
|
|
108
|
+
this.isInitializing = false;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private initializeState(): void {
|
|
113
|
+
// Determine if dark mode is active based on the document class
|
|
114
|
+
// This handles "system" correctly since initTheme already applied the right class
|
|
115
|
+
const isDark = document.documentElement.classList.contains("dark");
|
|
116
|
+
|
|
117
|
+
this.toggle.setAttribute("data-state", isDark ? "on" : "off");
|
|
118
|
+
this.toggle.setAttribute("aria-pressed", isDark.toString());
|
|
119
|
+
|
|
120
|
+
// Mark icons as ready to show (prevents flash of wrong icon)
|
|
121
|
+
this.toggle.querySelectorAll("[data-theme-icon]").forEach((icon) => {
|
|
122
|
+
icon.setAttribute("data-ready", "");
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private setupEventListeners(): void {
|
|
127
|
+
this.toggle.addEventListener("starwind-toggle:change", (event: Event) =>
|
|
128
|
+
this.handleToggleChange(event),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private handleToggleChange(event: Event): void {
|
|
133
|
+
// Don't dispatch theme:change during initialization
|
|
134
|
+
if (this.isInitializing) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const { pressed } = (event as ToggleChangeEvent).detail;
|
|
139
|
+
|
|
140
|
+
// Update theme based on toggle state
|
|
141
|
+
const newTheme = pressed ? "dark" : "light";
|
|
142
|
+
|
|
143
|
+
document.documentElement.classList.toggle("dark", pressed);
|
|
144
|
+
localStorage.setItem("colorTheme", newTheme);
|
|
145
|
+
|
|
146
|
+
// Dispatch custom event to sync other theme toggles
|
|
147
|
+
document.dispatchEvent(
|
|
148
|
+
new CustomEvent("theme:change", {
|
|
149
|
+
detail: { theme: newTheme },
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public syncState(theme: string): void {
|
|
155
|
+
let shouldBeOn: boolean;
|
|
156
|
+
if (theme === "system") {
|
|
157
|
+
shouldBeOn = document.documentElement.classList.contains("dark");
|
|
158
|
+
} else {
|
|
159
|
+
shouldBeOn = theme === "dark";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const newState = shouldBeOn ? "on" : "off";
|
|
163
|
+
|
|
164
|
+
// Only update if state actually changed to prevent loops
|
|
165
|
+
if (this.toggle.getAttribute("data-state") !== newState) {
|
|
166
|
+
this.toggle.setAttribute("data-state", newState);
|
|
167
|
+
this.toggle.setAttribute("aria-pressed", shouldBeOn.toString());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Store instances in a WeakMap to avoid memory leaks
|
|
173
|
+
const themeToggleInstances = new WeakMap<HTMLElement, ThemeToggleHandler>();
|
|
174
|
+
// Track active toggles for iteration (WeakMap is not iterable)
|
|
175
|
+
const activeToggles = new Set<HTMLButtonElement>();
|
|
176
|
+
|
|
177
|
+
const setupThemeToggles = (clearExisting = false) => {
|
|
178
|
+
// Clear stale references on page transitions to prevent memory leaks
|
|
179
|
+
if (clearExisting) {
|
|
180
|
+
activeToggles.clear();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
document.querySelectorAll<HTMLButtonElement>(".starwind-theme-toggle").forEach((toggle) => {
|
|
184
|
+
if (!themeToggleInstances.has(toggle)) {
|
|
185
|
+
themeToggleInstances.set(toggle, new ThemeToggleHandler(toggle));
|
|
186
|
+
}
|
|
187
|
+
activeToggles.add(toggle);
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Listen for theme changes from other toggles
|
|
192
|
+
const handleThemeChange = (event: Event) => {
|
|
193
|
+
const { theme } = (event as CustomEvent).detail;
|
|
194
|
+
|
|
195
|
+
activeToggles.forEach((toggle) => {
|
|
196
|
+
const instance = themeToggleInstances.get(toggle);
|
|
197
|
+
if (instance) {
|
|
198
|
+
instance.syncState(theme);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
document.addEventListener("theme:change", handleThemeChange);
|
|
204
|
+
|
|
205
|
+
setupThemeToggles();
|
|
206
|
+
document.addEventListener("astro:after-swap", () => setupThemeToggles(true));
|
|
207
|
+
document.addEventListener("starwind:init", () => setupThemeToggles());
|
|
208
|
+
</script>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
export const toastDescription = tv({
|
|
6
|
+
base: "starwind-toast-description text-muted-foreground text-sm",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
type Props = HTMLAttributes<"div">;
|
|
10
|
+
|
|
11
|
+
const { class: className, ...rest } = Astro.props;
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<div
|
|
15
|
+
class={toastDescription({ class: className })}
|
|
16
|
+
data-slot="toast-description"
|
|
17
|
+
data-toast-description
|
|
18
|
+
{...rest}
|
|
19
|
+
>
|
|
20
|
+
<slot />
|
|
21
|
+
</div>
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
export const toastItem = tv({
|
|
7
|
+
base: "starwind-toast bg-popover text-popover-foreground pointer-events-auto absolute inset-x-0 bottom-0 flex w-full origin-bottom flex-col gap-1 overflow-hidden rounded-lg border bg-clip-padding p-4 pr-10 shadow-lg transition-[transform,opacity] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] data-limited:pointer-events-none data-limited:opacity-0",
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "border-border",
|
|
11
|
+
success: "border-success/80",
|
|
12
|
+
error: "border-error/80",
|
|
13
|
+
warning: "border-warning/80",
|
|
14
|
+
info: "border-info/80",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
variant: "default",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
type Variant = "default" | "success" | "error" | "warning" | "info";
|
|
23
|
+
|
|
24
|
+
type Props = HTMLAttributes<"div"> & {
|
|
25
|
+
variant?: Variant;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const { class: className, variant = "default", ...rest } = Astro.props;
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
<div
|
|
32
|
+
class={toastItem({ variant, class: className })}
|
|
33
|
+
data-slot="toast"
|
|
34
|
+
data-variant={variant}
|
|
35
|
+
data-state="open"
|
|
36
|
+
role="dialog"
|
|
37
|
+
aria-modal="false"
|
|
38
|
+
{...rest}
|
|
39
|
+
>
|
|
40
|
+
<div
|
|
41
|
+
class="starwind-toast-content grid gap-1 transition-opacity duration-200 data-behind:opacity-0 data-expanded:opacity-100"
|
|
42
|
+
data-slot="toast-content"
|
|
43
|
+
>
|
|
44
|
+
<slot />
|
|
45
|
+
</div>
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
class="starwind-toast-close text-muted-foreground hover:text-foreground absolute top-2 right-2 rounded-md p-1 opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:outline-none"
|
|
49
|
+
data-slot="toast-close"
|
|
50
|
+
aria-label="Close notification"
|
|
51
|
+
>
|
|
52
|
+
<X class="size-4" />
|
|
53
|
+
</button>
|
|
54
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
import ToastDescription from "./ToastDescription.astro";
|
|
3
|
+
import ToastItem from "./ToastItem.astro";
|
|
4
|
+
import ToastTitle from "./ToastTitle.astro";
|
|
5
|
+
|
|
6
|
+
type Variant = "default" | "success" | "error" | "warning" | "info" | "loading";
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
variant: Variant;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { variant } = Astro.props;
|
|
13
|
+
|
|
14
|
+
// Loading variant uses default item styling but loading title styling
|
|
15
|
+
const itemVariant = variant === "loading" ? "default" : variant;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<template data-toast-template={variant}>
|
|
19
|
+
<slot>
|
|
20
|
+
<ToastItem variant={itemVariant}>
|
|
21
|
+
<ToastTitle variant={variant}>Title</ToastTitle>
|
|
22
|
+
<ToastDescription>Description</ToastDescription>
|
|
23
|
+
</ToastItem>
|
|
24
|
+
</slot>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
import WarningIcon from "@tabler/icons/outline/alert-triangle.svg";
|
|
3
|
+
import SuccessIcon from "@tabler/icons/outline/circle-check.svg";
|
|
4
|
+
import ErrorIcon from "@tabler/icons/outline/circle-x.svg";
|
|
5
|
+
import InfoIcon from "@tabler/icons/outline/info-circle.svg";
|
|
6
|
+
import LoaderIcon from "@tabler/icons/outline/loader-2.svg";
|
|
7
|
+
import type { HTMLAttributes } from "astro/types";
|
|
8
|
+
import { tv } from "tailwind-variants";
|
|
9
|
+
|
|
10
|
+
export const toastTitle = tv({
|
|
11
|
+
base: "starwind-toast-title flex items-center gap-1 text-sm font-semibold [&_svg]:size-4",
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: "",
|
|
15
|
+
success: "[&_svg]:text-success",
|
|
16
|
+
error: "[&_svg]:text-error",
|
|
17
|
+
warning: "[&_svg]:text-warning",
|
|
18
|
+
info: "[&_svg]:text-info",
|
|
19
|
+
loading: "[&_svg]:text-muted-foreground",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: {
|
|
23
|
+
variant: "default",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
type Variant = "default" | "success" | "error" | "warning" | "info" | "loading";
|
|
28
|
+
|
|
29
|
+
type Props = HTMLAttributes<"div"> & {
|
|
30
|
+
variant?: Variant;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { class: className, variant = "default", ...rest } = Astro.props;
|
|
34
|
+
|
|
35
|
+
const icons = {
|
|
36
|
+
default: null,
|
|
37
|
+
success: SuccessIcon,
|
|
38
|
+
error: ErrorIcon,
|
|
39
|
+
warning: WarningIcon,
|
|
40
|
+
info: InfoIcon,
|
|
41
|
+
loading: LoaderIcon,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const Icon = icons[variant];
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
<div
|
|
48
|
+
class={toastTitle({ variant, class: className })}
|
|
49
|
+
data-slot="toast-title"
|
|
50
|
+
data-toast-title
|
|
51
|
+
{...rest}
|
|
52
|
+
>
|
|
53
|
+
<slot name="icon">
|
|
54
|
+
{Icon && (variant === "loading" ? <Icon class="animate-spin" /> : <Icon />)}
|
|
55
|
+
</slot>
|
|
56
|
+
<span data-toast-title-text><slot /></span>
|
|
57
|
+
</div>
|