Skip to content
caliper ui docs

Components

Alert

An inline message that keeps context and recovery beside the work.

Free
pnpm dlx shadcn@latest add @caliper/alert

Pricing page copy

Edited by Lena Fischer · 2 minutes ago

Team is $12 per seat each month, billed yearly. Every plan includes SSO and a 30-day history.

Installs components/ui/alert.tsxDepends on @radix-ui/react-slot, lucide-reactMotion none in component source

When to use

Use it for

  • A state needs attention and the person can act on it right where they are.
  • Errors that should offer a retry, with the draft still safe.

Skip it when

  • The message is a passing confirmation; use a toast.
  • The message blocks a decision; use a dialog.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/alert

Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.

Usage

This is the code behind the preview above.

example.tsx
import { useState, type ReactNode } from "react"
import { Alert } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
import { cn } from "@/components/ui/lib/cn"

function Panel({ title, context, action, className, children }: { title: string; context: string; action?: ReactNode; className?: string; children: ReactNode }) {
  return (
    <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}>
      <div className="flex items-start justify-between gap-3">
        <div className="grid min-w-0 gap-1">
          <p className="font-medium">{title}</p>
          <p className="text-sm text-muted-foreground">{context}</p>
        </div>
        {action}
      </div>
      {children}
    </section>
  );
}

export function SyncFailed() {
  const [state, setState] = useState<"failed" | "busy" | "synced">("failed");
  return (
    <Panel title="Pricing page copy" context="Edited by Lena Fischer · 2 minutes ago">
      <p className="text-sm leading-6 text-muted-foreground">
        Team is $12 per seat each month, billed yearly. Every plan includes SSO and a 30-day history.
      </p>
      {state === "synced" ? (
        <Alert title="Changes synced" variant="success">3 edits are live on halden.example/pricing.</Alert>
      ) : (
        <Alert
          title="Couldn't sync changes"
          variant="error"
          loading={state === "busy"}
          action={
            <Button size="sm" variant="secondary" onClick={() => { setState("busy"); setTimeout(() => setState("synced"), 1200); }}>
              Retry
            </Button>
          }
        >
          Your draft is safe. Try syncing it again.
        </Alert>
      )}
    </Panel>
  );
}

API reference

Alert

component

Also accepts the native props of its root element and a ref.

PropTypeDefault
title *ReactNode—
variantFeedbackVariant"neutral"
loadingbooleanfalse
actionReactNode—
onDismiss(() => void)—

Accessibility

It is built on native elements and keeps aria-busy, aria-atomic, aria-labelledby, aria-label and aria-hidden in step with state.

No custom key handling; Tab and the native activation keys do the work.

Motion

It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.

All Feedback examples