{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-mail-folders",
  "type": "registry:component",
  "title": "Sidebar Mail Folders",
  "description": "A mail app sidebar with a compose button, folders with unread counts, colored labels and a storage meter that fills on mount.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "mail",
    "folders",
    "labels",
    "inbox",
    "storage"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-mail-folders",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-mail-folders.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-mail-folders.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst ICONS = {\n  inbox:\n    \"M3.5 11l1.7-5.6A1.2 1.2 0 0 1 6.3 4.5h7.4a1.2 1.2 0 0 1 1.1.9L16.5 11M3.5 11v3.6a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1V11M3.5 11h4l.8 1.8h3.4l.8-1.8h4\",\n  star: \"M10 3.2l2.1 4.3 4.7.7-3.4 3.3.8 4.7L10 13.9l-4.2 2.3.8-4.7L3.2 8.2l4.7-.7z\",\n  send: \"M17 3L8.5 11.5M17 3l-5.5 14-3-5.5L3 8.5z\",\n  drafts: \"M5 2.8h6.5L15 6.3v10.9H5zM11.5 2.8v3.5H15M7.5 10h5M7.5 13h5\",\n  trash: \"M4 6h12M8 6V4.2h4V6M5.5 6l.7 10h7.6l.7-10M8.5 9v4.5M11.5 9v4.5\",\n  archive: \"M3.5 5h13v3h-13zM4.5 8v8h11V8M8 11.5h4\",\n  pencil: \"M12.8 4.2l3 3L7.5 15.5l-3.7.7.7-3.7zM11.3 5.7l3 3\",\n} as const;\n\nexport type SidebarMailIconName = keyof typeof ICONS;\n\nexport function SidebarMailIcon({ name }: { name: SidebarMailIconName }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={ICONS[name]} />\n    </svg>\n  );\n}\n\nexport interface MailFolder {\n  id: string;\n  label: string;\n  icon?: SidebarMailIconName;\n  count?: number;\n}\n\nexport interface MailLabel {\n  id: string;\n  label: string;\n  color: string;\n}\n\nexport interface MailStorage {\n  used: number;\n  total: number;\n  unit?: string;\n}\n\nexport interface SidebarMailFoldersProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  folders?: MailFolder[];\n  labels?: MailLabel[];\n  storage?: MailStorage | null;\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  onCompose?: () => void;\n  composeLabel?: string;\n  labelsTitle?: string;\n  rowHeight?: number;\n  accent?: string;\n}\n\nconst defaultFolders: MailFolder[] = [\n  { id: \"inbox\", label: \"Inbox\", icon: \"inbox\", count: 12 },\n  { id: \"starred\", label: \"Starred\", icon: \"star\" },\n  { id: \"sent\", label: \"Sent\", icon: \"send\" },\n  { id: \"drafts\", label: \"Drafts\", icon: \"drafts\", count: 3 },\n  { id: \"archive\", label: \"Archive\", icon: \"archive\" },\n  { id: \"trash\", label: \"Trash\", icon: \"trash\" },\n];\n\nconst defaultLabels: MailLabel[] = [\n  { id: \"work\", label: \"Work\", color: \"#2f7bff\" },\n  { id: \"family\", label: \"Family\", color: \"#30a46c\" },\n  { id: \"travel\", label: \"Travel\", color: \"#f5a623\" },\n];\n\nconst defaultStorage: MailStorage = { used: 11.4, total: 15, unit: \"GB\" };\n\nconst css = `\n.hb-yc1 {\n  --hb-yc1-a: #2f7bff;\n  --hb-yc1-row: 30px;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 0;\n  padding: 8px;\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-yc1 *, .hb-yc1 *::before, .hb-yc1 *::after { box-sizing: border-box; }\n.hb-yc1-compose {\n  display: flex;\n  flex: none;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  width: 100%;\n  height: 32px;\n  margin: 0 0 8px;\n  padding: 0 12px;\n  border: 0;\n  border-radius: 10px;\n  background: var(--hb-yc1-a);\n  color: #ffffff;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 600;\n  cursor: pointer;\n  box-shadow: 0 6px 18px color-mix(in srgb, var(--hb-yc1-a) 38%, transparent);\n  transition: transform .18s ease, filter .18s ease, box-shadow .18s ease;\n}\n.hb-yc1-compose svg { width: 16px; height: 16px; flex: none; }\n.hb-yc1-compose:hover { filter: brightness(1.1); }\n.hb-yc1-compose:active { transform: scale(.97); }\n.hb-yc1-compose:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }\n.hb-yc1-scroll { flex: 1; min-height: 0; margin: 0 -8px; padding: 0 8px; overflow-y: auto; scrollbar-width: none; }\n.hb-yc1-scroll::-webkit-scrollbar { display: none; }\n.hb-yc1-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }\n.hb-yc1-head {\n  margin: 0;\n  padding: 10px 8px 4px;\n  color: #6f6f6f;\n  font-size: 10.5px;\n  font-weight: 600;\n  letter-spacing: .08em;\n  line-height: 14px;\n  text-transform: uppercase;\n}\n.hb-yc1-item {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  width: 100%;\n  height: var(--hb-yc1-row);\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .16s ease, color .16s ease;\n}\n.hb-yc1-item:hover { background: #181818; color: #ededed; }\n.hb-yc1-item:focus-visible { outline: 2px solid var(--hb-yc1-a); outline-offset: -2px; }\n.hb-yc1-item[aria-current=\"true\"] {\n  background: color-mix(in srgb, var(--hb-yc1-a) 15%, transparent);\n  color: #ffffff;\n}\n.hb-yc1-item[aria-current=\"true\"]::before {\n  content: \"\";\n  position: absolute;\n  top: 7px;\n  bottom: 7px;\n  left: -8px;\n  width: 3px;\n  border-radius: 0 3px 3px 0;\n  background: var(--hb-yc1-a);\n  animation: hb-yc1-bar .3s cubic-bezier(.2, .9, .2, 1) both;\n}\n.hb-yc1-ico { display: grid; flex: none; place-items: center; width: 16px; height: 16px; }\n.hb-yc1-ico svg { width: 16px; height: 16px; }\n.hb-yc1-item[aria-current=\"true\"] .hb-yc1-ico { color: var(--hb-yc1-a); }\n.hb-yc1-dot {\n  flex: none;\n  width: 8px;\n  height: 8px;\n  margin: 0 4px;\n  border-radius: 999px;\n  background: var(--hb-yc1-dot, #8f8f8f);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-yc1-dot, #8f8f8f) 22%, transparent);\n}\n.hb-yc1-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc1-item[data-unread=\"true\"] .hb-yc1-txt { color: #ededed; font-weight: 600; }\n.hb-yc1-count {\n  flex: none;\n  min-width: 20px;\n  padding: 0 6px;\n  border-radius: 999px;\n  background: #262626;\n  color: #ededed;\n  font-size: 11px;\n  font-variant-numeric: tabular-nums;\n  font-weight: 600;\n  line-height: 18px;\n  text-align: center;\n}\n.hb-yc1-item[aria-current=\"true\"] .hb-yc1-count { background: var(--hb-yc1-a); color: #ffffff; }\n.hb-yc1-store { flex: none; margin-top: 8px; padding: 10px 8px 2px; border-top: 1px solid #1f1f1f; }\n.hb-yc1-srow { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: #8f8f8f; font-size: 11px; line-height: 14px; }\n.hb-yc1-srow b { color: #ededed; font-weight: 600; }\n.hb-yc1-meter { position: relative; height: 4px; overflow: hidden; border-radius: 999px; background: #232323; }\n.hb-yc1-fill {\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-yc1-m) 60%, #ffffff), var(--hb-yc1-m));\n  transform: scaleX(var(--hb-yc1-p));\n  transform-origin: left;\n  animation: hb-yc1-fill .9s cubic-bezier(.2, .9, .2, 1) both;\n}\n@keyframes hb-yc1-bar {\n  from { transform: scaleY(0); }\n  to { transform: scaleY(1); }\n}\n@keyframes hb-yc1-fill {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(var(--hb-yc1-p)); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-yc1-compose, .hb-yc1-item { transition: none; }\n  .hb-yc1-item[aria-current=\"true\"]::before, .hb-yc1-fill { animation: none; }\n}\n`;\n\nfunction formatCount(n: number) {\n  return n > 99 ? \"99+\" : String(n);\n}\n\nfunction formatAmount(n: number) {\n  return Number.isInteger(n) ? String(n) : n.toFixed(1);\n}\n\nexport function SidebarMailFolders({\n  folders = defaultFolders,\n  labels = defaultLabels,\n  storage = defaultStorage,\n  active,\n  defaultActive,\n  onChange,\n  onCompose,\n  composeLabel = \"Compose\",\n  labelsTitle = \"Labels\",\n  rowHeight = 30,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarMailFoldersProps) {\n  const rootRef = React.useRef<HTMLElement>(null);\n  const [inner, setInner] = React.useState(defaultActive ?? folders[0]?.id ?? \"\");\n  const [focusId, setFocusId] = React.useState(\"\");\n  const current = active ?? inner;\n  const ids = [...folders.map((f) => f.id), ...labels.map((l) => l.id)];\n  const tabStop = ids.includes(focusId) ? focusId : ids.includes(current) ? current : ids[0];\n\n  function select(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\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-yc1-item\")) return;\n    const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc1-item]\") ?? []);\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    }\n  }\n\n  const pct = storage && storage.total > 0 ? Math.max(0, Math.min(1, storage.used / storage.total)) : 0;\n  const meterColor = pct > 0.95 ? \"#e5484d\" : pct > 0.8 ? \"#f5a623\" : accent;\n  const unit = storage?.unit ?? \"GB\";\n\n  const vars = { \"--hb-yc1-a\": accent, \"--hb-yc1-row\": `${rowHeight}px`, ...style } as React.CSSProperties;\n\n  return (\n    <nav ref={rootRef} className={`hb-yc1 ${className}`} aria-label=\"Mailbox\" style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-sidebar-mail-folders\" precedence=\"default\">{css}</style>\n      <button type=\"button\" className=\"hb-yc1-compose\" onClick={onCompose}>\n        <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <path d={ICONS.pencil} />\n        </svg>\n        {composeLabel}\n      </button>\n      <div className=\"hb-yc1-scroll\">\n        <ul className=\"hb-yc1-list\" role=\"list\">\n          {folders.map((f) => {\n            const unread = (f.count ?? 0) > 0;\n            return (\n              <li key={f.id}>\n                <button\n                  type=\"button\"\n                  className=\"hb-yc1-item\"\n                  data-yc1-item=\"\"\n                  data-unread={unread}\n                  aria-current={f.id === current ? true : undefined}\n                  tabIndex={f.id === tabStop ? 0 : -1}\n                  onFocus={() => setFocusId(f.id)}\n                  onClick={() => select(f.id)}\n                >\n                  <span className=\"hb-yc1-ico\">\n                    <SidebarMailIcon name={f.icon ?? \"inbox\"} />\n                  </span>\n                  <span className=\"hb-yc1-txt\">{f.label}</span>\n                  {unread ? (\n                    <span className=\"hb-yc1-count\" aria-label={`${f.count} unread`}>\n                      {formatCount(f.count ?? 0)}\n                    </span>\n                  ) : null}\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n        {labels.length > 0 ? (\n          <>\n            <p className=\"hb-yc1-head\">{labelsTitle}</p>\n            <ul className=\"hb-yc1-list\" role=\"list\">\n              {labels.map((l) => (\n                <li key={l.id}>\n                  <button\n                    type=\"button\"\n                    className=\"hb-yc1-item\"\n                    data-yc1-item=\"\"\n                    aria-current={l.id === current ? true : undefined}\n                    tabIndex={l.id === tabStop ? 0 : -1}\n                    onFocus={() => setFocusId(l.id)}\n                    onClick={() => select(l.id)}\n                  >\n                    <span className=\"hb-yc1-dot\" style={{ \"--hb-yc1-dot\": l.color } as React.CSSProperties} aria-hidden=\"true\" />\n                    <span className=\"hb-yc1-txt\">{l.label}</span>\n                  </button>\n                </li>\n              ))}\n            </ul>\n          </>\n        ) : null}\n      </div>\n      {storage ? (\n        <div className=\"hb-yc1-store\">\n          <div className=\"hb-yc1-srow\">\n            <span>\n              <b>{formatAmount(storage.used)}</b> of {formatAmount(storage.total)} {unit}\n            </span>\n            <span>{Math.round(pct * 100)}%</span>\n          </div>\n          <div\n            className=\"hb-yc1-meter\"\n            role=\"progressbar\"\n            aria-label=\"Storage used\"\n            aria-valuemin={0}\n            aria-valuemax={storage.total}\n            aria-valuenow={storage.used}\n          >\n            <span className=\"hb-yc1-fill\" style={{ \"--hb-yc1-m\": meterColor, \"--hb-yc1-p\": pct.toFixed(3) } as React.CSSProperties} />\n          </div>\n        </div>\n      ) : null}\n    </nav>\n  );\n}\n"
    }
  ]
}