alert.svelte 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <script lang="ts" module>
  2. import { type VariantProps, tv } from "tailwind-variants";
  3. export const alertVariants = tv({
  4. base: "grid gap-0.5 rounded-lg border px-4 py-3 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.5 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4 group/alert relative w-full",
  5. variants: {
  6. variant: {
  7. default: "bg-card text-card-foreground",
  8. destructive: "text-destructive bg-card *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",
  9. },
  10. },
  11. defaultVariants: {
  12. variant: "default",
  13. },
  14. });
  15. export type AlertVariant = VariantProps<typeof alertVariants>["variant"];
  16. </script>
  17. <script lang="ts">
  18. import type { HTMLAttributes } from "svelte/elements";
  19. import { cn, type WithElementRef } from "../../lib/utils.js";
  20. let {
  21. ref = $bindable(null),
  22. class: className,
  23. variant = "default",
  24. children,
  25. ...restProps
  26. }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
  27. variant?: AlertVariant;
  28. } = $props();
  29. </script>
  30. <div
  31. bind:this={ref}
  32. data-slot="alert"
  33. role="alert"
  34. class={cn(alertVariants({ variant }), className)}
  35. {...restProps}
  36. >
  37. {@render children?.()}
  38. </div>