Skip to content

Commit 98caf4c

Browse files
committed
Add request line editor
1 parent 5d9ae38 commit 98caf4c

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {
2+
Button,
3+
DropdownMenu,
4+
DropdownMenuCheckboxItem,
5+
DropdownMenuContent,
6+
DropdownMenuLabel,
7+
DropdownMenuSeparator,
8+
DropdownMenuTrigger,
9+
Input,
10+
11+
} from "../../index";
12+
13+
import {
14+
Check,
15+
ChevronDown,
16+
Copy,
17+
} from "lucide-react";
18+
import { useState } from "react";
19+
20+
const requestMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
21+
22+
23+
// Move to copy-button.tsx
24+
function CopyButton() {
25+
const [isActive, setIsActive] = useState(false);
26+
function handleClick() {
27+
setIsActive(true);
28+
setTimeout(() => {
29+
setIsActive(false);
30+
}, 1000);
31+
}
32+
return (
33+
<Button
34+
variant="ghost"
35+
className="p-1 absolute right-2 top-1.5 text-text-secondary"
36+
onClick={handleClick}
37+
>
38+
{isActive ? <Check /> : <Copy />}
39+
</Button>
40+
);
41+
}
42+
43+
function RequestMethodSelector() {
44+
const [selectedMethod, setMethod] = useState("GET");
45+
return (
46+
<DropdownMenu>
47+
<DropdownMenuTrigger asChild>
48+
<Button
49+
variant="outline"
50+
className="rounded-r-none! border-r-0! pr-3! w-26 h-9 bg-bg-secondary"
51+
>
52+
{selectedMethod}
53+
<ChevronDown />
54+
</Button>
55+
</DropdownMenuTrigger>
56+
<DropdownMenuContent>
57+
<DropdownMenuLabel>Request method</DropdownMenuLabel>
58+
<DropdownMenuSeparator></DropdownMenuSeparator>
59+
{requestMethods.map((requestMethod) => (
60+
<DropdownMenuCheckboxItem
61+
key={requestMethod}
62+
checked={selectedMethod === requestMethod}
63+
onCheckedChange={() => setMethod(requestMethod)}
64+
>
65+
{requestMethod}
66+
</DropdownMenuCheckboxItem>
67+
))}
68+
</DropdownMenuContent>
69+
</DropdownMenu>
70+
);
71+
}
72+
73+
function ReuqestLineEditor() {
74+
return (
75+
<div className="flex relative w-full">
76+
<RequestMethodSelector />
77+
<Input className="rounded-l-none!" defaultValue="/fhir/Patient" />
78+
<CopyButton />
79+
</div>
80+
);
81+
}

0 commit comments

Comments
 (0)