mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { Check, ChevronDown, UserRound } from 'lucide-react';
|
|
|
|
interface MUserPickerListProps {
|
|
users: { id: number; username: string }[];
|
|
selected: number | null;
|
|
onPick: (id: number) => void;
|
|
}
|
|
|
|
export default function MUserPickerList({ users, selected, onPick }: MUserPickerListProps) {
|
|
return (
|
|
<div className="mt-2 max-h-48 divide-y divide-m-rowbr overflow-y-auto rounded-xl bg-m-sheetop px-2">
|
|
{users.map((user) => (
|
|
<button
|
|
key={user.id}
|
|
type="button"
|
|
onClick={() => onPick(user.id)}
|
|
aria-pressed={user.id === selected}
|
|
className="flex min-h-11 w-full items-center gap-2 rounded-lg px-2 text-start text-control font-medium active:bg-m-ic aria-pressed:bg-m-ic"
|
|
>
|
|
<UserRound size={16} className="shrink-0 text-m-muted" aria-hidden />
|
|
<span dir="auto" className="min-w-0 flex-1 truncate">
|
|
{user.username}
|
|
</span>
|
|
{user.id === selected && <Check size={16} className="shrink-0" aria-hidden />}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface MUserPickerFieldProps extends MUserPickerListProps {
|
|
label: string;
|
|
placeholder: string;
|
|
open: boolean;
|
|
onToggle: () => void;
|
|
fieldClass: string;
|
|
}
|
|
|
|
export function MUserPickerField({ label, placeholder, open, onToggle, fieldClass, ...list }: MUserPickerFieldProps) {
|
|
return (
|
|
<>
|
|
<button type="button" onClick={onToggle} aria-expanded={open} className={`${fieldClass} gap-2 text-start`}>
|
|
<UserRound size={16} className="shrink-0 text-m-muted" aria-hidden />
|
|
<span dir="auto" className={`min-w-0 flex-1 truncate ${list.selected === null ? 'text-m-muted' : ''}`}>
|
|
{label || placeholder}
|
|
</span>
|
|
<ChevronDown size={16} className={`shrink-0 text-m-muted ${open ? 'rotate-180' : ''}`} aria-hidden />
|
|
</button>
|
|
{open && <MUserPickerList {...list} />}
|
|
</>
|
|
);
|
|
}
|