{
  "name": "expressions-picker",
  "type": "registry:ui",
  "framework": "react",
  "title": "Expressions Picker",
  "description": "A Discord-inspired picker for Unicode emoji and caller-supplied stickers and GIFs.",
  "dependencies": [
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "ui/expressions-picker.tsx",
      "content": "\"use client\"\n\nimport { cva } from \"class-variance-authority\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport type ExpressionKind = \"emoji\" | \"sticker\" | \"gif\"\n\n/** A section of one tab: a Unicode emoji group, a server's own emoji, or a sticker pack. */\nexport interface ExpressionCategory {\n  /** Unique across all categories. */\n  id: string\n  kind: ExpressionKind\n  label: string\n  /** A Unicode character for the category rail. */\n  glyph?: string\n  /** A static image for the category rail, such as a server icon. Wins over `glyph`. */\n  iconSrc?: string\n}\n\nexport interface ExpressionItem {\n  /** Unique across all items. */\n  id: string\n  kind: ExpressionKind\n  /** The `id` of the category this item belongs to. */\n  category: string\n  /** Accessible name, searched and shown in the preview bar. */\n  label: string\n  /** What a selection returns: Unicode text, or an application token for media. */\n  value: string\n  keywords?: readonly string[]\n  /** The emoji in the five skin tones, light to dark. Omit when it has none. */\n  skins?: readonly string[]\n  /** A static image: a server emoji, a sticker, or a GIF poster. */\n  src?: string\n  disabled?: boolean\n}\n\nexport type SkinTone = 0 | 1 | 2 | 3 | 4 | 5\n\nexport interface ExpressionsPickerProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"onSelect\"\n> {\n  items?: readonly ExpressionItem[]\n  categories?: readonly ExpressionCategory[]\n  /** Item IDs used last, most recent first. The application stores and updates them. */\n  recent?: readonly string[]\n  /** The value chosen now, marked as pressed in the grid. */\n  current?: string | null\n  label?: string\n  disabled?: boolean\n  /** Receives the item and its value in the chosen skin tone. */\n  onSelect?: (item: ExpressionItem, value: string) => void\n  /** Replaces the English names and texts; omitted keys keep their default. */\n  labels?: Partial<ExpressionsPickerLabels>\n}\n\n/** Every name and text the picker writes itself. */\nexport interface ExpressionsPickerLabels {\n  /** Name of the tab list. */\n  kinds: string\n  gif: string\n  sticker: string\n  emoji: string\n  /** Name of the search field. */\n  search: string\n  searchPlaceholder: string\n  clearSearch: string\n  /** Name of the skin tone button, built from the current tone's name. */\n  skinTone: (tone: string) => string\n  /** Name of the group of skin tones. */\n  skinTones: string\n  /** The six skin tones, from the default to the darkest. */\n  toneNames: readonly [string, string, string, string, string, string]\n  /** Name of the category rail. */\n  categories: string\n  searchResults: string\n  recent: string\n  noResults: string\n  noResultsHelp: string\n  empty: string\n  emptyHelp: string\n  /** Name of an item that cannot be chosen, built from its label. */\n  unavailable: (label: string) => string\n  /** Read out after each search. */\n  resultCount: (count: number) => string\n  /** Written before the category name in the preview bar. */\n  from: string\n  /** The preview bar while nothing is hovered or chosen. */\n  hint: string\n}\n\n/** The English defaults. */\nexport const defaultExpressionsPickerLabels: ExpressionsPickerLabels = {\n  kinds: \"Expression type\",\n  gif: \"GIFs\",\n  sticker: \"Stickers\",\n  emoji: \"Emoji\",\n  search: \"Search expressions\",\n  searchPlaceholder: \"Search by name or keyword\",\n  clearSearch: \"Clear search\",\n  skinTone: (tone) => `Skin tone: ${tone}`,\n  skinTones: \"Skin tone\",\n  toneNames: [\n    \"Default skin tone\",\n    \"Light skin tone\",\n    \"Medium-light skin tone\",\n    \"Medium skin tone\",\n    \"Medium-dark skin tone\",\n    \"Dark skin tone\",\n  ],\n  categories: \"Categories\",\n  searchResults: \"Search results\",\n  recent: \"Recently used\",\n  noResults: \"No expressions match your search.\",\n  noResultsHelp: \"Try another word or another tab.\",\n  empty: \"Nothing here yet.\",\n  emptyHelp: \"Try another tab.\",\n  unavailable: (label) => `${label}, unavailable`,\n  resultCount: (count) => (count === 1 ? \"1 result\" : `${count} results`),\n  from: \"from\",\n  hint: \"Hover or focus an expression to preview it.\",\n}\n\nconst kinds: readonly ExpressionKind[] = [\"gif\", \"sticker\", \"emoji\"]\n\nconst skinTones: { tone: SkinTone; sample: string }[] = [\n  { tone: 0, sample: \"👋\" },\n  { tone: 1, sample: \"👋🏻\" },\n  { tone: 2, sample: \"👋🏼\" },\n  { tone: 3, sample: \"👋🏽\" },\n  { tone: 4, sample: \"👋🏾\" },\n  { tone: 5, sample: \"👋🏿\" },\n]\n\n/** The value of an item in a skin tone, or its own value when it has none. */\nexport function expressionValue(item: ExpressionItem, tone: SkinTone): string {\n  return (tone === 0 ? undefined : item.skins?.[tone - 1]) ?? item.value\n}\n\n/** `:grinning_face:` for an emoji, the label for media. */\nexport function expressionShortcode(item: ExpressionItem): string {\n  if (item.kind !== \"emoji\") return item.label\n  const name = item.label\n    .toLowerCase()\n    .replaceAll(/[^\\p{L}\\p{N}]+/gu, \"_\")\n    .replaceAll(/^_+|_+$/gu, \"\")\n  return `:${name}:`\n}\n\n/** Every word of the query must appear in the label or the keywords. */\nexport function matchesExpression(item: ExpressionItem, query: string) {\n  const text = [item.label, ...(item.keywords ?? [])].join(\" \").toLowerCase()\n  return query\n    .toLowerCase()\n    .split(/[\\s_:]+/u)\n    .filter(Boolean)\n    .every((word) => text.includes(word))\n}\n\ninterface Section {\n  key: string\n  label: string\n  glyph?: string\n  iconSrc?: string\n  items: ExpressionItem[]\n  collapsible: boolean\n}\n\nfunction buildSections(\n  items: readonly ExpressionItem[],\n  categories: readonly ExpressionCategory[],\n  recent: readonly string[],\n  kind: ExpressionKind,\n  query: string,\n  labels: Pick<ExpressionsPickerLabels, \"searchResults\" | \"recent\">\n): Section[] {\n  const ofKind = items.filter((item) => item.kind === kind)\n  if (query.trim()) {\n    const found = ofKind.filter((item) => matchesExpression(item, query))\n    return found.length\n      ? [\n          {\n            key: \"results\",\n            label: labels.searchResults,\n            items: found,\n            collapsible: false,\n          },\n        ]\n      : []\n  }\n  const byId = new Map(ofKind.map((item) => [item.id, item]))\n  const sections: Section[] = []\n  const used = recent.flatMap((id) => {\n    const item = byId.get(id)\n    return item ? [item] : []\n  })\n  if (used.length)\n    sections.push({\n      key: \"recent\",\n      label: labels.recent,\n      glyph: \"🕘\",\n      items: used,\n      collapsible: true,\n    })\n  for (const category of categories) {\n    if (category.kind !== kind) continue\n    const list = ofKind.filter((item) => item.category === category.id)\n    if (list.length)\n      sections.push({\n        key: `category-${category.id}`,\n        label: category.label,\n        glyph: category.glyph,\n        iconSrc: category.iconSrc,\n        items: list,\n        collapsible: true,\n      })\n  }\n  return sections\n}\n\n/** The cell an arrow key leads to, by where the cells sit on screen. */\nfunction neighbour(\n  cells: HTMLElement[],\n  index: number,\n  key: string,\n  rtl: boolean\n): HTMLElement | undefined {\n  if (key === (rtl ? \"ArrowLeft\" : \"ArrowRight\")) return cells[index + 1]\n  if (key === (rtl ? \"ArrowRight\" : \"ArrowLeft\")) return cells[index - 1]\n  if (key === \"Home\") return cells[0]\n  if (key === \"End\") return cells.at(-1)\n  if (key !== \"ArrowDown\" && key !== \"ArrowUp\") return undefined\n  const from = cells[index]?.getBoundingClientRect()\n  if (!from) return undefined\n  const step = key === \"ArrowDown\" ? 1 : -1\n  let rowTop: number | null = null\n  let best: { cell: HTMLElement; distance: number } | undefined\n  for (let at = index + step; at >= 0 && at < cells.length; at += step) {\n    const cell = cells[at]\n    if (!cell) break\n    const rect = cell.getBoundingClientRect()\n    if (Math.abs(rect.top - from.top) < 4) continue\n    rowTop ??= rect.top\n    if (Math.abs(rect.top - rowTop) >= 4) break\n    const distance = Math.abs(rect.left - from.left)\n    if (!best || distance < best.distance) best = { cell, distance }\n  }\n  return best?.cell\n}\n\nconst focusRing =\n  \"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link\"\n\n/** Tabs and the small controls of the panel. */\nexport const expressionsPickerVariants = cva(\n  `inline-flex min-h-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))] min-w-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))] cursor-pointer items-center justify-center gap-[var(--newt-space-1)] rounded-[var(--newt-radius-md)] border-0 px-[var(--newt-space-3)] font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] font-semibold leading-[var(--newt-line-height-normal)] enabled:hover:bg-newt-bg-hover enabled:hover:text-newt-text-primary enabled:active:bg-newt-bg-active disabled:cursor-not-allowed disabled:text-newt-text-muted ${focusRing}`,\n  {\n    variants: {\n      selected: {\n        true: \"bg-newt-bg-active text-newt-text-primary\",\n        false: \"bg-transparent text-newt-text-secondary\",\n      },\n    },\n    defaultVariants: { selected: false },\n  }\n)\n\nconst triggerClass = `min-h-[var(--newt-expressions-target-size)] cursor-pointer rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-elevated px-[var(--newt-space-3)] py-[var(--newt-space-2)] font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] leading-[var(--newt-line-height-normal)] text-newt-text-primary enabled:hover:bg-newt-bg-hover enabled:active:bg-newt-bg-active disabled:cursor-not-allowed disabled:text-newt-text-muted ${focusRing}`\n\nfunction trapFocus(event: React.KeyboardEvent<HTMLDialogElement>) {\n  if (event.key !== \"Tab\") return\n  const controls = [\n    ...event.currentTarget.querySelectorAll<HTMLElement>(\n      \"button:not(:disabled), input:not(:disabled)\"\n    ),\n  ].filter(\n    (element) => element.tabIndex >= 0 && element.getClientRects().length > 0\n  )\n  const first = controls[0]\n  const last = controls[controls.length - 1]\n  if (event.shiftKey && document.activeElement === first) {\n    event.preventDefault()\n    last?.focus()\n  } else if (!event.shiftKey && document.activeElement === last) {\n    event.preventDefault()\n    first?.focus()\n  }\n}\n\nfunction ExpressionArt({\n  item,\n  value,\n  large,\n}: {\n  item: ExpressionItem\n  value: string\n  large?: boolean\n}) {\n  if (item.src)\n    return (\n      <img\n        src={item.src}\n        alt=\"\"\n        loading=\"lazy\"\n        className={cn(\n          \"object-contain\",\n          large\n            ? \"size-[calc(var(--newt-expressions-preview-size)-var(--newt-space-3))]\"\n            : \"size-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))]\"\n        )}\n      />\n    )\n  if (item.kind === \"emoji\")\n    return (\n      <span\n        aria-hidden=\"true\"\n        className=\"text-[length:var(--newt-font-size-expression)] leading-none\"\n      >\n        {value}\n      </span>\n    )\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"px-[var(--newt-space-1)] text-center text-[length:var(--newt-font-size-xs)] text-newt-text-secondary\"\n    >\n      {item.label}\n    </span>\n  )\n}\n\nfunction SectionIcon({ section }: { section: Section }) {\n  if (section.iconSrc)\n    return (\n      <img\n        src={section.iconSrc}\n        alt=\"\"\n        className=\"size-[calc(var(--newt-space-3)+var(--newt-space-1))] shrink-0 rounded-full\"\n      />\n    )\n  if (!section.glyph) return null\n  return (\n    <span aria-hidden=\"true\" className=\"shrink-0 leading-none\">\n      {section.glyph}\n    </span>\n  )\n}\n\nconst ExpressionsPicker = React.forwardRef<\n  HTMLDivElement,\n  ExpressionsPickerProps\n>(\n  (\n    {\n      items = [],\n      categories = [],\n      recent = [],\n      current = null,\n      label = \"Choose an expression\",\n      disabled = false,\n      onSelect,\n      labels: labelOverrides,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const labels = { ...defaultExpressionsPickerLabels, ...labelOverrides }\n    const id = React.useId()\n    const dialog = React.useRef<HTMLDialogElement>(null)\n    const trigger = React.useRef<HTMLButtonElement>(null)\n    const search = React.useRef<HTMLInputElement>(null)\n    const scroller = React.useRef<HTMLDivElement>(null)\n    const toneButton = React.useRef<HTMLButtonElement>(null)\n    const toneRoot = React.useRef<HTMLDivElement>(null)\n    const [open, setOpen] = React.useState(false)\n    const [kind, setKind] = React.useState<ExpressionKind>(\"emoji\")\n    const [query, setQuery] = React.useState(\"\")\n    const [tone, setTone] = React.useState<SkinTone>(0)\n    const [showTones, setShowTones] = React.useState(false)\n    const [collapsed, setCollapsed] = React.useState<string[]>([])\n    const [scrolledTo, setScrolledTo] = React.useState<string | null>(null)\n    const [pendingScroll, setPendingScroll] = React.useState<string | null>(\n      null\n    )\n    const [activeKey, setActiveKey] = React.useState<string | null>(null)\n    const [hovered, setHovered] = React.useState<{\n      item: ExpressionItem\n      where: string\n    } | null>(null)\n\n    const searching = query.trim().length > 0\n    const sections = buildSections(\n      items,\n      categories,\n      recent,\n      kind,\n      query,\n      labels\n    )\n    const isOpen = (key: string) => !collapsed.includes(key)\n    const activeSection = scrolledTo ?? sections[0]?.key\n    const cellKeys = sections\n      .filter((section) => isOpen(section.key))\n      .flatMap((section) =>\n        section.items\n          .filter((item) => !item.disabled)\n          .map((item) => `${section.key}|${item.id}`)\n      )\n    const tabKey =\n      activeKey && cellKeys.includes(activeKey) ? activeKey : cellKeys[0]\n    const resultCount = sections.reduce(\n      (count, section) => count + section.items.length,\n      0\n    )\n\n    const currentItem = React.useMemo(() => {\n      if (!current) return null\n      const item = items.find(\n        (entry) =>\n          entry.kind === kind &&\n          (entry.value === current || entry.skins?.includes(current))\n      )\n      if (!item) return null\n      return {\n        item,\n        where:\n          categories.find((category) => category.id === item.category)?.label ??\n          \"\",\n      }\n    }, [categories, current, items, kind])\n    const preview = hovered ?? currentItem\n\n    function toggleSection(key: string) {\n      setCollapsed((list) =>\n        list.includes(key)\n          ? list.filter((entry) => entry !== key)\n          : [...list, key]\n      )\n    }\n    function goTo(key: string) {\n      setCollapsed((list) => list.filter((entry) => entry !== key))\n      setScrolledTo(key)\n      setPendingScroll(key)\n    }\n    React.useLayoutEffect(() => {\n      if (!pendingScroll || !scroller.current) return\n      const section = scroller.current.querySelector<HTMLElement>(\n        `[data-section=\"${pendingScroll}\"]`\n      )\n      if (section) scroller.current.scrollTop = section.offsetTop\n      setPendingScroll(null)\n    }, [pendingScroll])\n\n    function onScroll() {\n      const element = scroller.current\n      if (!element) return\n      let found: string | null = null\n      for (const section of element.querySelectorAll<HTMLElement>(\n        \"[data-section]\"\n      )) {\n        if (section.offsetTop > element.scrollTop + 8) break\n        found = section.dataset.section ?? null\n      }\n      if (found) setScrolledTo(found)\n    }\n\n    function show() {\n      if (disabled) return\n      setQuery(\"\")\n      setHovered(null)\n      setShowTones(false)\n      dialog.current?.showModal()\n      setOpen(true)\n      search.current?.focus()\n    }\n    function close() {\n      dialog.current?.close()\n    }\n    React.useEffect(() => {\n      if (disabled) dialog.current?.close()\n    }, [disabled])\n\n    function changeKind(next: ExpressionKind) {\n      setKind(next)\n      setScrolledTo(null)\n      setHovered(null)\n      setShowTones(false)\n      if (scroller.current) scroller.current.scrollTop = 0\n    }\n\n    function tabKeyDown(\n      event: React.KeyboardEvent<HTMLButtonElement>,\n      index: number\n    ) {\n      const rtl = getComputedStyle(event.currentTarget).direction === \"rtl\"\n      const forward = rtl ? \"ArrowLeft\" : \"ArrowRight\"\n      const back = rtl ? \"ArrowRight\" : \"ArrowLeft\"\n      const next =\n        event.key === \"Home\"\n          ? 0\n          : event.key === \"End\"\n            ? kinds.length - 1\n            : event.key === forward\n              ? (index + 1) % kinds.length\n              : event.key === back\n                ? (index + kinds.length - 1) % kinds.length\n                : -1\n      const nextTab = kinds[next]\n      if (!nextTab) return\n      event.preventDefault()\n      changeKind(nextTab)\n      dialog.current\n        ?.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]')\n        .item(next)\n        ?.focus()\n    }\n\n    function gridKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n      const target = event.target\n      if (!(target instanceof HTMLElement) || !target.matches(\"[data-cell]\"))\n        return\n      const cells = [\n        ...(scroller.current?.querySelectorAll<HTMLElement>(\n          \"[data-cell]:not(:disabled)\"\n        ) ?? []),\n      ]\n      const rtl = getComputedStyle(target).direction === \"rtl\"\n      const next = neighbour(cells, cells.indexOf(target), event.key, rtl)\n      if (!next) return\n      event.preventDefault()\n      next.focus()\n      next.scrollIntoView({ block: \"nearest\" })\n    }\n\n    function focusFirstCell(event: React.KeyboardEvent<HTMLInputElement>) {\n      if (event.key !== \"ArrowDown\") return\n      event.preventDefault()\n      scroller.current\n        ?.querySelector<HTMLElement>('[data-cell][tabindex=\"0\"]')\n        ?.focus()\n    }\n\n    function onDialogKeyDown(event: React.KeyboardEvent<HTMLDialogElement>) {\n      if (event.key === \"Escape\" && showTones) {\n        event.preventDefault()\n        setShowTones(false)\n        toneButton.current?.focus()\n        return\n      }\n      trapFocus(event)\n    }\n\n    function pickTone(next: SkinTone) {\n      setTone(next)\n      setShowTones(false)\n      toneButton.current?.focus()\n    }\n    React.useEffect(() => {\n      if (!showTones) return\n      toneRoot.current\n        ?.querySelector<HTMLElement>('[aria-pressed=\"true\"]')\n        ?.focus()\n      function outside(event: PointerEvent) {\n        const target = event.target\n        if (!(target instanceof Node) || !toneRoot.current?.contains(target))\n          setShowTones(false)\n      }\n      document.addEventListener(\"pointerdown\", outside)\n      return () => document.removeEventListener(\"pointerdown\", outside)\n    }, [showTones])\n\n    function select(item: ExpressionItem) {\n      if (disabled || item.disabled) return\n      close()\n      onSelect?.(item, expressionValue(item, tone))\n    }\n\n    const toneSample = skinTones[tone]\n\n    return (\n      <div ref={ref} className={cn(\"inline-block\", className)} {...props}>\n        <button\n          ref={trigger}\n          type=\"button\"\n          disabled={disabled}\n          aria-haspopup=\"dialog\"\n          aria-expanded={open}\n          aria-controls={id}\n          onClick={show}\n          className={triggerClass}\n        >\n          {label}\n        </button>\n        <dialog\n          ref={dialog}\n          id={id}\n          aria-label={label}\n          onKeyDown={onDialogKeyDown}\n          onClick={(event) => {\n            // The panel fills the dialog, so only the backdrop targets it.\n            if (event.target === event.currentTarget) close()\n          }}\n          onClose={() => {\n            setOpen(false)\n            setShowTones(false)\n            trigger.current?.focus()\n          }}\n          className=\"m-auto box-border h-[min(var(--newt-expressions-height),calc(100dvh-2*var(--newt-space-3)))] w-[min(var(--newt-expressions-width),calc(100%-2*var(--newt-space-3)))] max-w-none overflow-hidden rounded-[var(--newt-radius-lg)] border border-newt-border bg-newt-bg-surface p-0 font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] leading-[var(--newt-line-height-normal)] text-newt-text-primary shadow-elevation-high backdrop:bg-[color-mix(in_srgb,var(--newt-bg-base)_80%,transparent)] open:flex open:flex-col\"\n        >\n          <div className=\"flex shrink-0 items-center gap-[var(--newt-space-2)] px-[var(--newt-space-3)] pt-[var(--newt-space-3)]\">\n            <div\n              role=\"tablist\"\n              aria-label={labels.kinds}\n              className=\"flex items-center gap-[var(--newt-space-2)]\"\n            >\n              {kinds.map((tab, index) => (\n                <button\n                  key={tab}\n                  id={`${id}-${tab}`}\n                  role=\"tab\"\n                  type=\"button\"\n                  aria-selected={kind === tab}\n                  aria-controls={`${id}-panel`}\n                  tabIndex={kind === tab ? 0 : -1}\n                  onClick={() => changeKind(tab)}\n                  onKeyDown={(event) => tabKeyDown(event, index)}\n                  className={expressionsPickerVariants({\n                    selected: kind === tab,\n                  })}\n                >\n                  {labels[tab]}\n                </button>\n              ))}\n            </div>\n          </div>\n\n          <div className=\"flex shrink-0 items-center gap-[var(--newt-space-2)] border-b border-newt-border p-[var(--newt-space-3)]\">\n            <div className=\"relative min-w-0 flex-1\">\n              <input\n                ref={search}\n                type=\"text\"\n                autoComplete=\"off\"\n                spellCheck={false}\n                value={query}\n                aria-label={labels.search}\n                placeholder={labels.searchPlaceholder}\n                onChange={(event) => {\n                  setQuery(event.target.value)\n                  setHovered(null)\n                }}\n                onKeyDown={focusFirstCell}\n                className={`box-border h-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))] w-full rounded-[var(--newt-radius-md)] border-0 bg-newt-bg-input pe-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))] ps-[calc(var(--newt-space-3)*3)] font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] text-newt-text-primary placeholder:text-newt-text-muted ${focusRing}`}\n              />\n              <svg\n                aria-hidden=\"true\"\n                viewBox=\"0 0 16 16\"\n                className=\"pointer-events-none absolute start-[var(--newt-space-3)] top-1/2 size-[calc(var(--newt-space-3)+var(--newt-space-1))] -translate-y-1/2 fill-none stroke-newt-text-secondary stroke-2\"\n              >\n                <circle cx=\"7\" cy=\"7\" r=\"5\" />\n                <path d=\"m11 11 4 4\" strokeLinecap=\"round\" />\n              </svg>\n              {query ? (\n                <button\n                  type=\"button\"\n                  aria-label={labels.clearSearch}\n                  onClick={() => {\n                    setQuery(\"\")\n                    search.current?.focus()\n                  }}\n                  className={cn(\n                    expressionsPickerVariants(),\n                    \"absolute end-[var(--newt-space-1)] top-1/2 min-h-0 min-w-0 -translate-y-1/2 size-[calc(var(--newt-expressions-target-size)-var(--newt-space-3)-var(--newt-space-2))] p-0\"\n                  )}\n                >\n                  <span aria-hidden=\"true\">×</span>\n                </button>\n              ) : null}\n            </div>\n            {kind === \"emoji\" ? (\n              <div ref={toneRoot} className=\"relative shrink-0\">\n                <button\n                  ref={toneButton}\n                  type=\"button\"\n                  aria-label={labels.skinTone(labels.toneNames[tone])}\n                  aria-expanded={showTones}\n                  onClick={() => setShowTones((value) => !value)}\n                  className={cn(\n                    expressionsPickerVariants({ selected: showTones }),\n                    \"p-0 no-underline\"\n                  )}\n                >\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"text-[length:var(--newt-font-size-expression)] leading-none\"\n                  >\n                    {toneSample?.sample}\n                  </span>\n                </button>\n                {showTones ? (\n                  <div\n                    role=\"group\"\n                    aria-label={labels.skinTones}\n                    className=\"absolute -end-[var(--newt-space-1)] -top-[var(--newt-space-1)] z-20 flex flex-col gap-[var(--newt-space-1)] rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-floating p-[var(--newt-space-1)] shadow-elevation-high\"\n                  >\n                    {skinTones.map((option) => (\n                      <button\n                        key={option.tone}\n                        type=\"button\"\n                        aria-label={labels.toneNames[option.tone]}\n                        title={labels.toneNames[option.tone]}\n                        aria-pressed={tone === option.tone}\n                        onClick={() => pickTone(option.tone)}\n                        className={cn(\n                          expressionsPickerVariants(),\n                          \"p-0 aria-pressed:bg-newt-bg-active aria-pressed:shadow-[inset_0_0_0_2px_var(--newt-brand)]\"\n                        )}\n                      >\n                        <span\n                          aria-hidden=\"true\"\n                          className=\"text-[length:var(--newt-font-size-expression)] leading-none\"\n                        >\n                          {option.sample}\n                        </span>\n                      </button>\n                    ))}\n                  </div>\n                ) : null}\n              </div>\n            ) : null}\n          </div>\n\n          <div\n            id={`${id}-panel`}\n            role=\"tabpanel\"\n            aria-labelledby={`${id}-${kind}`}\n            className=\"flex min-h-0 flex-1\"\n          >\n            {!searching && sections.length > 1 ? (\n              <nav\n                aria-label={labels.categories}\n                className=\"flex w-[calc(var(--newt-expressions-target-size)+var(--newt-space-2))] shrink-0 flex-col items-center gap-[var(--newt-space-1)] overflow-y-auto overflow-x-hidden border-e border-newt-border p-[var(--newt-space-2)] ![scrollbar-width:none]\"\n              >\n                {sections.map((section) => (\n                  <button\n                    key={section.key}\n                    type=\"button\"\n                    aria-label={section.label}\n                    title={section.label}\n                    aria-current={\n                      activeSection === section.key ? \"true\" : undefined\n                    }\n                    onClick={() => goTo(section.key)}\n                    className={cn(\n                      expressionsPickerVariants(),\n                      \"relative shrink-0 p-0\",\n                      activeSection === section.key &&\n                        \"text-newt-text-primary before:absolute before:-start-[var(--newt-space-2)] before:top-1/2 before:h-[calc(var(--newt-space-3)+var(--newt-space-2))] before:w-[var(--newt-space-1)] before:-translate-y-1/2 before:rounded-e-full before:bg-newt-text-primary before:content-['']\"\n                    )}\n                  >\n                    {section.iconSrc ? (\n                      <img\n                        src={section.iconSrc}\n                        alt=\"\"\n                        className=\"size-[calc(var(--newt-expressions-target-size)-var(--newt-space-3)-var(--newt-space-1))] rounded-full\"\n                      />\n                    ) : (\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"text-[length:calc(var(--newt-font-size-expression)*0.625)] leading-none\"\n                      >\n                        {section.glyph ?? section.label.slice(0, 1)}\n                      </span>\n                    )}\n                  </button>\n                ))}\n              </nav>\n            ) : null}\n\n            <div\n              ref={scroller}\n              onScroll={onScroll}\n              onKeyDown={gridKeyDown}\n              onMouseLeave={() => setHovered(null)}\n              className=\"relative min-w-0 flex-1 overflow-y-auto px-[var(--newt-space-2)] pb-[var(--newt-space-2)]\"\n            >\n              {sections.map((section) => (\n                <section\n                  key={section.key}\n                  data-section={section.key}\n                  aria-labelledby={`${id}-${section.key}-title`}\n                >\n                  <h3\n                    id={`${id}-${section.key}-title`}\n                    className=\"sticky top-0 z-10 m-0 bg-newt-bg-surface pb-[var(--newt-space-1)] pt-[var(--newt-space-2)] text-[length:var(--newt-font-size-sm)] font-semibold text-newt-text-secondary\"\n                  >\n                    {section.collapsible ? (\n                      <button\n                        type=\"button\"\n                        aria-expanded={isOpen(section.key)}\n                        aria-controls={`${id}-${section.key}`}\n                        onClick={() => toggleSection(section.key)}\n                        className={`inline-flex max-w-full cursor-pointer items-center gap-[var(--newt-space-2)] rounded-[var(--newt-radius-sm)] border-0 bg-transparent px-[var(--newt-space-1)] font-[inherit] text-[inherit] hover:text-newt-text-primary ${focusRing}`}\n                      >\n                        <SectionIcon section={section} />\n                        <span className=\"min-w-0 truncate\">\n                          {section.label}\n                        </span>\n                        <svg\n                          aria-hidden=\"true\"\n                          viewBox=\"0 0 16 16\"\n                          className={cn(\n                            \"size-[var(--newt-space-3)] shrink-0 fill-none stroke-current stroke-2\",\n                            !isOpen(section.key) &&\n                              \"[transform:rotate(calc(-90deg*var(--newt-dir)))]\"\n                          )}\n                        >\n                          <path\n                            d=\"m4 6 4 4 4-4\"\n                            strokeLinecap=\"round\"\n                            strokeLinejoin=\"round\"\n                          />\n                        </svg>\n                      </button>\n                    ) : (\n                      <span className=\"inline-flex items-center gap-[var(--newt-space-2)] px-[var(--newt-space-1)]\">\n                        {section.label}\n                      </span>\n                    )}\n                  </h3>\n                  {isOpen(section.key) ? (\n                    <div\n                      id={`${id}-${section.key}`}\n                      className={cn(\n                        \"grid pt-[var(--newt-space-1)]\",\n                        kind === \"emoji\"\n                          ? \"grid-cols-[repeat(auto-fill,var(--newt-expressions-target-size))]\"\n                          : \"grid-cols-[repeat(auto-fill,minmax(var(--newt-expressions-preview-size),1fr))] gap-[var(--newt-space-1)]\"\n                      )}\n                    >\n                      {section.items.map((item) => {\n                        const key = `${section.key}|${item.id}`\n                        const value = expressionValue(item, tone)\n                        const where =\n                          categories.find(\n                            (category) => category.id === item.category\n                          )?.label ?? \"\"\n                        return (\n                          <button\n                            key={key}\n                            type=\"button\"\n                            data-cell\n                            disabled={disabled || item.disabled}\n                            tabIndex={key === tabKey ? 0 : -1}\n                            aria-label={\n                              item.disabled\n                                ? labels.unavailable(item.label)\n                                : item.label\n                            }\n                            aria-pressed={\n                              current != null &&\n                              (item.value === current ||\n                                item.skins?.includes(current) === true)\n                            }\n                            onClick={() => select(item)}\n                            onFocus={() => {\n                              setActiveKey(key)\n                              setHovered({ item, where })\n                            }}\n                            onMouseEnter={() => setHovered({ item, where })}\n                            className={cn(\n                              \"flex cursor-pointer items-center justify-center rounded-[var(--newt-radius-md)] border border-transparent bg-transparent p-0 enabled:hover:bg-newt-bg-hover aria-pressed:bg-newt-bg-active aria-pressed:shadow-[inset_0_0_0_2px_var(--newt-brand)] disabled:cursor-not-allowed disabled:border-dashed disabled:border-newt-border disabled:opacity-50\",\n                              kind === \"emoji\"\n                                ? \"size-[var(--newt-expressions-target-size)]\"\n                                : \"aspect-square w-full\",\n                              focusRing\n                            )}\n                          >\n                            <ExpressionArt\n                              item={item}\n                              value={value}\n                              large={kind !== \"emoji\"}\n                            />\n                          </button>\n                        )\n                      })}\n                    </div>\n                  ) : null}\n                </section>\n              ))}\n              {sections.length === 0 ? (\n                <div\n                  role=\"status\"\n                  className=\"flex flex-col items-center px-[var(--newt-space-3)] py-[calc(var(--newt-space-3)*3)] text-center text-newt-text-secondary\"\n                >\n                  <p className=\"m-0 font-semibold text-newt-text-primary\">\n                    {searching ? labels.noResults : labels.empty}\n                  </p>\n                  <p className=\"m-0\">\n                    {searching ? labels.noResultsHelp : labels.emptyHelp}\n                  </p>\n                </div>\n              ) : searching ? (\n                <p role=\"status\" className=\"sr-only\">\n                  {labels.resultCount(resultCount)}\n                </p>\n              ) : null}\n            </div>\n          </div>\n\n          <div className=\"flex h-[calc(var(--newt-expressions-target-size)+var(--newt-space-3))] shrink-0 items-center gap-[var(--newt-space-3)] border-t border-newt-border bg-newt-bg-floating px-[var(--newt-space-3)]\">\n            {preview ? (\n              <>\n                <span\n                  aria-hidden=\"true\"\n                  className=\"flex size-[calc(var(--newt-expressions-target-size)-var(--newt-space-2))] shrink-0 items-center justify-center overflow-hidden\"\n                >\n                  {preview.item.src ? (\n                    <img\n                      src={preview.item.src}\n                      alt=\"\"\n                      className=\"size-full object-contain\"\n                    />\n                  ) : preview.item.kind === \"emoji\" ? (\n                    <span className=\"text-[length:var(--newt-font-size-expression)] leading-none\">\n                      {expressionValue(preview.item, tone)}\n                    </span>\n                  ) : null}\n                </span>\n                <span className=\"flex min-w-0 flex-col\">\n                  <span className=\"truncate font-semibold\">\n                    {expressionShortcode(preview.item)}\n                  </span>\n                  {preview.where ? (\n                    <span className=\"truncate text-[length:var(--newt-font-size-xs)] text-newt-text-secondary\">\n                      {labels.from}{\" \"}\n                      <strong className=\"font-semibold\">{preview.where}</strong>\n                    </span>\n                  ) : null}\n                </span>\n              </>\n            ) : (\n              <span className=\"text-newt-text-secondary\">{labels.hint}</span>\n            )}\n          </div>\n        </dialog>\n      </div>\n    )\n  }\n)\nExpressionsPicker.displayName = \"ExpressionsPicker\"\nexport { ExpressionsPicker }\n",
      "type": "registry:ui"
    }
  ]
}