Team selector
Sculptural team seat selector card with tinted overlapping initials avatars, bold circular stepper, live pricing and native form input.
pnpm dlx shadcn@latest add @haze/team-selector---
import { Minus, Plus } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface TeamMember {
name: string;
role?: string;
src?: string;
}
interface Props {
/** Unique on the page. Connects the label, native number input and stepper controls. */
id: string;
/** Form field name submitted with a parent form. */
name?: string;
/** Top-left eyebrow label for the card. */
label?: string;
/** Optional named roster used to derive stacked initials avatars. */
members?: TeamMember[];
/** Initial selected seat count. */
value?: number;
/** Minimum selectable seat count. */
min?: number;
/** Maximum selectable seat count. */
max?: number;
/** Maximum avatars shown before displaying a "+N" overflow badge. */
maxAvatars?: number;
/** Singular unit name displayed beneath the count and in the price line. */
unit?: string;
/** Plural unit name displayed beneath the count. */
unitPlural?: string;
/** Price per seat shown in the footer line; set to 0 to hide pricing. */
pricePerSeat?: number;
/** Currency prefix formatted before seat and total amounts. */
currency?: string;
/** Billing cadence label appended after the monthly total. */
billingPeriod?: string;
class?: string;
}
const defaultMembers: TeamMember[] = [
{ name: "Maya Lin", role: "Design" },
{ name: "Jonas Lind", role: "Frontend" },
{ name: "Priya Nair", role: "Backend" },
{ name: "Tariq Mansour", role: "Infra" },
{ name: "Chloe Park", role: "Product" },
{ name: "David Osei", role: "QA" },
];
const toInitials = (fullName: string) =>
fullName
.split(/\s+/)
.map((part) => part[0] ?? "")
.join("")
.slice(0, 2)
.toUpperCase();
const {
id,
name = "teamCount",
label = "Team size",
members = defaultMembers,
value = 3,
min = 1,
max = 10,
maxAvatars = 5,
unit = "seat",
unitPlural = "seats",
pricePerSeat = 12,
currency = "$",
billingPeriod = "month",
class: className,
} = Astro.props;
const safeMin = Math.max(1, Math.floor(min));
const safeMax = Math.max(safeMin, Math.floor(max));
const initial = Math.min(safeMax, Math.max(safeMin, Math.floor(value)));
const visibleCap = Math.max(1, Math.min(safeMax, Math.floor(maxAvatars)));
const avatarSlots = Array.from({ length: visibleCap }, (_, index) => {
const person = members[index] ?? { name: `Member ${index + 1}` };
return {
name: person.name,
src: person.src,
initials: toInitials(person.name),
};
});
const initialExtra = Math.max(0, initial - visibleCap);
const showPricing = pricePerSeat > 0;
---
<div
data-haze-team-selector
data-unit={unit}
data-unit-plural={unitPlural}
data-max-avatars={visibleCap}
data-price-per-seat={pricePerSeat}
data-currency={currency}
class={cn(
"w-full max-w-[290px] min-w-0 rounded-xl border border-border bg-card p-5 text-card-foreground",
className,
)}
>
<label for={id} class="block text-xs/4 font-medium text-muted-foreground">
{label}
</label>
<input
id={id}
name={name}
type="number"
value={initial}
min={safeMin}
max={safeMax}
step="1"
tabindex="-1"
data-ts-input
class="sr-only"
/>
<div
role="group"
aria-label="Selected team seats"
data-ts-avatars
class="mt-4 flex min-h-10 items-center justify-center -space-x-2"
>
{
avatarSlots.map((slot, index) => (
<span
data-ts-avatar={index}
class={cn(
"relative inline-flex size-10 shrink-0 rounded-full bg-card ring-2 ring-card",
"data-hidden:hidden",
)}
data-hidden={index >= initial ? "" : undefined}
>
<span
role="img"
aria-label={slot.name}
class={cn(
"inline-flex size-full items-center justify-center overflow-hidden rounded-full bg-muted text-xs/none font-medium text-foreground select-none inset-ring inset-ring-frame",
)}
>
{slot.src ? (
<img src={slot.src} alt="" width="40" height="40" loading="lazy" class="size-full object-cover" />
) : (
slot.initials
)}
</span>
</span>
))
}
<span
data-ts-overflow
role="img"
aria-label={`${initialExtra} more`}
class={cn(
"relative inline-flex size-10 shrink-0 items-center justify-center rounded-full bg-muted text-xs/none font-medium text-foreground tabular-nums inset-ring inset-ring-frame ring-2 ring-card",
"data-hidden:hidden",
)}
data-hidden={initialExtra === 0 ? "" : undefined}
>
+{initialExtra}
</span>
</div>
<div class="mt-5 flex items-center justify-center gap-6">
<button
type="button"
data-action="dec"
data-ts-step="down"
aria-label={`Decrease ${unitPlural}`}
aria-controls={id}
aria-disabled={initial <= safeMin ? "true" : "false"}
class="inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full border border-frame bg-background text-foreground transition-[background-color,border-color,box-shadow,opacity,scale] duration-150 ease-snappy hover:border-frame-hover hover:bg-accent hover:shadow-key active:scale-90 aria-[disabled=true]:cursor-not-allowed aria-[disabled=true]:opacity-40 motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<Minus class="size-4" aria-hidden="true" />
</button>
<div class="grid min-w-14 justify-items-center text-center" aria-live="polite" aria-atomic="true">
<span data-ts-count class="text-3xl/9 font-semibold tracking-tight tabular-nums text-foreground">
{initial}
</span>
<span data-ts-unit class="text-xs/4 text-muted-foreground">
{initial === 1 ? unit : unitPlural}
</span>
</div>
<button
type="button"
data-action="inc"
data-ts-step="up"
aria-label={`Increase ${unitPlural}`}
aria-controls={id}
aria-disabled={initial >= safeMax ? "true" : "false"}
class="inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full border border-frame bg-background text-foreground transition-[background-color,border-color,box-shadow,opacity,scale] duration-150 ease-snappy hover:border-frame-hover hover:bg-accent hover:shadow-key active:scale-90 aria-[disabled=true]:cursor-not-allowed aria-[disabled=true]:opacity-40 motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<Plus class="size-4" aria-hidden="true" />
</button>
</div>
{
showPricing && (
<div class="mt-5 flex items-center justify-center gap-3 border-t border-border pt-4 text-xs/4 text-muted-foreground">
<span class="tabular-nums">
{currency}
{pricePerSeat} / {unit}
</span>
<span aria-hidden="true">·</span>
<span>
<strong data-ts-total class="font-semibold tabular-nums text-foreground">
{currency}
{initial * pricePerSeat}
</strong>{" "}
/ {billingPeriod}
</span>
</div>
)
}
</div>
<script>
function enhanceTeamSelector(root: HTMLElement) {
if (root.hasAttribute("data-enhanced")) return;
const input = root.querySelector<HTMLInputElement>("[data-ts-input]");
const dec = root.querySelector<HTMLButtonElement>('[data-action="dec"]');
const inc = root.querySelector<HTMLButtonElement>('[data-action="inc"]');
const countEl = root.querySelector<HTMLElement>("[data-ts-count]");
const unitEl = root.querySelector<HTMLElement>("[data-ts-unit]");
const totalEl = root.querySelector<HTMLElement>("[data-ts-total]");
const overflow = root.querySelector<HTMLElement>("[data-ts-overflow]");
const avatars = Array.from(root.querySelectorAll<HTMLElement>("[data-ts-avatar]"));
if (!input || !dec || !inc) return;
const unit = root.dataset.unit ?? "seat";
const unitPlural = root.dataset.unitPlural ?? "seats";
const maxAvatars = Math.max(1, Number(root.dataset.maxAvatars) || avatars.length);
const pricePerSeat = Number(root.dataset.pricePerSeat) || 0;
const currency = root.dataset.currency ?? "$";
const min = input.min === "" ? 1 : Number(input.min);
const max = input.max === "" ? Math.max(maxAvatars, 1) : Number(input.max);
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
const clamp = (n: number) => Math.min(max, Math.max(min, Math.round(Number.isFinite(n) ? n : min)));
const sync = (previous?: number) => {
const count = clamp(input.valueAsNumber);
const locked = input.matches(":disabled") || input.readOnly;
dec.disabled = locked;
inc.disabled = locked;
dec.setAttribute("aria-disabled", String(count <= min));
inc.setAttribute("aria-disabled", String(count >= max));
if (countEl) countEl.textContent = String(count);
if (unitEl) unitEl.textContent = count === 1 ? unit : unitPlural;
if (totalEl && pricePerSeat > 0) {
totalEl.textContent = `${currency}${count * pricePerSeat}`;
}
avatars.forEach((slot, index) => {
const visible = index < count;
const wasHidden = slot.hasAttribute("data-hidden");
slot.toggleAttribute("data-hidden", !visible);
if (visible && wasHidden && previous !== undefined && !reduced.matches) {
slot.classList.remove("animate-pop");
void slot.offsetWidth;
slot.classList.add("animate-pop");
}
});
if (overflow) {
const extra = Math.max(0, count - maxAvatars);
const wasHidden = overflow.hasAttribute("data-hidden");
overflow.toggleAttribute("data-hidden", extra === 0);
overflow.textContent = `+${extra}`;
overflow.setAttribute("aria-label", `${extra} more`);
const prevExtra = previous === undefined ? extra : Math.max(0, previous - maxAvatars);
if (extra > 0 && (wasHidden || extra !== prevExtra) && previous !== undefined && !reduced.matches) {
overflow.classList.remove("animate-pop");
void overflow.offsetWidth;
overflow.classList.add("animate-pop");
}
}
};
const commit = (nextValue: number) => {
if (input.readOnly || input.matches(":disabled")) return;
const before = clamp(input.valueAsNumber);
const next = clamp(nextValue);
if (next === before && input.value === String(next)) return;
input.value = String(next);
sync(before);
input.dispatchEvent(new Event("input", { bubbles: true }));
input.dispatchEvent(new Event("change", { bubbles: true }));
root.dispatchEvent(new CustomEvent("haze:team-selector-change", { detail: { count: next, total: next * pricePerSeat }, bubbles: true }));
};
dec.addEventListener("click", () => {
if (dec.getAttribute("aria-disabled") === "true") return;
commit(clamp(input.valueAsNumber) - 1);
});
inc.addEventListener("click", () => {
if (inc.getAttribute("aria-disabled") === "true") return;
commit(clamp(input.valueAsNumber) + 1);
});
input.addEventListener("input", () => sync());
input.addEventListener("change", () => commit(input.valueAsNumber));
input.form?.addEventListener("reset", () => queueMicrotask(() => sync()));
sync();
root.setAttribute("data-enhanced", "");
}
const initTeamSelectors = () => {
document.querySelectorAll<HTMLElement>("[data-haze-team-selector]").forEach(enhanceTeamSelector);
};
initTeamSelectors();
if (!document.documentElement.hasAttribute("data-haze-team-selector-listener")) {
document.documentElement.setAttribute("data-haze-team-selector-listener", "");
document.addEventListener("astro:page-load", initTeamSelectors);
}
</script>When to use
- Onboarding, billing or plan upgrade forms let users pick a team size with live avatar and pricing feedback
- A compact card control needs to submit a numeric seat count inside a native HTML form
When not to use
- Only a read-only avatar stack is needed without editing; use avatar-group
- A plain numeric quantity without member identity or pricing is sufficient; use quantity-stepper
- Users switch between existing workspaces rather than selecting team size; use workspace-switcher
Installation
Add the Haze registry to components.json once, then install Team selector with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/team-selectornpx shadcn@latest add @haze/team-selectoryarn dlx shadcn@latest add @haze/team-selectorbunx --bun shadcn@latest add @haze/team-selectorFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique ID associating the label, native number input and stepper buttons. |
| name | string | "teamCount" | Form field name submitted when placed inside a native form. |
| label | string | "Team size" | Top-left eyebrow label for the selector card. |
| members | { name: string; role?: string; src?: string }[] | 6 sample members | Roster used to derive colored initials avatars. |
| value | number | 3 | Initial selected seat count clamped between min and max. |
| min | number | 1 | Lowest allowed seat count. |
| max | number | 10 | Highest allowed seat count. |
| maxAvatars | number | 5 | Maximum avatars shown before displaying a +N overflow badge. |
| unit | string | "seat" | Singular unit label displayed beneath the count and in the price line. |
| unitPlural | string | "seats" | Plural unit label displayed beneath the count. |
| pricePerSeat | number | 12 | Unit seat price used to compute the live footer total; set 0 to hide pricing. |
| currency | string | "$" | Currency symbol formatted before seat and total amounts. |
| billingPeriod | string | "month" | Billing period suffix shown after the live total. |
| class | string | – | Additional classes on the outer card container. |
Keyboard interactions
- TabShiftTab
- Move focus between the decrease and increase circular stepper buttons
- EnterSpace
- Decrement or increment the team seat count and update live avatars and total
Accessibility
- Includes a labeled native <input type="number" class="sr-only"> so the selected seat count submits inside standard forms.
- Circular stepper buttons use aria-controls pointing to the input and aria-disabled at min/max bounds so focus is never lost.
- Announces seat count updates via an aria-live polite region and disables avatar pop animation under prefers-reduced-motion.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Team selector" with `npx shadcn@latest add @haze/team-selector`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import TeamSelector from "@/components/haze/ui/team-selector.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/team-selector.md
Customize with real content
Adapt the Haze team-selector ui for our product. Replace the demo values of these props with our real content: id, name, label, members, value, min, max, maxAvatars, unit, unitPlural, pricePerSeat, currency, billingPeriod, class. Keep the layout, the heading level rules and these accessibility details: Includes a labeled native <input type="number" class="sr-only"> so the selected seat count submits inside standard forms. Circular stepper buttons use aria-controls pointing to the input and aria-disabled at min/max bounds so focus is never lost. Announces seat count updates via an aria-live polite region and disables avatar pop animation under prefers-reduced-motion. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using team-selector, check it fits: use it when onboarding, billing or plan upgrade forms let users pick a team size with live avatar and pricing feedback; a compact card control needs to submit a numeric seat count inside a native html form. Avoid it when only a read-only avatar stack is needed without editing; use avatar-group; a plain numeric quantity without member identity or pricing is sufficient; use quantity-stepper; users switch between existing workspaces rather than selecting team size; use workspace-switcher. Alternatives: @haze/avatar-group, @haze/quantity-stepper, @haze/workspace-switcher.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.