{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"urgency-badge","type":"registry:ui","title":"Urgency badge","description":"Scarcity badge with a live dot and an optional percent sold bar that animates into view.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/urgency-badge/urgency-badge.tsx","type":"registry:ui","target":"components/facade/urgency-badge.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useInView, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type UrgencyVariant = \"neutral\" | \"brand\" | \"warning\";\n\nexport interface UrgencyBadgeProps {\n  /** Main message, e.g. \"Only 3 homes left\". */\n  label?: React.ReactNode;\n  /** Secondary line shown next to the progress bar, e.g. \"Phase 2\". */\n  detail?: React.ReactNode;\n  /** Percent sold (0 to 100). When set, a progress bar animates in. */\n  progress?: number;\n  /** Text after the percentage, defaults to \"sold\". */\n  progressSuffix?: string;\n  variant?: UrgencyVariant;\n  /** Show the pulsing live dot. */\n  pulse?: boolean;\n  className?: string;\n}\n\nconst variants: Record<UrgencyVariant, { root: string; dot: string; ping: string; bar: string; track: string }> = {\n  neutral: {\n    root: \"bg-muted text-foreground\",\n    dot: \"bg-success\",\n    ping: \"bg-success/60\",\n    bar: \"bg-foreground\",\n    track: \"bg-foreground/[0.08]\",\n  },\n  brand: {\n    root: \"bg-accent text-accent-foreground\",\n    dot: \"bg-brand\",\n    ping: \"bg-brand/60\",\n    bar: \"bg-brand\",\n    track: \"bg-brand/15\",\n  },\n  warning: {\n    root: \"bg-warning/10 text-foreground\",\n    dot: \"bg-warning\",\n    ping: \"bg-warning/70\",\n    bar: \"bg-warning\",\n    track: \"bg-warning/20\",\n  },\n};\n\nexport function UrgencyBadge({\n  label = \"Only 3 homes left\",\n  detail,\n  progress,\n  progressSuffix = \"sold\",\n  variant = \"brand\",\n  pulse = true,\n  className,\n}: UrgencyBadgeProps) {\n  const reduce = useReducedMotion();\n  const ref = React.useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-40px 0px\" });\n  const v = variants[variant];\n  const hasProgress = typeof progress === \"number\";\n  const pct = hasProgress ? Math.min(100, Math.max(0, progress)) : 0;\n\n  return (\n    <div\n      ref={ref}\n      role=\"status\"\n      className={cn(\n        \"inline-flex flex-col gap-2.5 rounded-2xl px-4 py-3 text-sm\",\n        hasProgress ? \"min-w-[260px]\" : \"rounded-full px-3.5 py-1.5\",\n        v.root,\n        className,\n      )}\n    >\n      <div className=\"flex items-center gap-2\">\n        {pulse && (\n          <span className=\"relative flex size-2 shrink-0\" aria-hidden=\"true\">\n            {!reduce && <span className={cn(\"absolute inline-flex size-full animate-ping-slow rounded-full\", v.ping)} />}\n            <span className={cn(\"relative inline-flex size-2 rounded-full\", v.dot)} />\n          </span>\n        )}\n        <span className=\"font-medium\">{label}</span>\n        {detail && !hasProgress && <span className=\"opacity-60\">· {detail}</span>}\n      </div>\n      {hasProgress && (\n        <div className=\"space-y-1.5\">\n          <div\n            className={cn(\"h-1.5 w-full overflow-hidden rounded-full\", v.track)}\n            role=\"progressbar\"\n            aria-valuemin={0}\n            aria-valuemax={100}\n            aria-valuenow={Math.round(pct)}\n            aria-label={`${Math.round(pct)}% ${progressSuffix}`}\n          >\n            <motion.div\n              className={cn(\"relative h-full rounded-full\", v.bar)}\n              initial={{ width: reduce ? `${pct}%` : \"0%\" }}\n              animate={{ width: inView || reduce ? `${pct}%` : \"0%\" }}\n              transition={{ duration: 1.2, ease: [0.16, 1, 0.3, 1], delay: 0.15 }}\n            />\n          </div>\n          <div className=\"flex items-center justify-between text-xs opacity-70\">\n            <span>\n              <span className=\"font-semibold tabular-nums opacity-100\">{Math.round(pct)}%</span> {progressSuffix}\n            </span>\n            {detail && <span>{detail}</span>}\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default UrgencyBadge;\n"}],"categories":["feedback"],"meta":{"tier":"free","demo":"import { UrgencyBadge } from \"./urgency-badge\";\n\nexport default function Demo() {\n  return (\n    <div className=\"flex w-full max-w-[640px] flex-col items-center gap-8\">\n      <div className=\"flex flex-wrap items-center justify-center gap-3\">\n        <UrgencyBadge variant=\"brand\" label=\"Only 3 homes left\" />\n        <UrgencyBadge variant=\"neutral\" label=\"12 tours booked this week\" />\n        <UrgencyBadge variant=\"warning\" label=\"Open house Saturday\" detail=\"11 AM to 2 PM\" />\n      </div>\n      <div className=\"flex flex-wrap items-start justify-center gap-4\">\n        <UrgencyBadge variant=\"brand\" label=\"Only 3 homes left in Phase 2\" progress={88} detail=\"Mueller, Austin\" />\n        <UrgencyBadge variant=\"neutral\" label=\"Final release now open\" progress={64} detail=\"42 of 66 residences\" />\n      </div>\n    </div>\n  );\n}\n"}}