83bc1c616 days ago48 lines · 1.1 KB| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | Select, |
| 5 | SelectContent, |
| 6 | SelectItem, |
| 7 | SelectTrigger, |
| 8 | SelectValue, |
| 9 | } from "@/components/ui/select"; |
| 10 | import { roleLabels } |
| 11 | |
| 12 | /** A pick from a role ladder, restricted to `roles`. Repository roles by default; pass `labels` for another ladder. */ |
| 13 | export function RoleSelect<TRole |
| 14 | id, |
| 15 | roles, |
| 16 | labels = roleLabels |
| 17 | value, |
| 18 | onChange, |
| 19 | label, |
| 20 | disabled, |
| 21 | }: { |
| 22 | id?: string |
| 23 | roles: readonly |
| 24 | labels?: Record |
| 25 | value: TRole |
| 26 | onChange: (role |
| 27 | label?: string |
| 28 | disabled?: boolean |
| 29 | }) { |
| 30 | return ( |
| 31 | <Select |
| 32 | value={value} |
| 33 | disabled={disabled} |
| 34 | onValueChange={(next) |
| 35 | > |
| 36 | <SelectTrigger id={ |
| 37 | <SelectValue /> |
| 38 | </SelectTrigger> |
| 39 | <SelectContent> |
| 40 | {roles.map(( |
| 41 | <SelectItem key={ |
| 42 | {labels[role]} |
| 43 | </SelectItem> |
| 44 | ))} |
| 45 | </SelectContent> |
| 46 | </Select> |
| 47 | ); |
| 48 | } |