-
Notifications
You must be signed in to change notification settings - Fork 64
/
eval-scale-picker.tsx
80 lines (76 loc) · 2.06 KB
/
eval-scale-picker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Check, ChevronsUpDown } from "lucide-react";
import * as React from "react";
import { Button } from "@/components/ui/button";
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
} from "@/components/ui/command";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { cn } from "@/lib/utils";
export enum ScaleType {
Range = "range",
}
export interface Scale {
type: ScaleType;
min: number;
max: number;
step?: number;
}
export default function EvalScalePicker({
selectedScale,
setSelectedScale,
}: {
selectedScale: ScaleType | null;
setSelectedScale: (scale: ScaleType) => void;
}) {
const [open, setOpen] = React.useState(false);
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
role="combobox"
aria-expanded={open}
className="w-full capitalize"
>
{selectedScale || "Select scale..."}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="max-w-full p-0">
<Command>
<CommandInput placeholder="Search scale..." />
<CommandEmpty>No such scale found.</CommandEmpty>
<CommandGroup>
{Object.values(ScaleType).map((scale: ScaleType, i: number) => (
<CommandItem
className="capitalize"
key={i}
value={scale}
onSelect={(selection: string) => {
setSelectedScale(selection as ScaleType);
setOpen(false);
}}
>
<Check
className={cn(
"mr-2 h-4 w-4 capitalize",
selectedScale === scale ? "opacity-100" : "opacity-0"
)}
/>
{scale}
</CommandItem>
))}
</CommandGroup>
</Command>
</PopoverContent>
</Popover>
);
}