{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contextual-hints-panel",
  "title": "Contextual Hints Panel",
  "description": "A side panel of tips that follows what someone is doing: the hints change with the field or step in use, and learned ones fade away.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/contextual-hints-panel/contextual-hints-panel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PanelHint {\n  id: string;\n  title: string;\n  body: string;\n  /** A keyboard shortcut to show, e.g. \"⌘K\". */\n  shortcut?: string;\n}\n\nexport interface HintContext {\n  id: string;\n  label: string;\n  hints: PanelHint[];\n}\n\nexport interface ContextualHintsPanelProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  contexts?: HintContext[];\n  /** Which context to show. Leave out to let people switch with pills. */\n  context?: string;\n  /** Ids of hints already learned. */\n  defaultLearned?: string[];\n  onLearn?: (hint: PanelHint) => void;\n  onHide?: () => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\n\nconst PALETTES = {\n  dark: {\n    card: \"#0F1011\",\n    item: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    track: \"rgba(255,255,255,0.1)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    key: \"rgba(255,255,255,0.08)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    item: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.1)\",\n    track: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    key: \"rgba(8,9,10,0.07)\",\n  },\n};\n\nconst DEFAULT_CONTEXTS: HintContext[] = [\n  {\n    id: \"subject\",\n    label: \"Subject\",\n    hints: [\n      {\n        id: \"short\",\n        title: \"Keep it under 40 characters\",\n        body: \"Longer subjects get cut off on phones, where most people read.\",\n      },\n      {\n        id: \"name\",\n        title: \"Add a first name\",\n        body: \"Type a slash to drop in fields such as a reader's name.\",\n        shortcut: \"/\",\n      },\n    ],\n  },\n  {\n    id: \"audience\",\n    label: \"Audience\",\n    hints: [\n      {\n        id: \"segment\",\n        title: \"Start with a saved segment\",\n        body: \"Segments stay up to date as people join and leave.\",\n      },\n      {\n        id: \"exclude\",\n        title: \"Leave out recent buyers\",\n        body: \"Anyone who bought this week usually doesn't want an offer.\",\n      },\n    ],\n  },\n  {\n    id: \"schedule\",\n    label: \"Schedule\",\n    hints: [\n      {\n        id: \"timezone\",\n        title: \"Send in each reader's time zone\",\n        body: \"It lands at 9am for everyone, instead of 3am for some.\",\n      },\n      {\n        id: \"test\",\n        title: \"Send yourself a test first\",\n        body: \"It takes a moment and catches broken links.\",\n        shortcut: \"⌘T\",\n      },\n    ],\n  },\n];\n\nfunction Check({ color }: { color: string }) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 16 16\"\n      width=\"14\"\n      height=\"14\"\n      fill=\"none\"\n      className=\"block shrink-0\"\n    >\n      <path\n        d=\"m3.5 8.5 3 3 6-7\"\n        stroke={color}\n        strokeWidth=\"1.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function ContextualHintsPanel({\n  theme = \"dark\",\n  title = \"Tips for this step\",\n  contexts = DEFAULT_CONTEXTS,\n  context,\n  defaultLearned = [],\n  onLearn,\n  onHide,\n  className,\n  style,\n  ...rest\n}: ContextualHintsPanelProps) {\n  const c = PALETTES[theme];\n  const [own, setOwn] = React.useState(contexts[0]?.id ?? \"\");\n  const [learned, setLearned] = React.useState(defaultLearned);\n  const [hidden, setHidden] = React.useState(false);\n\n  const activeId = context ?? own;\n  const all = contexts.flatMap((x) => x.hints);\n  const done = all.filter((h) => learned.includes(h.id)).length;\n  const share = all.length ? done / all.length : 0;\n\n  const toggle = (hint: PanelHint) => {\n    const isDone = learned.includes(hint.id);\n    setLearned((prev) =>\n      isDone ? prev.filter((id) => id !== hint.id) : [...prev, hint.id],\n    );\n    if (!isDone) onLearn?.(hint);\n  };\n\n  const hide = () => {\n    setHidden(true);\n    onHide?.();\n  };\n\n  return (\n    <section\n      aria-label={title}\n      className={`grid w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        gridTemplateColumns: \"minmax(0, 1fr)\",\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      {/* Hiding swaps to a small note in the same cell, so the layout around it stays put. */}\n      <div\n        aria-hidden={hidden}\n        inert={hidden}\n        className={`flex min-w-0 flex-col p-4 [grid-area:1/1] ${hidden ? \"invisible\" : \"visible\"}`}\n      >\n        <header>\n          <div className=\"flex items-start justify-between gap-3\">\n            <h3 className=\"m-0 text-[15px] leading-[22px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <span\n              aria-live=\"polite\"\n              className=\"shrink-0 text-[12.5px] leading-[22px] tracking-[-0.008em] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              {done} of {all.length} learned\n            </span>\n          </div>\n          <svg\n            aria-hidden=\"true\"\n            width=\"100%\"\n            height=\"4\"\n            className=\"mt-2 block\"\n          >\n            <rect width=\"100%\" height=\"4\" rx=\"2\" fill={c.track} />\n            <rect\n              width={`${share * 100}%`}\n              height=\"4\"\n              rx=\"2\"\n              fill={ACCENT}\n              className=\"motion-safe:transition-[width] motion-safe:duration-300\"\n            />\n          </svg>\n        </header>\n\n        {context === undefined && (\n          <div\n            role=\"group\"\n            aria-label=\"Topic\"\n            className=\"mt-3 flex flex-wrap gap-1\"\n          >\n            {contexts.map((x) => {\n              const on = x.id === activeId;\n              return (\n                <button\n                  key={x.id}\n                  type=\"button\"\n                  data-context={x.id}\n                  aria-pressed={on}\n                  onClick={() => setOwn(x.id)}\n                  className={`h-7 cursor-pointer rounded-full border-0 px-2.5 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                  style={{\n                    background: on ? c.chip : \"transparent\",\n                    color: on ? c.text : c.sub,\n                  }}\n                >\n                  {x.label}\n                </button>\n              );\n            })}\n          </div>\n        )}\n\n        {/* Every context shares one cell, so moving between fields never resizes the panel. */}\n        <div\n          aria-live=\"polite\"\n          className=\"mt-3 grid flex-1\"\n          style={{ gridTemplateColumns: \"minmax(0, 1fr)\" }}\n        >\n          {contexts.map((x) => {\n            const on = x.id === activeId;\n            return (\n              <ul\n                key={x.id}\n                aria-hidden={!on}\n                inert={!on}\n                className={`m-0 flex list-none flex-col gap-2 p-0 [grid-area:1/1] motion-safe:transition-opacity motion-safe:duration-200 ${on ? \"visible opacity-100\" : \"invisible opacity-0\"}`}\n              >\n                {x.hints.map((hint) => {\n                  const isDone = learned.includes(hint.id);\n                  return (\n                    <li\n                      key={hint.id}\n                      data-hint={hint.id}\n                      className=\"rounded-xl p-3 motion-safe:transition-opacity motion-safe:duration-200\"\n                      style={{\n                        background: c.item,\n                        opacity: isDone ? 0.6 : 1,\n                      }}\n                    >\n                      <p className=\"m-0 flex items-start justify-between gap-2 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                        <span className=\"min-w-0\">{hint.title}</span>\n                        {hint.shortcut && (\n                          <kbd\n                            className=\"flex h-5 shrink-0 items-center rounded px-1.5 text-[11.5px] leading-[14px] font-[510]\"\n                            style={{\n                              fontFamily: \"inherit\",\n                              background: c.key,\n                              color: c.soft,\n                            }}\n                          >\n                            {hint.shortcut}\n                          </kbd>\n                        )}\n                      </p>\n                      <p\n                        className=\"m-0 mt-0.5 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n                        style={{ color: c.sub }}\n                      >\n                        {hint.body}\n                      </p>\n                      <button\n                        type=\"button\"\n                        data-learn={hint.id}\n                        aria-pressed={isDone}\n                        onClick={() => toggle(hint)}\n                        className={`mt-2 flex h-7 cursor-pointer items-center gap-1.5 rounded-full border-0 px-2.5 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] ${RING}`}\n                        style={{\n                          background: c.chip,\n                          color: isDone ? GREEN : c.soft,\n                        }}\n                      >\n                        {isDone && <Check color={GREEN} />}\n                        {isDone ? \"Learned\" : \"Got it\"}\n                      </button>\n                    </li>\n                  );\n                })}\n              </ul>\n            );\n          })}\n        </div>\n\n        <button\n          type=\"button\"\n          data-hide=\"\"\n          onClick={hide}\n          className={`mt-3 h-7 cursor-pointer self-start rounded-full border-0 bg-transparent px-1 text-[12.5px] leading-[18px] tracking-[-0.008em] ${RING}`}\n          style={{ color: c.faint }}\n        >\n          Hide tips\n        </button>\n      </div>\n\n      <div\n        aria-hidden={!hidden}\n        inert={!hidden}\n        className={`flex min-w-0 flex-col items-center justify-center p-4 text-center [grid-area:1/1] ${hidden ? \"visible\" : \"invisible\"}`}\n      >\n        <p\n          className=\"m-0 text-[13px] leading-[20px] tracking-[-0.011em]\"\n          style={{ color: c.sub }}\n        >\n          Tips are hidden\n        </p>\n        <button\n          type=\"button\"\n          data-show=\"\"\n          onClick={() => setHidden(false)}\n          className={`mt-2 h-8 cursor-pointer rounded-full border-0 px-3.5 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n          style={{ background: c.chip, color: c.soft }}\n        >\n          Show tips\n        </button>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}