|
1 | | -import type * as React from "react"; |
2 | 1 | import { cva, type VariantProps } from "class-variance-authority"; |
| 2 | +import type * as React from "react"; |
3 | 3 | import { Input } from "#shadcn/components/ui/input"; |
4 | 4 | import { |
5 | | - Select, |
6 | | - SelectContent, |
7 | | - SelectItem, |
8 | | - SelectTrigger, |
9 | | - SelectValue, |
| 5 | + Select, |
| 6 | + SelectContent, |
| 7 | + SelectItem, |
| 8 | + SelectTrigger, |
| 9 | + SelectValue, |
10 | 10 | } from "#shadcn/components/ui/select"; |
11 | 11 | import { cn } from "#shadcn/lib/utils"; |
12 | 12 | import { CopyIcon } from "./copy-icon"; |
13 | 13 |
|
14 | 14 | const requestMethodVariants = cva( |
15 | | - "min-w-26 border-r-0 rounded-r-none shadow-none typo-label text-left items-start", |
16 | | - { |
17 | | - variants: { |
18 | | - method: { |
19 | | - GET: "text-utility-green [&_svg]:text-utility-green", |
20 | | - POST: "text-utility-yellow [&_svg]:text-utility-yellow", |
21 | | - PUT: "text-utility-blue [&_svg]:text-utility-blue ", |
22 | | - PATCH: "text-utility-violet [&_svg]:text-utility-violet", |
23 | | - DELETE: "text-utility-red [&_svg]:text-utility-red", |
24 | | - }, |
25 | | - }, |
26 | | - defaultVariants: { |
27 | | - method: "GET", |
28 | | - }, |
29 | | - } |
| 15 | + "border-r-0 rounded-r-none shadow-none typo-label text-left items-start", |
| 16 | + { |
| 17 | + variants: { |
| 18 | + method: { |
| 19 | + GET: "text-utility-green [&_svg]:text-utility-green", |
| 20 | + POST: "text-utility-yellow [&_svg]:text-utility-yellow", |
| 21 | + PUT: "text-utility-blue [&_svg]:text-utility-blue ", |
| 22 | + PATCH: "text-utility-violet [&_svg]:text-utility-violet", |
| 23 | + DELETE: "text-utility-red [&_svg]:text-utility-red", |
| 24 | + }, |
| 25 | + }, |
| 26 | + defaultVariants: { |
| 27 | + method: "GET", |
| 28 | + }, |
| 29 | + }, |
30 | 30 | ); |
31 | 31 |
|
32 | 32 | type RequestMethod = VariantProps<typeof requestMethodVariants>["method"]; |
33 | 33 |
|
34 | 34 | interface RequestLineEditorProps extends React.ComponentProps<"div"> { |
35 | | - selectedMethod: string; |
36 | | - setMethod: (value: string) => void; |
37 | | - methods: string[]; |
38 | | - inputValue?: string | undefined; |
39 | | - onInputChange?: React.ChangeEventHandler<HTMLInputElement>; |
| 35 | + selectedMethod: string; |
| 36 | + setMethod: (value: string) => void; |
| 37 | + methods: string[]; |
| 38 | + inputValue?: string | undefined; |
| 39 | + onInputChange?: React.ChangeEventHandler<HTMLInputElement>; |
40 | 40 | } |
41 | 41 |
|
42 | 42 | function RequestMethodSelector({ |
43 | | - selectedMethod, |
44 | | - setMethod, |
45 | | - methods, |
| 43 | + selectedMethod, |
| 44 | + setMethod, |
| 45 | + methods, |
46 | 46 | }: RequestLineEditorProps) { |
47 | | - return ( |
48 | | - <Select value={selectedMethod} onValueChange={setMethod}> |
49 | | - <SelectTrigger |
50 | | - className={cn( |
51 | | - requestMethodVariants({ method: selectedMethod as RequestMethod }) |
52 | | - )} |
53 | | - > |
54 | | - <SelectValue /> |
55 | | - </SelectTrigger> |
56 | | - <SelectContent> |
57 | | - {methods.map((method) => ( |
58 | | - <SelectItem key={method} value={method}> |
59 | | - <span |
60 | | - className={cn( |
61 | | - requestMethodVariants({ method: method as RequestMethod }) |
62 | | - )} |
63 | | - > |
64 | | - {method} |
65 | | - </span> |
66 | | - </SelectItem> |
67 | | - ))} |
68 | | - </SelectContent> |
69 | | - </Select> |
70 | | - ); |
| 47 | + return ( |
| 48 | + <Select value={selectedMethod} onValueChange={setMethod}> |
| 49 | + <SelectTrigger |
| 50 | + className={cn( |
| 51 | + "w-30", |
| 52 | + requestMethodVariants({ method: selectedMethod as RequestMethod }), |
| 53 | + )} |
| 54 | + > |
| 55 | + <SelectValue /> |
| 56 | + </SelectTrigger> |
| 57 | + <SelectContent> |
| 58 | + {methods.map((method) => ( |
| 59 | + <SelectItem key={method} value={method}> |
| 60 | + <span |
| 61 | + className={cn( |
| 62 | + requestMethodVariants({ method: method as RequestMethod }), |
| 63 | + )} |
| 64 | + > |
| 65 | + {method} |
| 66 | + </span> |
| 67 | + </SelectItem> |
| 68 | + ))} |
| 69 | + </SelectContent> |
| 70 | + </Select> |
| 71 | + ); |
71 | 72 | } |
72 | 73 |
|
73 | 74 | function RequestLineEditor({ |
74 | | - className, |
75 | | - selectedMethod, |
76 | | - setMethod, |
77 | | - methods, |
78 | | - inputValue, |
79 | | - onInputChange, |
| 75 | + className, |
| 76 | + selectedMethod, |
| 77 | + setMethod, |
| 78 | + methods, |
| 79 | + inputValue, |
| 80 | + onInputChange, |
80 | 81 | }: RequestLineEditorProps) { |
81 | | - return ( |
82 | | - <div className={cn("flex", className)}> |
83 | | - <RequestMethodSelector |
84 | | - selectedMethod={selectedMethod} |
85 | | - setMethod={setMethod} |
86 | | - methods={methods} |
87 | | - /> |
88 | | - <Input |
89 | | - className="rounded-l-none" |
90 | | - value={inputValue} |
91 | | - rightSlot={<CopyIcon text={`${selectedMethod} ${inputValue}`} />} |
92 | | - {...(onInputChange !== undefined ? { onChange: onInputChange } : {})} |
93 | | - /> |
94 | | - </div> |
95 | | - ); |
| 82 | + return ( |
| 83 | + <div className={cn("flex", className)}> |
| 84 | + <RequestMethodSelector |
| 85 | + selectedMethod={selectedMethod} |
| 86 | + setMethod={setMethod} |
| 87 | + methods={methods} |
| 88 | + /> |
| 89 | + <Input |
| 90 | + className="rounded-l-none" |
| 91 | + value={inputValue} |
| 92 | + rightSlot={<CopyIcon text={`${selectedMethod} ${inputValue}`} />} |
| 93 | + {...(onInputChange !== undefined ? { onChange: onInputChange } : {})} |
| 94 | + /> |
| 95 | + </div> |
| 96 | + ); |
96 | 97 | } |
97 | 98 |
|
98 | 99 | export { |
99 | | - RequestLineEditor, |
100 | | - type RequestLineEditorProps, |
101 | | - requestMethodVariants, |
| 100 | + RequestLineEditor, |
| 101 | + type RequestLineEditorProps, |
| 102 | + requestMethodVariants, |
102 | 103 | }; |
0 commit comments