Displays a callout for user attention.
Installation
npx shadcn@latest add @caprice/alertnpm install @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactAdd a cn helper
import { defineConfig, type VariantProps } from 'cva';import { twMerge } from 'tailwind-merge';export const { compose, cva, cx: cn,} = defineConfig({ hooks: { onComplete: (className: string) => twMerge(className), },});export type { VariantProps };Copy and paste the following code into your project.
import { mergePropsN, useRender } from '@base-ui/react';import { cn, cva, type VariantProps } from '@/lib/utils';const alertVariants = cva({ base: 'relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-xl 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', variants: { variant: { default: 'bg-card text-card-foreground', success: 'border-success/30 bg-success/5 [&>svg]:text-success', info: 'border-info/30 bg-info/5 [&>svg]:text-info', warning: 'border-warning/30 bg-warning/5 [&>svg]:text-warning', destructive: 'border-destructive/30 bg-destructive/5 [&>svg]:text-destructive', }, }, defaultVariants: { variant: 'default', },});export namespace Root { export type Variants = VariantProps<typeof alertVariants>; export type Props = useRender.ComponentProps<'div'> & Root.Variants;}/** * A component that displays a message to the user. * Renders a `<div>` element. * * Documentation: [Caprice UI Alert](https://caprice-ui.com/docs/components/alert) */export function Root({ className, render, variant, ...props }: Root.Props) { const defaultProps: useRender.ElementProps<'div'> & { 'data-slot'?: string } = { 'data-slot': 'alert', role: 'alert', className: cn(alertVariants({ variant }), className), }; return useRender({ defaultTagName: 'div', render, props: mergePropsN<'div'>([defaultProps, props]), });}/** * A component that displays the title of the alert. * Renders a `<div>` element. * * Documentation: [Caprice UI Alert](https://caprice-ui.com/docs/components/alert) */export namespace Title { export type Props = useRender.ComponentProps<'div'>;}export function Title({ className, render, ...props }: Title.Props) { const defaultProps: useRender.ElementProps<'div'> & { 'data-slot'?: string } = { 'data-slot': 'alert-title', className: cn('col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight', className), }; return useRender({ defaultTagName: 'div', render, props: mergePropsN<'div'>([defaultProps, props]), });}/** * A component that displays the description of the alert. * Renders a `<div>` element. * * Documentation: [Caprice UI Alert](https://caprice-ui.com/docs/components/alert) */export namespace Description { export type Props = useRender.ComponentProps<'div'>;}export function Description({ className, render, ...props }: Description.Props) { const defaultProps: useRender.ElementProps<'div'> & { 'data-slot'?: string } = { 'data-slot': 'alert-description', className: cn( 'col-start-2 grid justify-items-start gap-1 text-muted-foreground text-sm [&_p]:leading-relaxed', className ), }; return useRender({ defaultTagName: 'div', render, props: mergePropsN<'div'>([defaultProps, props]), });}Update the import paths to match your project setup.
Usage
import * as Alert from "@/components/caprice-ui/alert"import * as Alert from "@caprice-ui/react/alert"Examples
Icon
info
Warning
Success
Destructive
Dismissible
Custom
Differences with shadcn/ui / Radix
If you're familiar with Radix UI and shadcn/ui, most patterns will carry over. This guide points out the differences so you can start using Caprice UI without surprises.
Key changes
| Feature | shadcn/ui | Caprice UI |
|---|---|---|
| Primitive | Native <div> elements | Base UI useRender + native <div> |
| Composition | None | render prop |
| API pattern | Flat exports (Alert, AlertTitle) | Namespace pattern (Alert.Root, Alert.Title) |
| Variants | default, destructive | default, success, info, warning, destructive |
| Border radius | rounded-lg | rounded-xl |
| Destructive style | text-destructive bg-card | border-destructive/30 bg-destructive/5 with icon coloring |
| Semantic colors | Not included | success, info, warning with opacity-based bg/border |
Comparison Example
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertTitle>Error</AlertTitle>
<AlertDescription>Something went wrong.</AlertDescription>
</Alert><Alert.Root variant="destructive">
<AlertCircle />
<Alert.Title>Error</Alert.Title>
<Alert.Description>Something went wrong.</Alert.Description>
</Alert.Root>Variants
Prop
Type
Default
API Reference
Root
Prop
Type
Default
Title
Prop
Type
Default
Description
Prop
Type
Default