Skip to content

Commit 78c1308

Browse files
committed
feat: add textarea component
1 parent 22db504 commit 78c1308

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

site/src/DynamicForm.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import ReactJson from 'react-json-view';
2020
import { RadioGroup, RadioGroupItem } from "./components/ui/radio-group"
2121
import { Label } from "./components/Label/Label";
2222
import { Checkbox } from "./components/Checkbox/Checkbox";
23+
import { Textarea } from "./components/Textarea/Textarea";
2324

2425
export function DynamicForm() {
2526
const serverAddress = "localhost:8100";
@@ -366,6 +367,31 @@ export function DynamicForm() {
366367
/>
367368
</div>
368369
)
370+
case "textarea":
371+
return (
372+
<div key={param.name} className="flex flex-col gap-2 items-center">
373+
<div className="flex items-center justify-between gap-2">
374+
<label>
375+
{param.display_name || param.name}
376+
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
377+
</label>
378+
</div>
379+
{param.description && <div className="text-sm">{param.description}</div>}
380+
<Controller
381+
name={param.name}
382+
control={methods.control}
383+
render={({ field }) => (
384+
<div className="w-[300px]">
385+
<Textarea
386+
value={field.value}
387+
onChange={(e) => field.onChange(e)}
388+
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
389+
/>
390+
</div>
391+
)}
392+
/>
393+
</div>
394+
)
369395
}
370396
}
371397

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from "react"
2+
3+
import { cn } from "../../utils/cn"
4+
5+
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
6+
return (
7+
<textarea
8+
data-slot="textarea"
9+
className={cn(
10+
"border-input placeholder:text-content-secondary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
11+
className
12+
)}
13+
{...props}
14+
/>
15+
)
16+
}
17+
18+
export { Textarea }

testdata/formtypes/main.tf

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,23 @@ data "coder_parameter" "string_without_opts" {
7979
icon = "/emojis/0031-fe0f-20e3.png"
8080
}
8181

82+
data "coder_parameter" "textarea_without_opts" {
83+
name = "textarea"
84+
display_name = "String"
85+
description = "Textarea"
86+
type = "string"
87+
form_type = "textarea"
88+
order = 4
89+
icon = "/emojis/0031-fe0f-20e3.png"
90+
}
91+
8292
data "coder_parameter" "bool_with_opts" {
8393
// should be 'radio'
8494
name = "bool_with_opts"
8595
display_name = "Bool"
8696
description = "Bool with options"
8797
type = "bool"
88-
order = 4
98+
order = 5
8999
icon = "/emojis/0031-fe0f-20e3.png"
90100
default = false
91101

@@ -108,7 +118,7 @@ data "coder_parameter" "bool_without_opts" {
108118
display_name = "Bool"
109119
description = "Bool without options"
110120
type = "bool"
111-
order = 5
121+
order = 6
112122
icon = "/emojis/0031-fe0f-20e3.png"
113123
default = false
114124
}
@@ -119,7 +129,7 @@ data "coder_parameter" "bool_without_opts_switch" {
119129
description = "Bool without options, but it is a switch"
120130
type = "bool"
121131
form_type = "switch"
122-
order = 6
132+
order = 7
123133
icon = "/emojis/0031-fe0f-20e3.png"
124134
default = false
125135
}
@@ -130,7 +140,7 @@ data "coder_parameter" "list_string_options" {
130140
display_name = "List(String)"
131141
description = "list(string) with options"
132142
type = "list(string)"
133-
order = 7
143+
order = 8
134144
icon = "/emojis/0031-fe0f-20e3.png"
135145
default = jsonencode(["purple", "blue", "green", "red", "orange"])
136146

@@ -159,7 +169,7 @@ data "coder_parameter" "list_string_without_options" {
159169
display_name = "List(String)"
160170
description = "list(string) with options"
161171
type = "list(string)"
162-
order = 8
172+
order = 9
163173
icon = "/emojis/0031-fe0f-20e3.png"
164174
default = jsonencode(["purple", "blue", "green", "red", "orange"])
165175
// You could send jsonencode(["airplane", "car", "school"])
@@ -172,7 +182,7 @@ data "coder_parameter" "list_string_multi_select_options" {
172182
description = "list(string) with options"
173183
type = "list(string)"
174184
form_type = "multi-select"
175-
order = 8
185+
order = 10
176186
icon = "/emojis/0031-fe0f-20e3.png"
177187
default = jsonencode(["blue", "green", "red"])
178188

0 commit comments

Comments
 (0)