Skip to content

Commit 0f304a3

Browse files
Merge pull request #150 from olaservo/handle-boolean
Add checkbox for handling boolean input params
2 parents d4df126 + 89ee2b1 commit 0f304a3

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@modelcontextprotocol/sdk": "^1.4.1",
25+
"@radix-ui/react-checkbox": "^1.1.4",
2526
"@radix-ui/react-icons": "^1.3.0",
2627
"@radix-ui/react-label": "^2.1.0",
2728
"@radix-ui/react-select": "^2.1.2",

client/src/components/ToolsTab.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
22
import { Button } from "@/components/ui/button";
3+
import { Checkbox } from "@/components/ui/checkbox";
34
import { Input } from "@/components/ui/input";
45
import { Label } from "@/components/ui/label";
56
import { TabsContent } from "@/components/ui/tabs";
@@ -176,7 +177,27 @@ const ToolsTab = ({
176177
>
177178
{key}
178179
</Label>
179-
{prop.type === "string" ? (
180+
{prop.type === "boolean" ? (
181+
<div className="flex items-center space-x-2 mt-2">
182+
<Checkbox
183+
id={key}
184+
name={key}
185+
checked={!!params[key]}
186+
onCheckedChange={(checked: boolean) =>
187+
setParams({
188+
...params,
189+
[key]: checked,
190+
})
191+
}
192+
/>
193+
<label
194+
htmlFor={key}
195+
className="text-sm font-medium text-gray-700 dark:text-gray-300"
196+
>
197+
{prop.description || "Toggle this option"}
198+
</label>
199+
</div>
200+
) : prop.type === "string" ? (
180201
<Textarea
181202
id={key}
182203
name={key}

client/src/components/ui/checkbox.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
5+
import { Check } from "lucide-react";
6+
7+
import { cn } from "@/lib/utils";
8+
9+
const Checkbox = React.forwardRef<
10+
React.ElementRef<typeof CheckboxPrimitive.Root>,
11+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
12+
>(({ className, ...props }, ref) => (
13+
<CheckboxPrimitive.Root
14+
ref={ref}
15+
className={cn(
16+
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
17+
className,
18+
)}
19+
{...props}
20+
>
21+
<CheckboxPrimitive.Indicator
22+
className={cn("flex items-center justify-center text-current")}
23+
>
24+
<Check className="h-4 w-4" />
25+
</CheckboxPrimitive.Indicator>
26+
</CheckboxPrimitive.Root>
27+
));
28+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
29+
30+
export { Checkbox };

client/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ button:focus-visible {
5757
outline: 4px auto -webkit-focus-ring-color;
5858
}
5959

60+
button[role="checkbox"] {
61+
padding: 0;
62+
}
63+
6064
@media (prefers-color-scheme: light) {
6165
:root {
6266
color: #213547;

package-lock.json

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

0 commit comments

Comments
 (0)