alert.tsx
This file
Path
apps/web/src/components/ui/alert.tsx
78 lines · 2.1 KiB · TypeScript
Last changed by
Draw text, controls, prose and code from one set of tokensoscabrielbefore adoption60f862e
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import { cva, type VariantProps } from "class-variance-authority";import { cn } from "cn";import * as React from "react";
const alertVariants = cva( "group/alert text-ui relative grid w-full gap-0.5 rounded-none border px-2.5 py-2 text-left 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 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4", { variants: { variant: { default: "bg-card text-card-foreground", destructive: "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current", }, }, defaultVariants: { variant: "default", }, });
function Alert({ className, variant, ...props}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) { return ( <div data-slot="alert" role="alert" className={cn(alertVariants({ variant }), className)} {...props} /> );}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-title" className={cn( "[&_a]:hover:text-foreground font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3", className )} {...props} /> );}
function AlertDescription({ className, ...props}: React.ComponentProps<"div">) { return ( <div data-slot="alert-description" className={cn( "text-muted-foreground [&_a]:hover:text-foreground text-ui text-balance md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-2", className )} {...props} /> );}
function AlertAction({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-action" className={cn( "absolute top-[calc(--spacing(1.25))] right-[calc(--spacing(1.25))]", className )} {...props} /> );}
export { Alert, AlertTitle, AlertDescription, AlertAction };