-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextarea.templ
More file actions
94 lines (91 loc) · 1.98 KB
/
textarea.templ
File metadata and controls
94 lines (91 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package popui
import (
"fmt"
"github.com/invopop/popui.go/classes"
"github.com/invopop/popui.go/props"
"github.com/invopop/popui.go/tailwind"
)
// Textarea provides a multi-line text input element.
//
// If the Label property is provided, a simple label will be rendered above the textarea.
templ Textarea(p ...props.Textarea) {
{{ prp := props.First(p) }}
<div class="flex flex-col gap-2 w-full">
if prp.Label != "" {
@Label(props.Label{ID: prp.ID}) {
{ prp.Label }
}
}
<textarea
id={ prp.ID }
class={ tailwind.Merge(
classes.FormField(),
classes.FormFieldState(!prp.Error.Empty()),
classes.If(prp.Monospace, "font-mono"),
prp.Class,
) }
rows={ prp.GetRows() }
if prp.Disabled {
disabled
}
if prp.Autofocus {
autofocus
}
if prp.Readonly {
readonly
}
if prp.Required {
required
}
if prp.Name != "" {
name={ prp.Name }
}
if prp.Placeholder != "" {
placeholder={ prp.Placeholder }
}
{ prp.Attributes... }
>
if prp.Value != "" {
{ prp.Value }
}
</textarea>
if !prp.Error.Empty() {
@InputError(prp.Error)
}
</div>
}
// Contenteditable provides a div with contenteditable set to true.
// It behaves as a Textarea component.
//
// If the Label property is provided, a simple label will be rendered above the contenteditable div.
templ Contenteditable(p ...props.Textarea) {
{{ prp := props.First(p) }}
<div class="flex flex-col gap-2 w-full">
if prp.Label != "" {
@Label(props.Label{ID: prp.ID}) {
{ prp.Label }
}
}
<div
tabindex="0"
role="textarea"
contenteditable="true"
id={ prp.ID }
style={ "min-height: " + fmt.Sprintf("%d", prp.Rows*34) + "px" }
class={ tailwind.Merge(
classes.FormField(),
"min-h-[80px]",
classes.FormFieldState(!prp.Error.Empty()),
prp.Class,
) }
{ prp.Attributes... }
>
if prp.Value != "" {
@templ.Raw(prp.Value)
}
</div>
if !prp.Error.Empty() {
@InputError(prp.Error)
}
</div>
}