-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
tag.gleam
68 lines (54 loc) · 1.9 KB
/
tag.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
// IMPORTS ---------------------------------------------------------------------
import lustre/attribute.{type Attribute, attribute}
import lustre/element.{type Element}
import lustre/element/html
// ELEMENTS --------------------------------------------------------------------
/// A simple tag. This shares styles with lustre_ui's buttons, but are much
/// smaller and uninteractive by default. They are useful for displaying small
/// amounts of information, such as category tags or labels.
///
/// If you want a tag to be interactive, you should either use the `of` function
/// below to construct a tag with `html.button` *or* you should set the tabindex
/// attribute and handle both click and key events for `Enter` and `Space`.
///
pub fn tag(attributes: List(Attribute(msg)), children: List(Element(msg))) {
of(html.span, attributes, children)
}
/// Use this function if you want to render something other than a `<span />`
/// element.
///
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-tag"), ..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 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")
}