-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
button.gleam
90 lines (74 loc) · 2.15 KB
/
button.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
// IMPORTS ---------------------------------------------------------------------
import lustre/attribute.{type Attribute, attribute}
import lustre/element.{type Element}
import lustre/element/html
// ELEMENTS --------------------------------------------------------------------
/// A styled native HTML button. You can use the `solid`, `soft`, and `outline`
/// attributes to configure the button's appearance.
///
pub fn button(attributes: List(Attribute(msg)), children: List(Element(msg))) {
html.button(
[
attribute.class("lustre-ui-button"),
attribute.type_("button"),
..attributes
],
children,
)
}
/// Use this function if you want to render something other than a `<button />`
/// element. It will automatically have the `role` and `tabindex` attributes
/// set.
///
/// 🚨 To make your non-standard buttons accessible, it is important that you
/// handle click events as well as key events for the `Enter` and `Space`.
///
pub fn of(
element: fn(List(Attribute(msg)), List(Element(msg))) -> Element(msg),
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element(
[
attribute.class("lustre-ui-button"),
attribute("role", "button"),
attribute("tabindex", "0"),
..attributes
],
children,
)
}
// ATTRIBUTES ------------------------------------------------------------------
pub fn solid() -> Attribute(msg) {
attribute.class("solid")
}
pub fn soft() -> Attribute(msg) {
attribute.class("soft")
}
pub fn outline() -> Attribute(msg) {
attribute.class("outline")
}
pub fn clear() -> Attribute(msg) {
attribute.class("clear")
}
pub fn small() -> Attribute(msg) {
attribute.class("small")
}
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")
}