Project Selector
Which project a chat belongs to: one button opens a searchable menu to switch it, and pressing the current project again removes it. Its rows also come alone, for a submenu of your own.
Installation
npx shadcn@latest add "@aiellie/project-selector"shadcn needs the @aiellie registry in components.json first. npx aiellie add project-selector adds it on its first run, then installs the same way.
Project selector files a chat under a project, or under none. The trigger shows the project's name; the menu lists every project with a search, and choosing the current one again takes the chat out of it.
Getting started
Pass the projects and the chat's project
valueisnullwhile the chat has no project.components/chat-project.tsx"use client" import * as React from "react" import { ProjectSelector, type ProjectOption, } from "@/components/aiellie/project-selector" export function ChatProject({ projects }: { projects: ProjectOption[] }) { const [project, setProject] = React.useState<string | null>(null) return ( <ProjectSelector projects={projects} value={project} onValueChange={setProject} /> ) }
Anatomy
<button data-slot="project-selector"> {/* render, a small ghost Button by default */}
<svg /> {/* a folder */}
<span class="sr-only">{label}: </span>
{selected.name} {/* or the placeholder */}
</button>
<div data-slot="menu-content">
<input /> {/* the search */}
<div data-slot="menu-checkbox-item" /> {/* one per project, the current one ticked */}
</div>Rows are checkboxes rather than radio rows, so pressing the ticked one unticks it and onValueChange gets null. Choosing a row closes the menu.
Examples
In a submenu
projectSelectorItems returns just the rows. It is a function rather than a component, so the search of the menu around it still sees each row.
Placeholder
Set what the trigger says while the chat has no project.
<ProjectSelector placeholder="Add to a project" {...props} />API reference
ProjectSelector
| Prop | Type | Default | Description |
|---|---|---|---|
projects | ProjectOption[] | required | Every project, as { id, name }, in the order to list them. |
value | string | null | required | The chat's project, or null when it has none. |
onValueChange | (value: string | null) => void | required | Called with the project chosen, or null when the current one is unticked. |
label | string | "Project" | What is being chosen, read out ahead of the project's name. |
placeholder | string | "Choose a project" | Shown while there's no project. |
render | ReactElement | <Button variant="ghost" size="sm" /> | The trigger's element. |
side / align | MenuContent placement | Where the menu opens. |
projectSelectorItems
| Export | Type | Description |
|---|---|---|
projectSelectorItems({ projects, value, onValueChange }) | ReactNode[] | The rows alone, for a menu of your own. |