-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinput.templ
More file actions
97 lines (94 loc) · 2.39 KB
/
input.templ
File metadata and controls
97 lines (94 loc) · 2.39 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
95
96
97
package components
type InputProps struct {
Id string
Type string
Name string
Placeholder string
HelperText string
Class string
Value string
Model string
AutoFocus bool
HideLabel bool
Required bool
IsDisabled bool
// HTMX options:
HXPost string
HXTrigger string
HXTarget string
HXSwap string
HXIndicator string
}
/**
* Text Input Component.
* ======================
* This is a input component that can be used to create text inputs.
*
* @params InputProps
* @author: github.com/tego101 <-> x.com/tegodotdev
* @license: MIT
*
* Usage:
* @components.Input(components.InputProps{
* Type: "text",
* Name: "First Name",
* Placeholder: "Enter your name",
* Class: "max-w-6xl",
* HideLabel: true,
* })
*/
templ Input(props InputProps) {
<label
class="relative flex flex-col w-full space-y-2"
>
<div class="flex flex-row items-center w-full space-x-4">
if !props.HideLabel {
<div class="flex flex-row items-center space-x-2">
if props.Required {
<div class="w-1 h-4 border border-red-500 bg-gradient-to-br from-red-400 rounded-xl"></div>
}
<strong class="capitalize">{ props.Name }</strong>
</div>
}
</div>
<input
if props.IsDisabled {
disabled
}
if props.Required {
required
}
if props.AutoFocus {
autofocus
}
class={ "w-full focus:outline-none focus-visible:outline-none px-3 py-2 text-base dark:text-white dark:ring-slate-500 bg-white dark:bg-black dark:border-slate-900 border rounded-md peer border-neutral-300 ring-offset-background placeholder:text-slate-400 text-slate-700 focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-neutral-400 disabled:cursor-not-allowed disabled:opacity-50 " + props.Class }
type={ props.Type }
id={ props.Id }
name={ props.Name }
placeholder={ props.Placeholder }
if props.Model != "" {
x-model={ props.Model }
}
if props.HXPost != "" {
hx-post={ props.HXPost }
}
if props.HXTrigger != "" {
hx-trigger={ props.HXTrigger }
}
if props.HXTarget != "" {
hx-target={ props.HXTarget }
}
if props.HXSwap != "" {
hx-swap={ props.HXSwap }
}
if props.HXIndicator != "" {
hx-indicator={ props.HXIndicator }
}
/>
if props.HelperText != "" {
<p class="w-full mt-1 text-xs text-slate-400">
{ props.HelperText }
</p>
}
</label>
}