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

45 lines
1.2 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({
2025-06-21 21:07:36 +02:00
base: "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
2025-06-08 16:32:41 +02:00
variants: {
variant: {
2025-06-21 21:07:36 +02:00
default: "bg-card text-card-foreground",
2025-06-08 16:32:41 +02:00
destructive:
2025-06-21 21:07:36 +02:00
"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"
class={cn(alertVariants({ variant }), className)}
{...restProps}
role="alert"
>
2025-06-08 16:32:41 +02:00
{@render children?.()}
2024-04-22 19:36:31 +02:00
</div>