Skip to content

Commit 22db504

Browse files
committed
feat: add checkbox component
1 parent 9b1575f commit 22db504

File tree

4 files changed

+105
-20
lines changed

4 files changed

+105
-20
lines changed

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"@radix-ui/react-checkbox": "^1.1.4",
1314
"@radix-ui/react-dialog": "^1.1.6",
1415
"@radix-ui/react-label": "^2.1.2",
1516
"@radix-ui/react-radio-group": "^1.2.3",

site/pnpm-lock.yaml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/DynamicForm.tsx

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Slider } from "./components/ui/slider";
1919
import ReactJson from 'react-json-view';
2020
import { RadioGroup, RadioGroupItem } from "./components/ui/radio-group"
2121
import { Label } from "./components/Label/Label";
22+
import { Checkbox } from "./components/Checkbox/Checkbox";
2223

2324
export function DynamicForm() {
2425
const serverAddress = "localhost:8100";
@@ -322,28 +323,49 @@ export function DynamicForm() {
322323
case "switch":
323324
return (
324325
<div key={param.name} className="flex flex-col gap-2 items-center">
325-
<div className="flex items-center justify-between gap-2">
326-
<label>
327-
{param.display_name || param.name}
328-
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
329-
</label>
326+
<div className="flex items-center justify-between gap-2">
327+
<label>
328+
{param.display_name || param.name}
329+
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
330+
</label>
331+
</div>
332+
{param.description && <div className="text-sm">{param.description}</div>}
333+
<Controller
334+
name={param.name}
335+
control={methods.control}
336+
render={({ field }) => (
337+
<div className="w-[300px]">
338+
<Switch
339+
checked={Boolean(field.value === "true")}
340+
onCheckedChange={(checked) => field.onChange(checked.toString())}
341+
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
342+
/>
343+
</div>
344+
)}
345+
/>
330346
</div>
331-
{param.description && <div className="text-sm">{param.description}</div>}
332-
<Controller
333-
name={param.name}
334-
control={methods.control}
335-
render={({ field }) => (
336-
<div className="w-[300px]">
337-
<Switch
338-
checked={Boolean(field.value === "true")}
339-
onCheckedChange={(checked) => field.onChange(checked.toString())}
340-
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
341-
/>
342-
</div>
343-
)}
344-
/>
345-
</div>
346347
)
348+
case "checkbox":
349+
return (
350+
<div key={param.name} className="flex flex-col gap-2 items-center">
351+
<div className="flex items-center justify-between gap-2">
352+
<label>
353+
{param.display_name || param.name}
354+
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
355+
</label>
356+
</div>
357+
{param.description && <div className="text-sm">{param.description}</div>}
358+
<Controller
359+
name={param.name}
360+
control={methods.control}
361+
render={({ field }) => (
362+
<div className="w-[300px]">
363+
<Checkbox checked={Boolean(field.value === "true")} onCheckedChange={(checked) => field.onChange(checked.toString())} disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled} />
364+
</div>
365+
)}
366+
/>
367+
</div>
368+
)
347369
}
348370
}
349371

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as React from "react"
2+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
3+
import { CheckIcon } from "lucide-react"
4+
5+
import { cn } from "../../utils/cn"
6+
7+
function Checkbox({
8+
className,
9+
...props
10+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
11+
return (
12+
<CheckboxPrimitive.Root
13+
data-slot="checkbox"
14+
className={cn(
15+
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
16+
className
17+
)}
18+
{...props}
19+
>
20+
<CheckboxPrimitive.Indicator
21+
data-slot="checkbox-indicator"
22+
className="flex items-center justify-center text-current transition-none"
23+
>
24+
<CheckIcon className="size-3.5" />
25+
</CheckboxPrimitive.Indicator>
26+
</CheckboxPrimitive.Root>
27+
)
28+
}
29+
30+
export { Checkbox }

0 commit comments

Comments
 (0)