DesignX
Core@paxeer/core/alertimplemented

Alert

shadcn Alert. Destructive maps to error-container.

Install

$pnpm exec designx add @paxeer/core/alert

Source code

components/designx/core/alert.tsxtsx
import { cva, type VariantProps } from "class-variance-authority";
import { type ComponentProps } from "react";
import { cn } from "../lib/cn";

/** Adapted from shadcn/ui Alert. */

const alertVariants = cva(
  "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-[var(--md-sys-shape-corner-medium)] border px-4 py-3 text-[length:var(--md-sys-typescale-body-medium-size)] has-[>svg]:grid-cols-[1rem_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
  {
    variants: {
      variant: {
        default: "border-outline-variant bg-surface-container text-on-surface",
        destructive:
          "border-error-container bg-error-container text-on-error-container",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  },
);

export function Alert({
  className,
  variant,
  ...props
}: ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
  return (
    <div
      data-slot="alert"
      role="alert"
      className={cn(alertVariants({ variant }), className)}
      {...props}
    />
  );
}

export function AlertTitle({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-title"
      className={cn("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight", className)}
      {...props}
    />
  );
}

export function AlertDescription({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-description"
      className={cn(
        "col-start-2 grid justify-items-start gap-1 text-[length:var(--md-sys-typescale-body-small-size)] text-on-surface-variant [&_p]:leading-relaxed",
        className,
      )}
      {...props}
    />
  );
}

Dependencies

Registry dependencies