Inputs

Speciality Picker

Choosing a doctor's speciality: branches as chips, specialities as a searchable list with doctor counts and the nearest appointment; specialities without free doctors cannot be picked.

  • cascader
  • clinic
  • booking
  • search

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/cascader-017?lang=en

Doctor speciality

Запись: Взрослым · Кардиолог

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "cascader-017" (Speciality Picker) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/cascader-017.json

Registry item: https://vibeui.ru/r/cascader-017.json
Installs to: components/vibeui/cascader-017.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
Choosing a doctor's speciality: branches as chips, specialities as a searchable list with doctor counts and the nearest appointment; specialities without free doctors cannot be picked.

A two-level picker for booking a doctor: the branch on top (adults, children, dentistry), the speciality list with search below. Each speciality shows how many doctors work in it and when the nearest appointment is, while a speciality with no free doctors is blocked and captioned. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Cascader017 } from "@/components/vibeui/cascader-017"

<Cascader017 defaultBranch="Adults" label="Doctor speciality" />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-cascader-017-* palette — do not swap it for your theme tokens (bg-muted, text-muted-foreground and the like)
- the two levels having different shapes: branches are few and fit as chips, specialities are dozens and need a filter
- searching inside the selected branch rather than the whole clinic: otherwise adult and children's lists merge
- the doctor count and nearest appointment on the row: a speciality name alone is not bookable
- native disabled on a speciality without doctors together with the “not seeing patients” caption
- the search field's aria-label naming the current branch — the search context has to be audible
- clearing the speciality and the query when the branch changes

## 6. You may change
- label — the heading above the chips
- branches — branches and their specialities with doctor counts and nearest appointments
- defaultBranch — the branch opened at first render
- defaultSpeciality — the speciality selected at first render
- onSelect — the handler; it receives branch and speciality
- accent — the colour of the active chip and the selected row

## 7. Rules
- The nearest appointment is a string, not a date: format it on the server or time zones will spoil “today”.
- Do not remove a speciality without doctors: people will look for it and conclude the clinic dropped it.
- Doctor counts go stale fast: refresh on open rather than on page mount.
- For a clinic with two branches the chips are redundant — a single list is enough.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/cascader-017.json
https://vibeui.ru/r/cascader-017.json

Компонент самодостаточен: один файл, ноль зависимостей, собственная палитра в локальных переменных --vibeui-cascader-017-*. Клиентский: направление, специальность и строка поиска живут в useState. Верхний уровень выведен фишками, потому что направлений всегда три-четыре, а нижний остался списком с фильтром: специальностей десятки, и колонка без поиска бесполезна. Фильтрация вынесена в useMemo и работает внутри выбранного направления, поэтому результаты не смешиваются между разделами. Специальность без врачей получает нативный disabled и объяснение «приём не ведётся» вместо исчезновения из списка. Поле поиска — type="search" с собственным aria-label, в котором названо текущее направление.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useId, useMemo, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Cascader017Speciality = {
  name: string
  doctors: number
  nearest?: string
}

export type Cascader017Branch = {
  name: string
  specialities: Cascader017Speciality[]
}

export type Cascader017Props = Omit<
  ComponentPropsWithoutRef<"section">,
  "children" | "onSelect"
> & {
  label?: string
  branches?: Cascader017Branch[]
  defaultBranch?: string
  defaultSpeciality?: string
  onSelect?: (branch: string, speciality: string) => void
  accent?: string
}

// Идея компонента: специальностей в клинике под сотню, и человек редко
// знает нужную точно — он знает «взрослым» и «что-то с сердцем». Поэтому
// верхний уровень стоит фишками (их всегда три-четыре), а нижний остаётся
// списком с фильтром по названию. У каждой специальности видно число врачей
// и ближайший приём: специальность без свободных врачей выбрать нельзя.
const STYLES = `
:where([data-vibeui-block="cascader-017"]){
--vibeui-cascader-017-bg:oklch(1 0 0);
--vibeui-cascader-017-fg:oklch(0.22 0.014 190);
--vibeui-cascader-017-muted:oklch(0.55 0.014 190);
--vibeui-cascader-017-faint:oklch(0.75 0.01 190);
--vibeui-cascader-017-border:oklch(0.9 0.008 190);
--vibeui-cascader-017-field:oklch(0.985 0.004 190);
--vibeui-cascader-017-soft:oklch(0.965 0.008 190);
--vibeui-cascader-017-accent:oklch(0.47 0.1 190);
--vibeui-cascader-017-accentsoft:oklch(0.93 0.045 190);
--vibeui-cascader-017-radius:0.625rem;
--vibeui-cascader-017-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="cascader-017"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:23rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-cascader-017-bg);
border:1px solid var(--vibeui-cascader-017-border);
border-radius:calc(var(--vibeui-cascader-017-radius) + 0.25rem);
color:var(--vibeui-cascader-017-fg);
font-family:var(--vibeui-cascader-017-font);
}
[data-vibeui-block="cascader-017"] [data-part="title"]{
margin:0;font-size:0.875rem;font-weight:700;letter-spacing:-0.01em;
}
[data-vibeui-block="cascader-017"] [data-part="branches"]{
display:flex;flex-wrap:wrap;gap:0.3rem;margin:0;padding:0;list-style:none;
}
[data-vibeui-block="cascader-017"] [data-part="branch"]{
appearance:none;cursor:pointer;font:inherit;
padding:0.3rem 0.7rem;border-radius:999px;
border:1px solid var(--vibeui-cascader-017-border);
background:transparent;color:var(--vibeui-cascader-017-muted);
font-size:0.78rem;font-weight:600;
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="cascader-017"] [data-part="branch"][aria-pressed="true"]{
background:var(--vibeui-cascader-017-accent);border-color:transparent;
color:var(--vibeui-cascader-017-bg);
}
[data-vibeui-block="cascader-017"] [data-part="branch"]:focus-visible,
[data-vibeui-block="cascader-017"] [data-part="row"]:focus-visible{
outline:2px solid var(--vibeui-cascader-017-accent);outline-offset:2px;
}
[data-vibeui-block="cascader-017"] input{
box-sizing:border-box;width:100%;height:2.35rem;padding:0 0.6rem;
border:1px solid var(--vibeui-cascader-017-border);
border-radius:var(--vibeui-cascader-017-radius);
background:var(--vibeui-cascader-017-field);
color:inherit;font:inherit;font-size:0.875rem;
}
[data-vibeui-block="cascader-017"] input::placeholder{color:var(--vibeui-cascader-017-muted)}
[data-vibeui-block="cascader-017"] input:focus-visible{
outline:2px solid var(--vibeui-cascader-017-accent);outline-offset:1px;border-color:transparent;
}
[data-vibeui-block="cascader-017"] [data-part="list"]{
margin:0;padding:0.2rem;list-style:none;display:flex;flex-direction:column;gap:0.1rem;
max-height:12.5rem;overflow:auto;
border:1px solid var(--vibeui-cascader-017-border);
border-radius:var(--vibeui-cascader-017-radius);
}
[data-vibeui-block="cascader-017"] [data-part="row"]{
appearance:none;cursor:pointer;font:inherit;width:100%;
display:flex;flex-direction:column;gap:0.1rem;
box-sizing:border-box;padding:0.4rem 0.5rem;
border:0;border-radius:0.45rem;background:transparent;color:inherit;text-align:left;
transition:background-color .16s ease;
}
[data-vibeui-block="cascader-017"] [data-part="row"]:hover:not(:disabled){background:var(--vibeui-cascader-017-soft)}
[data-vibeui-block="cascader-017"] [data-part="row"][aria-pressed="true"]{
background:var(--vibeui-cascader-017-accentsoft);
}
[data-vibeui-block="cascader-017"] [data-part="row"]:disabled{cursor:not-allowed;color:var(--vibeui-cascader-017-faint)}
[data-vibeui-block="cascader-017"] [data-part="name"]{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="cascader-017"] [data-part="meta"]{font-size:0.7rem;color:var(--vibeui-cascader-017-muted)}
[data-vibeui-block="cascader-017"] [data-part="row"]:disabled [data-part="meta"]{color:inherit}
[data-vibeui-block="cascader-017"] [data-part="empty"]{
margin:0;padding:0.5rem;font-size:0.8125rem;color:var(--vibeui-cascader-017-muted);
}
[data-vibeui-block="cascader-017"] [data-part="foot"]{
margin:0;font-size:0.8125rem;color:var(--vibeui-cascader-017-muted);
}
[data-vibeui-block="cascader-017"] [data-part="foot"] b{color:var(--vibeui-cascader-017-fg)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="cascader-017"] *{animation:none!important;transition:none!important}}
`

const CLINIC: Cascader017Branch[] = [
  {
    name: "Взрослым",
    specialities: [
      { name: "Терапевт", doctors: 9, nearest: "сегодня, 18:20" },
      { name: "Кардиолог", doctors: 4, nearest: "завтра, 10:00" },
      { name: "Невролог", doctors: 3, nearest: "17 апреля" },
      { name: "Эндокринолог", doctors: 0 },
    ],
  },
  {
    name: "Детям",
    specialities: [
      { name: "Педиатр", doctors: 7, nearest: "сегодня, 16:40" },
      { name: "Детский лор", doctors: 2, nearest: "завтра, 09:30" },
      { name: "Детский хирург", doctors: 0 },
    ],
  },
  {
    name: "Стоматология",
    specialities: [
      { name: "Терапевт-стоматолог", doctors: 5, nearest: "завтра, 12:15" },
      { name: "Ортодонт", doctors: 2, nearest: "20 апреля" },
    ],
  },
]

function pluralize(count: number, forms: [string, string, string]) {
  const tens = count % 100
  const ones = count % 10

  if (tens > 10 && tens < 20) return forms[2]
  if (ones === 1) return forms[0]
  if (ones > 1 && ones < 5) return forms[1]

  return forms[2]
}

/**
 * Выбор специальности врача: направление фишками, специальность списком.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Cascader017({
  label = "Специальность врача",
  branches = CLINIC,
  defaultBranch = "Взрослым",
  defaultSpeciality = "Кардиолог",
  onSelect,
  accent,
  className,
  style,
  ...props
}: Cascader017Props) {
  const id = useId()
  const [branch, setBranch] = useState(defaultBranch)
  const [speciality, setSpeciality] = useState(defaultSpeciality)
  const [query, setQuery] = useState("")

  const current = branches.find((entry) => entry.name === branch)

  const matches = useMemo(() => {
    const needle = query.trim().toLowerCase()

    return (current?.specialities ?? []).filter((entry) =>
      entry.name.toLowerCase().includes(needle),
    )
  }, [query, current])

  const picked = current?.specialities.find(
    (entry) => entry.name === speciality,
  )

  const palette = {
    ...(accent ? { "--vibeui-cascader-017-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-cascader-017" precedence="medium">
        {STYLES}
      </style>
      <section
        {...props}
        data-vibeui-block="cascader-017"
        className={className}
        style={palette}
      >
        <h3 data-part="title">{label}</h3>
        <ul data-part="branches" aria-label="Направления">
          {branches.map((entry) => (
            <li key={entry.name}>
              <button
                type="button"
                data-part="branch"
                aria-pressed={entry.name === branch}
                onClick={() => {
                  setBranch(entry.name)
                  setSpeciality("")
                  setQuery("")
                }}
              >
                {entry.name}
              </button>
            </li>
          ))}
        </ul>
        <input
          id={`${id}-search`}
          type="search"
          autoComplete="off"
          placeholder="Найти специальность"
          aria-label={`Поиск специальности в направлении «${branch}»`}
          value={query}
          onChange={(event) => setQuery(event.target.value)}
        />
        <ul data-part="list" aria-label={`Специальности: ${branch}`}>
          {matches.length === 0 ? (
            <li>
              <p data-part="empty">В этом направлении ничего не нашлось</p>
            </li>
          ) : (
            matches.map((entry) => (
              <li key={entry.name}>
                <button
                  type="button"
                  data-part="row"
                  disabled={entry.doctors === 0}
                  aria-pressed={entry.name === speciality}
                  onClick={() => {
                    setSpeciality(entry.name)
                    onSelect?.(branch, entry.name)
                  }}
                >
                  <span data-part="name">{entry.name}</span>
                  <span data-part="meta">
                    {entry.doctors === 0
                      ? "приём не ведётся"
                      : `${entry.doctors} ${pluralize(entry.doctors, ["врач", "врача", "врачей"])} · ближайший приём ${entry.nearest}`}
                  </span>
                </button>
              </li>
            ))
          )}
        </ul>
        <p data-part="foot" aria-live="polite">
          {picked ? (
            <>
              Запись:{" "}
              <b>
                {branch} · {picked.name}
              </b>
            </>
          ) : (
            "Специальность не выбрана"
          )}
        </p>
      </section>
    </>
  )
}