@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 @@
|
|
|
1
|
+
export * from "./toast-manager"
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starwind Toast API
|
|
3
|
+
*
|
|
4
|
+
* A simple, framework-agnostic toast notification system.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ;```ts
|
|
8
|
+
* import { toast } from "./toast/toast-manager"
|
|
9
|
+
*
|
|
10
|
+
* // Simple usage
|
|
11
|
+
* toast("Hello world")
|
|
12
|
+
* toast({ title: "Success", description: "Item saved" })
|
|
13
|
+
*
|
|
14
|
+
* // Variant shortcuts
|
|
15
|
+
* toast.success("Saved successfully")
|
|
16
|
+
* toast.error("Something went wrong")
|
|
17
|
+
* toast.warning("Please check your input")
|
|
18
|
+
* toast.info("New update available")
|
|
19
|
+
* toast.loading("Processing...")
|
|
20
|
+
*
|
|
21
|
+
* // Promise handling
|
|
22
|
+
* toast.promise(saveData(), {
|
|
23
|
+
* loading: "Saving...",
|
|
24
|
+
* success: "Saved!",
|
|
25
|
+
* error: "Failed to save"
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Management
|
|
29
|
+
* const id = toast("Processing...")
|
|
30
|
+
* toast.update(id, { title: "Almost done..." })
|
|
31
|
+
* toast.dismiss(id)
|
|
32
|
+
* toast.dismiss() // dismiss all
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export type Variant = "default" | "success" | "error" | "warning" | "info" | "loading"
|
|
37
|
+
|
|
38
|
+
export interface ToastOptions {
|
|
39
|
+
id?: string
|
|
40
|
+
title?: string
|
|
41
|
+
description?: string
|
|
42
|
+
variant?: Variant
|
|
43
|
+
/**
|
|
44
|
+
* Duration in ms. Set to 0 for infinite (no auto-dismiss).
|
|
45
|
+
*/
|
|
46
|
+
duration?: number
|
|
47
|
+
/**
|
|
48
|
+
* Callback when toast close animation starts
|
|
49
|
+
*/
|
|
50
|
+
onClose?: () => void
|
|
51
|
+
/**
|
|
52
|
+
* Callback when toast is removed from DOM
|
|
53
|
+
*/
|
|
54
|
+
onRemove?: () => void
|
|
55
|
+
action?: {
|
|
56
|
+
label: string
|
|
57
|
+
onClick: () => void
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare global {
|
|
62
|
+
interface Window {
|
|
63
|
+
__starwind__: {
|
|
64
|
+
toast?: ToastManager
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PromiseStateOption {
|
|
70
|
+
title?: string
|
|
71
|
+
description?: string
|
|
72
|
+
duration?: number
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type PromiseStateValue<T> =
|
|
76
|
+
| string
|
|
77
|
+
| PromiseStateOption
|
|
78
|
+
| ((data: T) => string | PromiseStateOption)
|
|
79
|
+
|
|
80
|
+
export interface PromiseOptions<T, E = Error> {
|
|
81
|
+
loading: string | PromiseStateOption
|
|
82
|
+
success: PromiseStateValue<T>
|
|
83
|
+
error: PromiseStateValue<E>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface ToastManager {
|
|
87
|
+
add(options: ToastOptions): string
|
|
88
|
+
update(id: string, options: Partial<ToastOptions>): void
|
|
89
|
+
close(id: string): void
|
|
90
|
+
closeAll(): void
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the toast manager instance from the window
|
|
95
|
+
*/
|
|
96
|
+
function getManager(): ToastManager | null {
|
|
97
|
+
if (typeof window === "undefined") return null
|
|
98
|
+
return window.__starwind__?.toast ?? null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Normalize a string or options object to ToastOptions
|
|
103
|
+
*/
|
|
104
|
+
function normalizeOption<T>(
|
|
105
|
+
value: string | PromiseStateOption | ((data: T) => string | PromiseStateOption),
|
|
106
|
+
data?: T
|
|
107
|
+
): Omit<ToastOptions, "variant"> {
|
|
108
|
+
// We use a cast here because T is generic and can't be automatically matched internally
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
110
|
+
const resolved = typeof value === "function" ? value(data as T) : value
|
|
111
|
+
if (typeof resolved === "string") {
|
|
112
|
+
return { title: resolved }
|
|
113
|
+
}
|
|
114
|
+
return resolved
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create a toast notification
|
|
119
|
+
*/
|
|
120
|
+
function createToast(
|
|
121
|
+
messageOrOptions: string | ToastOptions,
|
|
122
|
+
extraOptions?: Omit<ToastOptions, "title">
|
|
123
|
+
): string {
|
|
124
|
+
let options: ToastOptions
|
|
125
|
+
if (typeof messageOrOptions === "string") {
|
|
126
|
+
options = { title: messageOrOptions, ...extraOptions }
|
|
127
|
+
} else {
|
|
128
|
+
options = messageOrOptions
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const manager = getManager()
|
|
132
|
+
if (manager) {
|
|
133
|
+
return manager.add(options)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.warn("Toast: No Toaster found. Add <Toaster /> to your layout.")
|
|
137
|
+
return ""
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create a toast with a specific variant
|
|
142
|
+
*/
|
|
143
|
+
function createVariantToast(
|
|
144
|
+
variant: Variant,
|
|
145
|
+
message: string,
|
|
146
|
+
options?: Omit<ToastOptions, "variant">
|
|
147
|
+
): string {
|
|
148
|
+
return createToast({ ...options, title: message, variant })
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Toast API interface
|
|
153
|
+
*/
|
|
154
|
+
interface ToastAPI {
|
|
155
|
+
(message: string, options?: Omit<ToastOptions, "title">): string
|
|
156
|
+
(options: ToastOptions): string
|
|
157
|
+
success(message: string, options?: Omit<ToastOptions, "variant">): string
|
|
158
|
+
error(message: string, options?: Omit<ToastOptions, "variant">): string
|
|
159
|
+
warning(message: string, options?: Omit<ToastOptions, "variant">): string
|
|
160
|
+
info(message: string, options?: Omit<ToastOptions, "variant">): string
|
|
161
|
+
loading(message: string, options?: Omit<ToastOptions, "variant">): string
|
|
162
|
+
promise<T, E = Error>(promise: Promise<T>, options: PromiseOptions<T, E>): Promise<T>
|
|
163
|
+
update(id: string, options: Partial<ToastOptions>): void
|
|
164
|
+
dismiss(id?: string): void
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Main toast function with variant methods attached
|
|
169
|
+
*/
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
171
|
+
const toast = createToast as unknown as ToastAPI
|
|
172
|
+
|
|
173
|
+
toast.success = (message: string, options?: Omit<ToastOptions, "variant">) =>
|
|
174
|
+
createVariantToast("success", message, options)
|
|
175
|
+
|
|
176
|
+
toast.error = (message: string, options?: Omit<ToastOptions, "variant">) =>
|
|
177
|
+
createVariantToast("error", message, options)
|
|
178
|
+
|
|
179
|
+
toast.warning = (message: string, options?: Omit<ToastOptions, "variant">) =>
|
|
180
|
+
createVariantToast("warning", message, options)
|
|
181
|
+
|
|
182
|
+
toast.info = (message: string, options?: Omit<ToastOptions, "variant">) =>
|
|
183
|
+
createVariantToast("info", message, options)
|
|
184
|
+
|
|
185
|
+
toast.loading = (message: string, options?: Omit<ToastOptions, "variant">) =>
|
|
186
|
+
createVariantToast("loading", message, { ...options, duration: 0 })
|
|
187
|
+
|
|
188
|
+
toast.promise = async <T, E = Error>(
|
|
189
|
+
promise: Promise<T>,
|
|
190
|
+
options: PromiseOptions<T, E>
|
|
191
|
+
): Promise<T> => {
|
|
192
|
+
const loadingOpts = normalizeOption(options.loading)
|
|
193
|
+
const id = createToast({
|
|
194
|
+
...loadingOpts,
|
|
195
|
+
variant: "loading",
|
|
196
|
+
duration: 0 // Don't auto-dismiss while loading
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const data = await promise
|
|
201
|
+
const successOpts = normalizeOption(options.success, data)
|
|
202
|
+
toast.update(id, { ...successOpts, variant: "success" })
|
|
203
|
+
return data
|
|
204
|
+
} catch (error) {
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
206
|
+
const errorOpts = normalizeOption(options.error, error as E)
|
|
207
|
+
toast.update(id, { ...errorOpts, variant: "error" })
|
|
208
|
+
throw error
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
toast.update = (id: string, options: Partial<ToastOptions>): void => {
|
|
213
|
+
const manager = getManager()
|
|
214
|
+
if (manager) {
|
|
215
|
+
manager.update(id, options)
|
|
216
|
+
} else {
|
|
217
|
+
console.warn("Toast: No Toaster found. Add <Toaster /> to your layout.")
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
toast.dismiss = (id?: string): void => {
|
|
222
|
+
const manager = getManager()
|
|
223
|
+
if (!manager) {
|
|
224
|
+
// Can't dismiss if manager isn't ready
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
if (id) {
|
|
228
|
+
manager.close(id)
|
|
229
|
+
} else {
|
|
230
|
+
manager.closeAll()
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export { toast }
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
import { cv } from "css-variants";
|
|
4
|
+
|
|
5
|
+
export const toggle = cv({
|
|
6
|
+
base: [
|
|
7
|
+
"inline-flex items-center justify-center gap-3xs rounded-md font-medium ws-nowrap",
|
|
8
|
+
"disabled:pointer-events-none disabled:op-50",
|
|
9
|
+
"data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
|
|
10
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='w-'])]:w-md [&_svg:not([class*='h-'])]:h-md",
|
|
11
|
+
"focus-visible:border-outline focus-visible:ring-outline/50 focus-visible:ring-3",
|
|
12
|
+
"transition-colors outline-none",
|
|
13
|
+
"aria-invalid:ring-error/40 aria-invalid:border-error",
|
|
14
|
+
],
|
|
15
|
+
variants: {
|
|
16
|
+
variant: {
|
|
17
|
+
default: "hover:bg-muted hover:text-muted-foreground bg-transparent",
|
|
18
|
+
outline:
|
|
19
|
+
"border-input hover:bg-accent hover:text-accent-foreground b bg-transparent shadow-xs",
|
|
20
|
+
ghost: "hover:bg-accent hover:text-accent-foreground bg-transparent",
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
sm: "h-2xl px-3xs text-sm",
|
|
24
|
+
md: "h-3xl px-2xs text-base",
|
|
25
|
+
lg: "h-3xl px-xs text-lg",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
defaultVariants: {
|
|
29
|
+
variant: "default",
|
|
30
|
+
size: "md",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
type Props = NonNullable<Parameters<typeof toggle>[0]> &
|
|
35
|
+
HTMLAttributes<"button"> & {
|
|
36
|
+
/**
|
|
37
|
+
* The pressed state of the toggle when initially rendered
|
|
38
|
+
*/
|
|
39
|
+
defaultPressed?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Optional sync group name. When set, all toggles with the same sync group will mirror each other's state
|
|
42
|
+
*/
|
|
43
|
+
syncGroup?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const { class: className, defaultPressed = false, syncGroup, variant, size, ...rest } = Astro.props;
|
|
47
|
+
|
|
48
|
+
const dataState = defaultPressed ? "on" : "off";
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
class:list={[toggle({ variant, size }), "starwind-toggle", className]}
|
|
54
|
+
data-state={dataState}
|
|
55
|
+
data-sync-group={syncGroup}
|
|
56
|
+
aria-pressed={defaultPressed}
|
|
57
|
+
{...rest}
|
|
58
|
+
data-slot="toggle"
|
|
59
|
+
>
|
|
60
|
+
<slot />
|
|
61
|
+
</button>
|
|
62
|
+
|
|
63
|
+
<script>
|
|
64
|
+
import type { ToggleSyncEvent } from "./ToggleTypes";
|
|
65
|
+
|
|
66
|
+
class ToggleHandler {
|
|
67
|
+
private toggle: HTMLButtonElement;
|
|
68
|
+
private syncGroup: string | undefined;
|
|
69
|
+
|
|
70
|
+
constructor(toggle: HTMLButtonElement, idx: number) {
|
|
71
|
+
this.toggle = toggle;
|
|
72
|
+
this.syncGroup = toggle.dataset.syncGroup;
|
|
73
|
+
|
|
74
|
+
if (!this.toggle.id) {
|
|
75
|
+
this.toggle.id = `starwind-toggle${idx}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.setupEventListeners();
|
|
79
|
+
|
|
80
|
+
if (this.syncGroup) {
|
|
81
|
+
this.setupSyncListener();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private setupEventListeners(): void {
|
|
86
|
+
this.toggle.addEventListener("click", () => this.handleToggle());
|
|
87
|
+
this.toggle.addEventListener("keydown", (event) => this.handleKeyDown(event));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private setupSyncListener(): void {
|
|
91
|
+
if (!this.syncGroup) return;
|
|
92
|
+
|
|
93
|
+
document.addEventListener(`starwind-toggle-sync:${this.syncGroup}`, ((e: ToggleSyncEvent) => {
|
|
94
|
+
// Don't sync if this toggle triggered the event
|
|
95
|
+
if (e.detail.sourceId === this.toggle.id) return;
|
|
96
|
+
|
|
97
|
+
const newPressed = e.detail.pressed;
|
|
98
|
+
this.updateState(newPressed, false); // false = don't dispatch sync event
|
|
99
|
+
}) as EventListener);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private handleToggle(): void {
|
|
103
|
+
if (this.isDisabled()) return;
|
|
104
|
+
|
|
105
|
+
const isPressed = this.toggle.getAttribute("aria-pressed") === "true";
|
|
106
|
+
const newPressed = !isPressed;
|
|
107
|
+
|
|
108
|
+
this.updateState(newPressed, true);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private handleKeyDown(event: KeyboardEvent): void {
|
|
112
|
+
if (this.isDisabled()) return;
|
|
113
|
+
|
|
114
|
+
if (event.key === " " || event.key === "Enter") {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
this.handleToggle();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private isDisabled(): boolean {
|
|
121
|
+
return this.toggle.disabled;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private updateState(pressed: boolean, dispatchSync: boolean): void {
|
|
125
|
+
const newState = pressed ? "on" : "off";
|
|
126
|
+
|
|
127
|
+
this.toggle.setAttribute("aria-pressed", pressed.toString());
|
|
128
|
+
this.toggle.setAttribute("data-state", newState);
|
|
129
|
+
|
|
130
|
+
const changeEvent = new CustomEvent("starwind-toggle:change", {
|
|
131
|
+
detail: {
|
|
132
|
+
pressed,
|
|
133
|
+
toggleId: this.toggle.id,
|
|
134
|
+
...(this.syncGroup ? { syncGroup: this.syncGroup } : {}),
|
|
135
|
+
},
|
|
136
|
+
bubbles: true,
|
|
137
|
+
cancelable: true,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
this.toggle.dispatchEvent(changeEvent);
|
|
141
|
+
|
|
142
|
+
// Dispatch sync event if in a sync group and requested
|
|
143
|
+
if (this.syncGroup && dispatchSync) {
|
|
144
|
+
const syncEvent = new CustomEvent<ToggleSyncEvent["detail"]>(
|
|
145
|
+
`starwind-toggle-sync:${this.syncGroup}`,
|
|
146
|
+
{
|
|
147
|
+
detail: {
|
|
148
|
+
pressed,
|
|
149
|
+
sourceId: this.toggle.id,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
document.dispatchEvent(syncEvent);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Store instances in a WeakMap to avoid memory leaks
|
|
160
|
+
const toggleInstances = new WeakMap<HTMLElement, ToggleHandler>();
|
|
161
|
+
let toggleCounter = 0;
|
|
162
|
+
|
|
163
|
+
const setupToggles = () => {
|
|
164
|
+
document.querySelectorAll<HTMLButtonElement>(".starwind-toggle").forEach((toggle) => {
|
|
165
|
+
if (!toggleInstances.has(toggle)) {
|
|
166
|
+
toggleInstances.set(toggle, new ToggleHandler(toggle, toggleCounter++));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
setupToggles();
|
|
172
|
+
document.addEventListener("astro:after-swap", setupToggles);
|
|
173
|
+
document.addEventListener("starwind:init", setupToggles);
|
|
174
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ToggleChangeEvent extends CustomEvent {
|
|
2
|
+
detail: {
|
|
3
|
+
pressed: boolean
|
|
4
|
+
toggleId: string
|
|
5
|
+
syncGroup?: string
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ToggleSyncEvent extends CustomEvent {
|
|
10
|
+
detail: {
|
|
11
|
+
pressed: boolean
|
|
12
|
+
sourceId: string
|
|
13
|
+
}
|
|
14
|
+
}
|