{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-chat-channels",
  "type": "registry:component",
  "title": "Sidebar Chat Channels",
  "description": "A team chat sidebar with channels and direct messages in two collapsible sections, presence dots and bold unread rows.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "chat",
    "channels",
    "presence",
    "messages",
    "collapsible"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-chat-channels",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-chat-channels.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-chat-channels.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ChatPresence = \"online\" | \"away\" | \"busy\" | \"offline\";\n\nexport interface ChatChannel {\n  id: string;\n  name: string;\n  unread?: number;\n  muted?: boolean;\n  private?: boolean;\n}\n\nexport interface ChatPerson {\n  id: string;\n  name: string;\n  status?: ChatPresence;\n  unread?: number;\n}\n\nexport interface SidebarChatChannelsProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  channels?: ChatChannel[];\n  people?: ChatPerson[];\n  title?: string;\n  subtitle?: string;\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  openSections?: string[];\n  defaultOpenSections?: string[];\n  onOpenSectionsChange?: (open: string[]) => void;\n  channelsTitle?: string;\n  peopleTitle?: string;\n  accent?: string;\n}\n\nconst defaultChannels: ChatChannel[] = [\n  { id: \"general\", name: \"general\" },\n  { id: \"design\", name: \"design-crit\", unread: 4 },\n  { id: \"launch\", name: \"launch-room\", unread: 1 },\n  { id: \"payroll\", name: \"payroll\", private: true },\n  { id: \"random\", name: \"random\", muted: true },\n];\n\nconst defaultPeople: ChatPerson[] = [\n  { id: \"maya\", name: \"Maya Chen\", status: \"online\" },\n  { id: \"daniel\", name: \"Daniel Okafor\", status: \"away\", unread: 2 },\n  { id: \"priya\", name: \"Priya Raman\", status: \"busy\" },\n  { id: \"leo\", name: \"Leo Marsh\", status: \"offline\" },\n];\n\nconst PALETTE = [\"#2f7bff\", \"#8b5cf6\", \"#e5484d\", \"#30a46c\", \"#f5a623\", \"#0ea5b7\", \"#d6409f\"];\n\nfunction hash(text: string) {\n  let h = 2166136261;\n  for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);\n  return h >>> 0;\n}\n\nfunction initials(name: string) {\n  const parts = name.trim().split(/\\s+/).filter(Boolean);\n  return ((parts[0]?.[0] ?? \"\") + (parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? \"\") : \"\")).toUpperCase();\n}\n\nconst css = `\n.hb-yc2 {\n  --hb-yc2-a: #2f7bff;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 0;\n  border-right: 1px solid #262626;\n  background: #0f0f0f;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-yc2 *, .hb-yc2 *::before, .hb-yc2 *::after { box-sizing: border-box; }\n.hb-yc2-top { display: flex; flex: none; align-items: center; gap: 9px; padding: 12px 12px 10px; border-bottom: 1px solid #1f1f1f; }\n.hb-yc2-logo {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  border-radius: 8px;\n  background: linear-gradient(135deg, var(--hb-yc2-a), color-mix(in srgb, var(--hb-yc2-a) 45%, #8b5cf6));\n  color: #ffffff;\n  font-size: 13px;\n  font-weight: 700;\n}\n.hb-yc2-ttl { min-width: 0; }\n.hb-yc2-name { margin: 0; overflow: hidden; font-size: 13px; font-weight: 600; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc2-sub { margin: 0; overflow: hidden; color: #77777f; font-size: 11px; line-height: 14px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc2-scroll { flex: 1; min-height: 0; padding: 6px; overflow-y: auto; scrollbar-width: none; }\n.hb-yc2-scroll::-webkit-scrollbar { display: none; }\n.hb-yc2-sec + .hb-yc2-sec { margin-top: 6px; }\n.hb-yc2-toggle {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  width: 100%;\n  height: 26px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 11.5px;\n  font-weight: 600;\n  letter-spacing: .02em;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-yc2-toggle:hover { background: #161616; color: #ededed; }\n.hb-yc2-toggle:focus-visible { outline: 2px solid var(--hb-yc2-a); outline-offset: -2px; }\n.hb-yc2-chev { width: 12px; height: 12px; flex: none; transition: transform .22s cubic-bezier(.2, .9, .2, 1); }\n.hb-yc2-toggle[aria-expanded=\"false\"] .hb-yc2-chev { transform: rotate(-90deg); }\n.hb-yc2-tt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc2-sum { display: none; flex: none; min-width: 16px; padding: 0 5px; border-radius: 999px; background: var(--hb-yc2-a); color: #ffffff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; animation: hb-yc2-pop .25s cubic-bezier(.3, 1.5, .5, 1) both; }\n.hb-yc2-toggle[aria-expanded=\"false\"] .hb-yc2-sum[data-on=\"true\"] { display: block; }\n.hb-yc2-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s cubic-bezier(.2, .9, .2, 1); }\n.hb-yc2-body[data-open=\"false\"] { grid-template-rows: 0fr; }\n.hb-yc2-inner { min-height: 0; overflow: hidden; }\n.hb-yc2-list { display: flex; flex-direction: column; margin: 0; padding: 2px 0 0; list-style: none; }\n.hb-yc2-item {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: 28px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 7px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-yc2-item:hover { background: #181818; color: #ededed; }\n.hb-yc2-item:focus-visible { outline: 2px solid var(--hb-yc2-a); outline-offset: -2px; }\n.hb-yc2-item[aria-current=\"true\"] { background: var(--hb-yc2-a); color: #ffffff; }\n.hb-yc2-item[data-muted=\"true\"]:not([aria-current=\"true\"]) { color: #6a6a6a; }\n.hb-yc2-hash { width: 14px; flex: none; color: #6f6f6f; font-size: 15px; font-weight: 500; line-height: 1; text-align: center; }\n.hb-yc2-item[aria-current=\"true\"] .hb-yc2-hash { color: rgba(255, 255, 255, .8); }\n.hb-yc2-lock { width: 12px; height: 12px; flex: none; margin: 0 1px; color: #6f6f6f; }\n.hb-yc2-item[aria-current=\"true\"] .hb-yc2-lock { color: rgba(255, 255, 255, .8); }\n.hb-yc2-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc2-item[data-unread=\"true\"] .hb-yc2-txt { color: #ffffff; font-weight: 700; }\n.hb-yc2-badge { flex: none; min-width: 18px; padding: 0 6px; border-radius: 999px; background: #e5484d; color: #ffffff; font-size: 10.5px; font-weight: 700; line-height: 18px; text-align: center; }\n.hb-yc2-item[aria-current=\"true\"] .hb-yc2-badge { background: rgba(255, 255, 255, .24); }\n.hb-yc2-av {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  border-radius: 7px;\n  background: var(--hb-yc2-c, #2f7bff);\n  color: #ffffff;\n  font-size: 9px;\n  font-weight: 700;\n  letter-spacing: .02em;\n}\n.hb-yc2-pres {\n  position: absolute;\n  right: -3px;\n  bottom: -3px;\n  width: 9px;\n  height: 9px;\n  border: 2px solid #0f0f0f;\n  border-radius: 999px;\n  background: var(--hb-yc2-s, #4a4a4a);\n  transition: border-color .15s ease;\n}\n.hb-yc2-pres[data-s=\"offline\"] { background: #0f0f0f; box-shadow: inset 0 0 0 1.5px #5a5a5a; }\n.hb-yc2-item:hover .hb-yc2-pres { border-color: #181818; }\n.hb-yc2-item[aria-current=\"true\"] .hb-yc2-pres { border-color: var(--hb-yc2-a); }\n.hb-yc2-item[aria-current=\"true\"] .hb-yc2-pres[data-s=\"offline\"] { background: var(--hb-yc2-a); }\n.hb-yc2-pres[data-s=\"online\"] { animation: hb-yc2-pulse 2.6s ease-in-out infinite; }\n@keyframes hb-yc2-pop {\n  from { opacity: 0; transform: scale(.5); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-yc2-pulse {\n  0%, 100% { box-shadow: 0 0 0 0 rgba(48, 164, 108, 0); }\n  50% { box-shadow: 0 0 0 3px rgba(48, 164, 108, .28); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-yc2-toggle, .hb-yc2-item, .hb-yc2-body, .hb-yc2-chev { transition: none; }\n  .hb-yc2-pres[data-s=\"online\"], .hb-yc2-sum { animation: none; }\n}\n`;\n\nconst PRESENCE: Record<ChatPresence, string> = {\n  online: \"#30a46c\",\n  away: \"#f5a623\",\n  busy: \"#e5484d\",\n  offline: \"#4a4a4a\",\n};\n\nfunction Chevron() {\n  return (\n    <svg className=\"hb-yc2-chev\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M3 4.5L6 7.5l3-3\" />\n    </svg>\n  );\n}\n\nexport function SidebarChatChannels({\n  channels = defaultChannels,\n  people = defaultPeople,\n  title = \"Northwind\",\n  subtitle = \"12 online\",\n  active,\n  defaultActive,\n  onChange,\n  openSections,\n  defaultOpenSections = [\"channels\", \"people\"],\n  onOpenSectionsChange,\n  channelsTitle = \"Channels\",\n  peopleTitle = \"Direct messages\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarChatChannelsProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const [inner, setInner] = React.useState(defaultActive ?? channels[0]?.id ?? \"\");\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpenSections);\n  const [focusKey, setFocusKey] = React.useState(\"\");\n  const current = active ?? inner;\n  const open = openSections ?? innerOpen;\n\n  function select(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function setOpen(id: string, next: boolean) {\n    const has = open.includes(id);\n    if (has === next) return;\n    const value = next ? [...open, id] : open.filter((x) => x !== id);\n    if (openSections === undefined) setInnerOpen(value);\n    onOpenSectionsChange?.(value);\n  }\n\n  function ring() {\n    return Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc2-nav]\") ?? []).filter((el) => !el.closest(\"[inert]\"));\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (e.key === \"Escape\") {\n      (document.activeElement as HTMLElement | null)?.blur();\n      return;\n    }\n    const target = e.target as HTMLElement;\n    if (!target.hasAttribute(\"data-yc2-nav\")) return;\n    const items = ring();\n    const at = items.indexOf(target);\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(items.length - 1, at + 1);\n    else if (e.key === \"ArrowUp\") next = Math.max(0, at - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = items.length - 1;\n    if (next >= 0) {\n      e.preventDefault();\n      items[next]?.focus();\n      return;\n    }\n    const section = target.dataset.yc2Section;\n    if (section && e.key === \"ArrowRight\") {\n      e.preventDefault();\n      setOpen(section, true);\n    } else if (section && e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      setOpen(section, false);\n    }\n  }\n\n  const keys = [\n    \"s:channels\",\n    ...(open.includes(\"channels\") ? channels.map((c) => c.id) : []),\n    \"s:people\",\n    ...(open.includes(\"people\") ? people.map((p) => p.id) : []),\n  ];\n  const wanted = keys.includes(focusKey) ? focusKey : keys.includes(current) ? current : keys[0];\n\n  const channelUnread = channels.reduce((n, c) => n + (c.muted ? 0 : (c.unread ?? 0)), 0);\n  const peopleUnread = people.reduce((n, p) => n + (p.unread ?? 0), 0);\n\n  const vars = { \"--hb-yc2-a\": accent, ...style } as React.CSSProperties;\n\n  function toggle(id: string, label: string, unread: number) {\n    const isOpen = open.includes(id);\n    return (\n      <button\n        type=\"button\"\n        className=\"hb-yc2-toggle\"\n        data-yc2-nav=\"\"\n        data-yc2-section={id}\n        aria-expanded={isOpen}\n        aria-controls={`${uid}-${id}`}\n        tabIndex={wanted === `s:${id}` ? 0 : -1}\n        onFocus={() => setFocusKey(`s:${id}`)}\n        onClick={() => setOpen(id, !isOpen)}\n      >\n        <Chevron />\n        <span className=\"hb-yc2-tt\">{label}</span>\n        <span className=\"hb-yc2-sum\" data-on={unread > 0} aria-hidden=\"true\">\n          {unread}\n        </span>\n      </button>\n    );\n  }\n\n  return (\n    <nav ref={rootRef} className={`hb-yc2 ${className}`} aria-label=\"Conversations\" style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-sidebar-chat-channels\" precedence=\"default\">{css}</style>\n      <div className=\"hb-yc2-top\">\n        <span className=\"hb-yc2-logo\" aria-hidden=\"true\">\n          {title.trim().charAt(0).toUpperCase()}\n        </span>\n        <div className=\"hb-yc2-ttl\">\n          <p className=\"hb-yc2-name\">{title}</p>\n          {subtitle ? <p className=\"hb-yc2-sub\">{subtitle}</p> : null}\n        </div>\n      </div>\n      <div className=\"hb-yc2-scroll\">\n        <div className=\"hb-yc2-sec\">\n          {toggle(\"channels\", channelsTitle, channelUnread)}\n          <div id={`${uid}-channels`} className=\"hb-yc2-body\" data-open={open.includes(\"channels\")}>\n            <div className=\"hb-yc2-inner\" inert={!open.includes(\"channels\")}>\n              <ul className=\"hb-yc2-list\" role=\"list\">\n                {channels.map((c) => (\n                  <li key={c.id}>\n                    <button\n                      type=\"button\"\n                      className=\"hb-yc2-item\"\n                      data-yc2-nav=\"\"\n                      data-unread={!!c.unread && !c.muted}\n                      data-muted={!!c.muted}\n                      aria-current={c.id === current ? true : undefined}\n                      tabIndex={wanted === c.id ? 0 : -1}\n                      onFocus={() => setFocusKey(c.id)}\n                      onClick={() => select(c.id)}\n                    >\n                      {c.private ? (\n                        <svg className=\"hb-yc2-lock\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                          <rect x=\"2.5\" y=\"5.3\" width=\"7\" height=\"5\" rx=\"1.2\" />\n                          <path d=\"M4 5.3V3.8a2 2 0 0 1 4 0v1.5\" />\n                        </svg>\n                      ) : (\n                        <span className=\"hb-yc2-hash\" aria-hidden=\"true\">\n                          #\n                        </span>\n                      )}\n                      <span className=\"hb-yc2-txt\">{c.name}</span>\n                      {c.unread && !c.muted ? (\n                        <span className=\"hb-yc2-badge\" aria-label={`${c.unread} unread`}>\n                          {c.unread}\n                        </span>\n                      ) : null}\n                    </button>\n                  </li>\n                ))}\n              </ul>\n            </div>\n          </div>\n        </div>\n        <div className=\"hb-yc2-sec\">\n          {toggle(\"people\", peopleTitle, peopleUnread)}\n          <div id={`${uid}-people`} className=\"hb-yc2-body\" data-open={open.includes(\"people\")}>\n            <div className=\"hb-yc2-inner\" inert={!open.includes(\"people\")}>\n              <ul className=\"hb-yc2-list\" role=\"list\">\n                {people.map((p) => {\n                  const status = p.status ?? \"offline\";\n                  return (\n                    <li key={p.id}>\n                      <button\n                        type=\"button\"\n                        className=\"hb-yc2-item\"\n                        data-yc2-nav=\"\"\n                        data-unread={!!p.unread}\n                        aria-current={p.id === current ? true : undefined}\n                        tabIndex={wanted === p.id ? 0 : -1}\n                        onFocus={() => setFocusKey(p.id)}\n                        onClick={() => select(p.id)}\n                      >\n                        <span className=\"hb-yc2-av\" style={{ \"--hb-yc2-c\": PALETTE[hash(p.name) % PALETTE.length] } as React.CSSProperties} aria-hidden=\"true\">\n                          {initials(p.name)}\n                          <span className=\"hb-yc2-pres\" data-s={status} style={{ \"--hb-yc2-s\": PRESENCE[status] } as React.CSSProperties} />\n                        </span>\n                        <span className=\"hb-yc2-txt\">\n                          {p.name}\n                          <span style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clip: \"rect(0 0 0 0)\" }}>, {status}</span>\n                        </span>\n                        {p.unread ? (\n                          <span className=\"hb-yc2-badge\" aria-label={`${p.unread} unread`}>\n                            {p.unread}\n                          </span>\n                        ) : null}\n                      </button>\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          </div>\n        </div>\n      </div>\n    </nav>\n  );\n}\n"
    }
  ]
}