-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathFlagControls.tsx
More file actions
78 lines (73 loc) · 1.58 KB
/
FlagControls.tsx
File metadata and controls
78 lines (73 loc) · 1.58 KB
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
import { Switch } from "~/components/primitives/Switch";
import { Select, SelectItem } from "~/components/primitives/Select";
import { Input } from "~/components/primitives/Input";
import { cn } from "~/utils/cn";
export const UNSET_VALUE = "__unset__";
export function BooleanControl({
value,
onChange,
dimmed,
}: {
value: boolean | undefined;
onChange: (val: boolean) => void;
dimmed: boolean;
}) {
return (
<Switch
variant="small"
checked={value ?? false}
onCheckedChange={onChange}
className={cn(dimmed && "opacity-50")}
/>
);
}
export function EnumControl({
value,
options,
onChange,
dimmed,
}: {
value: string | undefined;
options: string[];
onChange: (val: string) => void;
dimmed: boolean;
}) {
const items = [UNSET_VALUE, ...options];
return (
<Select
variant="tertiary/small"
value={value ?? UNSET_VALUE}
setValue={onChange}
items={items}
text={(val) => (val === UNSET_VALUE ? "unset" : val)}
className={cn(dimmed && "opacity-50")}
>
{(items) =>
items.map((item) => (
<SelectItem key={item} value={item}>
{item === UNSET_VALUE ? "unset" : item}
</SelectItem>
))
}
</Select>
);
}
export function StringControl({
value,
onChange,
dimmed,
}: {
value: string;
onChange: (val: string) => void;
dimmed: boolean;
}) {
return (
<Input
variant="small"
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder="unset"
className={cn("w-40", dimmed && "opacity-50")}
/>
);
}