@starwind-ui/core 1.6.2 → 1.7.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/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/src/components/accordion/Accordion.astro +224 -224
- package/dist/src/components/accordion/AccordionContent.astro +13 -13
- package/dist/src/components/accordion/AccordionItem.astro +6 -6
- package/dist/src/components/accordion/AccordionTrigger.astro +13 -13
- package/dist/src/components/accordion/index.ts +4 -4
- package/dist/src/components/alert/Alert.astro +15 -15
- package/dist/src/components/alert/AlertDescription.astro +1 -1
- package/dist/src/components/alert/AlertTitle.astro +2 -2
- package/dist/src/components/alert/index.ts +3 -3
- package/dist/src/components/avatar/Avatar.astro +16 -16
- package/dist/src/components/avatar/AvatarFallback.astro +3 -3
- package/dist/src/components/avatar/AvatarImage.astro +12 -12
- package/dist/src/components/avatar/index.ts +4 -4
- package/dist/src/components/badge/Badge.astro +33 -33
- package/dist/src/components/breadcrumb/Breadcrumb.astro +1 -1
- package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +6 -6
- package/dist/src/components/breadcrumb/BreadcrumbItem.astro +1 -1
- package/dist/src/components/breadcrumb/BreadcrumbLink.astro +8 -8
- package/dist/src/components/breadcrumb/BreadcrumbList.astro +2 -2
- package/dist/src/components/breadcrumb/BreadcrumbPage.astro +6 -6
- package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +7 -7
- package/dist/src/components/breadcrumb/index.ts +14 -14
- package/dist/src/components/button/Button.astro +38 -38
- package/dist/src/components/card/Card.astro +1 -1
- package/dist/src/components/card/CardContent.astro +1 -1
- package/dist/src/components/card/CardDescription.astro +1 -1
- package/dist/src/components/card/CardFooter.astro +1 -1
- package/dist/src/components/card/CardHeader.astro +1 -1
- package/dist/src/components/card/CardTitle.astro +1 -1
- package/dist/src/components/card/index.ts +7 -7
- package/dist/src/components/checkbox/Checkbox.astro +89 -89
- package/dist/src/components/dialog/Dialog.astro +237 -178
- package/dist/src/components/dialog/DialogClose.astro +14 -14
- package/dist/src/components/dialog/DialogContent.astro +32 -32
- package/dist/src/components/dialog/DialogDescription.astro +1 -1
- package/dist/src/components/dialog/DialogFooter.astro +1 -1
- package/dist/src/components/dialog/DialogHeader.astro +1 -1
- package/dist/src/components/dialog/DialogTitle.astro +6 -6
- package/dist/src/components/dialog/DialogTrigger.astro +26 -20
- package/dist/src/components/dialog/index.ts +16 -16
- package/dist/src/components/dropdown/Dropdown.astro +359 -359
- package/dist/src/components/dropdown/DropdownContent.astro +63 -63
- package/dist/src/components/dropdown/DropdownItem.astro +31 -31
- package/dist/src/components/dropdown/DropdownLabel.astro +14 -14
- package/dist/src/components/dropdown/DropdownSeparator.astro +5 -5
- package/dist/src/components/dropdown/DropdownTrigger.astro +26 -26
- package/dist/src/components/dropdown/index.ts +12 -12
- package/dist/src/components/dropzone/Dropzone.astro +232 -0
- package/dist/src/components/dropzone/DropzoneFilesList.astro +25 -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 +13 -0
- package/dist/src/components/input/Input.astro +12 -12
- package/dist/src/components/label/Label.astro +8 -8
- package/dist/src/components/pagination/Pagination.astro +1 -1
- package/dist/src/components/pagination/PaginationContent.astro +3 -3
- package/dist/src/components/pagination/PaginationEllipsis.astro +2 -2
- package/dist/src/components/pagination/PaginationItem.astro +3 -3
- package/dist/src/components/pagination/PaginationLink.astro +27 -27
- package/dist/src/components/pagination/PaginationNext.astro +7 -6
- package/dist/src/components/pagination/PaginationPrevious.astro +7 -6
- package/dist/src/components/pagination/index.ts +14 -14
- package/dist/src/components/progress/Progress.astro +151 -0
- package/dist/src/components/progress/index.ts +5 -0
- package/dist/src/components/radio-group/RadioGroup.astro +156 -0
- package/dist/src/components/radio-group/RadioGroupItem.astro +125 -0
- package/dist/src/components/radio-group/RadioGroupTypes.ts +6 -0
- package/dist/src/components/radio-group/index.ts +10 -0
- package/dist/src/components/select/Select.astro +515 -475
- package/dist/src/components/select/SelectContent.astro +62 -62
- package/dist/src/components/select/SelectItem.astro +27 -27
- package/dist/src/components/select/SelectLabel.astro +1 -1
- package/dist/src/components/select/SelectTrigger.astro +28 -28
- package/dist/src/components/select/SelectTypes.ts +11 -5
- package/dist/src/components/select/SelectValue.astro +5 -5
- package/dist/src/components/select/index.ts +16 -16
- package/dist/src/components/skeleton/Skeleton.astro +14 -0
- package/dist/src/components/skeleton/index.ts +5 -0
- package/dist/src/components/switch/Switch.astro +150 -150
- package/dist/src/components/switch/SwitchTypes.ts +4 -4
- package/dist/src/components/table/Table.astro +5 -5
- package/dist/src/components/table/TableBody.astro +3 -3
- package/dist/src/components/table/TableCaption.astro +3 -3
- package/dist/src/components/table/TableCell.astro +3 -3
- package/dist/src/components/table/TableFoot.astro +3 -3
- package/dist/src/components/table/TableHead.astro +3 -3
- package/dist/src/components/table/TableHeader.astro +3 -3
- package/dist/src/components/table/TableRow.astro +3 -3
- package/dist/src/components/table/index.ts +8 -8
- package/dist/src/components/tabs/Tabs.astro +250 -250
- package/dist/src/components/tabs/TabsContent.astro +10 -10
- package/dist/src/components/tabs/TabsList.astro +2 -2
- package/dist/src/components/tabs/TabsTrigger.astro +15 -15
- package/dist/src/components/tabs/index.ts +4 -4
- package/dist/src/components/textarea/Textarea.astro +16 -16
- package/dist/src/components/tooltip/Tooltip.astro +217 -217
- package/dist/src/components/tooltip/TooltipContent.astro +81 -81
- package/dist/src/components/tooltip/index.ts +3 -3
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { join } from "
|
|
3
|
-
import { fileURLToPath } from "
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
4
|
|
|
5
5
|
// src/registry.json
|
|
6
6
|
var registry_default = {
|
|
@@ -14,12 +14,16 @@ var registry_default = {
|
|
|
14
14
|
{ name: "button", type: "component", version: "2.0.1", dependencies: [] },
|
|
15
15
|
{ name: "card", type: "component", version: "1.1.0", dependencies: [] },
|
|
16
16
|
{ name: "checkbox", type: "component", version: "1.2.0", dependencies: [] },
|
|
17
|
-
{ name: "dialog", type: "component", version: "1.
|
|
17
|
+
{ name: "dialog", type: "component", version: "1.2.0", dependencies: [] },
|
|
18
18
|
{ name: "dropdown", type: "component", version: "1.0.3", dependencies: [] },
|
|
19
|
+
{ name: "dropzone", type: "component", version: "1.0.0", dependencies: [] },
|
|
19
20
|
{ name: "input", type: "component", version: "1.1.1", dependencies: [] },
|
|
20
21
|
{ name: "label", type: "component", version: "1.1.1", dependencies: [] },
|
|
21
22
|
{ name: "pagination", type: "component", version: "2.0.1", dependencies: [] },
|
|
22
|
-
{ name: "
|
|
23
|
+
{ name: "progress", type: "component", version: "1.0.0", dependencies: [] },
|
|
24
|
+
{ name: "radio-group", type: "component", version: "1.0.0", dependencies: [] },
|
|
25
|
+
{ name: "select", type: "component", version: "1.4.0", dependencies: [] },
|
|
26
|
+
{ name: "skeleton", type: "component", version: "1.0.0", dependencies: [] },
|
|
23
27
|
{ name: "switch", type: "component", version: "1.1.0", dependencies: [] },
|
|
24
28
|
{ name: "table", type: "component", version: "1.0.0", dependencies: [] },
|
|
25
29
|
{ name: "tabs", type: "component", version: "1.2.0", dependencies: [] },
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/registry.json"],"sourcesContent":["import { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport componentRegistry from \"./registry.json\" with { type: \"json\" };\n\n/**\n * Component metadata interface describing a Starwind UI component\n */\nexport interface ComponentMeta {\n
|
|
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.1.0\", \"dependencies\": [] },\n { \"name\": \"alert\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"avatar\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"badge\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"breadcrumb\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"button\", \"type\": \"component\", \"version\": \"2.0.1\", \"dependencies\": [] },\n { \"name\": \"card\", \"type\": \"component\", \"version\": \"1.1.0\", \"dependencies\": [] },\n { \"name\": \"checkbox\", \"type\": \"component\", \"version\": \"1.2.0\", \"dependencies\": [] },\n { \"name\": \"dialog\", \"type\": \"component\", \"version\": \"1.2.0\", \"dependencies\": [] },\n { \"name\": \"dropdown\", \"type\": \"component\", \"version\": \"1.0.3\", \"dependencies\": [] },\n { \"name\": \"dropzone\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"input\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"label\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"pagination\", \"type\": \"component\", \"version\": \"2.0.1\", \"dependencies\": [] },\n { \"name\": \"progress\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"radio-group\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"select\", \"type\": \"component\", \"version\": \"1.4.0\", \"dependencies\": [] },\n { \"name\": \"skeleton\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"switch\", \"type\": \"component\", \"version\": \"1.1.0\", \"dependencies\": [] },\n { \"name\": \"table\", \"type\": \"component\", \"version\": \"1.0.0\", \"dependencies\": [] },\n { \"name\": \"tabs\", \"type\": \"component\", \"version\": \"1.2.0\", \"dependencies\": [] },\n { \"name\": \"textarea\", \"type\": \"component\", \"version\": \"1.1.1\", \"dependencies\": [] },\n { \"name\": \"tooltip\", \"type\": \"component\", \"version\": \"1.1.2\", \"dependencies\": [] }\n ]\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,qBAAqB;;;ACD9B;AAAA,EACE,SAAW;AAAA,EACX,YAAc;AAAA,IACZ,EAAE,MAAQ,aAAa,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IACnF,EAAE,MAAQ,SAAS,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC/E,EAAE,MAAQ,UAAU,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAChF,EAAE,MAAQ,SAAS,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC/E,EAAE,MAAQ,cAAc,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IACpF,EAAE,MAAQ,UAAU,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAChF,EAAE,MAAQ,QAAQ,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC9E,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,UAAU,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAChF,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,SAAS,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC/E,EAAE,MAAQ,SAAS,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC/E,EAAE,MAAQ,cAAc,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IACpF,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,eAAe,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IACrF,EAAE,MAAQ,UAAU,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAChF,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,UAAU,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAChF,EAAE,MAAQ,SAAS,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC/E,EAAE,MAAQ,QAAQ,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAC9E,EAAE,MAAQ,YAAY,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,IAClF,EAAE,MAAQ,WAAW,MAAQ,aAAa,SAAW,SAAS,cAAgB,CAAC,EAAE;AAAA,EACnF;AACF;;;ADLA,IAAM,YAAY,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC;AAQtD,IAAM,mBAAmB,CAAC,eAAuB,aAA6B;AAGnF,QAAM,gBAAgB,UAAU,SAAS,MAAM,IAAI,mBAAmB;AACtE,SAAO,KAAK,WAAW,eAAe,eAAe,QAAQ;AAC/D;AAKO,IAAM,WAAW,iBAAkB;","names":[]}
|
|
@@ -3,14 +3,14 @@ import type { HTMLAttributes } from "astro/types";
|
|
|
3
3
|
import { tv } from "tailwind-variants";
|
|
4
4
|
|
|
5
5
|
type Props = HTMLAttributes<"div"> & {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
14
|
};
|
|
15
15
|
|
|
16
16
|
const accordion = tv({ base: "starwind-accordion" });
|
|
@@ -19,223 +19,223 @@ const { type = "single", defaultValue, class: className, ...rest } = Astro.props
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
21
|
<div class={accordion({ class: className })} data-type={type} data-value={defaultValue} {...rest}>
|
|
22
|
-
|
|
22
|
+
<slot />
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
25
|
<script>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
26
|
+
type AccordionType = "single" | "multiple";
|
|
27
|
+
type AccordionState = "open" | "closed";
|
|
28
|
+
|
|
29
|
+
/** Represents a single accordion item with its associated elements */
|
|
30
|
+
interface AccordionItem {
|
|
31
|
+
element: HTMLElement;
|
|
32
|
+
trigger: HTMLElement;
|
|
33
|
+
content: HTMLElement;
|
|
34
|
+
value: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Handles the functionality of an accordion component.
|
|
39
|
+
* Supports single and multiple open items, keyboard navigation,
|
|
40
|
+
* and maintains ARIA accessibility standards.
|
|
41
|
+
*/
|
|
42
|
+
class AccordionHandler {
|
|
43
|
+
private accordion: HTMLElement;
|
|
44
|
+
private type: AccordionType;
|
|
45
|
+
private items: AccordionItem[];
|
|
46
|
+
private itemsByValue: Map<string, AccordionItem>;
|
|
47
|
+
private accordionId: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new AccordionHandler instance
|
|
51
|
+
* @param accordion - The root accordion element
|
|
52
|
+
* @param idx - Unique index for this accordion instance
|
|
53
|
+
*/
|
|
54
|
+
constructor(accordion: HTMLElement, idx: number) {
|
|
55
|
+
this.accordion = accordion;
|
|
56
|
+
this.type = (accordion.dataset.type || "single") as AccordionType;
|
|
57
|
+
this.accordionId = `starwind-accordion${idx}`;
|
|
58
|
+
|
|
59
|
+
// Cache all items and create lookup maps
|
|
60
|
+
this.items = this.initializeItems();
|
|
61
|
+
this.itemsByValue = new Map(this.items.map((item) => [item.value, item]));
|
|
62
|
+
|
|
63
|
+
this.setupItems();
|
|
64
|
+
this.setInitialState();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Initializes accordion items by querying the DOM and setting up data structures
|
|
69
|
+
* @returns Array of AccordionItem objects
|
|
70
|
+
*/
|
|
71
|
+
private initializeItems(): AccordionItem[] {
|
|
72
|
+
return Array.from(this.accordion.querySelectorAll<HTMLElement>(".starwind-accordion-item"))
|
|
73
|
+
.map((element, idx) => {
|
|
74
|
+
const trigger = element.querySelector<HTMLElement>(".starwind-accordion-trigger");
|
|
75
|
+
const content = element.querySelector<HTMLElement>(".starwind-accordion-content");
|
|
76
|
+
const value = element.getAttribute("data-value") || String(idx);
|
|
77
|
+
|
|
78
|
+
if (!trigger || !content) return null;
|
|
79
|
+
|
|
80
|
+
return { element, trigger, content, value };
|
|
81
|
+
})
|
|
82
|
+
.filter((item): item is AccordionItem => item !== null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sets up initial state and event listeners for all accordion items
|
|
87
|
+
*/
|
|
88
|
+
private setupItems(): void {
|
|
89
|
+
this.items.forEach((item, idx) => {
|
|
90
|
+
this.setupAccessibility(item, idx);
|
|
91
|
+
this.setContentHeight(item.content);
|
|
92
|
+
this.setupEventListeners(item);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Sets up ARIA attributes and IDs for accessibility
|
|
98
|
+
* @param item - The accordion item to setup
|
|
99
|
+
* @param idx - Index of the item
|
|
100
|
+
*/
|
|
101
|
+
private setupAccessibility(item: AccordionItem, idx: number): void {
|
|
102
|
+
const triggerId = `${this.accordionId}-t${idx}`;
|
|
103
|
+
const contentId = `${this.accordionId}-c${idx}`;
|
|
104
|
+
|
|
105
|
+
item.trigger.id = triggerId;
|
|
106
|
+
item.trigger.setAttribute("aria-controls", contentId);
|
|
107
|
+
item.trigger.setAttribute("aria-expanded", "false");
|
|
108
|
+
|
|
109
|
+
item.content.id = contentId;
|
|
110
|
+
item.content.setAttribute("aria-labelledby", triggerId);
|
|
111
|
+
item.content.setAttribute("role", "region");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Calculates and sets the content height CSS variable for animations
|
|
116
|
+
* @param content - The content element to measure
|
|
117
|
+
*/
|
|
118
|
+
private setContentHeight(content: HTMLElement): void {
|
|
119
|
+
const contentInner = content.firstElementChild as HTMLElement;
|
|
120
|
+
if (contentInner) {
|
|
121
|
+
const height = contentInner.getBoundingClientRect().height;
|
|
122
|
+
content.style.setProperty("--starwind-accordion-content-height", `${height}px`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets the initial state based on the default value attribute
|
|
128
|
+
*/
|
|
129
|
+
private setInitialState(): void {
|
|
130
|
+
const defaultValue = this.accordion.dataset.value;
|
|
131
|
+
if (defaultValue) {
|
|
132
|
+
const item = this.itemsByValue.get(defaultValue);
|
|
133
|
+
if (item) {
|
|
134
|
+
this.setItemState(item, true);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Sets up click and keyboard event listeners for an accordion item
|
|
141
|
+
* @param item - The accordion item to setup listeners for
|
|
142
|
+
*/
|
|
143
|
+
private setupEventListeners(item: AccordionItem): void {
|
|
144
|
+
item.trigger.addEventListener("click", () => this.handleClick(item));
|
|
145
|
+
item.trigger.addEventListener("keydown", (e) => this.handleKeyDown(e, item));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Handles click events on accordion triggers
|
|
150
|
+
* @param item - The clicked accordion item
|
|
151
|
+
*/
|
|
152
|
+
private handleClick(item: AccordionItem): void {
|
|
153
|
+
const isOpen = item.element.getAttribute("data-state") === "open";
|
|
154
|
+
this.toggleItem(item, !isOpen);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Handles keyboard navigation events
|
|
159
|
+
* @param event - The keyboard event
|
|
160
|
+
* @param item - The current accordion item
|
|
161
|
+
*/
|
|
162
|
+
private handleKeyDown(event: KeyboardEvent, item: AccordionItem): void {
|
|
163
|
+
const index = this.items.indexOf(item);
|
|
164
|
+
|
|
165
|
+
const keyActions: Record<string, () => void> = {
|
|
166
|
+
ArrowDown: () => this.focusItem(index + 1),
|
|
167
|
+
ArrowUp: () => this.focusItem(index - 1),
|
|
168
|
+
Home: () => this.focusItem(0),
|
|
169
|
+
End: () => this.focusItem(this.items.length - 1),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const action = keyActions[event.key];
|
|
173
|
+
if (action) {
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
action();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Focuses an accordion item by index with wrapping
|
|
181
|
+
* @param index - The target index to focus
|
|
182
|
+
*/
|
|
183
|
+
private focusItem(index: number): void {
|
|
184
|
+
const targetIndex = (index + this.items.length) % this.items.length;
|
|
185
|
+
this.items[targetIndex].trigger.focus();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Toggles an accordion item's state
|
|
190
|
+
* @param item - The item to toggle
|
|
191
|
+
* @param shouldOpen - Whether the item should be opened
|
|
192
|
+
*/
|
|
193
|
+
private toggleItem(item: AccordionItem, shouldOpen: boolean): void {
|
|
194
|
+
if (this.type === "single" && shouldOpen) {
|
|
195
|
+
// Close other items if in single mode
|
|
196
|
+
this.items.forEach((otherItem) => {
|
|
197
|
+
if (otherItem !== item && otherItem.element.getAttribute("data-state") === "open") {
|
|
198
|
+
this.setItemState(otherItem, false);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
this.setItemState(item, shouldOpen);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Sets the state of an accordion item
|
|
208
|
+
* @param item - The item to update
|
|
209
|
+
* @param isOpen - Whether the item should be open
|
|
210
|
+
*/
|
|
211
|
+
private setItemState(item: AccordionItem, isOpen: boolean): void {
|
|
212
|
+
const state: AccordionState = isOpen ? "open" : "closed";
|
|
213
|
+
|
|
214
|
+
if (isOpen) {
|
|
215
|
+
item.content.style.removeProperty("animation");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Set content height variable for animations
|
|
219
|
+
this.setContentHeight(item.content);
|
|
220
|
+
|
|
221
|
+
item.element.setAttribute("data-state", state);
|
|
222
|
+
item.content.setAttribute("data-state", state);
|
|
223
|
+
item.trigger.setAttribute("data-state", state);
|
|
224
|
+
item.trigger.setAttribute("aria-expanded", isOpen.toString());
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Store instances in a WeakMap to avoid memory leaks
|
|
229
|
+
const accordionInstances = new WeakMap<HTMLElement, AccordionHandler>();
|
|
230
|
+
|
|
231
|
+
const setupAccordions = () => {
|
|
232
|
+
document.querySelectorAll<HTMLElement>(".starwind-accordion").forEach((accordion, idx) => {
|
|
233
|
+
if (!accordionInstances.has(accordion)) {
|
|
234
|
+
accordionInstances.set(accordion, new AccordionHandler(accordion, idx));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
setupAccordions();
|
|
240
|
+
document.addEventListener("astro:after-swap", setupAccordions);
|
|
241
241
|
</script>
|
|
@@ -9,24 +9,24 @@ import { tv } from "tailwind-variants";
|
|
|
9
9
|
type Props = HTMLAttributes<"div">;
|
|
10
10
|
|
|
11
11
|
const accordionContent = tv({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
18
|
});
|
|
19
19
|
|
|
20
20
|
const { class: className, ...rest } = Astro.props;
|
|
21
21
|
---
|
|
22
22
|
|
|
23
23
|
<div
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
class={accordionContent({ class: className })}
|
|
25
|
+
data-state="closed"
|
|
26
|
+
style="animation: none;"
|
|
27
|
+
{...rest}
|
|
28
28
|
>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
<div class="overflow-hidden px-5 pt-0 pb-4">
|
|
30
|
+
<slot />
|
|
31
|
+
</div>
|
|
32
32
|
</div>
|
|
@@ -3,19 +3,19 @@ import type { HTMLAttributes } from "astro/types";
|
|
|
3
3
|
import { tv } from "tailwind-variants";
|
|
4
4
|
|
|
5
5
|
type Props = HTMLAttributes<"div"> & {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The value of the item
|
|
8
|
+
*/
|
|
9
|
+
value: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const accordionItem = tv({
|
|
13
|
-
|
|
13
|
+
base: "starwind-accordion-item border-x border-b first:rounded-t-lg first:border-t last:rounded-b-lg",
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const { value, class: className, ...rest } = Astro.props;
|
|
17
17
|
---
|
|
18
18
|
|
|
19
19
|
<div class={accordionItem({ class: className })} data-value={value} data-state="closed" {...rest}>
|
|
20
|
-
|
|
20
|
+
<slot />
|
|
21
21
|
</div>
|
|
@@ -6,24 +6,24 @@ import { tv } from "tailwind-variants";
|
|
|
6
6
|
type Props = HTMLAttributes<"button">;
|
|
7
7
|
|
|
8
8
|
const accordionTrigger = tv({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
base: [
|
|
10
|
+
"starwind-accordion-trigger",
|
|
11
|
+
"flex w-full items-center justify-between gap-4 rounded-md px-5 py-4",
|
|
12
|
+
"starwind-transition-colors hover:text-muted-foreground text-left font-medium",
|
|
13
|
+
"[&[data-state=open]>svg]:rotate-180",
|
|
14
|
+
"focus-visible:outline-outline focus-visible:outline-2 focus-visible:outline-offset-0",
|
|
15
|
+
],
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
const { class: className, ...rest } = Astro.props;
|
|
19
19
|
---
|
|
20
20
|
|
|
21
21
|
<button
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
type="button"
|
|
23
|
+
class={accordionTrigger({ class: className })}
|
|
24
|
+
aria-expanded="false"
|
|
25
|
+
{...rest}
|
|
26
26
|
>
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
<slot />
|
|
28
|
+
<ChevronDown class="size-5 shrink-0 transition-transform duration-200" />
|
|
29
29
|
</button>
|
|
@@ -6,8 +6,8 @@ import AccordionTrigger from "./AccordionTrigger.astro";
|
|
|
6
6
|
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger };
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
Root: Accordion,
|
|
10
|
+
Content: AccordionContent,
|
|
11
|
+
Item: AccordionItem,
|
|
12
|
+
Trigger: AccordionTrigger,
|
|
13
13
|
};
|