{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-heading",
  "title": "Card Heading",
  "description": "Three working card headings: a person heading with avatar, time, a Follow button and a ⋯ menu (pin, copy link, hide with undo), a title and description heading with a period menu that redraws a chart, and a settings heading with a switch and a collapse toggle.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/card-heading/card-heading.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface CardHeadingProps {\n  author?: { name: string; role: string; avatar?: string };\n  post?: string;\n  metric?: { title: string; description: string; periods: { id: string; label: string; values: number[]; total: string; delta: string }[] };\n  setting?: { title: string; description: string; enabled: boolean };\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", border: \"rgba(255,255,255,0.09)\", chip: \"rgba(255,255,255,0.06)\", hover: \"rgba(255,255,255,0.04)\", input: \"#0D0D0D\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", accent: \"#FB923C\", ring: \"rgba(245,244,241,0.6)\", pop: \"#181818\", shadow: \"0 20px 50px -16px rgba(0,0,0,0.8)\", bar: \"rgba(255,255,255,0.14)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", chip: \"rgba(10,10,10,0.05)\", hover: \"rgba(10,10,10,0.03)\", input: \"#FAFAF8\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", accent: \"#EA580C\", ring: \"rgba(10,10,10,0.5)\", pop: \"#FFFFFF\", shadow: \"0 20px 50px -20px rgba(0,0,0,0.25)\", bar: \"rgba(10,10,10,0.12)\" },\n};\n\nconst DEFAULT_METRIC = {\n  title: \"Revenue\",\n  description: \"Net of refunds and taxes\",\n  periods: [\n    { id: \"7d\", label: \"Last 7 days\", values: [42, 55, 38, 61, 70, 52, 78], total: \"$48,210\", delta: \"+12.4%\" },\n    { id: \"30d\", label: \"Last 30 days\", values: [30, 44, 52, 40, 58, 66, 49, 72, 61, 80, 74, 88], total: \"$186,940\", delta: \"+8.1%\" },\n    { id: \"12m\", label: \"Last 12 months\", values: [40, 48, 45, 52, 60, 58, 66, 70, 68, 76, 82, 90], total: \"$2.1M\", delta: \"+31.6%\" },\n  ],\n};\n\nexport function CardHeading({ author = { name: \"Lena Brandt\", role: \"Design lead\", avatar: \"/demo/55.webp\" }, post = \"Shipped the new onboarding flow today. Activation is up 18% in the first cohort, and support tickets about setup dropped by a third. Huge thanks to everyone who tested it.\", metric = DEFAULT_METRIC, setting = { title: \"Weekly digest\", description: \"A Monday email with what changed in your workspace.\", enabled: true }, theme = \"dark\", className }: CardHeadingProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [following, setFollowing] = React.useState(false);\n  const [menu, setMenu] = React.useState<\"post\" | \"period\" | null>(null);\n  const [pinned, setPinned] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  const [toast, setToast] = React.useState<string | null>(null);\n  const [period, setPeriod] = React.useState(metric.periods[0].id);\n  const [enabled, setEnabled] = React.useState(setting.enabled);\n  const [expanded, setExpanded] = React.useState(true);\n  const [day, setDay] = React.useState(\"Monday\");\n  // Toasts clear themselves; no ref needed, so handlers that show one can be built during render.\n  React.useEffect(() => {\n    if (!toast) return;\n    const t = setTimeout(() => setToast(null), 1800);\n    return () => clearTimeout(t);\n  }, [toast]);\n  React.useEffect(() => {\n    if (!menu) return;\n    const down = (e: MouseEvent) => !(e.target as HTMLElement).closest(\"[data-menu]\") && setMenu(null);\n    const key = (e: KeyboardEvent) => e.key === \"Escape\" && setMenu(null);\n    document.addEventListener(\"mousedown\", down);\n    document.addEventListener(\"keydown\", key);\n    return () => {\n      document.removeEventListener(\"mousedown\", down);\n      document.removeEventListener(\"keydown\", key);\n    };\n  }, [menu]);\n\n  const say = (t: string) => setToast(t);\n  const per = metric.periods.find((x) => x.id === period) ?? metric.periods[0];\n  const max = Math.max(...per.values);\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const card = \"relative rounded-2xl border\";\n  const menuBox = (children: React.ReactNode, label: string) => (\n    <motion.div initial={reduce ? false : { opacity: 0, y: -4, scale: 0.98 }} animate={{ opacity: 1, y: 0, scale: 1 }} exit={reduce ? undefined : { opacity: 0, y: -4 }} transition={{ duration: 0.14 }} className=\"absolute right-0 z-20 mt-1.5 w-48 origin-top-right rounded-xl border p-1.5\" style={{ background: p.pop, borderColor: p.border, boxShadow: p.shadow }} role=\"menu\" aria-label={label}>\n      {children}\n    </motion.div>\n  );\n  const menuItem = (label: string, onClick: () => void, danger = false, checked?: boolean) => (\n    <button\n      key={label}\n      type=\"button\"\n      role={checked === undefined ? \"menuitem\" : \"menuitemradio\"}\n      aria-checked={checked}\n      onClick={() => {\n        onClick();\n        setMenu(null);\n      }}\n      className={cn(\"flex w-full cursor-pointer items-center justify-between rounded-lg border-0 bg-transparent px-2.5 py-1.5 text-left text-[13px] hover:bg-[var(--ch-h)]\", focus)}\n      style={{ color: danger ? \"#F87171\" : p.text, [\"--ch-h\" as string]: p.hover, ...ring }}\n    >\n      {label}\n      {checked && (\n        <svg width=\"13\" height=\"13\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <path d=\"m3 8.5 3 3 7-7\" />\n        </svg>\n      )}\n    </button>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"relative mx-auto max-w-6xl px-4 py-10 @[640px]:px-6 @[640px]:py-14\">\n        <div className=\"grid items-start gap-4 @[900px]:grid-cols-3\">\n          {/* 1 · Person heading */}\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            {hidden ? (\n              <motion.div key=\"hidden\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} className=\"flex items-center justify-between gap-3 rounded-2xl border border-dashed px-5 py-4 text-[13px]\" style={{ borderColor: p.border, color: p.muted }}>\n                Post hidden from your feed.\n                <button type=\"button\" onClick={() => setHidden(false)} className={cn(\"cursor-pointer rounded border-0 bg-transparent text-[13px] font-medium underline-offset-2 hover:underline\", focus)} style={{ color: p.text, ...ring }}>\n                  Undo\n                </button>\n              </motion.div>\n            ) : (\n              <motion.article key=\"post\" initial={reduce ? false : { opacity: 0, scale: 0.98 }} animate={{ opacity: 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.98 }} className={card} style={{ background: p.card, borderColor: p.border }} aria-labelledby={`${uid}-a`}>\n                <header className=\"flex items-center gap-3 border-b px-5 py-4\" style={{ borderColor: p.border }}>\n                  {author.avatar ? (\n                    // eslint-disable-next-line @next/next/no-img-element\n                    <img src={author.avatar} alt=\"\" className=\"h-10 w-10 rounded-full object-cover\" />\n                  ) : (\n                    <span className=\"flex h-10 w-10 items-center justify-center rounded-full text-[13px] font-semibold\" style={{ background: p.chip }}>\n                      {author.name[0]}\n                    </span>\n                  )}\n                  <div className=\"min-w-0 flex-1\">\n                    <h3 id={`${uid}-a`} className=\"m-0 flex min-w-0 items-center gap-1.5 text-[14px] font-semibold\">\n                      <span className=\"min-w-0 truncate\">{author.name}</span>\n                      <AnimatePresence>\n                        {pinned && (\n                          <motion.span initial={reduce ? false : { scale: 0 }} animate={{ scale: 1 }} exit={reduce ? undefined : { scale: 0 }} className=\"shrink-0 rounded px-1 text-[10.5px] font-semibold\" style={{ background: p.chip, color: p.accent }}>\n                            Pinned\n                          </motion.span>\n                        )}\n                      </AnimatePresence>\n                    </h3>\n                    <p className=\"m-0 text-[12px]\" style={{ color: p.faint }}>\n                      {author.role} · 2h ago\n                    </p>\n                  </div>\n                  <button type=\"button\" aria-pressed={following} onClick={() => setFollowing((f) => !f)} className={cn(\"relative h-8 cursor-pointer overflow-hidden rounded-full border px-3 text-[12.5px] font-medium\", focus)} style={{ borderColor: following ? p.border : \"transparent\", background: following ? \"transparent\" : p.on, color: following ? p.text : p.onText, ...ring }}>\n                    <AnimatePresence mode=\"wait\" initial={false}>\n                      <motion.span key={String(following)} className=\"block\" initial={reduce ? false : { y: 10, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={reduce ? undefined : { y: -10, opacity: 0 }} transition={{ duration: 0.14 }}>\n                        {following ? \"Following\" : \"Follow\"}\n                      </motion.span>\n                    </AnimatePresence>\n                  </button>\n                  <div className=\"relative\" data-menu>\n                    <button type=\"button\" aria-label=\"Post options\" aria-haspopup=\"menu\" aria-expanded={menu === \"post\"} onClick={() => setMenu(menu === \"post\" ? null : \"post\")} className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent\", focus)} style={{ color: p.muted, ...ring }}>\n                      <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n                        <circle cx=\"5\" cy=\"12\" r=\"1.8\" />\n                        <circle cx=\"12\" cy=\"12\" r=\"1.8\" />\n                        <circle cx=\"19\" cy=\"12\" r=\"1.8\" />\n                      </svg>\n                    </button>\n                    <AnimatePresence>\n                      {menu === \"post\" &&\n                        menuBox(\n                          <>\n                            {menuItem(pinned ? \"Unpin\" : \"Pin to profile\", () => setPinned((x) => !x))}\n                            {menuItem(\"Copy link\", () => {\n                              navigator.clipboard?.writeText(\"https://nexora.io/posts/onboarding-flow\").catch(() => {});\n                              say(\"Link copied\");\n                            })}\n                            {menuItem(\"Hide post\", () => setHidden(true), true)}\n                          </>,\n                          \"Post options\",\n                        )}\n                    </AnimatePresence>\n                  </div>\n                </header>\n                <p className=\"m-0 px-5 py-4 text-[14px] leading-[1.6]\" style={{ color: p.muted }}>\n                  {post}\n                </p>\n              </motion.article>\n            )}\n          </AnimatePresence>\n\n          {/* 2 · Title, description and controls */}\n          <article className={card} style={{ background: p.card, borderColor: p.border }} aria-labelledby={`${uid}-m`}>\n            <header className=\"flex items-start justify-between gap-3 border-b px-5 py-4\" style={{ borderColor: p.border }}>\n              <div className=\"min-w-0\">\n                <h3 id={`${uid}-m`} className=\"m-0 text-[14px] font-semibold\">\n                  {metric.title}\n                </h3>\n                <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.faint }}>\n                  {metric.description}\n                </p>\n              </div>\n              <div className=\"relative\" data-menu>\n                <button type=\"button\" aria-haspopup=\"menu\" aria-expanded={menu === \"period\"} onClick={() => setMenu(menu === \"period\" ? null : \"period\")} className={cn(\"flex h-8 cursor-pointer items-center gap-1.5 rounded-lg border bg-transparent px-2.5 text-[12.5px] whitespace-nowrap\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                  {per.label}\n                  <motion.svg width=\"11\" height=\"11\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" animate={{ rotate: menu === \"period\" ? 180 : 0 }} aria-hidden=\"true\">\n                    <path d=\"m4 6 4 4 4-4\" />\n                  </motion.svg>\n                </button>\n                <AnimatePresence>{menu === \"period\" && menuBox(<>{metric.periods.map((x) => menuItem(x.label, () => setPeriod(x.id), false, x.id === period))}</>, \"Period\")}</AnimatePresence>\n              </div>\n            </header>\n            <div className=\"px-5 py-4\">\n              <div className=\"flex items-baseline gap-2\">\n                <AnimatePresence mode=\"wait\" initial={false}>\n                  <motion.span key={per.total} className=\"text-[26px] font-semibold tracking-[-0.02em] tabular-nums\" initial={reduce ? false : { opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -6 }} transition={{ duration: 0.16 }}>\n                    {per.total}\n                  </motion.span>\n                </AnimatePresence>\n                <span className=\"text-[12.5px] font-semibold\" style={{ color: p.green }}>\n                  {per.delta}\n                </span>\n              </div>\n              <div className=\"mt-4 flex h-20 items-end gap-1\" role=\"img\" aria-label={`${metric.title} ${per.label}: ${per.total}, ${per.delta}`}>\n                {per.values.map((v, i) => (\n                  <motion.span key={`${period}-${i}`} className=\"flex-1 rounded-t\" style={{ background: i === per.values.length - 1 ? p.accent : p.bar }} initial={reduce ? false : { height: 0 }} animate={{ height: `${(v / max) * 100}%` }} transition={{ duration: 0.4, delay: reduce ? 0 : i * 0.025 }} />\n                ))}\n              </div>\n            </div>\n            <footer className=\"border-t px-5 py-3\" style={{ borderColor: p.border }}>\n              <a href=\"#\" onClick={(e) => e.preventDefault()} className={cn(\"group inline-flex items-center gap-1 rounded text-[12.5px] font-medium no-underline\", focus)} style={{ color: p.text, ...ring }}>\n                View report\n                <span className=\"transition-transform group-hover:translate-x-0.5\" aria-hidden=\"true\">\n                  →\n                </span>\n              </a>\n            </footer>\n          </article>\n\n          {/* 3 · Heading with a switch and collapse */}\n          <article className={card} style={{ background: p.card, borderColor: p.border }} aria-labelledby={`${uid}-s`}>\n            <header className=\"flex items-start gap-3 px-5 py-4\">\n              <div className=\"min-w-0 flex-1\">\n                <h3 id={`${uid}-s`} className=\"m-0 text-[14px] font-semibold\">\n                  {setting.title}\n                </h3>\n                <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.faint }}>\n                  {setting.description}\n                </p>\n              </div>\n              <button type=\"button\" role=\"switch\" aria-checked={enabled} aria-labelledby={`${uid}-s`} onClick={() => setEnabled((e) => !e)} className={cn(\"relative mt-0.5 h-5 w-9 shrink-0 cursor-pointer rounded-full border-0 transition-colors\", focus)} style={{ background: enabled ? p.green : p.chip, ...ring }}>\n                <motion.span className=\"absolute top-0.5 h-4 w-4 rounded-full\" style={{ background: enabled ? \"#fff\" : p.faint }} initial={false} animate={{ left: enabled ? 18 : 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 34 }} />\n              </button>\n              <button type=\"button\" aria-label={expanded ? \"Collapse\" : \"Expand\"} aria-expanded={expanded} aria-controls={`${uid}-sbody`} onClick={() => setExpanded((x) => !x)} className={cn(\"-mt-1 flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent\", focus)} style={{ color: p.faint, ...ring }}>\n                <motion.svg width=\"13\" height=\"13\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" animate={{ rotate: expanded ? 180 : 0 }} aria-hidden=\"true\">\n                  <path d=\"m4 6 4 4 4-4\" />\n                </motion.svg>\n              </button>\n            </header>\n            <AnimatePresence initial={false}>\n              {expanded && (\n                <motion.div id={`${uid}-sbody`} initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} transition={{ duration: 0.22 }} className=\"overflow-hidden\">\n                  <motion.fieldset className=\"m-0 border-0 border-t px-5 py-4\" style={{ borderColor: p.border }} animate={{ opacity: enabled ? 1 : 0.4 }} disabled={!enabled}>\n                    <legend className=\"sr-only\">Digest options</legend>\n                    <p className=\"m-0 mb-2 text-[12.5px]\" style={{ color: p.muted }}>\n                      Send on\n                    </p>\n                    <div role=\"radiogroup\" aria-label=\"Send on\" className=\"flex flex-wrap gap-1.5\">\n                      {[\"Monday\", \"Wednesday\", \"Friday\"].map((d) => (\n                        <button key={d} type=\"button\" role=\"radio\" aria-checked={day === d} onClick={() => setDay(d)} className={cn(\"h-8 cursor-pointer rounded-full border px-3 text-[12.5px] disabled:cursor-not-allowed\", focus)} style={{ borderColor: day === d ? p.text : p.border, background: day === d ? p.chip : \"transparent\", color: day === d ? p.text : p.muted, ...ring }}>\n                          {d}\n                        </button>\n                      ))}\n                    </div>\n                    <p className=\"m-0 mt-3 text-[12px]\" style={{ color: p.faint }} aria-live=\"polite\">\n                      {enabled ? `Next digest: ${day} at 9:00` : \"Digest is off.\"}\n                    </p>\n                  </motion.fieldset>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </article>\n        </div>\n\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-3 flex justify-center px-4\" aria-live=\"polite\">\n          <AnimatePresence>\n            {toast && (\n              <motion.div initial={reduce ? false : { opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: 6 }} className=\"rounded-full px-4 py-2 text-[13px] font-medium shadow-lg\" style={{ background: p.on, color: p.onText }}>\n                {toast}\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default CardHeading;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}