{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-04",
  "title": "右侧上下文面板",
  "description": "右侧上下文面板，组合项目进度、状态分布与分给我的任务。",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "sidebar",
    "button",
    "badge",
    "avatar",
    "dropdown-menu",
    "breadcrumb",
    "https://yiui.dev/r/grid-layout.json",
    "select"
  ],
  "files": [
    {
      "path": "src/registry/blocks/sidebar-04/sidebar-04.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronsUpDown, CircleHelp, X } from \"lucide-react\"\nimport { Button } from \"@/components/ui/button\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Avatar, AvatarFallback } from \"@/components/ui/avatar\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport {\n  Sidebar,\n  SidebarContent,\n  SidebarFooter,\n  SidebarHeader,\n  useSidebar,\n} from \"@/components/ui/sidebar\"\nimport { useControllableState } from \"@/hooks/use-controllable-state\"\nimport { cn } from \"@/lib/utils\"\nimport { DEFAULT_LABELS, type Sidebar04Labels } from \"./config\"\nimport { SAMPLE_PROJECTS } from \"./sample-data\"\nimport { ProgressSection, StatusSection, TaskSection } from \"./sections\"\nimport type { ContextProject, ContextTask } from \"./types\"\n\ntype Sidebar04Props = Omit<\n  React.ComponentProps<typeof Sidebar>,\n  \"side\" | \"collapsible\"\n> & {\n  /** 项目数据；默认中文研发示例 */ projects?: ContextProject[]\n  /** 受控项目 id */ projectId?: string\n  /** 非受控初始项目；默认第一项 */ defaultProjectId?: string\n  /** 项目变化通知 */ onProjectChange?: (payload: { projectId: string }) => void\n  /** 点击任务标题及描述 */ onTaskSelect?: (task: ContextTask) => void\n  /** 帮助入口 */ onHelp?: () => void\n  /** 覆盖默认文案 */ labels?: Partial<Sidebar04Labels>\n}\nfunction Sidebar04({\n  projects = SAMPLE_PROJECTS,\n  projectId,\n  defaultProjectId,\n  onProjectChange,\n  onTaskSelect,\n  onHelp,\n  labels,\n  children,\n  className,\n  ...props\n}: Sidebar04Props) {\n  const l = { ...DEFAULT_LABELS, ...labels }\n  const { toggleSidebar } = useSidebar()\n  const [id, setId] = useControllableState({\n    prop: projectId,\n    defaultProp: defaultProjectId ?? projects[0]?.id ?? \"\",\n    onChange: (projectId) => onProjectChange?.({ projectId }),\n  })\n  const project = projects.find((p) => p.id === id) ?? projects[0]\n  return (\n    <Sidebar\n      data-slot=\"sidebar-04\"\n      side=\"right\"\n      collapsible=\"offcanvas\"\n      className={cn(\"[--sidebar-width:20rem]\", className)}\n      {...props}\n    >\n      <SidebarHeader\n        data-slot=\"sidebar-04-header\"\n        className=\"h-14 flex-row items-center gap-2 border-b border-sidebar-border px-3 py-0\"\n      >\n        <DropdownMenu>\n          <DropdownMenuTrigger\n            render={\n              <Button\n                variant=\"ghost\"\n                size=\"sm\"\n                className=\"min-w-0 flex-1 justify-start pointer-coarse:h-9\"\n                aria-label={l.project}\n              />\n            }\n          >\n            <span\n              aria-hidden=\"true\"\n              className=\"flex size-6 shrink-0 items-center justify-center rounded-md bg-sidebar-primary text-sidebar-primary-foreground\"\n            >\n              {project?.name.slice(0, 1)}\n            </span>\n            <span className=\"truncate\">{project?.name ?? l.empty}</span>\n            <ChevronsUpDown aria-hidden=\"true\" className=\"ml-auto shrink-0\" />\n          </DropdownMenuTrigger>\n          <DropdownMenuContent align=\"start\">\n            <DropdownMenuRadioGroup\n              value={project?.id ?? \"\"}\n              onValueChange={(value) => setId(String(value))}\n            >\n              {projects.map((p) => (\n                <DropdownMenuRadioItem key={p.id} value={p.id}>\n                  {p.name}\n                </DropdownMenuRadioItem>\n              ))}\n            </DropdownMenuRadioGroup>\n          </DropdownMenuContent>\n        </DropdownMenu>\n        <div role=\"group\" aria-label={l.members} className=\"flex -space-x-1.5\">\n          {project?.members.slice(0, 2).map((name) => (\n            <Avatar\n              key={name}\n              className=\"size-6 ring-2 ring-sidebar\"\n              title={name}\n            >\n              <AvatarFallback className=\"bg-sidebar-accent text-[10px] text-sidebar-accent-foreground\">\n                {name.slice(-1)}\n              </AvatarFallback>\n            </Avatar>\n          ))}\n        </div>\n        <Button\n          size=\"icon-sm\"\n          variant=\"ghost\"\n          aria-label={l.close}\n          onClick={toggleSidebar}\n        >\n          <X aria-hidden=\"true\" />\n        </Button>\n      </SidebarHeader>\n      <SidebarContent className=\"gap-0\">\n        {children ??\n          (project && (\n            <>\n              <ProgressSection\n                data={project.progress}\n                range={project.range}\n                labels={l}\n              />\n              <StatusSection data={project.statuses} labels={l} />\n              <TaskSection\n                tasks={project.tasks}\n                onTaskSelect={onTaskSelect}\n                labels={l}\n              />\n            </>\n          ))}\n      </SidebarContent>\n      <SidebarFooter className=\"flex-row items-center justify-between border-t border-sidebar-border px-4\">\n        <Button size=\"sm\" variant=\"ghost\" onClick={onHelp}>\n          <CircleHelp aria-hidden=\"true\" />\n          {l.help}\n        </Button>\n        <Badge variant=\"outline\">{l.plan}</Badge>\n      </SidebarFooter>\n    </Sidebar>\n  )\n}\nexport { Sidebar04 }\nexport {\n  ContextSection,\n  ProgressSection,\n  StatusSection,\n  TaskSection,\n} from \"./sections\"\nexport type { Sidebar04Props }\nexport type {\n  ContextProject,\n  ContextPoint,\n  ContextStatus,\n  ContextTask,\n} from \"./types\"\nexport type { Sidebar04Labels } from \"./config\"\n",
      "type": "registry:component",
      "target": "@components/sidebar-04/sidebar-04.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-04/config.ts",
      "content": "const DEFAULT_LABELS = {\n  project: \"切换项目\",\n  close: \"关闭面板\",\n  toggle: \"切换上下文面板\",\n  members: \"项目成员\",\n  progress: \"进度\",\n  metric: \"进度指标\",\n  trend: \"任务变化趋势\",\n  volume: \"完成量\",\n  area: \"面积图\",\n  bar: \"柱状图\",\n  completed: \"已完成\",\n  active: \"进行中\",\n  status: \"状态\",\n  distribution: \"当前任务分布\",\n  tasks: \"分给我的任务\",\n  taskSubtitle: \"优先处理，保持推进\",\n  empty: \"暂无任务\",\n  help: \"帮助\",\n  plan: \"免费版\",\n  table: \"查看图表数据\",\n}\ntype Sidebar04Labels = typeof DEFAULT_LABELS\nexport { DEFAULT_LABELS }\nexport type { Sidebar04Labels }\n",
      "type": "registry:component",
      "target": "@components/sidebar-04/config.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-04/types.ts",
      "content": "/** 数值必须非负；颜色序号在项目切换时保持一致。 */\ntype ContextStatus = {\n  id: string\n  name: string\n  count: number\n  color: 1 | 2 | 3 | 4 | 5\n}\ntype ContextTask = {\n  id: string\n  title: string\n  description: string\n  tags: string[]\n  due: string\n  priority: string\n}\ntype ContextPoint = { label: string; completed: number; active: number }\ntype ContextProject = {\n  id: string\n  name: string\n  range: string\n  members: string[]\n  progress: ContextPoint[]\n  statuses: ContextStatus[]\n  tasks: ContextTask[]\n}\nexport type { ContextStatus, ContextTask, ContextPoint, ContextProject }\n",
      "type": "registry:component",
      "target": "@components/sidebar-04/types.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-04/sample-data.ts",
      "content": "import type { ContextProject } from \"./types\"\nconst SAMPLE_PROJECTS: ContextProject[] = [\n  {\n    id: \"platform\",\n    name: \"研发协作平台\",\n    range: \"6 月 29 日 — 7 月 29 日\",\n    members: [\"陈知夏\", \"周明远\"],\n    progress: [\n      { label: \"6/29\", completed: 8, active: 12 },\n      { label: \"7/5\", completed: 16, active: 14 },\n      { label: \"7/11\", completed: 22, active: 10 },\n      { label: \"7/17\", completed: 29, active: 16 },\n      { label: \"7/23\", completed: 38, active: 12 },\n      { label: \"7/29\", completed: 46, active: 8 },\n    ],\n    statuses: [\n      { id: \"done\", name: \"已完成\", count: 46, color: 1 },\n      { id: \"active\", name: \"进行中\", count: 8, color: 2 },\n      { id: \"review\", name: \"待评审\", count: 6, color: 3 },\n      { id: \"todo\", name: \"待开始\", count: 20, color: 4 },\n    ],\n    tasks: [\n      {\n        id: \"ci\",\n        title: \"搭建持续集成流水线\",\n        description: \"补齐类型检查与自动构建，在合并前完成回归验证。\",\n        tags: [\"后端\", \"内部\"],\n        due: \"7 月 24 日\",\n        priority: \"高优先级\",\n      },\n      {\n        id: \"refactor\",\n        title: \"重构旧版模块\",\n        description: \"拆分数据访问与界面逻辑，逐步迁移存量调用。\",\n        tags: [\"架构\"],\n        due: \"7 月 28 日\",\n        priority: \"中优先级\",\n      },\n      {\n        id: \"flag\",\n        title: \"接入灰度发布开关\",\n        description: \"为新版结算流程加上按团队放量的开关，并补齐监控告警。\",\n        tags: [\"前端\", \"发布\"],\n        due: \"7 月 26 日\",\n        priority: \"中优先级\",\n      },\n    ],\n  },\n  {\n    id: \"docs\",\n    name: \"开发者文档\",\n    range: \"7 月 1 日 — 7 月 31 日\",\n    members: [\"苏晓宁\"],\n    progress: [\n      { label: \"7/1\", completed: 2, active: 6 },\n      { label: \"7/7\", completed: 4, active: 7 },\n      { label: \"7/13\", completed: 7, active: 5 },\n      { label: \"7/19\", completed: 11, active: 5 },\n      { label: \"7/25\", completed: 15, active: 3 },\n      { label: \"7/31\", completed: 18, active: 2 },\n    ],\n    statuses: [\n      { id: \"done\", name: \"已完成\", count: 18, color: 1 },\n      { id: \"active\", name: \"进行中\", count: 2, color: 2 },\n    ],\n    tasks: [\n      {\n        id: \"guide\",\n        title: \"完善接入指南\",\n        description: \"整理本地安装与常见问题，补充可运行的示例。\",\n        tags: [\"文档\"],\n        due: \"7 月 30 日\",\n        priority: \"中优先级\",\n      },\n    ],\n  },\n]\nexport { SAMPLE_PROJECTS }\n",
      "type": "registry:component",
      "target": "@components/sidebar-04/sample-data.ts"
    },
    {
      "path": "src/registry/blocks/sidebar-04/sections.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CalendarDays, ChartArea, ChartColumn } from \"lucide-react\"\nimport { Button } from \"@/components/ui/button\"\nimport { Badge } from \"@/components/ui/badge\"\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from \"@/components/ui/select\"\nimport { cn } from \"@/lib/utils\"\nimport { DEFAULT_LABELS, type Sidebar04Labels } from \"./config\"\nimport type { ContextPoint, ContextStatus, ContextTask } from \"./types\"\n\ntype SectionProps = React.ComponentProps<\"section\"> & {\n  title: string\n  subtitle?: string\n}\nfunction ContextSection({\n  title,\n  subtitle,\n  className,\n  children,\n  ...props\n}: SectionProps) {\n  const id = React.useId()\n  return (\n    <section\n      data-slot=\"context-section\"\n      aria-labelledby={id}\n      className={cn(\n        \"border-b border-dashed border-sidebar-border p-4 last:border-b-0\",\n        className,\n      )}\n      {...props}\n    >\n      <h2 id={id} className=\"text-sm font-semibold\">\n        {title}\n      </h2>\n      {subtitle && (\n        <p className=\"mt-1 text-xs text-sidebar-foreground/65\">{subtitle}</p>\n      )}\n      <div className=\"mt-4\">{children}</div>\n    </section>\n  )\n}\ntype ProgressProps = Omit<React.ComponentProps<\"section\">, \"children\"> & {\n  /** 按日期排序的非负数据 */ data: ContextPoint[]\n  /** 日期范围 */ range?: string\n  labels?: Partial<Sidebar04Labels>\n}\nfunction ProgressSection({ data, range, labels, ...props }: ProgressProps) {\n  const l = { ...DEFAULT_LABELS, ...labels }\n  const [type, setType] = React.useState(\"area\")\n  const [metric, setMetric] = React.useState(\"trend\")\n  const points = data.map((p) => ({\n    ...p,\n    completed: Math.max(0, p.completed),\n    active: metric === \"volume\" ? 0 : Math.max(0, p.active),\n  }))\n  const max = Math.max(1, ...points.map((p) => p.completed + p.active))\n  const x = (i: number) => 12 + (i * 252) / Math.max(1, points.length - 1)\n  const y = (n: number) => 116 - (n / max) * 100\n  const path = (\n    upper: (p: ContextPoint) => number,\n    lower: (p: ContextPoint) => number,\n  ) =>\n    points.length\n      ? `M ${points.map((p, i) => `${x(i)},${y(upper(p))}`).join(\" L \")} L ${points\n          .map((p, i) => `${x(i)},${y(lower(p))}`)\n          .reverse()\n          .join(\" L \")} Z`\n      : \"\"\n  return (\n    <ContextSection title={l.progress} subtitle={range} {...props}>\n      <div className=\"mb-3 flex items-center gap-2\">\n        <Select\n          items={[\n            { value: \"trend\", label: l.trend },\n            { value: \"volume\", label: l.volume },\n          ]}\n          value={metric}\n          onValueChange={(value) => {\n            if (value) setMetric(value)\n          }}\n        >\n          <SelectTrigger\n            size=\"sm\"\n            aria-label={l.metric}\n            className=\"min-w-0 flex-1 bg-sidebar text-xs pointer-coarse:h-9\"\n          >\n            <SelectValue />\n          </SelectTrigger>\n          <SelectContent alignItemWithTrigger={false} align=\"start\">\n            <SelectItem value=\"trend\" className=\"text-xs\">\n              {l.trend}\n            </SelectItem>\n            <SelectItem value=\"volume\" className=\"text-xs\">\n              {l.volume}\n            </SelectItem>\n          </SelectContent>\n        </Select>\n        {[\n          { id: \"area\", label: l.area, icon: ChartArea },\n          { id: \"bar\", label: l.bar, icon: ChartColumn },\n        ].map((item) => (\n          <Button\n            key={item.id}\n            size=\"icon-sm\"\n            variant=\"ghost\"\n            aria-label={item.label}\n            aria-pressed={type === item.id}\n            onClick={() => setType(item.id)}\n          >\n            <item.icon aria-hidden=\"true\" />\n          </Button>\n        ))}\n      </div>\n      <svg\n        data-slot=\"context-progress-chart\"\n        data-type={type}\n        viewBox=\"0 0 276 140\"\n        className=\"w-full\"\n        role=\"img\"\n        aria-label={`${l.progress}：${metric === \"trend\" ? l.trend : l.volume}`}\n      >\n        <path d=\"M 10 116 H 266\" stroke=\"var(--sidebar-border)\" />\n        {type === \"area\" ? (\n          <>\n            <path\n              d={path(\n                (p) => p.completed,\n                () => 0,\n              )}\n              fill=\"var(--chart-1)\"\n              stroke=\"var(--sidebar)\"\n              strokeWidth=\"2\"\n            />\n            <path\n              d={path(\n                (p) => p.completed + p.active,\n                (p) => p.completed,\n              )}\n              fill=\"var(--chart-2)\"\n              stroke=\"var(--sidebar)\"\n              strokeWidth=\"2\"\n            />\n          </>\n        ) : (\n          points.map((p, i) => (\n            <g key={p.label}>\n              <title>{`${p.label}：${l.completed} ${p.completed}，${l.active} ${p.active}`}</title>\n              <rect\n                x={x(i) - 8}\n                y={y(p.completed)}\n                width=\"16\"\n                height={(p.completed / max) * 100}\n                rx=\"2\"\n                fill=\"var(--chart-1)\"\n              />\n              <rect\n                x={x(i) - 8}\n                y={y(p.completed + p.active)}\n                width=\"16\"\n                height={Math.max(0, (p.active / max) * 100 - 2)}\n                rx=\"2\"\n                fill=\"var(--chart-2)\"\n              />\n            </g>\n          ))\n        )}\n        {points.map((p, i) => (\n          <g key={p.label}>\n            <rect\n              x={x(i) - 10}\n              y=\"10\"\n              width=\"20\"\n              height=\"108\"\n              fill=\"transparent\"\n            >\n              <title>{`${p.label}：${l.completed} ${p.completed}，${l.active} ${p.active}`}</title>\n            </rect>\n            {(i === 0 || i === points.length - 1) && (\n              <text\n                x={x(i)}\n                y=\"136\"\n                textAnchor={i === 0 ? \"start\" : \"end\"}\n                fill=\"var(--sidebar-foreground)\"\n                fontSize=\"10\"\n              >\n                {p.label}\n              </text>\n            )}\n          </g>\n        ))}\n      </svg>\n      <div className=\"flex gap-4 text-xs\">\n        <span>\n          <i className=\"mr-1 inline-block size-2 rounded-sm bg-chart-1\" />\n          {l.completed}\n        </span>\n        {metric === \"trend\" && (\n          <span>\n            <i className=\"mr-1 inline-block size-2 rounded-sm bg-chart-2\" />\n            {l.active}\n          </span>\n        )}\n      </div>\n      <details className=\"mt-3 text-xs\">\n        <summary className=\"cursor-pointer text-sidebar-foreground/65\">\n          {l.table}\n        </summary>\n        <table className=\"mt-2 w-full tabular-nums\">\n          <thead>\n            <tr>\n              <th />\n              <th>{l.completed}</th>\n              <th>{l.active}</th>\n            </tr>\n          </thead>\n          <tbody>\n            {points.map((p) => (\n              <tr key={p.label}>\n                <th className=\"text-left font-normal\">{p.label}</th>\n                <td className=\"text-center\">{p.completed}</td>\n                <td className=\"text-center\">{p.active}</td>\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </details>\n    </ContextSection>\n  )\n}\nconst STATUS_COLORS = {\n  1: \"bg-chart-1\",\n  2: \"bg-chart-2\",\n  3: \"bg-chart-3\",\n  4: \"bg-chart-4\",\n  5: \"bg-chart-5\",\n}\nfunction StatusSection({\n  data,\n  labels,\n  ...props\n}: Omit<React.ComponentProps<\"section\">, \"children\"> & {\n  data: ContextStatus[]\n  labels?: Partial<Sidebar04Labels>\n}) {\n  const l = { ...DEFAULT_LABELS, ...labels }\n  const total = data.reduce((sum, s) => sum + Math.max(0, s.count), 0)\n  const percent = (count: number) =>\n    new Intl.NumberFormat(\"zh-CN\", {\n      style: \"percent\",\n      maximumFractionDigits: 0,\n    }).format(total ? Math.max(0, count) / total : 0)\n  return (\n    <ContextSection title={l.status} subtitle={l.distribution} {...props}>\n      <div\n        aria-hidden=\"true\"\n        className=\"mb-3 flex h-2 gap-0.5 overflow-hidden rounded-full\"\n      >\n        {data.map((s) => (\n          <span\n            key={s.id}\n            className={STATUS_COLORS[s.color]}\n            style={{ width: percent(s.count) }}\n          />\n        ))}\n      </div>\n      <ul className=\"space-y-1.5\">\n        {data.map((s) => (\n          <li\n            key={s.id}\n            className=\"flex items-center gap-2 rounded-md bg-sidebar-accent/50 px-3 py-2 text-xs\"\n          >\n            <i\n              aria-hidden=\"true\"\n              className={cn(\"size-2 rounded-full\", STATUS_COLORS[s.color])}\n            />\n            <span className=\"flex-1\">{s.name}</span>\n            <span className=\"tabular-nums\">{s.count}</span>\n            <span className=\"w-10 text-right text-sidebar-foreground/65 tabular-nums\">\n              {percent(s.count)}\n            </span>\n          </li>\n        ))}\n      </ul>\n    </ContextSection>\n  )\n}\nfunction TaskSection({\n  tasks,\n  onTaskSelect,\n  labels,\n  ...props\n}: Omit<React.ComponentProps<\"section\">, \"children\"> & {\n  tasks: ContextTask[]\n  onTaskSelect?: (task: ContextTask) => void\n  labels?: Partial<Sidebar04Labels>\n}) {\n  const l = { ...DEFAULT_LABELS, ...labels }\n  return (\n    <ContextSection title={l.tasks} subtitle={l.taskSubtitle} {...props}>\n      <div className=\"space-y-3\">\n        {tasks.length ? (\n          tasks.map((task) => (\n            <article\n              key={task.id}\n              className=\"rounded-lg border border-sidebar-border bg-sidebar-accent/20 p-3\"\n            >\n              <button\n                type=\"button\"\n                onClick={() => onTaskSelect?.(task)}\n                className=\"w-full rounded-sm text-left focus-visible:outline-2 focus-visible:outline-ring\"\n              >\n                <span className=\"text-sm font-medium\">{task.title}</span>\n                <span className=\"mt-1.5 line-clamp-2 text-xs leading-5 text-sidebar-foreground/65\">\n                  {task.description}\n                </span>\n              </button>\n              <div className=\"mt-3 flex flex-wrap gap-1\">\n                {task.tags.map((tag) => (\n                  <Badge key={tag} variant=\"secondary\">\n                    {tag}\n                  </Badge>\n                ))}\n              </div>\n              <div className=\"mt-3 flex items-center justify-between gap-2 text-xs text-sidebar-foreground/65\">\n                <span className=\"flex items-center gap-1\">\n                  <CalendarDays aria-hidden=\"true\" className=\"size-3\" />\n                  {task.due}\n                </span>\n                <span>{task.priority}</span>\n              </div>\n            </article>\n          ))\n        ) : (\n          <p className=\"text-xs\">{l.empty}</p>\n        )}\n      </div>\n    </ContextSection>\n  )\n}\nexport { ContextSection, ProgressSection, StatusSection, TaskSection }\nexport type { SectionProps, ProgressProps }\n",
      "type": "registry:component",
      "target": "@components/sidebar-04/sections.tsx"
    },
    {
      "path": "src/registry/blocks/sidebar-04/page.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { PanelRight } from \"lucide-react\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Breadcrumb,\n  BreadcrumbList,\n  BreadcrumbItem,\n  BreadcrumbPage,\n  BreadcrumbSeparator,\n} from \"@/components/ui/breadcrumb\"\nimport {\n  SidebarProvider,\n  SidebarInset,\n  useSidebar,\n} from \"@/components/ui/sidebar\"\nimport {\n  GridContainer,\n  GridSection,\n  GridColumns,\n  GridSeparator,\n} from \"@/components/ui/grid-layout/grid-layout\"\nimport { Sidebar04 } from \"@/components/sidebar-04/sidebar-04\"\nimport { SAMPLE_PROJECTS } from \"@/components/sidebar-04/sample-data\"\n\nfunction PanelToggle() {\n  const { toggleSidebar, open, openMobile, isMobile } = useSidebar()\n  return (\n    <Button\n      data-slot=\"sidebar-04-toggle\"\n      size=\"icon-sm\"\n      variant=\"ghost\"\n      aria-label=\"切换上下文面板\"\n      aria-expanded={isMobile ? openMobile : open}\n      onClick={toggleSidebar}\n    >\n      <PanelRight aria-hidden=\"true\" />\n    </Button>\n  )\n}\nexport default function Sidebar04Page() {\n  const [projectId, setProjectId] = React.useState(SAMPLE_PROJECTS[0]!.id)\n  const [message, setMessage] =\n    React.useState(\"选择任务，查看当前工作的上下文。\")\n  const project = SAMPLE_PROJECTS.find((p) => p.id === projectId)!\n  return (\n    <SidebarProvider\n      defaultOpen\n      style={{ \"--sidebar-width\": \"20rem\" } as React.CSSProperties}\n    >\n      <SidebarInset>\n        <header\n          data-slot=\"sidebar-04-main-header\"\n          className=\"flex h-14 shrink-0 items-center justify-between gap-2 border-b border-edge px-4\"\n        >\n          <Breadcrumb>\n            <BreadcrumbList>\n              <BreadcrumbItem className=\"hidden sm:block\">\n                研发工作区\n              </BreadcrumbItem>\n              <BreadcrumbSeparator className=\"hidden sm:block\" />\n              <BreadcrumbItem>\n                <BreadcrumbPage>{project.name}</BreadcrumbPage>\n              </BreadcrumbItem>\n            </BreadcrumbList>\n          </Breadcrumb>\n          <PanelToggle />\n        </header>\n        <GridContainer className=\"w-full min-w-0 flex-1\">\n          <GridSection className=\"px-4 py-8 sm:px-6\">\n            <p className=\"text-xs text-muted-foreground\">项目看板</p>\n            <h1 className=\"mt-2 text-2xl font-semibold tracking-tight\">\n              让每一次交付都有进展\n            </h1>\n            <p className=\"mt-3 text-sm leading-7 text-muted-foreground\">\n              梳理本轮研发计划，让任务、评审和交付保持同步。\n            </p>\n            <p role=\"status\" className=\"mt-4 text-sm\">\n              {message}\n            </p>\n          </GridSection>\n          <GridSeparator />\n          <GridSection>\n            <GridColumns className=\"md:grid-cols-3\">\n              {[\"待开始\", \"进行中\", \"待评审\"].map((name, i) => (\n                <div key={name} className=\"min-h-72 p-4\">\n                  <h2 className=\"mb-5 text-sm font-medium\">{name}</h2>\n                  {project.tasks.slice(i, i + 1).map((task) => (\n                    <div\n                      key={task.id}\n                      className=\"mb-3 border-l-2 border-edge pl-3\"\n                    >\n                      <h3 className=\"text-sm\">{task.title}</h3>\n                      <p className=\"mt-2 text-xs leading-6 text-muted-foreground\">\n                        {task.description}\n                      </p>\n                    </div>\n                  ))}\n                </div>\n              ))}\n            </GridColumns>\n          </GridSection>\n        </GridContainer>\n      </SidebarInset>\n      <Sidebar04\n        projects={SAMPLE_PROJECTS}\n        projectId={projectId}\n        onProjectChange={({ projectId }) => {\n          setProjectId(projectId)\n          setMessage(\"已切换项目。\")\n        }}\n        onTaskSelect={(task) => setMessage(`已选择：${task.title}`)}\n        onHelp={() =>\n          setMessage(\"打开右侧面板查看进度；按 ⌘B 或 Ctrl B 切换面板。\")\n        }\n      />\n    </SidebarProvider>\n  )\n}\n",
      "type": "registry:page",
      "target": "app/sidebar-04/page.tsx"
    },
    {
      "path": "src/registry/hooks/use-controllable-state.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\ntype UseControllableStateParams<T> = {\n  /** 受控值；传入后组件不再维护内部状态 */\n  prop?: T\n  /** 非受控时的初始值 */\n  defaultProp: T\n  /** 值变化时回调（受控与非受控都会触发） */\n  onChange?: (value: T) => void\n}\n\n/**\n * 同时支持受控与非受控的状态 hook。\n * 约定见 component-conventions 技能第 4 节：open/defaultOpen/onOpenChange 等成对 props 都用它实现。\n */\nfunction useControllableState<T>({\n  prop,\n  defaultProp,\n  onChange,\n}: UseControllableStateParams<T>) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n  const isControlled = prop !== undefined\n  const value = isControlled ? prop : uncontrolled\n\n  // 用 ref 保存最新的回调和值，保证 setValue 引用稳定\n  const onChangeRef = React.useRef(onChange)\n  const valueRef = React.useRef(value)\n  React.useEffect(() => {\n    onChangeRef.current = onChange\n    valueRef.current = value\n  })\n\n  const setValue = React.useCallback(\n    (next: React.SetStateAction<T>) => {\n      const resolved =\n        typeof next === \"function\"\n          ? (next as (prev: T) => T)(valueRef.current)\n          : next\n      if (Object.is(resolved, valueRef.current)) return\n      valueRef.current = resolved\n      if (!isControlled) setUncontrolled(resolved)\n      onChangeRef.current?.(resolved)\n    },\n    [isControlled],\n  )\n\n  return [value, setValue] as const\n}\n\nexport { useControllableState }\n",
      "type": "registry:hook",
      "target": "hooks/use-controllable-state.ts"
    }
  ],
  "cssVars": {
    "theme": {
      "color-edge": "var(--edge)"
    },
    "light": {
      "edge": "color-mix(in oklch, var(--foreground) 12%, transparent)"
    },
    "dark": {
      "edge": "color-mix(in oklch, var(--foreground) 18%, transparent)"
    }
  },
  "type": "registry:block"
}
