@rimelight/ui 0.0.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/LICENSE +21 -0
- package/README.md +30 -0
- package/i18n-data.json +186 -0
- package/package.json +49 -0
- package/src/components/FormattedDate.astro +22 -0
- package/src/components/HeaderLink.astro +24 -0
- package/src/components/HttpObservatory.astro +103 -0
- package/src/components/LighthouseScores.astro +204 -0
- package/src/components/MissingTranslationBanner.astro +39 -0
- package/src/components/TableOfContents.astro +106 -0
- package/src/components/ThemeToggle.astro +71 -0
- package/src/components/accordion/Accordion.astro +257 -0
- package/src/components/accordion/AccordionContent.astro +34 -0
- package/src/components/accordion/AccordionItem.astro +29 -0
- package/src/components/accordion/AccordionTrigger.astro +33 -0
- package/src/components/alert/Alert.astro +34 -0
- package/src/components/alert/AlertDescription.astro +15 -0
- package/src/components/alert/AlertTitle.astro +17 -0
- package/src/components/alert-dialog/AlertDialog.astro +275 -0
- package/src/components/alert-dialog/AlertDialogAction.astro +46 -0
- package/src/components/alert-dialog/AlertDialogCancel.astro +46 -0
- package/src/components/alert-dialog/AlertDialogContent.astro +52 -0
- package/src/components/alert-dialog/AlertDialogDescription.astro +18 -0
- package/src/components/alert-dialog/AlertDialogFooter.astro +16 -0
- package/src/components/alert-dialog/AlertDialogHeader.astro +14 -0
- package/src/components/alert-dialog/AlertDialogTitle.astro +20 -0
- package/src/components/alert-dialog/AlertDialogTrigger.astro +47 -0
- package/src/components/aspect-ratio/AspectRatio.astro +32 -0
- package/src/components/avatar/Avatar.astro +29 -0
- package/src/components/avatar/AvatarFallback.astro +18 -0
- package/src/components/avatar/AvatarImage.astro +66 -0
- package/src/components/badge/Badge.astro +57 -0
- package/src/components/breadcrumb/Breadcrumb.astro +12 -0
- package/src/components/breadcrumb/BreadcrumbEllipsis.astro +29 -0
- package/src/components/breadcrumb/BreadcrumbItem.astro +15 -0
- package/src/components/breadcrumb/BreadcrumbLink.astro +24 -0
- package/src/components/breadcrumb/BreadcrumbList.astro +17 -0
- package/src/components/breadcrumb/BreadcrumbPage.astro +22 -0
- package/src/components/breadcrumb/BreadcrumbSeparator.astro +24 -0
- package/src/components/button/Button.astro +58 -0
- package/src/components/button-group/ButtonGroup.astro +64 -0
- package/src/components/button-group/ButtonGroupSeparator.astro +20 -0
- package/src/components/button-group/ButtonGroupText.astro +19 -0
- package/src/components/card/Card.astro +36 -0
- package/src/components/card/CardAction.astro +16 -0
- package/src/components/card/CardContent.astro +16 -0
- package/src/components/card/CardDescription.astro +16 -0
- package/src/components/card/CardFooter.astro +16 -0
- package/src/components/card/CardHeader.astro +19 -0
- package/src/components/card/CardTitle.astro +16 -0
- package/src/components/carousel/Carousel.astro +55 -0
- package/src/components/carousel/CarouselContent.astro +26 -0
- package/src/components/carousel/CarouselItem.astro +26 -0
- package/src/components/carousel/CarouselNext.astro +39 -0
- package/src/components/carousel/CarouselPrevious.astro +41 -0
- package/src/components/carousel/carousel-script.ts +188 -0
- package/src/components/carousel/index.ts +1 -0
- package/src/components/checkbox/Checkbox.astro +133 -0
- package/src/components/collapsible/Collapsible.astro +161 -0
- package/src/components/collapsible/CollapsibleContent.astro +22 -0
- package/src/components/collapsible/CollapsibleTrigger.astro +44 -0
- package/src/components/dialog/Dialog.astro +389 -0
- package/src/components/dialog/DialogClose.astro +35 -0
- package/src/components/dialog/DialogContent.astro +78 -0
- package/src/components/dialog/DialogDescription.astro +14 -0
- package/src/components/dialog/DialogFooter.astro +14 -0
- package/src/components/dialog/DialogHeader.astro +14 -0
- package/src/components/dialog/DialogTitle.astro +18 -0
- package/src/components/dialog/DialogTrigger.astro +47 -0
- package/src/components/dropdown/Dropdown.astro +604 -0
- package/src/components/dropdown/DropdownContent.astro +118 -0
- package/src/components/dropdown/DropdownItem.astro +48 -0
- package/src/components/dropdown/DropdownLabel.astro +29 -0
- package/src/components/dropdown/DropdownSeparator.astro +21 -0
- package/src/components/dropdown/DropdownShortcut.astro +17 -0
- package/src/components/dropdown/DropdownSub.astro +15 -0
- package/src/components/dropdown/DropdownSubContent.astro +39 -0
- package/src/components/dropdown/DropdownSubTrigger.astro +34 -0
- package/src/components/dropdown/DropdownTrigger.astro +52 -0
- package/src/components/dropzone/Dropzone.astro +236 -0
- package/src/components/dropzone/DropzoneFilesList.astro +26 -0
- package/src/components/dropzone/DropzoneLoadingIndicator.astro +10 -0
- package/src/components/dropzone/DropzoneUploadIndicator.astro +10 -0
- package/src/components/embeds/YoutubeEmbed.astro +94 -0
- package/src/components/hero/Hero.astro +166 -0
- package/src/components/icons/Flag.astro +62 -0
- package/src/components/image/ExtendedImage.astro +46 -0
- package/src/components/image/Image.astro +25 -0
- package/src/components/input/Input.astro +27 -0
- package/src/components/input-group/InputGroup.astro +28 -0
- package/src/components/input-group/InputGroupAddon.astro +76 -0
- package/src/components/input-group/InputGroupButton.astro +36 -0
- package/src/components/input-group/InputGroupInput.astro +18 -0
- package/src/components/input-group/InputGroupText.astro +17 -0
- package/src/components/input-group/InputGroupTextarea.astro +22 -0
- package/src/components/input-otp/InputOtp.astro +352 -0
- package/src/components/input-otp/InputOtpGroup.astro +16 -0
- package/src/components/input-otp/InputOtpSeparator.astro +25 -0
- package/src/components/input-otp/InputOtpSlot.astro +50 -0
- package/src/components/input-otp/InputOtpTypes.ts +6 -0
- package/src/components/item/Item.astro +52 -0
- package/src/components/item/ItemActions.astro +16 -0
- package/src/components/item/ItemContent.astro +16 -0
- package/src/components/item/ItemDescription.astro +19 -0
- package/src/components/item/ItemFooter.astro +16 -0
- package/src/components/item/ItemGroup.astro +16 -0
- package/src/components/item/ItemHeader.astro +16 -0
- package/src/components/item/ItemMedia.astro +40 -0
- package/src/components/item/ItemSeparator.astro +23 -0
- package/src/components/item/ItemTitle.astro +16 -0
- package/src/components/kbd/Kbd.astro +21 -0
- package/src/components/kbd/KbdGroup.astro +16 -0
- package/src/components/label/Label.astro +24 -0
- package/src/components/marquee/Marquee.astro +73 -0
- package/src/components/native-select/NativeSelect.astro +68 -0
- package/src/components/native-select/NativeSelectOptGroup.astro +15 -0
- package/src/components/native-select/NativeSelectOption.astro +15 -0
- package/src/components/pagination/Pagination.astro +20 -0
- package/src/components/pagination/PaginationContent.astro +16 -0
- package/src/components/pagination/PaginationEllipsis.astro +37 -0
- package/src/components/pagination/PaginationItem.astro +16 -0
- package/src/components/pagination/PaginationLink.astro +27 -0
- package/src/components/pagination/PaginationNext.astro +33 -0
- package/src/components/pagination/PaginationPrevious.astro +33 -0
- package/src/components/popover/Popover.astro +717 -0
- package/src/components/popover/PopoverContent.astro +102 -0
- package/src/components/popover/PopoverDescription.astro +14 -0
- package/src/components/popover/PopoverHeader.astro +14 -0
- package/src/components/popover/PopoverTitle.astro +14 -0
- package/src/components/popover/PopoverTrigger.astro +51 -0
- package/src/components/progress/Progress.astro +154 -0
- package/src/components/prose/Prose.astro +619 -0
- package/src/components/radio-group/RadioGroup.astro +162 -0
- package/src/components/radio-group/RadioGroupItem.astro +133 -0
- package/src/components/radio-group/RadioGroupTypes.ts +6 -0
- package/src/components/section/Section.astro +167 -0
- package/src/components/select/Select.astro +752 -0
- package/src/components/select/SelectContent.astro +94 -0
- package/src/components/select/SelectGroup.astro +9 -0
- package/src/components/select/SelectItem.astro +51 -0
- package/src/components/select/SelectLabel.astro +14 -0
- package/src/components/select/SelectSearch.astro +49 -0
- package/src/components/select/SelectSeparator.astro +12 -0
- package/src/components/select/SelectTrigger.astro +56 -0
- package/src/components/select/SelectTypes.ts +13 -0
- package/src/components/select/SelectValue.astro +19 -0
- package/src/components/separator/Separator.astro +36 -0
- package/src/components/sheet/Sheet.astro +15 -0
- package/src/components/sheet/SheetClose.astro +15 -0
- package/src/components/sheet/SheetContent.astro +89 -0
- package/src/components/sheet/SheetDescription.astro +16 -0
- package/src/components/sheet/SheetFooter.astro +16 -0
- package/src/components/sheet/SheetHeader.astro +16 -0
- package/src/components/sheet/SheetTitle.astro +16 -0
- package/src/components/sheet/SheetTrigger.astro +15 -0
- package/src/components/sidebar/Sidebar.astro +231 -0
- package/src/components/sidebar/SidebarContent.astro +25 -0
- package/src/components/sidebar/SidebarFooter.astro +22 -0
- package/src/components/sidebar/SidebarGroup.astro +22 -0
- package/src/components/sidebar/SidebarGroupContent.astro +22 -0
- package/src/components/sidebar/SidebarGroupLabel.astro +53 -0
- package/src/components/sidebar/SidebarHeader.astro +22 -0
- package/src/components/sidebar/SidebarInput.astro +24 -0
- package/src/components/sidebar/SidebarInset.astro +22 -0
- package/src/components/sidebar/SidebarMenu.astro +22 -0
- package/src/components/sidebar/SidebarMenuAction.astro +63 -0
- package/src/components/sidebar/SidebarMenuBadge.astro +31 -0
- package/src/components/sidebar/SidebarMenuButton.astro +124 -0
- package/src/components/sidebar/SidebarMenuItem.astro +22 -0
- package/src/components/sidebar/SidebarMenuSkeleton.astro +43 -0
- package/src/components/sidebar/SidebarMenuSub.astro +25 -0
- package/src/components/sidebar/SidebarMenuSubButton.astro +52 -0
- package/src/components/sidebar/SidebarMenuSubItem.astro +17 -0
- package/src/components/sidebar/SidebarProvider.astro +215 -0
- package/src/components/sidebar/SidebarRail.astro +72 -0
- package/src/components/sidebar/SidebarSeparator.astro +25 -0
- package/src/components/sidebar/SidebarTrigger.astro +69 -0
- package/src/components/skeleton/Skeleton.astro +14 -0
- package/src/components/slider/Slider.astro +425 -0
- package/src/components/spinner/Spinner.astro +23 -0
- package/src/components/switch/Switch.astro +192 -0
- package/src/components/switch/SwitchTypes.ts +6 -0
- package/src/components/table/Table.astro +20 -0
- package/src/components/table/TableBody.astro +18 -0
- package/src/components/table/TableCaption.astro +18 -0
- package/src/components/table/TableCell.astro +18 -0
- package/src/components/table/TableFoot.astro +18 -0
- package/src/components/table/TableHead.astro +18 -0
- package/src/components/table/TableHeader.astro +18 -0
- package/src/components/table/TableRow.astro +17 -0
- package/src/components/tabs/Tabs.astro +270 -0
- package/src/components/tabs/TabsContent.astro +28 -0
- package/src/components/tabs/TabsList.astro +23 -0
- package/src/components/tabs/TabsTrigger.astro +34 -0
- package/src/components/textarea/Textarea.astro +31 -0
- package/src/components/toast/ToastDescription.astro +22 -0
- package/src/components/toast/ToastItem.astro +56 -0
- package/src/components/toast/ToastTemplate.astro +27 -0
- package/src/components/toast/ToastTitle.astro +59 -0
- package/src/components/toast/Toaster.astro +981 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/toast/toast-manager.ts +234 -0
- package/src/components/toggle/Toggle.astro +174 -0
- package/src/components/toggle/ToggleTypes.ts +14 -0
- package/src/components/tooltip/Tooltip.astro +422 -0
- package/src/components/tooltip/TooltipContent.astro +83 -0
- package/src/components/tooltip/TooltipTrigger.astro +13 -0
- package/src/components/video/Video.astro +121 -0
- package/src/config/cookies.ts +5 -0
- package/src/config/index.ts +3 -0
- package/src/config/links.ts +4 -0
- package/src/config/site.config.ts +45 -0
- package/src/domain/cms/index.ts +1 -0
- package/src/domain/cms/types.ts +20 -0
- package/src/domain/i18n/constants.ts +21 -0
- package/src/domain/i18n/cookie-storage.ts +13 -0
- package/src/domain/i18n/country-to-locale-map.ts +67 -0
- package/src/domain/i18n/fallbacks.generated.ts +230 -0
- package/src/domain/i18n/fetcher.ts +268 -0
- package/src/domain/i18n/flags.ts +16 -0
- package/src/domain/i18n/format.ts +90 -0
- package/src/domain/i18n/index.ts +10 -0
- package/src/domain/i18n/middleware/i18n.ts +160 -0
- package/src/domain/i18n/resolve-locale.ts +55 -0
- package/src/domain/i18n/runtime-constants.ts +14 -0
- package/src/domain/i18n/schema.ts +29 -0
- package/src/domain/index.ts +4 -0
- package/src/domain/seo/constants.ts +20 -0
- package/src/domain/seo/index.ts +3 -0
- package/src/domain/seo/services/index.ts +3 -0
- package/src/domain/seo/services/llms.ts +53 -0
- package/src/domain/seo/services/robots.ts +12 -0
- package/src/domain/seo/services/sitemap.ts +56 -0
- package/src/domain/seo/utils.ts +37 -0
- package/src/domain/theme/constants.ts +6 -0
- package/src/domain/theme/index.ts +2 -0
- package/src/domain/theme/schema.ts +10 -0
- package/src/env.d.ts +49 -0
- package/src/i18n.generated.d.ts +202 -0
- package/src/lib/component-preview.ts +73 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/remark/remark-modified-time.ts +13 -0
- package/src/lib/showcase-preview-elements.ts +408 -0
- package/src/lib/showcase-renderer.ts +218 -0
- package/src/lib/showcase-utils.ts +189 -0
- package/src/lib/turnstile.ts +35 -0
- package/src/lib/utils/starwind/positioning.ts +318 -0
- package/src/locales/de/blog.json +9 -0
- package/src/locales/de/common.json +19 -0
- package/src/locales/de/errors.json +6 -0
- package/src/locales/de/home.json +20 -0
- package/src/locales/de/messages.json +8 -0
- package/src/locales/de/nav.json +13 -0
- package/src/locales/de/projects.json +9 -0
- package/src/locales/de/services.json +43 -0
- package/src/locales/en/blog.json +9 -0
- package/src/locales/en/chat.json +29 -0
- package/src/locales/en/common.json +19 -0
- package/src/locales/en/cookie_notice.json +11 -0
- package/src/locales/en/editor.json +24 -0
- package/src/locales/en/errors.json +6 -0
- package/src/locales/en/home.json +20 -0
- package/src/locales/en/messages.json +8 -0
- package/src/locales/en/nav.json +13 -0
- package/src/locales/en/projects.json +9 -0
- package/src/locales/en/services.json +43 -0
- package/src/locales/es/blog.json +9 -0
- package/src/locales/es/common.json +19 -0
- package/src/locales/es/errors.json +6 -0
- package/src/locales/es/home.json +20 -0
- package/src/locales/es/messages.json +8 -0
- package/src/locales/es/nav.json +13 -0
- package/src/locales/es/projects.json +9 -0
- package/src/locales/es/services.json +43 -0
- package/src/locales/ja/blog.json +9 -0
- package/src/locales/ja/common.json +19 -0
- package/src/locales/ja/errors.json +6 -0
- package/src/locales/ja/home.json +20 -0
- package/src/locales/ja/messages.json +8 -0
- package/src/locales/ja/nav.json +13 -0
- package/src/locales/ja/projects.json +9 -0
- package/src/locales/ja/services.json +43 -0
- package/src/locales/pt/blog.json +9 -0
- package/src/locales/pt/chat.json +29 -0
- package/src/locales/pt/common.json +19 -0
- package/src/locales/pt/cookie_notice.json +11 -0
- package/src/locales/pt/editor.json +24 -0
- package/src/locales/pt/errors.json +6 -0
- package/src/locales/pt/home.json +20 -0
- package/src/locales/pt/messages.json +8 -0
- package/src/locales/pt/nav.json +13 -0
- package/src/locales/pt/projects.json +9 -0
- package/src/locales/pt/services.json +43 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/server/cookies.ts +98 -0
- package/src/utils/server/index.ts +1 -0
- package/src/utils/shared/deep-merge.ts +36 -0
- package/src/utils/shared/embed.ts +105 -0
- package/src/utils/shared/index.ts +3 -0
- package/src/utils/shared/parse-boolean.ts +14 -0
- package/worker-configuration.d.ts +14791 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { scv } from "css-variants";
|
|
4
|
+
|
|
5
|
+
export const slider = scv({
|
|
6
|
+
slots: ["root", "control", "track", "range", "thumb"],
|
|
7
|
+
base: {
|
|
8
|
+
root: "starwind-slider relative flex w-full touch-none items-center select-none data-[disabled]:op-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto",
|
|
9
|
+
control:
|
|
10
|
+
"starwind-slider-control relative w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto",
|
|
11
|
+
track:
|
|
12
|
+
"starwind-slider-track bg-muted relative overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5",
|
|
13
|
+
range:
|
|
14
|
+
"starwind-slider-range absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full",
|
|
15
|
+
thumb:
|
|
16
|
+
"starwind-slider-thumb absolute block size-4 shrink-0 rounded-full b bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:op-50 data-[orientation=horizontal]:top-1/2 data-[orientation=horizontal]:-translate-x-1/2 data-[orientation=horizontal]:-translate-y-1/2 data-[orientation=vertical]:left-1/2 data-[orientation=vertical]:-translate-x-1/2 data-[orientation=vertical]:translate-y-1/2",
|
|
17
|
+
},
|
|
18
|
+
variants: {
|
|
19
|
+
variant: {
|
|
20
|
+
default: {
|
|
21
|
+
range: "bg-foreground",
|
|
22
|
+
thumb: "border-foreground ring-outline/50",
|
|
23
|
+
},
|
|
24
|
+
primary: {
|
|
25
|
+
range: "bg-primary",
|
|
26
|
+
thumb: "border-primary ring-primary/50",
|
|
27
|
+
},
|
|
28
|
+
secondary: {
|
|
29
|
+
range: "bg-secondary",
|
|
30
|
+
thumb: "border-secondary ring-secondary/50",
|
|
31
|
+
},
|
|
32
|
+
info: {
|
|
33
|
+
range: "bg-info",
|
|
34
|
+
thumb: "border-info ring-info/50",
|
|
35
|
+
},
|
|
36
|
+
success: {
|
|
37
|
+
range: "bg-success",
|
|
38
|
+
thumb: "border-success ring-success/50",
|
|
39
|
+
},
|
|
40
|
+
warning: {
|
|
41
|
+
range: "bg-warning",
|
|
42
|
+
thumb: "border-warning ring-warning/50",
|
|
43
|
+
},
|
|
44
|
+
error: {
|
|
45
|
+
range: "bg-error",
|
|
46
|
+
thumb: "border-error ring-error/50",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
defaultVariants: {
|
|
51
|
+
variant: "default",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
type Variant = "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error";
|
|
56
|
+
|
|
57
|
+
type Props = HTMLAttributes<"div"> & {
|
|
58
|
+
defaultValue?: number | number[];
|
|
59
|
+
value?: number | number[];
|
|
60
|
+
min?: number;
|
|
61
|
+
max?: number;
|
|
62
|
+
step?: number;
|
|
63
|
+
largeStep?: number;
|
|
64
|
+
orientation?: "horizontal" | "vertical";
|
|
65
|
+
disabled?: boolean;
|
|
66
|
+
name?: string;
|
|
67
|
+
variant?: Variant;
|
|
68
|
+
"aria-label"?: string;
|
|
69
|
+
"aria-labelledby"?: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
class: className,
|
|
74
|
+
defaultValue = 0,
|
|
75
|
+
value,
|
|
76
|
+
min = 0,
|
|
77
|
+
max = 100,
|
|
78
|
+
step = 1,
|
|
79
|
+
largeStep = 10,
|
|
80
|
+
orientation = "horizontal",
|
|
81
|
+
disabled = false,
|
|
82
|
+
name,
|
|
83
|
+
variant = "default",
|
|
84
|
+
"aria-label": ariaLabel,
|
|
85
|
+
"aria-labelledby": ariaLabelledby,
|
|
86
|
+
...rest
|
|
87
|
+
} = Astro.props;
|
|
88
|
+
|
|
89
|
+
const { root, control, track, range, thumb } = slider({ variant });
|
|
90
|
+
|
|
91
|
+
const initialValue = value ?? defaultValue ?? min;
|
|
92
|
+
const values = Array.isArray(initialValue) ? initialValue : [initialValue];
|
|
93
|
+
const isRange = values.length > 1;
|
|
94
|
+
|
|
95
|
+
function getPercentage(val: number): number {
|
|
96
|
+
return ((val - min) / (max - min)) * 100;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const rangeStart = isRange ? getPercentage(Math.min(...(values as number[]))) : 0;
|
|
100
|
+
const rangeEnd = isRange
|
|
101
|
+
? getPercentage(Math.max(...(values as number[])))
|
|
102
|
+
: getPercentage((values[0] as number) ?? min);
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
<div
|
|
106
|
+
class:list={[root, className]}
|
|
107
|
+
data-orientation={orientation}
|
|
108
|
+
data-disabled={disabled ? "" : undefined}
|
|
109
|
+
role="group"
|
|
110
|
+
aria-labelledby={ariaLabelledby}
|
|
111
|
+
data-min={min}
|
|
112
|
+
data-max={max}
|
|
113
|
+
data-step={step}
|
|
114
|
+
data-large-step={largeStep}
|
|
115
|
+
{...rest}
|
|
116
|
+
data-slot="slider"
|
|
117
|
+
>
|
|
118
|
+
<div class={control} data-slot="slider-control" data-orientation={orientation}>
|
|
119
|
+
<div class={track} data-slot="slider-track" data-orientation={orientation}>
|
|
120
|
+
<div
|
|
121
|
+
class={range}
|
|
122
|
+
data-slot="slider-range"
|
|
123
|
+
data-orientation={orientation}
|
|
124
|
+
style={orientation === "horizontal"
|
|
125
|
+
? `left: ${rangeStart}%; width: ${rangeEnd - rangeStart}%`
|
|
126
|
+
: `bottom: ${rangeStart}%; height: ${rangeEnd - rangeStart}%`}
|
|
127
|
+
>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
{
|
|
131
|
+
values.map((val, index) => (
|
|
132
|
+
<div
|
|
133
|
+
class={thumb}
|
|
134
|
+
data-slot="slider-thumb"
|
|
135
|
+
data-index={index}
|
|
136
|
+
data-orientation={orientation}
|
|
137
|
+
style={
|
|
138
|
+
orientation === "horizontal"
|
|
139
|
+
? `left: ${getPercentage(val)}%`
|
|
140
|
+
: `bottom: ${getPercentage(val)}%`
|
|
141
|
+
}
|
|
142
|
+
tabindex={disabled ? -1 : 0}
|
|
143
|
+
role="slider"
|
|
144
|
+
aria-label={ariaLabel}
|
|
145
|
+
aria-valuemin={min}
|
|
146
|
+
aria-valuemax={max}
|
|
147
|
+
aria-valuenow={val}
|
|
148
|
+
aria-orientation={orientation}
|
|
149
|
+
aria-disabled={disabled}
|
|
150
|
+
>
|
|
151
|
+
<input
|
|
152
|
+
type="range"
|
|
153
|
+
min={min}
|
|
154
|
+
max={max}
|
|
155
|
+
step={step}
|
|
156
|
+
value={val}
|
|
157
|
+
name={name ? (isRange ? `${name}[${index}]` : name) : undefined}
|
|
158
|
+
disabled={disabled}
|
|
159
|
+
tabindex={-1}
|
|
160
|
+
aria-hidden="true"
|
|
161
|
+
class="sr-only"
|
|
162
|
+
/>
|
|
163
|
+
</div>
|
|
164
|
+
))
|
|
165
|
+
}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<script>
|
|
170
|
+
class StarwindSlider {
|
|
171
|
+
private root: HTMLElement;
|
|
172
|
+
private track: HTMLElement;
|
|
173
|
+
private range: HTMLElement;
|
|
174
|
+
private thumbs: HTMLElement[];
|
|
175
|
+
private inputs: HTMLInputElement[];
|
|
176
|
+
private min: number;
|
|
177
|
+
private max: number;
|
|
178
|
+
private step: number;
|
|
179
|
+
private largeStep: number;
|
|
180
|
+
private orientation: "horizontal" | "vertical";
|
|
181
|
+
private disabled: boolean;
|
|
182
|
+
private values: number[];
|
|
183
|
+
private activeThumbIndex: number = -1;
|
|
184
|
+
private dragging: boolean = false;
|
|
185
|
+
|
|
186
|
+
constructor(root: HTMLElement) {
|
|
187
|
+
this.root = root;
|
|
188
|
+
this.track = root.querySelector('[data-slot="slider-track"]')!;
|
|
189
|
+
this.range = root.querySelector('[data-slot="slider-range"]')!;
|
|
190
|
+
this.thumbs = Array.from(root.querySelectorAll('[data-slot="slider-thumb"]'));
|
|
191
|
+
this.inputs = Array.from(root.querySelectorAll('input[type="range"]'));
|
|
192
|
+
|
|
193
|
+
this.min = Number(root.dataset.min) || 0;
|
|
194
|
+
this.max = Number(root.dataset.max) || 100;
|
|
195
|
+
this.step = Number(root.dataset.step) || 1;
|
|
196
|
+
this.largeStep = Number(root.dataset.largeStep) || 10;
|
|
197
|
+
this.orientation = (root.dataset.orientation as "horizontal" | "vertical") || "horizontal";
|
|
198
|
+
this.disabled = root.hasAttribute("data-disabled");
|
|
199
|
+
|
|
200
|
+
this.values = this.inputs.map((input) => Number(input.value));
|
|
201
|
+
|
|
202
|
+
this.init();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private init(): void {
|
|
206
|
+
if (this.disabled) return;
|
|
207
|
+
|
|
208
|
+
this.thumbs.forEach((thumb, index) => {
|
|
209
|
+
thumb.addEventListener("pointerdown", (e) => this.handleThumbPointerDown(e, index));
|
|
210
|
+
thumb.addEventListener("keydown", (e) => this.handleKeyDown(e, index));
|
|
211
|
+
thumb.addEventListener("focus", () => this.handleFocus(index));
|
|
212
|
+
thumb.addEventListener("blur", () => this.handleBlur());
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
this.track.addEventListener("pointerdown", (e) => this.handleTrackClick(e));
|
|
216
|
+
|
|
217
|
+
document.addEventListener("pointermove", (e) => this.handlePointerMove(e));
|
|
218
|
+
document.addEventListener("pointerup", () => this.handlePointerUp());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private getPercentage(val: number): number {
|
|
222
|
+
return ((val - this.min) / (this.max - this.min)) * 100;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private getValueFromPosition(clientX: number, clientY: number): number {
|
|
226
|
+
const rect = this.track.getBoundingClientRect();
|
|
227
|
+
let percentage: number;
|
|
228
|
+
|
|
229
|
+
if (this.orientation === "horizontal") {
|
|
230
|
+
percentage = (clientX - rect.left) / rect.width;
|
|
231
|
+
} else {
|
|
232
|
+
percentage = 1 - (clientY - rect.top) / rect.height;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
percentage = Math.max(0, Math.min(1, percentage));
|
|
236
|
+
const rawValue = this.min + percentage * (this.max - this.min);
|
|
237
|
+
return this.snapToStep(rawValue);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private snapToStep(value: number): number {
|
|
241
|
+
const snapped = Math.round((value - this.min) / this.step) * this.step + this.min;
|
|
242
|
+
return Math.max(this.min, Math.min(this.max, snapped));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private updateValue(index: number, newValue: number): void {
|
|
246
|
+
const isRange = this.values.length > 1;
|
|
247
|
+
|
|
248
|
+
if (isRange) {
|
|
249
|
+
if (index === 0 && newValue > this.values[1]!) {
|
|
250
|
+
newValue = this.values[1]!;
|
|
251
|
+
} else if (index === 1 && newValue < this.values[0]!) {
|
|
252
|
+
newValue = this.values[0]!;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.values[index] = newValue;
|
|
257
|
+
if (this.inputs[index]) {
|
|
258
|
+
this.inputs[index]!.value = String(newValue);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.updateVisuals();
|
|
262
|
+
this.dispatchChangeEvent();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private updateVisuals(): void {
|
|
266
|
+
const isRange = this.values.length > 1;
|
|
267
|
+
const rangeStart = isRange ? this.getPercentage(Math.min(...this.values)) : 0;
|
|
268
|
+
const rangeEnd = isRange
|
|
269
|
+
? this.getPercentage(Math.max(...this.values))
|
|
270
|
+
: this.getPercentage(this.values[0]!);
|
|
271
|
+
|
|
272
|
+
if (this.orientation === "horizontal") {
|
|
273
|
+
this.range.style.left = `${rangeStart}%`;
|
|
274
|
+
this.range.style.width = `${rangeEnd - rangeStart}%`;
|
|
275
|
+
} else {
|
|
276
|
+
this.range.style.bottom = `${rangeStart}%`;
|
|
277
|
+
this.range.style.height = `${rangeEnd - rangeStart}%`;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.thumbs.forEach((thumb, index) => {
|
|
281
|
+
const val = this.values[index];
|
|
282
|
+
if (val === undefined) return;
|
|
283
|
+
const percentage = this.getPercentage(val);
|
|
284
|
+
if (this.orientation === "horizontal") {
|
|
285
|
+
thumb.style.left = `${percentage}%`;
|
|
286
|
+
} else {
|
|
287
|
+
thumb.style.bottom = `${percentage}%`;
|
|
288
|
+
}
|
|
289
|
+
thumb.setAttribute("aria-valuenow", String(this.values[index]));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private dispatchChangeEvent(): void {
|
|
294
|
+
const value = this.values.length === 1 ? this.values[0] : [...this.values];
|
|
295
|
+
this.root.dispatchEvent(
|
|
296
|
+
new CustomEvent("slider-change", {
|
|
297
|
+
detail: { value },
|
|
298
|
+
bubbles: true,
|
|
299
|
+
}),
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private handleThumbPointerDown(e: PointerEvent, index: number): void {
|
|
304
|
+
if (this.disabled) return;
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
this.activeThumbIndex = index;
|
|
307
|
+
this.dragging = true;
|
|
308
|
+
this.root.setAttribute("data-dragging", "");
|
|
309
|
+
if (this.thumbs[index]) {
|
|
310
|
+
this.thumbs[index]!.setAttribute("data-dragging", "");
|
|
311
|
+
this.thumbs[index]!.focus();
|
|
312
|
+
}
|
|
313
|
+
(e.target as HTMLElement).setPointerCapture(e.pointerId);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private handlePointerMove(e: PointerEvent): void {
|
|
317
|
+
if (!this.dragging || this.activeThumbIndex === -1) return;
|
|
318
|
+
const newValue = this.getValueFromPosition(e.clientX, e.clientY);
|
|
319
|
+
this.updateValue(this.activeThumbIndex, newValue);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private handlePointerUp(): void {
|
|
323
|
+
if (!this.dragging) return;
|
|
324
|
+
this.dragging = false;
|
|
325
|
+
this.root.removeAttribute("data-dragging");
|
|
326
|
+
this.thumbs.forEach((thumb) => thumb.removeAttribute("data-dragging"));
|
|
327
|
+
|
|
328
|
+
const value = this.values.length === 1 ? this.values[0] : [...this.values];
|
|
329
|
+
this.root.dispatchEvent(
|
|
330
|
+
new CustomEvent("slider-commit", {
|
|
331
|
+
detail: { value },
|
|
332
|
+
bubbles: true,
|
|
333
|
+
}),
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
this.activeThumbIndex = -1;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private handleTrackClick(e: PointerEvent): void {
|
|
340
|
+
if (this.disabled) return;
|
|
341
|
+
const newValue = this.getValueFromPosition(e.clientX, e.clientY);
|
|
342
|
+
|
|
343
|
+
let closestIndex = 0;
|
|
344
|
+
if (this.values.length > 1) {
|
|
345
|
+
const distances = this.values.map((v) => Math.abs(v - newValue));
|
|
346
|
+
closestIndex = distances.indexOf(Math.min(...distances));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
this.updateValue(closestIndex, newValue);
|
|
350
|
+
this.thumbs[closestIndex]?.focus();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private handleKeyDown(e: KeyboardEvent, index: number): void {
|
|
354
|
+
if (this.disabled) return;
|
|
355
|
+
|
|
356
|
+
const val = this.values[index]!;
|
|
357
|
+
if (val === undefined) return;
|
|
358
|
+
let newValue = val;
|
|
359
|
+
const isHorizontal = this.orientation === "horizontal";
|
|
360
|
+
|
|
361
|
+
switch (e.key) {
|
|
362
|
+
case "ArrowRight":
|
|
363
|
+
case "ArrowUp":
|
|
364
|
+
e.preventDefault();
|
|
365
|
+
newValue += isHorizontal === (e.key === "ArrowRight") ? this.step : -this.step;
|
|
366
|
+
if (e.shiftKey) newValue = val + this.largeStep;
|
|
367
|
+
break;
|
|
368
|
+
case "ArrowLeft":
|
|
369
|
+
case "ArrowDown":
|
|
370
|
+
e.preventDefault();
|
|
371
|
+
newValue -= isHorizontal === (e.key === "ArrowLeft") ? this.step : -this.step;
|
|
372
|
+
if (e.shiftKey) newValue = val - this.largeStep;
|
|
373
|
+
break;
|
|
374
|
+
case "PageUp":
|
|
375
|
+
e.preventDefault();
|
|
376
|
+
if (newValue === undefined) break;
|
|
377
|
+
newValue += this.largeStep;
|
|
378
|
+
break;
|
|
379
|
+
case "PageDown":
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
if (newValue === undefined) break;
|
|
382
|
+
newValue -= this.largeStep;
|
|
383
|
+
break;
|
|
384
|
+
case "Home":
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
newValue = this.min;
|
|
387
|
+
break;
|
|
388
|
+
case "End":
|
|
389
|
+
e.preventDefault();
|
|
390
|
+
newValue = this.max;
|
|
391
|
+
break;
|
|
392
|
+
default:
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (newValue === undefined) return;
|
|
397
|
+
newValue = this.snapToStep(newValue);
|
|
398
|
+
this.updateValue(index, newValue);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private handleFocus(index: number): void {
|
|
402
|
+
this.root.setAttribute("data-focused", "");
|
|
403
|
+
this.thumbs[index]?.setAttribute("data-focused", "");
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private handleBlur(): void {
|
|
407
|
+
this.root.removeAttribute("data-focused");
|
|
408
|
+
this.thumbs.forEach((thumb) => thumb.removeAttribute("data-focused"));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const sliderInstances = new WeakMap<HTMLElement, StarwindSlider>();
|
|
413
|
+
|
|
414
|
+
function initSliders(): void {
|
|
415
|
+
document.querySelectorAll<HTMLElement>('[data-slot="slider"]').forEach((slider) => {
|
|
416
|
+
if (!sliderInstances.has(slider)) {
|
|
417
|
+
sliderInstances.set(slider, new StarwindSlider(slider));
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
initSliders();
|
|
423
|
+
document.addEventListener("astro:after-swap", initSliders);
|
|
424
|
+
document.addEventListener("starwind:init", initSliders);
|
|
425
|
+
</script>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { cv } from "css-variants";
|
|
4
|
+
import IconLoader from "~icons/lucide/loader";
|
|
5
|
+
|
|
6
|
+
type Props = Omit<HTMLAttributes<"svg">, "role" | "aria-label">;
|
|
7
|
+
|
|
8
|
+
export const spinner = cv({
|
|
9
|
+
base: "size-4 animate-spin",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const { class: className, ...rest } = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<span
|
|
16
|
+
role="status"
|
|
17
|
+
aria-label="Loading"
|
|
18
|
+
class:list={[spinner(), className]}
|
|
19
|
+
{...rest}
|
|
20
|
+
data-slot="spinner"
|
|
21
|
+
>
|
|
22
|
+
<IconLoader />
|
|
23
|
+
</span>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { cv } from "css-variants";
|
|
4
|
+
|
|
5
|
+
type Props = Omit<HTMLAttributes<"button">, "role" | "type" | "aria-checked"> & {
|
|
6
|
+
/**
|
|
7
|
+
* Unique identifier for the switch component.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional text label to display alongside the switch.
|
|
12
|
+
*/
|
|
13
|
+
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Controls the checked state of the switch.
|
|
16
|
+
*/
|
|
17
|
+
checked?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Custom padding in pixels to apply around the switch.
|
|
20
|
+
*/
|
|
21
|
+
padding?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Size variant of the switch component.
|
|
24
|
+
*/
|
|
25
|
+
size?: "sm" | "md" | "lg";
|
|
26
|
+
/**
|
|
27
|
+
* Visual style variant of the switch.
|
|
28
|
+
* @default "default"
|
|
29
|
+
*/
|
|
30
|
+
variant?: "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error";
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
id,
|
|
35
|
+
label,
|
|
36
|
+
checked = false,
|
|
37
|
+
padding,
|
|
38
|
+
size = "md",
|
|
39
|
+
variant = "default",
|
|
40
|
+
class: className,
|
|
41
|
+
...rest
|
|
42
|
+
} = Astro.props;
|
|
43
|
+
|
|
44
|
+
// if no specific padding is set, base it off of size
|
|
45
|
+
let newPadding = padding;
|
|
46
|
+
if (!padding) {
|
|
47
|
+
newPadding = size === "sm" ? 2.5 : size === "lg" ? 4 : 3;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const sizeMultiplier = size === "sm" ? 4 : size === "lg" ? 6 : 5;
|
|
51
|
+
|
|
52
|
+
let ariaLabel;
|
|
53
|
+
if (rest["aria-label"]) {
|
|
54
|
+
ariaLabel = rest["aria-label"];
|
|
55
|
+
delete rest["aria-label"];
|
|
56
|
+
} else if (label) {
|
|
57
|
+
ariaLabel = label;
|
|
58
|
+
} else {
|
|
59
|
+
ariaLabel = "switch";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const switchButton = cv({
|
|
63
|
+
base: [
|
|
64
|
+
"border-input bg-muted inline-flex h-(--height) w-(--width) items-center rounded-full border",
|
|
65
|
+
"group peer ring-offset-background transition outline-none focus-visible:ring-3",
|
|
66
|
+
"not-disabled:cursor-pointer disabled:cursor-not-allowed disabled:op-50",
|
|
67
|
+
],
|
|
68
|
+
variants: {
|
|
69
|
+
variant: {
|
|
70
|
+
primary: "aria-checked:border-primary focus-visible:border-primary/70 focus:ring-primary/50",
|
|
71
|
+
secondary:
|
|
72
|
+
"aria-checked:border-secondary focus-visible:border-secondary/70 focus:ring-secondary/50",
|
|
73
|
+
default: "aria-checked:border-foreground focus-visible:border-outline focus:ring-outline/50",
|
|
74
|
+
info: "aria-checked:border-info focus-visible:border-info/70 focus:ring-info/50",
|
|
75
|
+
success: "aria-checked:border-success focus-visible:border-success/70 focus:ring-success/50",
|
|
76
|
+
warning: "aria-checked:border-warning focus-visible:border-warning/70 focus:ring-warning/50",
|
|
77
|
+
error: "aria-checked:border-error focus-visible:border-error/70 focus:ring-error/50",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
defaultVariants: { variant: "default" },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const switchToggle = cv({
|
|
84
|
+
base: [
|
|
85
|
+
"bg-foreground i-block transform rounded-full transition-transform",
|
|
86
|
+
"group-aria-checked:translate-x-(--translation) group-aria-[checked=false]:translate-x-[calc(var(--padding)-var(--border-offset))]",
|
|
87
|
+
],
|
|
88
|
+
variants: { size: { sm: "size-4", md: "size-5", lg: "size-6" } },
|
|
89
|
+
defaultVariants: { size: "md" },
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const switchLabel = cv({
|
|
93
|
+
base: "text-foreground ml-3xs font-medium peer-disabled:cursor-not-allowed peer-disabled:op-70",
|
|
94
|
+
variants: { size: { sm: "text-sm", md: "text-base", lg: "text-lg" } },
|
|
95
|
+
defaultVariants: { size: "md" },
|
|
96
|
+
});
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
<div class="starwind-switch flex items-center">
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
id={id}
|
|
103
|
+
role="switch"
|
|
104
|
+
aria-checked={checked ? "true" : "false"}
|
|
105
|
+
aria-label={ariaLabel}
|
|
106
|
+
class:list={[switchButton({ variant }), className]}
|
|
107
|
+
style={{
|
|
108
|
+
"--padding": `${newPadding}px`,
|
|
109
|
+
"--height": `calc((var(--spacing) * ${sizeMultiplier}) + (var(--padding) * 2))`,
|
|
110
|
+
"--width": `calc((var(--spacing) * ${sizeMultiplier} * 2) + (var(--padding) * 3))`,
|
|
111
|
+
"--border-offset": "1px",
|
|
112
|
+
}}
|
|
113
|
+
{...rest}
|
|
114
|
+
data-slot="switch-button"
|
|
115
|
+
>
|
|
116
|
+
<span
|
|
117
|
+
class={switchToggle({ size })}
|
|
118
|
+
data-slot="switch-toggle"
|
|
119
|
+
style={{
|
|
120
|
+
"--translation": `calc((var(--spacing) * ${sizeMultiplier}) + (var(--padding) * 2) - var(--border-offset))`,
|
|
121
|
+
}}></span>
|
|
122
|
+
</button>
|
|
123
|
+
{
|
|
124
|
+
label && (
|
|
125
|
+
<label for={id} class={switchLabel({ size })} data-slot="switch-label">
|
|
126
|
+
{label}
|
|
127
|
+
</label>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<script>
|
|
133
|
+
import type { SwitchChangeEvent } from "./SwitchTypes";
|
|
134
|
+
|
|
135
|
+
class SwitchHandler {
|
|
136
|
+
private switchButton: HTMLButtonElement;
|
|
137
|
+
|
|
138
|
+
constructor(switchButton: HTMLButtonElement) {
|
|
139
|
+
this.switchButton = switchButton;
|
|
140
|
+
this.setupEventListeners();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private setupEventListeners(): void {
|
|
144
|
+
this.switchButton.addEventListener("click", () => this.handleStateChange());
|
|
145
|
+
this.switchButton.addEventListener("keydown", (event) => this.handleKeyDown(event));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private handleStateChange(): void {
|
|
149
|
+
if (this.switchButton.disabled) return;
|
|
150
|
+
|
|
151
|
+
const isChecked = this.switchButton.getAttribute("aria-checked") === "true";
|
|
152
|
+
const newState = !isChecked;
|
|
153
|
+
|
|
154
|
+
this.switchButton.setAttribute("aria-checked", newState.toString());
|
|
155
|
+
|
|
156
|
+
// Dispatch custom event with the new state
|
|
157
|
+
const event = new CustomEvent<SwitchChangeEvent["detail"]>("starwind-switch:change", {
|
|
158
|
+
detail: { checked: newState, switchId: this.switchButton.id },
|
|
159
|
+
bubbles: true,
|
|
160
|
+
cancelable: true,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
this.switchButton.dispatchEvent(event);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private handleKeyDown(event: KeyboardEvent): void {
|
|
167
|
+
if (this.switchButton.disabled) return;
|
|
168
|
+
|
|
169
|
+
if (event.key === " " || event.key === "Enter") {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
this.handleStateChange();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Store instances in a WeakMap to avoid memory leaks
|
|
177
|
+
const switchInstances = new WeakMap<HTMLButtonElement, SwitchHandler>();
|
|
178
|
+
|
|
179
|
+
const setupSwitches = () => {
|
|
180
|
+
document
|
|
181
|
+
.querySelectorAll<HTMLButtonElement>('.starwind-switch button[role="switch"]')
|
|
182
|
+
.forEach((switchButton) => {
|
|
183
|
+
if (!switchInstances.has(switchButton)) {
|
|
184
|
+
switchInstances.set(switchButton, new SwitchHandler(switchButton));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
setupSwitches();
|
|
190
|
+
document.addEventListener("astro:after-swap", setupSwitches);
|
|
191
|
+
document.addEventListener("starwind:init", setupSwitches);
|
|
192
|
+
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { cv } from "css-variants";
|
|
4
|
+
|
|
5
|
+
type VariantProps<T extends (...args: any) => any> = NonNullable<Parameters<T>[0]>;
|
|
6
|
+
|
|
7
|
+
type Props = HTMLAttributes<"table"> & VariantProps<typeof table>;
|
|
8
|
+
|
|
9
|
+
export const table = cv({
|
|
10
|
+
base: "w-full caption-bottom text-sm",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const { class: className, ...rest } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<div data-slot="table-container" class="relative w-full overflow-x-auto">
|
|
17
|
+
<table class:list={[table(), className]} {...rest} data-slot="table">
|
|
18
|
+
<slot />
|
|
19
|
+
</table>
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { cv } from "css-variants";
|
|
4
|
+
|
|
5
|
+
type VariantProps<T extends (...args: any) => any> = NonNullable<Parameters<T>[0]>;
|
|
6
|
+
|
|
7
|
+
type Props = HTMLAttributes<"tbody"> & VariantProps<typeof tableBody>;
|
|
8
|
+
|
|
9
|
+
export const tableBody = cv({
|
|
10
|
+
base: "[&_tr:last-child]:border-0",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const { class: className, ...rest } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<tbody class:list={[tableBody(), className]} {...rest} data-slot="table-body">
|
|
17
|
+
<slot />
|
|
18
|
+
</tbody>
|