UIPin
ComponentsIconsIllustrationsMotionTemplatesApps
Boards
UIPin

Free, open-source UI components, icons, illustrations, motion, templates and apps, in one search. Every item links to its source and licence.

UIPin is free. If it saved you time, you can keep it running:

Buy me a coffee
ComponentsIconsIllustrationsMotionTemplatesAppsLibrariesCompareNew this weekMCP for agentsBoardsPrivacy

Components, icons and artwork belong to their authors and are shown under their open-source licences.

shadcn/ui/Alert

Feedback & loaders
1 of 7
Compiling

Theme it

Every preview, live

Brand colour

Corner radius

Font

Recolours shadcn’s tokens, Tailwind’s accent colours and colours set in the code. Red, amber and green classes stay, since they usually mean error, warning or success.

7 versions·4 librariesCompare all alerts →

  • Alert
  • 8-bit Alert
  • 8-bit Alert Dialog
  • Alert
  • Alert dialog
  • Alert Dialog
  • SmoothUI

Alert

npx shadcn@latest add https://ui.shadcn.com/r/styles/new-york-v4/alert.json
Open in v0 Docs Repo
Library
shadcn/ui
License
MIT
Stack
React · Tailwind CSS
Packages
cn
Size
66 lines
Demo
From shadcn/ui

Code

registry/new-york-v4/ui/alert.tsx

import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"

const alertVariants = cva(
  "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg 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",
        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(
        "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
        className
      )}
      {...props}
    />
  )
}

function AlertDescription({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-description"
      className={cn(
        "col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed",
        className
      )}
      {...props}
    />
  )
}

export { Alert, AlertTitle, AlertDescription }

More like this

Animated List

SmoothUI·Data display

Tabs

shadcn/ui·Navigation

Spinner

shadcn/ui·Feedback & loaders

Animated List

Magic UI·Data display

Table

shadcn/ui·Navigation

Field

shadcn/ui·Backgrounds

Magic Card

Magic UI·Cards

Card

shadcn/ui·Cards

Alert

HextaUI·Feedback & loaders

Scroll Area

shadcn/ui·Data display

Shine Border

Magic UI·Cursor & effects

Message Scroller

shadcn/ui·Other

Cool Mode

Magic UI·Buttons

Label

HextaUI·Inputs & forms

Navigation menu

HextaUI·Overlays