{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "integrations-directory",
  "title": "Integrations directory",
  "description": "Every tool your product works with as cards, narrowed by category and by name; the cards that stay glide to their new places, and an empty search offers every category and a way to ask for a tool.",
  "dependencies": [
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/announce.json",
    "https://kinoui.com/r/badge.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/card.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/empty.json",
    "https://kinoui.com/r/flow.json",
    "https://kinoui.com/r/hero-parts.json",
    "https://kinoui.com/r/integrations-parts.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/search-field.json",
    "https://kinoui.com/r/section-heading.json",
    "https://kinoui.com/r/segmented-control.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/integrations-directory/integrations-directory.tsx",
      "content": "'use client'\n\nimport { Badge } from '@/registry/components/kino/badge'\nimport { Button, buttonVariants } from '@/registry/components/kino/button'\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardLink,\n  CardTitle,\n} from '@/registry/components/kino/card'\nimport {\n  Empty,\n  EmptyContent,\n  EmptyDescription,\n  EmptyHeader,\n  EmptyMedia,\n  EmptyTitle,\n} from '@/registry/components/kino/empty'\nimport { resultsLabel, SearchField } from '@/registry/components/kino/search-field'\nimport {\n  SegmentedControl,\n  SegmentedControlItem,\n} from '@/registry/components/kino/segmented-control'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { announce } from '@/registry/lib/announce'\nimport { useControllable } from '@/registry/lib/controllable'\nimport { flowItemClassName, useFlow } from '@/registry/lib/flow'\nimport { pageColumnClassName } from '@/registry/lib/hero-parts'\nimport {\n  type Integration,\n  integrationsSectionClassName,\n  type IntegrationsSectionProps,\n  IntegrationTile,\n} from '@/registry/lib/integrations-parts'\nimport { markMounted, mergeRefs } from '@/registry/lib/refs'\nimport { HEADING_BELOW, SectionHeading } from '@/registry/lib/section-heading'\nimport { matchRanges } from '@ui-sdk/core/text-match'\nimport { type ComponentProps, type ReactNode, useId, useMemo, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * Every tool your product works with, as a grid of cards a visitor narrows\n * by category and by name. The cards that stay glide to their new places,\n * the ones that go fade where they were, and the grid moves to its new\n * height, so a filter shows what it took away rather than swapping the page.\n * When nothing matches, it says so, offers the same search in every\n * category, and asks what to connect next.\n *\n *   <IntegrationsDirectory\n *     title='Kino works with the tools you have'\n *     categories={[{ value: 'engineering', label: 'Engineering' }]}\n *     integrations={[{ value: 'github', name: 'GitHub', description: 'Link pull requests to issues.', category: 'engineering', logo: { src: '/logos/tools/github.svg', width: 24, height: 24 }, href: '/integrations/github' }]}\n *     requestHref='/integrations/request'\n *   />\n */\n\n/** A tool in the directory: filed under a category, with a word beside its name if it has one. */\ninterface DirectoryIntegration extends Integration {\n  /** The `value` of the category it is filed under. */\n  category: string\n  /** A word beside its name, such as New or Beta. */\n  badge?: ReactNode\n}\n\n/** A group of tools under a name, such as Engineering. */\ninterface IntegrationCategory {\n  value: string\n  label: string\n}\n\n/** The category that holds every tool. */\nconst ALL = 'all'\n\ninterface IntegrationsDirectoryProps\n  extends\n    IntegrationsSectionProps,\n    Omit<ComponentProps<'section'>, 'title' | 'children'> {\n  integrations: DirectoryIntegration[]\n  /** In the order they read; a first category, All, holds every tool. */\n  categories: IntegrationCategory[]\n  /** The category shown, by its `value`, or `all`. */\n  category?: string\n  /** The category shown at first: All, unless you give another. */\n  defaultCategory?: string\n  onCategoryChange?: (category: string) => void\n  /** What the search field holds. */\n  query?: string\n  defaultQuery?: string\n  onQueryChange?: (query: string) => void\n  /** Where a visitor asks for a tool that isn't listed. */\n  requestHref?: string\n}\n\nfunction IntegrationsDirectory({\n  title,\n  eyebrow,\n  description,\n  heading = 'h2',\n  integrations,\n  categories,\n  category: categoryProp,\n  defaultCategory = ALL,\n  onCategoryChange,\n  query: queryProp,\n  defaultQuery = '',\n  onQueryChange,\n  requestHref,\n  className,\n  ...props\n}: IntegrationsDirectoryProps) {\n  const titleId = useId()\n  const gridId = useId()\n  const [category, setCategory] = useControllable(\n    categoryProp,\n    defaultCategory,\n    onCategoryChange,\n  )\n  const [query, setQuery] = useControllable(queryProp, defaultQuery, onQueryChange)\n  const { frame, row } = useFlow<HTMLDivElement, HTMLUListElement>(\n    '[data-slot=integrations-directory-item]',\n    'data-integration',\n  )\n  const rowRef = useMemo(() => mergeRefs(row, markMounted), [row])\n  // The empty state's buttons go with it, so the focus goes back to the search.\n  const search = useRef<HTMLInputElement>(null)\n\n  const shown = filterIntegrations(integrations, categories, category, query)\n  const elsewhere =\n    shown.length === 0 && category !== ALL\n      ? filterIntegrations(integrations, categories, ALL, query).length\n      : 0\n  const picked = categories.find((entry) => entry.value === category)\n  const searching = query.trim() !== ''\n  const cardHeading = HEADING_BELOW[heading]\n\n  const pick = (next: string) => {\n    setCategory(next)\n    // The search field reads its own count; a category's is said here.\n    if (!searching) {\n      const count = filterIntegrations(integrations, categories, next, '').length\n      announce(toolCount(count))\n    }\n  }\n\n  return (\n    <section\n      data-slot='integrations-directory'\n      aria-labelledby={titleId}\n      className={cn(integrationsSectionClassName, className)}\n      {...props}\n    >\n      <div className={cn(pageColumnClassName, 'flex flex-col gap-10 py-16 @3xl:py-24')}>\n        <SectionHeading\n          id={titleId}\n          eyebrow={eyebrow}\n          title={title}\n          description={description}\n          heading={heading}\n        />\n        <div className='flex min-w-0 flex-col gap-6'>\n          {/* Side by side only where every category fits beside the search. */}\n          <div className='flex min-w-0 flex-col gap-3 @5xl/integrations:flex-row @5xl/integrations:items-center @5xl/integrations:justify-between'>\n            <SegmentedControl\n              aria-label='Category'\n              aria-controls={gridId}\n              value={category}\n              onValueChange={(next) => pick(String(next))}\n            >\n              <SegmentedControlItem value={ALL}>All</SegmentedControlItem>\n              {categories.map((entry) => (\n                <SegmentedControlItem key={entry.value} value={entry.value}>\n                  {entry.label}\n                </SegmentedControlItem>\n              ))}\n            </SegmentedControl>\n            <SearchField\n              ref={search}\n              aria-label='Search integrations'\n              aria-controls={gridId}\n              placeholder='Search integrations'\n              shortcut='/'\n              value={query}\n              onValueChange={(next) => setQuery(String(next))}\n              count={searching ? shown.length : undefined}\n              countLabel={toolCount}\n              className='@5xl/integrations:w-72'\n            />\n          </div>\n          <div\n            ref={frame}\n            className='overflow-clip transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none'\n          >\n            <ul\n              ref={rowRef}\n              id={gridId}\n              aria-label={picked ? picked.label : 'All integrations'}\n              className='group/flow relative isolate grid min-w-0 grid-cols-1 gap-3 @xl/integrations:grid-cols-2 @4xl/integrations:grid-cols-3'\n            >\n              {shown.map((integration) => (\n                <li\n                  key={integration.value}\n                  data-slot='integrations-directory-item'\n                  data-integration={integration.value}\n                  className={cn(flowItemClassName, 'flex min-w-0')}\n                >\n                  <IntegrationCard integration={integration} heading={cardHeading} />\n                </li>\n              ))}\n              {/* In the grid, so the grid moves to its height as the last cards fade. */}\n              <li className='col-span-full flex empty:hidden'>\n                <Empty show={shown.length === 0} className='py-10'>\n                  <EmptyHeader>\n                    <EmptyMedia variant='icon'>\n                      <IconPlaceholder\n                        lucide='SearchIcon'\n                        tabler='IconSearch'\n                        hugeicons='Search01Icon'\n                        phosphor='MagnifyingGlassIcon'\n                        remixicon='RiSearchLine'\n                        aria-hidden\n                      />\n                    </EmptyMedia>\n                    <EmptyTitle>{emptyTitle(picked?.label, query)}</EmptyTitle>\n                    <EmptyDescription>\n                      {elsewhere > 0\n                        ? `${toolCount(elsewhere)} in other categories.`\n                        : searching\n                          ? 'Check the spelling, or tell us what to connect next.'\n                          : 'Tell us what to connect next.'}\n                    </EmptyDescription>\n                  </EmptyHeader>\n                  <EmptyContent className='flex-row flex-wrap justify-center'>\n                    {elsewhere > 0 ? (\n                      <Button\n                        variant='outline'\n                        size='sm'\n                        onClick={() => {\n                          pick(ALL)\n                          search.current?.focus()\n                        }}\n                      >\n                        {searching ? 'Search all categories' : 'Show all integrations'}\n                      </Button>\n                    ) : searching ? (\n                      <Button\n                        variant='outline'\n                        size='sm'\n                        onClick={() => {\n                          setQuery('')\n                          // The search field says nothing once it is empty, so the count is said here.\n                          announce(\n                            toolCount(\n                              filterIntegrations(integrations, categories, category, '')\n                                .length,\n                            ),\n                          )\n                          search.current?.focus()\n                        }}\n                      >\n                        Clear search\n                      </Button>\n                    ) : null}\n                    {requestHref ? (\n                      <a\n                        href={requestHref}\n                        className={buttonVariants({\n                          variant: 'ghost',\n                          size: 'sm',\n                        })}\n                      >\n                        Request an integration\n                      </a>\n                    ) : null}\n                  </EmptyContent>\n                </Empty>\n              </li>\n            </ul>\n          </div>\n          {requestHref && shown.length > 0 ? (\n            <p className='text-muted-foreground text-center text-sm'>\n              Missing a tool?{' '}\n              <a\n                href={requestHref}\n                className='text-foreground focus-visible:ring-ring/50 rounded-(--control-radius-xs) font-medium underline-offset-4 hover:underline focus-visible:ring-3 focus-visible:outline-hidden'\n              >\n                Request an integration\n              </a>\n            </p>\n          ) : null}\n        </div>\n      </div>\n    </section>\n  )\n}\n\n/** A tool's card: its mark, its name, which leads to its page, and what it does. */\nfunction IntegrationCard({\n  integration,\n  heading: Heading,\n}: {\n  integration: DirectoryIntegration\n  heading: 'h2' | 'h3' | 'h4'\n}) {\n  return (\n    <Card className='flex-1'>\n      <CardContent className='flex items-start gap-3'>\n        <IntegrationTile logo={integration.logo} />\n        <div className='flex min-w-0 flex-1 flex-col gap-1'>\n          <div className='flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1'>\n            <CardTitle render={<Heading />}>\n              <CardLink href={integration.href}>\n                <bdi>{integration.name}</bdi>\n              </CardLink>\n            </CardTitle>\n            {integration.badge ? (\n              <Badge variant='secondary'>{integration.badge}</Badge>\n            ) : null}\n          </div>\n          <CardDescription>{integration.description}</CardDescription>\n        </div>\n      </CardContent>\n    </Card>\n  )\n}\n\n/**\n * What the empty grid says: that nothing matches what was typed, or, with\n * nothing typed, that the category has no tools yet.\n */\nfunction emptyTitle(category: string | undefined, query: string): string {\n  const typed = query.trim()\n  if (typed === '') return category ? `No ${category} tools yet` : 'No tools yet'\n  return category\n    ? `No ${category} tool matches “${typed}”`\n    : `No tool matches “${typed}”`\n}\n\n/**\n * The tools in `category` (or every one, for `all`) whose name, category or\n * line holds every word of `query`, ignoring case and accents, in the order\n * given.\n */\nfunction filterIntegrations(\n  integrations: readonly DirectoryIntegration[],\n  categories: readonly IntegrationCategory[],\n  category: string,\n  query: string,\n): DirectoryIntegration[] {\n  const words = query.split(/\\s+/).filter(Boolean)\n  const labels = new Map(categories.map((entry) => [entry.value, entry.label]))\n  return integrations.filter((integration) => {\n    if (category !== ALL && integration.category !== category) return false\n    const text = [\n      integration.name,\n      labels.get(integration.category) ?? '',\n      integration.description,\n    ].join(' ')\n    return words.every((word) => matchRanges(text, word, 'contains').length > 0)\n  })\n}\n\n/** How many tools there are, in words: “1 integration”, “12 integrations”. */\nfunction toolCount(count: number): string {\n  return resultsLabel(count, ['integration', 'integrations'])\n}\n\nexport { IntegrationsDirectory }\nexport { emptyTitle, filterIntegrations, toolCount }\nexport type { DirectoryIntegration, IntegrationCategory }\n",
      "type": "registry:component",
      "target": "@components/kino/integrations-directory/integrations-directory.tsx"
    }
  ],
  "type": "registry:block"
}