-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
field.gleam
101 lines (82 loc) · 2.3 KB
/
field.gleam
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
98
99
100
101
// IMPORTS ---------------------------------------------------------------------
import lustre/attribute.{type Attribute, attribute}
import lustre/element.{type Element}
import lustre/element/html
import lustre/ui/stack.{stack}
// ELEMENTS --------------------------------------------------------------------
pub fn field(
attributes: List(Attribute(msg)),
label: List(Element(msg)),
input: Element(msg),
message: List(Element(msg)),
) -> Element(msg) {
of(html.label, attributes, label, input, message)
}
pub fn with_label(
attributes: List(Attribute(msg)),
label: List(Element(msg)),
input: Element(msg),
) -> Element(msg) {
of(html.label, attributes, label, input, [])
}
pub fn with_message(
attributes: List(Attribute(msg)),
input: Element(msg),
message: List(Element(msg)),
) -> Element(msg) {
of(html.div, attributes, [], input, message)
}
pub fn of(
element: fn(List(Attribute(msg)), List(Element(msg))) -> Element(msg),
attributes: List(Attribute(msg)),
label: List(Element(msg)),
input: Element(msg),
message: List(Element(msg)),
) -> Element(msg) {
stack.of(
element,
[attribute.class("lustre-ui-field"), stack.packed(), ..attributes],
[
html.span([attribute.class("label")], label),
input,
html.span([attribute.class("message")], message),
],
)
}
// ATTRIBUTES ------------------------------------------------------------------
pub fn label_start() -> Attribute(msg) {
attribute.class("label-start")
}
pub fn label_end() -> Attribute(msg) {
attribute.class("label-end")
}
pub fn label_centre() -> Attribute(msg) {
attribute.class("label-centre")
}
pub fn message_start() -> Attribute(msg) {
attribute.class("message-start")
}
pub fn message_end() -> Attribute(msg) {
attribute.class("message-end")
}
pub fn message_centre() -> Attribute(msg) {
attribute.class("message-centre")
}
pub fn primary() -> Attribute(msg) {
attribute("data-variant", "primary")
}
pub fn greyscale() -> Attribute(msg) {
attribute("data-variant", "greyscale")
}
pub fn error() -> Attribute(msg) {
attribute("data-variant", "error")
}
pub fn warning() -> Attribute(msg) {
attribute("data-variant", "warning")
}
pub fn success() -> Attribute(msg) {
attribute("data-variant", "success")
}
pub fn info() -> Attribute(msg) {
attribute("data-variant", "info")
}