@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component metadata interface describing a Starwind UI component
|
|
3
|
+
*/
|
|
4
|
+
interface ComponentMeta {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
type: "component";
|
|
8
|
+
dependencies: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Registry interface containing all available components
|
|
12
|
+
*/
|
|
13
|
+
interface Registry {
|
|
14
|
+
components: ComponentMeta[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the absolute path to a component file
|
|
18
|
+
* @param {string} componentName - The name of the component
|
|
19
|
+
* @param {string} fileName - The name of the file within the component
|
|
20
|
+
* @returns {string} The absolute path to the component file
|
|
21
|
+
*/
|
|
22
|
+
declare const getComponentPath: (componentName: string, fileName: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Map of all components and their metadata from registry
|
|
25
|
+
*/
|
|
26
|
+
declare const registry: ComponentMeta[];
|
|
27
|
+
|
|
28
|
+
export { type ComponentMeta, type Registry, getComponentPath, registry };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
// src/registry.json
|
|
6
|
+
var registry_default = {
|
|
7
|
+
$schema: "https://starwind.dev/registry-schema.json",
|
|
8
|
+
components: [
|
|
9
|
+
{ name: "accordion", type: "component", version: "1.3.3", dependencies: [] },
|
|
10
|
+
{ name: "alert", type: "component", version: "1.3.0", dependencies: [] },
|
|
11
|
+
{
|
|
12
|
+
name: "alert-dialog",
|
|
13
|
+
type: "component",
|
|
14
|
+
version: "1.0.3",
|
|
15
|
+
dependencies: ["@starwind-ui/core/button@^2.1.0"]
|
|
16
|
+
},
|
|
17
|
+
{ name: "aspect-ratio", type: "component", version: "1.0.0", dependencies: [] },
|
|
18
|
+
{ name: "avatar", type: "component", version: "1.2.1", dependencies: [] },
|
|
19
|
+
{ name: "badge", type: "component", version: "1.4.0", dependencies: [] },
|
|
20
|
+
{ name: "breadcrumb", type: "component", version: "1.1.1", dependencies: [] },
|
|
21
|
+
{
|
|
22
|
+
name: "button-group",
|
|
23
|
+
type: "component",
|
|
24
|
+
version: "1.0.0",
|
|
25
|
+
dependencies: ["@starwind-ui/core/separator@^1.0.0"]
|
|
26
|
+
},
|
|
27
|
+
{ name: "button", type: "component", version: "2.3.0", dependencies: [] },
|
|
28
|
+
{ name: "card", type: "component", version: "1.3.0", dependencies: [] },
|
|
29
|
+
{
|
|
30
|
+
name: "carousel",
|
|
31
|
+
type: "component",
|
|
32
|
+
version: "1.0.1",
|
|
33
|
+
dependencies: ["@starwind-ui/core/button@^2.1.0", "embla-carousel@^8.6.0"]
|
|
34
|
+
},
|
|
35
|
+
{ name: "checkbox", type: "component", version: "1.4.1", dependencies: [] },
|
|
36
|
+
{ name: "collapsible", type: "component", version: "1.0.0", dependencies: [] },
|
|
37
|
+
{ name: "dialog", type: "component", version: "1.4.3", dependencies: [] },
|
|
38
|
+
{ name: "dropdown", type: "component", version: "1.2.3", dependencies: [] },
|
|
39
|
+
{ name: "dropzone", type: "component", version: "1.2.2", dependencies: [] },
|
|
40
|
+
{ name: "image", type: "component", version: "1.0.0", dependencies: [] },
|
|
41
|
+
{ name: "input", type: "component", version: "1.3.1", dependencies: [] },
|
|
42
|
+
{ name: "input-otp", type: "component", version: "1.0.1", dependencies: [] },
|
|
43
|
+
{
|
|
44
|
+
name: "item",
|
|
45
|
+
type: "component",
|
|
46
|
+
version: "1.0.0",
|
|
47
|
+
dependencies: ["@starwind-ui/core/separator@^1.0.0"]
|
|
48
|
+
},
|
|
49
|
+
{ name: "kbd", type: "component", version: "1.0.0", dependencies: [] },
|
|
50
|
+
{ name: "label", type: "component", version: "1.2.0", dependencies: [] },
|
|
51
|
+
{ name: "pagination", type: "component", version: "3.0.2", dependencies: [] },
|
|
52
|
+
{ name: "progress", type: "component", version: "1.1.1", dependencies: [] },
|
|
53
|
+
{ name: "prose", type: "component", version: "1.0.0", dependencies: [] },
|
|
54
|
+
{ name: "radio-group", type: "component", version: "1.2.4", dependencies: [] },
|
|
55
|
+
{ name: "select", type: "component", version: "1.8.3", dependencies: [] },
|
|
56
|
+
{ name: "separator", type: "component", version: "1.0.0", dependencies: [] },
|
|
57
|
+
{
|
|
58
|
+
name: "sheet",
|
|
59
|
+
type: "component",
|
|
60
|
+
version: "1.1.1",
|
|
61
|
+
dependencies: ["@starwind-ui/core/dialog@^1.3.0"]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "sidebar",
|
|
65
|
+
type: "component",
|
|
66
|
+
version: "1.0.0",
|
|
67
|
+
dependencies: [
|
|
68
|
+
"@starwind-ui/core/button@^2.3.0",
|
|
69
|
+
"@starwind-ui/core/dialog@^1.4.3",
|
|
70
|
+
"@starwind-ui/core/input@^1.3.1",
|
|
71
|
+
"@starwind-ui/core/separator@^1.0.0",
|
|
72
|
+
"@starwind-ui/core/sheet@^1.1.1",
|
|
73
|
+
"@starwind-ui/core/skeleton@^1.2.0",
|
|
74
|
+
"@starwind-ui/core/tooltip@^1.4.0"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{ name: "skeleton", type: "component", version: "1.2.0", dependencies: [] },
|
|
78
|
+
{ name: "slider", type: "component", version: "1.0.0", dependencies: [] },
|
|
79
|
+
{ name: "spinner", type: "component", version: "1.0.0", dependencies: [] },
|
|
80
|
+
{ name: "switch", type: "component", version: "1.3.1", dependencies: [] },
|
|
81
|
+
{ name: "table", type: "component", version: "1.1.0", dependencies: [] },
|
|
82
|
+
{ name: "tabs", type: "component", version: "1.4.1", dependencies: [] },
|
|
83
|
+
{ name: "textarea", type: "component", version: "1.3.1", dependencies: [] },
|
|
84
|
+
{
|
|
85
|
+
name: "theme-toggle",
|
|
86
|
+
type: "component",
|
|
87
|
+
version: "1.0.0",
|
|
88
|
+
dependencies: ["@starwind-ui/core/toggle@^1.0.1"]
|
|
89
|
+
},
|
|
90
|
+
{ name: "toast", type: "component", version: "1.0.0", dependencies: [] },
|
|
91
|
+
{ name: "toggle", type: "component", version: "1.0.1", dependencies: [] },
|
|
92
|
+
{ name: "tooltip", type: "component", version: "1.4.0", dependencies: [] },
|
|
93
|
+
{ name: "video", type: "component", version: "1.0.0", dependencies: [] }
|
|
94
|
+
]
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/index.ts
|
|
98
|
+
var __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
99
|
+
var getComponentPath = (componentName, fileName) => {
|
|
100
|
+
const componentsDir = __dirname.includes("dist") ? "src/components" : "src/components";
|
|
101
|
+
return join(__dirname, componentsDir, componentName, fileName);
|
|
102
|
+
};
|
|
103
|
+
var registry = registry_default.components;
|
|
104
|
+
export {
|
|
105
|
+
getComponentPath,
|
|
106
|
+
registry
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/registry.json"],"sourcesContent":["import { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport componentRegistry from \"./registry.json\" with { type: \"json\" };\n\n/**\n * Component metadata interface describing a Starwind UI component\n */\nexport interface ComponentMeta {\n name: string;\n version: string;\n type: \"component\";\n dependencies: string[];\n}\n\n/**\n * Registry interface containing all available components\n */\nexport interface Registry {\n components: ComponentMeta[];\n}\n\nconst __dirname = fileURLToPath(new URL(\".\", import.meta.url));\n\n/**\n * Get the absolute path to a component file\n * @param {string} componentName - The name of the component\n * @param {string} fileName - The name of the file within the component\n * @returns {string} The absolute path to the component file\n */\nexport const getComponentPath = (componentName: string, fileName: string): string => {\n // In production (when installed as a dependency), the components will be in dist/src/components\n // In development, they will be in src/components\n const componentsDir = __dirname.includes(\"dist\") ? \"src/components\" : \"src/components\";\n return join(__dirname, componentsDir, componentName, fileName);\n};\n\n/**\n * Map of all components and their metadata from registry\n */\nexport const registry = componentRegistry.components as ComponentMeta[];\n","{\n \"$schema\": \"https://starwind.dev/registry-schema.json\",\n \"components\": [\n { \"name\": \"accordion\", \"type\": \"component\", \"version\": \"1.3.3\", \"dependencies\": [] },\n { \"name\": \"alert\", \"type\": \"component\", \"version\": \"1.3.0\", \"dependencies\": [] },\n {\n \"name\": \"alert-dialog\",\n \"type\": \"component\",\n \"version\": \"1.0.3\",\n \"dependencies\": [\"@starwind-ui/core/button@^2.1.0\"]\n },\n { \"name\": \"aspect-ratio\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"avatar\", \"type\": \"component\", \"version\": \"1.2.1\", \"dependencies\": [] },\n { \"name\": \"badge\", \"type\": \"component\", \"version\": \"1.4.0\", \"dependencies\": [] },\n { \"name\": \"breadcrumb\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n {\n \"name\": \"button-group\",\n \"type\": \"component\",\n \"version\": \"1.0.0\",\n \"dependencies\": [\"@starwind-ui/core/separator@^1.0.0\"]\n },\n { \"name\": \"button\", \"type\": \"component\", \"version\": \"2.3.0\", \"dependencies\": [] },\n { \"name\": \"card\", \"type\": \"component\", \"version\": \"1.3.0\", \"dependencies\": [] },\n {\n \"name\": \"carousel\",\n \"type\": \"component\",\n \"version\": \"1.0.1\",\n \"dependencies\": [\"@starwind-ui/core/button@^2.1.0\", \"embla-carousel@^8.6.0\"]\n },\n { \"name\": \"checkbox\", \"type\": \"component\", \"version\": \"1.4.1\", \"dependencies\": [] },\n { \"name\": \"collapsible\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"dialog\", \"type\": \"component\", \"version\": \"1.4.3\", \"dependencies\": [] },\n { \"name\": \"dropdown\", \"type\": \"component\", \"version\": \"1.2.3\", \"dependencies\": [] },\n { \"name\": \"dropzone\", \"type\": \"component\", \"version\": \"1.2.2\", \"dependencies\": [] },\n { \"name\": \"image\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"input\", \"type\": \"component\", \"version\": \"1.3.1\", \"dependencies\": [] },\n { \"name\": \"input-otp\", \"type\": \"component\", \"version\": \"1.0.1\", \"dependencies\": [] },\n {\n \"name\": \"item\",\n \"type\": \"component\",\n \"version\": \"1.0.0\",\n \"dependencies\": [\"@starwind-ui/core/separator@^1.0.0\"]\n },\n { \"name\": \"kbd\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"label\", \"type\": \"component\", \"version\": \"1.2.0\", \"dependencies\": [] },\n { \"name\": \"pagination\", \"type\": \"component\", \"version\": \"3.0.2\", \"dependencies\": [] },\n { \"name\": \"progress\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"prose\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"radio-group\", \"type\": \"component\", \"version\": \"1.2.4\", \"dependencies\": [] },\n { \"name\": \"select\", \"type\": \"component\", \"version\": \"1.8.3\", \"dependencies\": [] },\n { \"name\": \"separator\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n {\n \"name\": \"sheet\",\n \"type\": \"component\",\n \"version\": \"1.1.1\",\n \"dependencies\": [\"@starwind-ui/core/dialog@^1.3.0\"]\n },\n {\n \"name\": \"sidebar\",\n \"type\": \"component\",\n \"version\": \"1.0.0\",\n \"dependencies\": [\n \"@starwind-ui/core/button@^2.3.0\",\n \"@starwind-ui/core/dialog@^1.4.3\",\n \"@starwind-ui/core/input@^1.3.1\",\n \"@starwind-ui/core/separator@^1.0.0\",\n \"@starwind-ui/core/sheet@^1.1.1\",\n \"@starwind-ui/core/skeleton@^1.2.0\",\n \"@starwind-ui/core/tooltip@^1.4.0\"\n ]\n },\n { \"name\": \"skeleton\", \"type\": \"component\", \"version\": \"1.2.0\", \"dependencies\": [] },\n { \"name\": \"slider\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"spinner\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"switch\", \"type\": \"component\", \"version\": \"1.3.1\", \"dependencies\": [] },\n { \"name\": \"table\", \"type\": \"component\", \"version\": \"1.1.0\", \"dependencies\": [] },\n { \"name\": \"tabs\", \"type\": \"component\", \"version\": \"1.4.1\", \"dependencies\": [] },\n { \"name\": \"textarea\", \"type\": \"component\", \"version\": \"1.3.1\", \"dependencies\": [] },\n {\n \"name\": \"theme-toggle\",\n \"type\": \"component\",\n \"version\": \"1.0.0\",\n \"dependencies\": [\"@starwind-ui/core/toggle@^1.0.1\"]\n },\n { \"name\": \"toast\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"toggle\", \"type\": \"component\", \"version\": \"1.0.1\", \"dependencies\": [] },\n { \"name\": \"tooltip\", \"type\": \"component\", \"version\": \"1.4.0\", \"dependencies\": [] },\n { \"name\": \"video\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] }\n ]\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
type Props = HTMLAttributes<"div"> & {
|
|
6
|
+
/**
|
|
7
|
+
* The type of accordion. If "single", only one item can be open at a time.
|
|
8
|
+
*/
|
|
9
|
+
type?: "single" | "multiple";
|
|
10
|
+
/**
|
|
11
|
+
* The value of the item that should be open by default
|
|
12
|
+
*/
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const accordion = tv({ base: "starwind-accordion" });
|
|
17
|
+
|
|
18
|
+
const { type = "single", defaultValue, class: className, ...rest } = Astro.props;
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
<div
|
|
22
|
+
class={accordion({ class: className })}
|
|
23
|
+
data-type={type}
|
|
24
|
+
data-value={defaultValue}
|
|
25
|
+
data-slot="accordion"
|
|
26
|
+
{...rest}
|
|
27
|
+
>
|
|
28
|
+
<slot />
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<script>
|
|
32
|
+
type AccordionType = "single" | "multiple";
|
|
33
|
+
type AccordionState = "open" | "closed";
|
|
34
|
+
|
|
35
|
+
/** Represents a single accordion item with its associated elements */
|
|
36
|
+
interface AccordionItem {
|
|
37
|
+
element: HTMLElement;
|
|
38
|
+
trigger: HTMLElement;
|
|
39
|
+
content: HTMLElement;
|
|
40
|
+
value: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Handles the functionality of an accordion component.
|
|
45
|
+
* Supports single and multiple open items, keyboard navigation,
|
|
46
|
+
* and maintains ARIA accessibility standards.
|
|
47
|
+
*/
|
|
48
|
+
class AccordionHandler {
|
|
49
|
+
private accordion: HTMLElement;
|
|
50
|
+
private type: AccordionType;
|
|
51
|
+
private items: AccordionItem[];
|
|
52
|
+
private itemsByValue: Map<string, AccordionItem>;
|
|
53
|
+
private accordionId: string;
|
|
54
|
+
private isInitialized: boolean = false;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new AccordionHandler instance
|
|
58
|
+
* @param accordion - The root accordion element
|
|
59
|
+
* @param idx - Unique index for this accordion instance
|
|
60
|
+
*/
|
|
61
|
+
constructor(accordion: HTMLElement, idx: number) {
|
|
62
|
+
this.accordion = accordion;
|
|
63
|
+
this.type = (accordion.dataset.type || "single") as AccordionType;
|
|
64
|
+
this.accordionId = `starwind-accordion${idx}`;
|
|
65
|
+
|
|
66
|
+
// Cache all items and create lookup maps
|
|
67
|
+
this.items = this.initializeItems();
|
|
68
|
+
this.itemsByValue = new Map(this.items.map((item) => [item.value, item]));
|
|
69
|
+
|
|
70
|
+
this.setupItems();
|
|
71
|
+
this.setInitialState();
|
|
72
|
+
this.isInitialized = true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Initializes accordion items by querying the DOM and setting up data structures
|
|
77
|
+
* @returns Array of AccordionItem objects
|
|
78
|
+
*/
|
|
79
|
+
private initializeItems(): AccordionItem[] {
|
|
80
|
+
return Array.from(this.accordion.querySelectorAll<HTMLElement>(".starwind-accordion-item"))
|
|
81
|
+
.map((element, idx) => {
|
|
82
|
+
const trigger = element.querySelector<HTMLElement>(".starwind-accordion-trigger");
|
|
83
|
+
const content = element.querySelector<HTMLElement>(".starwind-accordion-content");
|
|
84
|
+
const value = element.getAttribute("data-value") || String(idx);
|
|
85
|
+
|
|
86
|
+
if (!trigger || !content) return null;
|
|
87
|
+
|
|
88
|
+
return { element, trigger, content, value };
|
|
89
|
+
})
|
|
90
|
+
.filter((item): item is AccordionItem => item !== null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sets up initial state and event listeners for all accordion items
|
|
95
|
+
*/
|
|
96
|
+
private setupItems(): void {
|
|
97
|
+
this.items.forEach((item, idx) => {
|
|
98
|
+
this.setupAccessibility(item, idx);
|
|
99
|
+
this.setContentHeight(item.content);
|
|
100
|
+
this.setupEventListeners(item);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets up ARIA attributes and IDs for accessibility
|
|
106
|
+
* @param item - The accordion item to setup
|
|
107
|
+
* @param idx - Index of the item
|
|
108
|
+
*/
|
|
109
|
+
private setupAccessibility(item: AccordionItem, idx: number): void {
|
|
110
|
+
const triggerId = `${this.accordionId}-t${idx}`;
|
|
111
|
+
const contentId = `${this.accordionId}-c${idx}`;
|
|
112
|
+
|
|
113
|
+
item.trigger.id = triggerId;
|
|
114
|
+
item.trigger.setAttribute("aria-controls", contentId);
|
|
115
|
+
item.trigger.setAttribute("aria-expanded", "false");
|
|
116
|
+
|
|
117
|
+
item.content.id = contentId;
|
|
118
|
+
item.content.setAttribute("aria-labelledby", triggerId);
|
|
119
|
+
item.content.setAttribute("role", "region");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Calculates and sets the content height CSS variable for animations
|
|
124
|
+
* @param content - The content element to measure
|
|
125
|
+
*/
|
|
126
|
+
private setContentHeight(content: HTMLElement): void {
|
|
127
|
+
const contentInner = content.firstElementChild as HTMLElement;
|
|
128
|
+
if (contentInner) {
|
|
129
|
+
const height = contentInner.getBoundingClientRect().height;
|
|
130
|
+
content.style.setProperty("--starwind-accordion-content-height", `${height}px`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sets the initial state based on the default value attribute
|
|
136
|
+
*/
|
|
137
|
+
private setInitialState(): void {
|
|
138
|
+
const defaultValue = this.accordion.dataset.value;
|
|
139
|
+
if (defaultValue) {
|
|
140
|
+
const item = this.itemsByValue.get(defaultValue);
|
|
141
|
+
if (item) {
|
|
142
|
+
this.setItemState(item, true);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Sets up click and keyboard event listeners for an accordion item
|
|
149
|
+
* @param item - The accordion item to setup listeners for
|
|
150
|
+
*/
|
|
151
|
+
private setupEventListeners(item: AccordionItem): void {
|
|
152
|
+
item.trigger.addEventListener("click", () => this.handleClick(item));
|
|
153
|
+
item.trigger.addEventListener("keydown", (e) => this.handleKeyDown(e, item));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Handles click events on accordion triggers
|
|
158
|
+
* @param item - The clicked accordion item
|
|
159
|
+
*/
|
|
160
|
+
private handleClick(item: AccordionItem): void {
|
|
161
|
+
const isOpen = item.element.getAttribute("data-state") === "open";
|
|
162
|
+
this.toggleItem(item, !isOpen);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Handles keyboard navigation events
|
|
167
|
+
* @param event - The keyboard event
|
|
168
|
+
* @param item - The current accordion item
|
|
169
|
+
*/
|
|
170
|
+
private handleKeyDown(event: KeyboardEvent, item: AccordionItem): void {
|
|
171
|
+
const index = this.items.indexOf(item);
|
|
172
|
+
|
|
173
|
+
const keyActions: Record<string, () => void> = {
|
|
174
|
+
ArrowDown: () => this.focusItem(index + 1),
|
|
175
|
+
ArrowUp: () => this.focusItem(index - 1),
|
|
176
|
+
Home: () => this.focusItem(0),
|
|
177
|
+
End: () => this.focusItem(this.items.length - 1),
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const action = keyActions[event.key];
|
|
181
|
+
if (action) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
action();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Focuses an accordion item by index with wrapping
|
|
189
|
+
* @param index - The target index to focus
|
|
190
|
+
*/
|
|
191
|
+
private focusItem(index: number): void {
|
|
192
|
+
const targetIndex = (index + this.items.length) % this.items.length;
|
|
193
|
+
this.items[targetIndex].trigger.focus();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Toggles an accordion item's state
|
|
198
|
+
* @param item - The item to toggle
|
|
199
|
+
* @param shouldOpen - Whether the item should be opened
|
|
200
|
+
*/
|
|
201
|
+
private toggleItem(item: AccordionItem, shouldOpen: boolean): void {
|
|
202
|
+
if (this.type === "single" && shouldOpen) {
|
|
203
|
+
// Close other items if in single mode
|
|
204
|
+
this.items.forEach((otherItem) => {
|
|
205
|
+
if (otherItem !== item && otherItem.element.getAttribute("data-state") === "open") {
|
|
206
|
+
this.setItemState(otherItem, false);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.setItemState(item, shouldOpen);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Sets the state of an accordion item
|
|
216
|
+
* @param item - The item to update
|
|
217
|
+
* @param isOpen - Whether the item should be open
|
|
218
|
+
*/
|
|
219
|
+
private setItemState(item: AccordionItem, isOpen: boolean): void {
|
|
220
|
+
const state: AccordionState = isOpen ? "open" : "closed";
|
|
221
|
+
|
|
222
|
+
// Skip animation during initial setup, enable for subsequent toggles
|
|
223
|
+
if (!this.isInitialized) {
|
|
224
|
+
item.content.style.setProperty("animation", "none");
|
|
225
|
+
} else {
|
|
226
|
+
item.content.style.removeProperty("animation");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Set content height variable for animations
|
|
230
|
+
this.setContentHeight(item.content);
|
|
231
|
+
|
|
232
|
+
item.element.setAttribute("data-state", state);
|
|
233
|
+
item.content.setAttribute("data-state", state);
|
|
234
|
+
item.trigger.setAttribute("data-state", state);
|
|
235
|
+
item.trigger.setAttribute("aria-expanded", isOpen.toString());
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Store instances in a WeakMap to avoid memory leaks
|
|
240
|
+
const accordionInstances = new WeakMap<HTMLElement, AccordionHandler>();
|
|
241
|
+
let accordionCounter = 0;
|
|
242
|
+
|
|
243
|
+
const setupAccordions = () => {
|
|
244
|
+
document.querySelectorAll<HTMLElement>(".starwind-accordion").forEach((accordion) => {
|
|
245
|
+
if (!accordionInstances.has(accordion)) {
|
|
246
|
+
accordionInstances.set(accordion, new AccordionHandler(accordion, accordionCounter++));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
setupAccordions();
|
|
252
|
+
document.addEventListener("astro:after-swap", setupAccordions);
|
|
253
|
+
document.addEventListener("starwind:init", setupAccordions);
|
|
254
|
+
</script>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: style="animation: none;" makes it so the close animation doesn't run on page load
|
|
4
|
+
* It is later removed in the Accordion.astro script
|
|
5
|
+
*/
|
|
6
|
+
import type { HTMLAttributes } from "astro/types";
|
|
7
|
+
import { tv } from "tailwind-variants";
|
|
8
|
+
|
|
9
|
+
type Props = HTMLAttributes<"div">;
|
|
10
|
+
|
|
11
|
+
export const accordionContent = tv({
|
|
12
|
+
base: [
|
|
13
|
+
"starwind-accordion-content",
|
|
14
|
+
"transform-gpu overflow-hidden",
|
|
15
|
+
"data-[state=closed]:animate-accordion-up data-[state=closed]:h-0",
|
|
16
|
+
"data-[state=open]:animate-accordion-down",
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { class: className, ...rest } = Astro.props;
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<div
|
|
24
|
+
class={accordionContent({ class: className })}
|
|
25
|
+
data-state="closed"
|
|
26
|
+
style="animation: none;"
|
|
27
|
+
data-slot="accordion-content"
|
|
28
|
+
{...rest}
|
|
29
|
+
>
|
|
30
|
+
<div class="pt-0 pb-4">
|
|
31
|
+
<slot />
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
type Props = HTMLAttributes<"div"> & {
|
|
6
|
+
/**
|
|
7
|
+
* The value of the item
|
|
8
|
+
*/
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const accordionItem = tv({
|
|
13
|
+
base: "starwind-accordion-item border-b last:border-b-0",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const { value, class: className, ...rest } = Astro.props;
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<div
|
|
20
|
+
class={accordionItem({ class: className })}
|
|
21
|
+
data-value={value}
|
|
22
|
+
data-state="closed"
|
|
23
|
+
data-slot="accordion-item"
|
|
24
|
+
{...rest}
|
|
25
|
+
>
|
|
26
|
+
<slot />
|
|
27
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
import ChevronDown from "@tabler/icons/outline/chevron-down.svg";
|
|
3
|
+
import type { HTMLAttributes } from "astro/types";
|
|
4
|
+
import { tv } from "tailwind-variants";
|
|
5
|
+
|
|
6
|
+
type Props = HTMLAttributes<"button">;
|
|
7
|
+
|
|
8
|
+
export const accordionTrigger = tv({
|
|
9
|
+
base: [
|
|
10
|
+
"starwind-accordion-trigger",
|
|
11
|
+
"flex w-full items-center justify-between gap-4 rounded-md py-4",
|
|
12
|
+
"hover:text-muted-foreground text-left font-medium transition-all",
|
|
13
|
+
"[&[data-state=open]>svg]:rotate-180",
|
|
14
|
+
"focus-visible:border-outline focus-visible:ring-outline/50 outline-none focus-visible:ring-3",
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const { class: className, ...rest } = Astro.props;
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
class={accordionTrigger({ class: className })}
|
|
24
|
+
data-slot="accordion-trigger"
|
|
25
|
+
aria-expanded="false"
|
|
26
|
+
{...rest}
|
|
27
|
+
>
|
|
28
|
+
<slot />
|
|
29
|
+
<slot name="icon">
|
|
30
|
+
<ChevronDown class="size-5 shrink-0 transition-transform duration-200" />
|
|
31
|
+
</slot>
|
|
32
|
+
</button>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Accordion, { accordion } from "./Accordion.astro";
|
|
2
|
+
import AccordionContent, { accordionContent } from "./AccordionContent.astro";
|
|
3
|
+
import AccordionItem, { accordionItem } from "./AccordionItem.astro";
|
|
4
|
+
import AccordionTrigger, { accordionTrigger } from "./AccordionTrigger.astro";
|
|
5
|
+
|
|
6
|
+
const AccordionVariants = { accordion, accordionContent, accordionItem, accordionTrigger };
|
|
7
|
+
|
|
8
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AccordionVariants };
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
Root: Accordion,
|
|
12
|
+
Content: AccordionContent,
|
|
13
|
+
Item: AccordionItem,
|
|
14
|
+
Trigger: AccordionTrigger,
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv, type VariantProps } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
type Props = HTMLAttributes<"div"> & VariantProps<typeof alert>;
|
|
6
|
+
|
|
7
|
+
export const alert = tv({
|
|
8
|
+
base: "text-foreground relative w-full rounded-lg border p-4",
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-background dark:bg-input/30 [&>h5>svg]:text-foreground",
|
|
12
|
+
primary: "border-primary bg-primary/7 [&>h5>svg]:text-primary",
|
|
13
|
+
secondary: "border-secondary bg-secondary/7 [&>h5>svg]:text-secondary",
|
|
14
|
+
info: "border-info bg-info/7 [&>h5>svg]:text-info",
|
|
15
|
+
success: "border-success bg-success/7 [&>h5>svg]:text-success",
|
|
16
|
+
warning: "border-warning bg-warning/7 [&>h5>svg]:text-warning",
|
|
17
|
+
error: "border-error bg-error/7 [&>h5>svg]:text-error",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: { variant: "default" },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const { variant, class: className, ...rest } = Astro.props;
|
|
24
|
+
|
|
25
|
+
const inferredRole =
|
|
26
|
+
rest.role ?? (variant === "error" || variant === "warning" ? "alert" : "status");
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<div class={alert({ variant, class: className })} data-slot="alert" role={inferredRole} {...rest}>
|
|
30
|
+
<slot />
|
|
31
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
export const alertDescription = tv({ base: "leading-relaxed" });
|
|
6
|
+
|
|
7
|
+
type Props = HTMLAttributes<"p">;
|
|
8
|
+
|
|
9
|
+
const { class: className, ...rest } = Astro.props;
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<p class={alertDescription({ class: className })} data-slot="alert-description" {...rest}>
|
|
13
|
+
<slot />
|
|
14
|
+
</p>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { tv } from "tailwind-variants";
|
|
4
|
+
|
|
5
|
+
export const alertTitle = tv({
|
|
6
|
+
base: "font-heading mb-2 flex items-center gap-2 text-lg leading-none font-medium tracking-tight",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
type Props = HTMLAttributes<"h5">;
|
|
10
|
+
|
|
11
|
+
const { class: className, ...rest } = Astro.props;
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<h5 class={alertTitle({ class: className })} data-slot="alert-title" {...rest}>
|
|
15
|
+
<slot />
|
|
16
|
+
</h5>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Alert, { alert } from "./Alert.astro";
|
|
2
|
+
import AlertDescription, { alertDescription } from "./AlertDescription.astro";
|
|
3
|
+
import AlertTitle, { alertTitle } from "./AlertTitle.astro";
|
|
4
|
+
|
|
5
|
+
const AlertVariants = { alert, alertDescription, alertTitle };
|
|
6
|
+
|
|
7
|
+
export { Alert, AlertDescription, AlertTitle, AlertVariants };
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
Root: Alert,
|
|
11
|
+
Description: AlertDescription,
|
|
12
|
+
Title: AlertTitle,
|
|
13
|
+
};
|