Files
gpx.studio/website/src/lib/components/ui/alert/alert.svelte

44 lines
1.3 KiB
Svelte
Raw Normal View History

2025-06-08 16:32:41 +02:00
<script lang="ts" module>
import { type VariantProps, tv } from "tailwind-variants";
export const alertVariants = tv({
2026-04-06 18:22:01 +02:00
base: "grid gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4 group/alert relative w-full",
2025-06-08 16:32:41 +02:00
variants: {
variant: {
2025-06-21 21:07:36 +02:00
default: "bg-card text-card-foreground",
2026-04-06 18:22:01 +02:00
destructive: "text-destructive bg-card *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",
2025-06-08 16:32:41 +02:00
},
},
defaultVariants: {
variant: "default",
},
});
export type AlertVariant = VariantProps<typeof alertVariants>["variant"];
</script>
2024-04-22 19:36:31 +02:00
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
2025-06-21 21:07:36 +02:00
import { cn, type WithElementRef } from "$lib/utils.js";
2024-04-22 19:36:31 +02:00
2025-06-08 16:32:41 +02:00
let {
ref = $bindable(null),
class: className,
variant = "default",
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
variant?: AlertVariant;
} = $props();
2024-04-22 19:36:31 +02:00
</script>
2025-06-21 21:07:36 +02:00
<div
bind:this={ref}
data-slot="alert"
2026-04-06 18:22:01 +02:00
role="alert"
2025-06-21 21:07:36 +02:00
class={cn(alertVariants({ variant }), className)}
{...restProps}
>
2025-06-08 16:32:41 +02:00
{@render children?.()}
2024-04-22 19:36:31 +02:00
</div>