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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use crate::AsClasses;
use yew::html::IntoPropValue;
use yew::prelude::*;
use yew::virtual_dom::VNode;
pub enum State {
None,
Danger,
Default,
Info,
Success,
Warning,
Disabled,
}
impl State {
fn var(name: &str, weight: usize) -> String {
format!("--pf-global--{}-color--{}", name, weight)
}
pub fn as_var(&self, weight: usize) -> Option<String> {
match self {
Self::None => None,
Self::Danger => Some(Self::var("danger", weight)),
Self::Default => Some(Self::var("default", weight)),
Self::Info => Some(Self::var("info", weight)),
Self::Success => Some(Self::var("success", weight)),
Self::Warning => Some(Self::var("warning", weight)),
Self::Disabled => Some(Self::var("disabled", weight)),
}
}
}
macro_rules! icons {
($($n:ident => $e:expr),* $(,)?) => {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Icon {
$($n),*
}
impl AsClasses for Icon {
fn extend(&self, classes: &mut Classes) {
match self {
$(Self::$n => classes.extend($e)),*
}
}
}
};
}
icons! {
AngleDown => fas("fa-angle-down"),
AngleLeft => fas("fa-angle-left"),
AngleDoubleLeft => fas("fa-angle-double-left"),
AngleRight => fas("fa-angle-right"),
AngleDoubleRight => fas("fa-angle-double-right"),
AngleUp => fas("fa-angle-up"),
ArrowDown => fas("fa-arrow-down"),
ArrowLeft => fas("fa-arrow-left"),
ArrowRight => fas("fa-arrow-right"),
ArrowUp => fas("fa-arrow-up"),
Bell => fas("fa-bell"),
CaretDown => fas("fa-caret-down"),
CaretUp => fas("fa-caret-up"),
Check => fas("fa-check"),
CheckCircle => fas("fa-check-circle"),
Copy => fas("fa-copy"),
Cubes => fas("fa-cubes"),
EllipsisH => fas("fa-ellipsis-h"),
EllipsisV => fas("fa-ellipsis-v"),
ExclamationCircle => fas("fa-exclamation-circle"),
ExclamationTriangle => fas("fa-exclamation-triangle"),
ExternalLinkAlt => fas("fa-external-link-alt"),
InfoCircle => fas("fa-info-circle"),
Minus => fas("fa-minus"),
MinusCircleIcon => fas("fa-minus-circle"),
Pause => fas("fa-pause"),
Play => fas("fa-play"),
PlusCircleIcon => fas("fa-plus-circle"),
QuestionCircle => fas("fa-question-circle"),
Times => fas("fa-times"),
Th => fas("fa-th"),
Help => pf("pf-icon-help"),
Pending => pf("pf-icon-pending")
}
impl Icon {
pub fn as_html(&self) -> Html {
self.with_classes(Classes::new())
}
pub fn with_state(&self, state: State) -> Html {
self.with_state_weight(state, 200)
}
pub fn with_state_weight(&self, state: State, weight: usize) -> Html {
let style = state
.as_var(weight)
.map(|v| format!("color: var({});", v))
.unwrap_or_default();
html! {
<span style={style}>
{ self.as_html() }
</span>
}
}
pub fn with_classes(&self, mut classes: Classes) -> Html {
self.extend(&mut classes);
html! {
<i class={classes} aria-hidden="true"></i>
}
}
}
fn fas(name: &str) -> [&str; 2] {
["fas", name]
}
fn pf(name: &str) -> [&str; 2] {
["pficon", name]
}
impl From<Icon> for VNode {
fn from(icon: Icon) -> Self {
icon.as_html()
}
}
impl IntoPropValue<Html> for Icon {
fn into_prop_value(self) -> Html {
self.as_html()
}
}
impl IntoPropValue<Option<Html>> for Icon {
fn into_prop_value(self) -> Option<Html> {
Some(self.as_html())
}
}