{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mobile-filter-modal",
  "title": "Mobile Filter Modal",
  "description": "A phone-first filter sheet: a floating Filter & sort button with an active-count badge opens a bottom sheet you can drag down to close, with sort radios and collapsible category, price, colour, rating and in-stock sections that summarise their choice, plus a sticky footer with Clear and a live Show N results button.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/mobile-filter-modal/mobile-filter-modal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, type PanInfo } 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 MobileFilterProduct {\n  id: string;\n  name: string;\n  price: number;\n  was?: number;\n  image: string;\n  category: string;\n  color: string;\n  rating: number;\n  inStock: boolean;\n}\ntype Sort = \"featured\" | \"price-asc\" | \"price-desc\" | \"rating\";\ntype Filters = { categories: string[]; colors: string[]; max: number; rating: number; inStock: boolean; sort: Sort };\n\nexport interface MobileFilterModalProps {\n  title?: string;\n  products?: MobileFilterProduct[];\n  colors?: Record<string, string>;\n  currency?: string;\n  /** Called when the shopper taps Show results. */\n  onApply?: (filters: Filters) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    phone: \"#0F0F0F\",\n    sheet: \"#161616\",\n    title: \"#FFFFFF\",\n    muted: \"rgba(255,255,255,0.45)\",\n    body: \"rgba(255,255,255,0.62)\",\n    line: \"rgba(255,255,255,0.12)\",\n    tile: \"#F1F1F1\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    star: \"#F5C451\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    ring: \"rgba(255,255,255,0.55)\",\n    scrim: \"rgba(0,0,0,0.55)\",\n  },\n  light: {\n    bg: \"#F4F4F4\",\n    phone: \"#FFFFFF\",\n    sheet: \"#FFFFFF\",\n    title: \"#111111\",\n    muted: \"rgba(0,0,0,0.45)\",\n    body: \"rgba(0,0,0,0.62)\",\n    line: \"rgba(0,0,0,0.1)\",\n    tile: \"#F1F1F1\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    star: \"#E0A100\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    ring: \"rgba(0,0,0,0.45)\",\n    scrim: \"rgba(0,0,0,0.3)\",\n  },\n};\n\nconst L = \"/demo/blocks/product-list\";\nconst PRODUCTS: MobileFilterProduct[] = [\n  { id: \"earbuds\", name: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\", category: \"Audio\", color: \"Black\", rating: 4.7, inStock: true },\n  { id: \"headphones\", name: \"Studio Headphones\", price: 199, image: `${L}/headphones.webp`, category: \"Audio\", color: \"Grey\", rating: 4.6, inStock: false },\n  { id: \"watch\", name: \"Minimal Watch\", price: 79, was: 129, image: \"/demo/minimal-watch.webp\", category: \"Wearables\", color: \"Black\", rating: 4.8, inStock: true },\n  { id: \"shoes\", name: \"Running Shoes\", price: 99, was: 149, image: \"/demo/running-shoes.webp\", category: \"Outdoor\", color: \"Grey\", rating: 4.5, inStock: true },\n  { id: \"bottle\", name: \"Insulated Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\", category: \"Outdoor\", color: \"Black\", rating: 4.9, inStock: true },\n  { id: \"stand\", name: \"Laptop Stand\", price: 49, was: 89, image: \"/demo/laptop-stand.webp\", category: \"Desk\", color: \"Silver\", rating: 4.6, inStock: true },\n  { id: \"lamp\", name: \"Desk Lamp\", price: 59, image: `${L}/lamp.webp`, category: \"Desk\", color: \"Black\", rating: 4.4, inStock: true },\n  { id: \"notebook\", name: \"Dot Notebook\", price: 24, image: \"/demo/notebook.webp\", category: \"Desk\", color: \"Sand\", rating: 4.8, inStock: true },\n];\nconst COLORS: Record<string, string> = { Black: \"#1E1E1E\", Grey: \"#9A9A9A\", Silver: \"#D6D6D6\", Sand: \"#D8C8AD\" };\nconst SORTS: { id: Sort; label: string }[] = [\n  { id: \"featured\", label: \"Featured\" },\n  { id: \"price-asc\", label: \"Price: low to high\" },\n  { id: \"price-desc\", label: \"Price: high to low\" },\n  { id: \"rating\", label: \"Top rated\" },\n];\nconst MAX = 200;\nconst EMPTY: Filters = { categories: [], colors: [], max: MAX, rating: 0, inStock: false, sort: \"featured\" };\nconst money = (n: number, c: string) => `${c}${n % 1 ? n.toFixed(2) : n}`;\nconst toggle = <T,>(l: T[], v: T) => (l.includes(v) ? l.filter((x) => x !== v) : [...l, v]);\nconst apply = (list: MobileFilterProduct[], f: Filters) =>\n  list\n    .filter((x) => (!f.categories.length || f.categories.includes(x.category)) && (!f.colors.length || f.colors.includes(x.color)) && (f.max >= MAX || x.price <= f.max) && x.rating >= f.rating && (!f.inStock || x.inStock))\n    .sort((a, b) => (f.sort === \"price-asc\" ? a.price - b.price : f.sort === \"price-desc\" ? b.price - a.price : f.sort === \"rating\" ? b.rating - a.rating : 0));\n\nexport function MobileFilterModal({ title = \"Shop all\", products = PRODUCTS, colors = COLORS, currency = \"$\", onApply, theme = \"dark\", className }: MobileFilterModalProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [applied, setApplied] = React.useState<Filters>(EMPTY);\n  const [draft, setDraft] = React.useState<Filters>(EMPTY);\n  const [open, setOpen] = React.useState(false);\n  const [section, setSection] = React.useState<string | null>(\"category\");\n  const openerRef = React.useRef<HTMLButtonElement>(null);\n  const sheetRef = React.useRef<HTMLDivElement>(null);\n  const categories = React.useMemo(() => [...new Set(products.map((x) => x.category))], [products]);\n  const results = apply(products, applied);\n  const preview = apply(products, draft).length;\n  const activeCount = applied.categories.length + applied.colors.length + (applied.max < MAX ? 1 : 0) + (applied.rating ? 1 : 0) + (applied.inStock ? 1 : 0);\n\n  const show = () => {\n    setDraft(applied);\n    setOpen(true);\n  };\n  const close = React.useCallback(() => {\n    setOpen(false);\n    setTimeout(() => openerRef.current?.focus(), 0);\n  }, []);\n  const commit = () => {\n    setApplied(draft);\n    onApply?.(draft);\n    close();\n  };\n\n  React.useEffect(() => {\n    if (!open) return;\n    const el = sheetRef.current;\n    const t = setTimeout(() => el?.querySelector<HTMLElement>(\"[data-autofocus]\")?.focus(), 60);\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") return close();\n      if (e.key !== \"Tab\" || !el) return;\n      const f = [...el.querySelectorAll<HTMLElement>(\"button:not([disabled]), input\")];\n      if (e.shiftKey && document.activeElement === f[0]) {\n        e.preventDefault();\n        f[f.length - 1].focus();\n      } else if (!e.shiftKey && document.activeElement === f[f.length - 1]) {\n        e.preventDefault();\n        f[0].focus();\n      }\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => {\n      clearTimeout(t);\n      window.removeEventListener(\"keydown\", onKey);\n    };\n  }, [open, close]);\n\n  const onDragEnd = (_: unknown, info: PanInfo) => {\n    if (info.offset.y > 120 || info.velocity.y > 600) close();\n  };\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const summary: Record<string, string> = {\n    sort: SORTS.find((s) => s.id === draft.sort)!.label,\n    category: draft.categories.length ? draft.categories.join(\", \") : \"All\",\n    price: draft.max >= MAX ? \"Any\" : `Up to ${money(draft.max, currency)}`,\n    color: draft.colors.length ? draft.colors.join(\", \") : \"Any\",\n    rating: draft.rating ? `${draft.rating}★ & up` : \"Any\",\n  };\n\n  const group = (id: string, label: string, body: React.ReactNode) => {\n    const isOpen = section === id;\n    return (\n      <div key={id} className=\"border-b\" style={{ borderColor: p.line }}>\n        <button\n          type=\"button\"\n          aria-expanded={isOpen}\n          aria-controls={`${uid}-${id}`}\n          onClick={() => setSection(isOpen ? null : id)}\n          className={cn(\"flex w-full cursor-pointer items-center gap-3 border-0 bg-transparent px-5 py-4 text-left\", focus)}\n          style={{ color: p.title }}\n        >\n          <span className=\"flex-1\">\n            <span className=\"block text-[15px] font-semibold\">{label}</span>\n            {!isOpen && (\n              <span className=\"block truncate text-[12.5px]\" style={{ color: summary[id] && summary[id] !== \"Any\" && summary[id] !== \"All\" && summary[id] !== \"Featured\" ? p.accent : p.muted }}>\n                {summary[id]}\n              </span>\n            )}\n          </span>\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\" className={cn(\"transition-transform\", isOpen && \"rotate-180\")} style={{ color: p.muted }}>\n            <path d=\"m6 9 6 6 6-6\" />\n          </svg>\n        </button>\n        <AnimatePresence initial={false}>\n          {isOpen && (\n            <motion.div id={`${uid}-${id}`} 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              <div className=\"px-5 pb-5\">{body}</div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    );\n  };\n  const chip = (on: boolean) => ({ background: on ? p.buttonBg : \"transparent\", color: on ? p.buttonText : p.title, borderColor: on ? p.buttonBg : p.line });\n\n  return (\n    <section aria-labelledby={`${uid}-h`} className={cn(\"relative flex w-full justify-center px-4 py-10 sm:px-8\", className)} style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.phone } as React.CSSProperties}>\n      {/* Phone-width column (full width on phones) */}\n      <div className=\"relative h-[700px] w-full max-w-[400px] overflow-hidden rounded-[32px] border\" style={{ background: p.phone, borderColor: p.line }}>\n        <div className=\"h-full overflow-y-auto overscroll-contain px-4 pt-5 pb-24\" inert={open ? true : undefined}>\n          <h2 id={`${uid}-h`} className=\"m-0 text-[22px] font-semibold tracking-[-0.02em]\">\n            {title}\n          </h2>\n          <p className=\"m-0 mt-0.5 text-[13px]\" style={{ color: p.muted }} aria-live=\"polite\">\n            {results.length} products\n          </p>\n          <ul className=\"m-0 mt-4 grid list-none grid-cols-2 gap-x-3 gap-y-5 p-0\">\n            <AnimatePresence initial={false}>\n              {results.map((x) => (\n                <motion.li key={x.id} layout={!reduce} initial={reduce ? false : { opacity: 0, scale: 0.96 }} animate={{ opacity: 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.96 }} transition={{ duration: 0.25 }}>\n                  <div className=\"relative aspect-square overflow-hidden rounded-2xl\" style={{ background: p.tile }}>\n                    {/* eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic */}\n                    <img src={x.image} alt={x.name} width={300} height={300} className={cn(\"h-full w-full object-contain p-3\", !x.inStock && \"opacity-50 grayscale\")} />\n                    {x.was && (\n                      <span className=\"absolute top-2 left-2 rounded-full px-1.5 py-0.5 text-[10.5px] font-semibold\" style={{ background: p.accent, color: p.accentText }}>\n                        −{Math.round((1 - x.price / x.was) * 100)}%\n                      </span>\n                    )}\n                  </div>\n                  <p className=\"m-0 mt-2 truncate text-[13px] font-medium\">{x.name}</p>\n                  <p className=\"m-0 text-[12.5px] tabular-nums\" style={{ color: p.body }}>\n                    {money(x.price, currency)} <span style={{ color: p.star }}>★</span> {x.rating}\n                  </p>\n                </motion.li>\n              ))}\n            </AnimatePresence>\n          </ul>\n          {!results.length && (\n            <p className=\"m-0 mt-10 text-center text-[14px]\" style={{ color: p.muted }}>\n              Nothing matches. Loosen a filter.\n            </p>\n          )}\n        </div>\n\n        {/* Floating trigger */}\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-5 flex justify-center\">\n          <button\n            ref={openerRef}\n            type=\"button\"\n            onClick={show}\n            aria-haspopup=\"dialog\"\n            className={cn(\"pointer-events-auto flex h-12 cursor-pointer items-center gap-2 rounded-full border-0 px-5 text-[14px] font-semibold shadow-[0_12px_30px_rgba(0,0,0,0.35)]\", focus)}\n            style={{ background: p.buttonBg, color: p.buttonText }}\n          >\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <path d=\"M4 7h10M18 7h2M4 17h2M10 17h10\" />\n              <circle cx=\"16\" cy=\"7\" r=\"2\" />\n              <circle cx=\"8\" cy=\"17\" r=\"2\" />\n            </svg>\n            Filter & sort\n            {activeCount > 0 && (\n              <span className=\"flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[11px] font-bold\" style={{ background: p.accent, color: p.accentText }}>\n                {activeCount}\n              </span>\n            )}\n          </button>\n        </div>\n\n        {/* Sheet */}\n        <AnimatePresence>\n          {open && (\n            <motion.div\n              className=\"absolute inset-0 z-20 flex flex-col justify-end\"\n              style={{ background: p.scrim }}\n              initial={reduce ? false : { opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={reduce ? undefined : { opacity: 0 }}\n              onMouseDown={(e) => e.target === e.currentTarget && close()}\n            >\n              <motion.div\n                ref={sheetRef}\n                role=\"dialog\"\n                aria-modal=\"true\"\n                aria-labelledby={`${uid}-st`}\n                initial={reduce ? false : { y: \"100%\" }}\n                animate={{ y: 0 }}\n                exit={reduce ? undefined : { y: \"100%\" }}\n                transition={{ type: \"spring\", stiffness: 380, damping: 38 }}\n                drag={reduce ? false : \"y\"}\n                dragConstraints={{ top: 0, bottom: 0 }}\n                dragElastic={{ top: 0, bottom: 0.6 }}\n                onDragEnd={onDragEnd}\n                className=\"flex max-h-[92%] flex-col rounded-t-[28px]\"\n                style={{ background: p.sheet }}\n              >\n                <div className=\"flex shrink-0 cursor-grab flex-col items-center pt-2.5 active:cursor-grabbing\">\n                  <span aria-hidden=\"true\" className=\"h-1.5 w-10 rounded-full\" style={{ background: p.line }} />\n                  <div className=\"flex w-full items-center justify-between px-5 pt-3 pb-3\">\n                    <h3 id={`${uid}-st`} className=\"m-0 text-[17px] font-semibold\">\n                      Filter & sort\n                    </h3>\n                    <button\n                      type=\"button\"\n                      data-autofocus\n                      onClick={close}\n                      aria-label=\"Close filters\"\n                      className={cn(\"flex h-9 w-9 cursor-pointer items-center justify-center rounded-full border-0 text-[20px]\", focus)}\n                      style={{ background: p.ghost, color: p.title }}\n                    >\n                      ×\n                    </button>\n                  </div>\n                </div>\n                <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain border-t\" style={{ borderColor: p.line }} onPointerDownCapture={(e) => e.stopPropagation()}>\n                  {group(\n                    \"sort\",\n                    \"Sort by\",\n                    <div role=\"radiogroup\" aria-label=\"Sort by\" className=\"flex flex-col gap-1\">\n                      {SORTS.map((s) => (\n                        <button\n                          key={s.id}\n                          type=\"button\"\n                          role=\"radio\"\n                          aria-checked={draft.sort === s.id}\n                          onClick={() => setDraft((d) => ({ ...d, sort: s.id }))}\n                          className={cn(\"flex cursor-pointer items-center justify-between rounded-xl border-0 px-3 py-2.5 text-left text-[14px]\", focus)}\n                          style={{ background: draft.sort === s.id ? p.ghost : \"transparent\", color: p.title }}\n                        >\n                          {s.label}\n                          <span aria-hidden=\"true\" className=\"flex h-4 w-4 items-center justify-center rounded-full border-2\" style={{ borderColor: draft.sort === s.id ? p.accent : p.line }}>\n                            {draft.sort === s.id && <span className=\"h-1.5 w-1.5 rounded-full\" style={{ background: p.accent }} />}\n                          </span>\n                        </button>\n                      ))}\n                    </div>,\n                  )}\n                  {group(\n                    \"category\",\n                    \"Category\",\n                    <div className=\"flex flex-wrap gap-2\">\n                      {categories.map((c) => {\n                        const on = draft.categories.includes(c);\n                        const n = apply(products, { ...draft, categories: [c] }).length;\n                        return (\n                          <button\n                            key={c}\n                            type=\"button\"\n                            aria-pressed={on}\n                            onClick={() => setDraft((d) => ({ ...d, categories: toggle(d.categories, c) }))}\n                            className={cn(\"flex h-10 cursor-pointer items-center gap-1.5 rounded-full border px-4 text-[13.5px]\", focus)}\n                            style={chip(on)}\n                          >\n                            {c}\n                            <span className=\"text-[11.5px] opacity-60\">{n}</span>\n                          </button>\n                        );\n                      })}\n                    </div>,\n                  )}\n                  {group(\n                    \"price\",\n                    \"Price\",\n                    <div>\n                      <div className=\"flex justify-between text-[13px]\">\n                        <span style={{ color: p.muted }}>Up to</span>\n                        <span className=\"font-semibold tabular-nums\">{draft.max >= MAX ? \"Any price\" : money(draft.max, currency)}</span>\n                      </div>\n                      <label htmlFor={`${uid}-max`} className=\"sr-only\">\n                        Maximum price\n                      </label>\n                      <input id={`${uid}-max`} type=\"range\" min={20} max={MAX} step={10} value={draft.max} onChange={(e) => setDraft((d) => ({ ...d, max: Number(e.target.value) }))} className=\"mt-3 w-full\" style={{ accentColor: p.accent }} />\n                    </div>,\n                  )}\n                  {group(\n                    \"color\",\n                    \"Colour\",\n                    <div className=\"flex flex-wrap gap-3\">\n                      {Object.entries(colors).map(([name, hex]) => {\n                        const on = draft.colors.includes(name);\n                        return (\n                          <button\n                            key={name}\n                            type=\"button\"\n                            aria-pressed={on}\n                            onClick={() => setDraft((d) => ({ ...d, colors: toggle(d.colors, name) }))}\n                            className={cn(\"flex cursor-pointer flex-col items-center gap-1.5 border-0 bg-transparent p-0 text-[12px]\", focus)}\n                            style={{ color: on ? p.title : p.body }}\n                          >\n                            <span className=\"flex h-11 w-11 items-center justify-center rounded-full border-2\" style={{ borderColor: on ? p.accent : \"transparent\" }}>\n                              <span className=\"h-8 w-8 rounded-full ring-1 ring-white/15\" style={{ background: hex }} />\n                            </span>\n                            {name}\n                          </button>\n                        );\n                      })}\n                    </div>,\n                  )}\n                  {group(\n                    \"rating\",\n                    \"Rating\",\n                    <div role=\"radiogroup\" aria-label=\"Minimum rating\" className=\"flex gap-2\">\n                      {[0, 4.5, 4.7].map((r) => (\n                        <button\n                          key={r}\n                          type=\"button\"\n                          role=\"radio\"\n                          aria-checked={draft.rating === r}\n                          onClick={() => setDraft((d) => ({ ...d, rating: r }))}\n                          className={cn(\"h-10 flex-1 cursor-pointer rounded-xl border text-[13px]\", focus)}\n                          style={chip(draft.rating === r)}\n                        >\n                          {r ? `${r}★+` : \"Any\"}\n                        </button>\n                      ))}\n                    </div>,\n                  )}\n                  <div className=\"flex items-center justify-between px-5 py-4 text-[15px] font-semibold\">\n                    <span id={`${uid}-stock`}>In stock only</span>\n                    <button\n                      type=\"button\"\n                      role=\"switch\"\n                      aria-labelledby={`${uid}-stock`}\n                      aria-checked={draft.inStock}\n                      onClick={() => setDraft((d) => ({ ...d, inStock: !d.inStock }))}\n                      className={cn(\"relative h-7 w-12 cursor-pointer rounded-full border-0 p-0 transition-colors\", focus)}\n                      style={{ background: draft.inStock ? p.accent : p.line }}\n                    >\n                      <motion.span className=\"absolute top-0.5 left-0.5 h-6 w-6 rounded-full bg-white shadow\" animate={{ x: draft.inStock ? 20 : 0 }} transition={{ type: \"spring\", stiffness: 500, damping: 30 }} />\n                    </button>\n                  </div>\n                </div>\n                <div className=\"flex shrink-0 gap-2 border-t px-5 pt-3 pb-5\" style={{ borderColor: p.line }}>\n                  <button type=\"button\" onClick={() => setDraft(EMPTY)} className={cn(\"h-12 cursor-pointer rounded-full border px-5 text-[14px] font-semibold\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title }}>\n                    Clear\n                  </button>\n                  <button\n                    type=\"button\"\n                    onClick={commit}\n                    disabled={preview === 0}\n                    className={cn(\"h-12 flex-1 cursor-pointer rounded-full border-0 text-[14px] font-semibold disabled:cursor-not-allowed disabled:opacity-40\", focus)}\n                    style={{ background: p.buttonBg, color: p.buttonText }}\n                    aria-live=\"polite\"\n                  >\n                    {preview ? `Show ${preview} result${preview === 1 ? \"\" : \"s\"}` : \"No results\"}\n                  </button>\n                </div>\n              </motion.div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}