{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-data-filters",
  "type": "registry:block",
  "title": "App, filter bar",
  "description": "A search box and select filters above a list, active filters as removable chips with a clear-all, and a result count read from a list (one entry per filter removed) and announced politely. Focus moves on when a chip goes. The block filters nothing itself.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/native-select.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-data-filters/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-data-filters/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  /** Names the search landmark for screen readers; not shown. */\n  title: req(60),\n  searchLabel: req(40),\n  /** What the search box starts with. Not editable copy: the sample content of the input. */\n  sample: t(60),\n  selects: z.array(z.object({ label: req(30), options: z.array(t(30)).min(2).max(8), sample: t(30) })).min(1).max(3),\n  /** Filters that are on, each removable. */\n  chips: z.array(t(40)).max(5),\n  removeLabel: t(30),\n  clear: req(30),\n  /** The result count to say when 0, 1, 2 ... filters have been removed (the block holds no data to count): [\"14 bookings\", \"31 bookings\", ...]. Removing more than there are entries shows the last. */\n  results: z.array(t(40)).min(1).max(6),\n});\n\nexport const spec = defineSpec({\n  type: 'app-data-filters',\n  headingSlot: false, // the title is the filter bar's label, not a section heading\n  aliases: ['app/data-filters'],\n  name: 'App, filter bar',\n  category: 'app',\n  role: 'body',\n  description: 'A search box and select filters above a list, active filters as removable chips with a clear-all, and a result count read from a list (one entry per filter removed) and announced politely. Focus moves on when a chip goes. The block filters nothing itself.',\n  schema,\n  defaults: {\n    \"title\": \"Name what is filtered\",\n    \"searchLabel\": \"Name what to search\",\n    \"sample\": \"\",\n    \"selects\": [\n      {\n        \"label\": \"First filter\",\n        \"options\": [\n          \"All of the first\",\n          \"Name option one\",\n          \"Name option two\",\n          \"Name option three\"\n        ],\n        \"sample\": \"Name option one\"\n      },\n      {\n        \"label\": \"Second filter\",\n        \"options\": [\n          \"Any of the second\",\n          \"Name option one\",\n          \"Name option two\",\n          \"Name option three\"\n        ],\n        \"sample\": \"Name option one\"\n      }\n    ],\n    \"chips\": [\n      \"First option\",\n      \"Second option\",\n      \"Third option\"\n    ],\n    \"removeLabel\": \"Remove filter\",\n    \"clear\": \"Clear all\",\n    \"results\": [\n      \"00 results\",\n      \"00 results\",\n      \"00 results\",\n      \"000 results\"\n    ]\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-data-filters/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-data-filters/index.tsx",
      "content": "import { useEffect, useId, useRef } from 'react';\nimport { Search, X } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Button } from '../../ui/button';\nimport { Input } from '../../ui/input';\nimport { NativeSelect } from '../../ui/native-select';\nimport { Container, Named, Section, useNamed } from '../_shared/kit';\nimport { StateSlot, useSynced } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppDataFilters({ props }: BlockProps<Props>) {\n  const searchNamed = useNamed(props.searchLabel);\n  const id = useId();\n  const [removed, setRemoved] = useSynced<number[]>([], props.chips);\n  const search = useRef<HTMLInputElement>(null);\n  const chips = useRef<Record<number, HTMLButtonElement | null>>({});\n  const next = useRef<number | 'search' | null>(null); // where focus goes once the chip that had it is gone\n  useEffect(() => {\n    const target = next.current;\n    next.current = null;\n    if (target === null) return;\n    if (target === 'search') search.current?.focus();\n    else chips.current[target]?.focus();\n  }, [removed]);\n  const remove = (i: number) => {\n    const rest = props.chips.map((_, k) => k).filter((k) => !removed.includes(k) && k !== i);\n    next.current = rest.find((k) => k > i) ?? rest[rest.length - 1] ?? 'search';\n    setRemoved((r) => [...r, i]);\n  };\n  const clearAll = () => {\n    next.current = 'search';\n    setRemoved(props.chips.map((_, i) => i));\n  };\n  const at = Math.min(removed.length, props.results.length - 1);\n  const left = props.chips.map((c, i) => ({ c, i })).filter(({ i }) => !removed.includes(i));\n  return (\n    <Section className=\"py-8\">\n      <Container>\n        <form role=\"search\" aria-labelledby={id} onSubmit={(e) => e.preventDefault()} className=\"flex flex-col gap-4\">\n          <Named as=\"h2\" id={id} className=\"sr-only\">\n            <Text path={['title']} value={props.title} as=\"span\" />\n          </Named>\n          <div className=\"flex flex-col gap-3 @3xl:flex-row @3xl:items-end\">\n            {searchNamed && (\n            <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">\n              <label htmlFor={`${id}-q`} className=\"text-kh-small font-medium\">\n                <Text path={['searchLabel']} value={props.searchLabel} as=\"span\" />\n              </label>\n              <div className=\"relative\">\n                <Search aria-hidden className=\"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-kh-muted\" />\n                <Input key={props.sample} ref={search} id={`${id}-q`} type=\"search\" autoComplete=\"off\" name=\"q\" defaultValue={props.sample} className=\"pl-9\" />\n              </div>\n            </div>\n            )}\n            {props.selects.map((s, i) => (\n              <div key={i} className=\"flex flex-col gap-1.5 @3xl:w-48\">\n                <label htmlFor={`${id}-s${i}`} className=\"text-kh-small font-medium\">\n                  <Text path={['selects', i, 'label']} value={s.label} as=\"span\" />\n                </label>\n                <NativeSelect key={s.sample} id={`${id}-s${i}`} name={`filter-${i}`} defaultValue={s.sample} className=\"w-full\">\n                  {s.options.map((o, k) => (\n                    <Text key={k} path={['selects', i, 'options', k]} value={o} as=\"option\" />\n                  ))}\n                </NativeSelect>\n              </div>\n            ))}\n          </div>\n          <div className=\"flex flex-wrap items-center gap-2\">\n            <ul className=\"flex max-w-full min-w-0 flex-wrap items-center gap-2\">\n              {left.map(({ c, i }) => (\n                <li key={i} className=\"min-w-0 max-w-full\">\n                  <button\n                    type=\"button\"\n                    ref={(el) => {\n                      chips.current[i] = el;\n                    }}\n                    onClick={() => remove(i)}\n                    className=\"inline-flex min-h-11 max-w-full items-center gap-2 rounded-kh-pill border border-kh-line-strong bg-kh-surface px-4 text-kh-small text-kh-ink hover:bg-kh-surface-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)\"\n                  >\n                    <Text path={['chips', i]} value={c} as=\"span\" className=\"min-w-0 truncate\" />\n                    <span className=\"sr-only\">\n                      <Text path={['removeLabel']} value={props.removeLabel} as=\"span\" />\n                    </span>\n                    <X aria-hidden className=\"size-3.5 text-kh-muted\" />\n                  </button>\n                </li>\n              ))}\n            </ul>\n            {left.length > 0 && (\n              <Button variant=\"ghost\" onClick={clearAll}>\n                <Text path={['clear']} value={props.clear} as=\"span\" />\n              </Button>\n            )}\n            <p role=\"status\" className=\"ml-auto text-kh-small text-kh-muted\">\n              <Text path={['results', at]} value={props.results[at] ?? ''} as=\"span\" />\n            </p>\n          </div>\n          <StateSlot show={false}>\n            {props.results.map((r, i) => (i === at ? null : <Text key={i} path={['results', i]} value={r} as=\"p\" />))}\n          </StateSlot>\n        </form>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppDataFilters);\n"
    }
  ]
}
