aiellie

Search

Find a component, template or page

GitHub
Components

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.

Open full screen
fig. 01 · open it full screen from the corner

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

  1. Pass the projects and the chat's project

    value is null while 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.

No project

Placeholder

Set what the trigger says while the chat has no project.

<ProjectSelector placeholder="Add to a project" {...props} />

API reference

ProjectSelector

PropTypeDefaultDescription
projectsProjectOption[]requiredEvery project, as { id, name }, in the order to list them.
valuestring | nullrequiredThe chat's project, or null when it has none.
onValueChange(value: string | null) => voidrequiredCalled with the project chosen, or null when the current one is unticked.
labelstring"Project"What is being chosen, read out ahead of the project's name.
placeholderstring"Choose a project"Shown while there's no project.
renderReactElement<Button variant="ghost" size="sm" />The trigger's element.
side / alignMenuContent placementWhere the menu opens.

projectSelectorItems

ExportTypeDescription
projectSelectorItems({ projects, value, onValueChange })ReactNode[]The rows alone, for a menu of your own.