-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskill_view.rs
191 lines (184 loc) · 6.6 KB
/
skill_view.rs
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
use dioxus::prelude::*;
use dioxus_router::prelude::Link;
use data::token::{Token, Tokens};
use crate::components::tabs::{Tab, TabGroup, TabList, TabPanel, TabPanels};
use crate::components::Rarity;
use crate::components::Sprite;
use crate::pages::Route;
#[component]
fn LocalTab<'a>(cx: Scope<'a>, index: usize, children: Element<'a>) -> Element {
render! {
Tab {
index: *index,
render: move |attrs, children, selected| {
let active = if selected { "tab-active" } else { "" };
render! {
button {
class: "tab {active}",
..*attrs,
{children}
}
}
},
{children}
}
}
}
#[component]
fn LocalTabPanel<'a>(cx: Scope<'a>, index: usize, children: Element<'a>) -> Element {
render! {
TabPanel {
index: *index,
render: move |attrs, children, selected| {
let active = if selected { "" } else { "" };
render! {
div {
class: "{active}",
..*attrs,
{children}
}
}
},
{children}
}
}
}
#[component]
pub fn SkillView<'a>(cx: Scope<'a>, skill: &'a data::skill::Skill) -> Element {
render! {
div {
class: "flex flex-col border-solid border border-base-300 rounded-md my-2",
div {
class: "flex flex-row items-center gap-2 bg-base-300 text-base-content p-2",
Sprite { sprite: &skill.modes[0].icon, scale: 0.5 }
span {
class: "flex-grow",
Link {
class: "text-primary hover:underline cursor-pointer",
to: Route::SkillPage { skill_id: skill.id.clone() },
"{skill.name}"
}
}
span {
Rarity { rarity: skill.rarity }
}
}
TabGroup {
render: move |children, _selected_index| {
render! {
div {
{children}
}
}
},
TabList {
render: move |attrs, children, _selected_index| {
render! {
div {
class: "tabs tabs-bordered",
..*attrs,
{children}
}
}
},
LocalTab {
index: 0,
"NORMAL"
}
LocalTab {
index: 1,
"ALTERNATE"
}
}
TabPanels {
render: move |attrs, children, _selected_index| {
render! {
div {
..*attrs,
{children}
}
}
},
LocalTabPanel {
index: 0,
ul { class: "flex flex-row gap-2 p-2",
for mode in skill.modes.iter().filter(|m| !m.is_alt) {
li {
SkillMode { mode: &mode }
}
}
}
}
LocalTabPanel {
index: 1,
ul { class: "flex flex-row gap-2 p-2",
for mode in skill.modes.iter().filter(|m| m.is_alt) {
li {
SkillMode { mode: &mode }
}
}
}
}
}
}
}
}
}
#[component]
pub fn SkillMode<'a>(cx: Scope<'a>, mode: &'a data::skill::SkillMode) -> Element {
render! {
div { class: "flex flex-col gap-2 bg-base-200 text-base-content rounded-md p-2",
div { class: "flex flex-row items-center gap-2",
Sprite { sprite: &mode.icon, scale: 0.5 }
div { class: "flex-grow",
"{mode.name}"
}
div { class: "dropdown",
div { class: "btn btn-ghost btn-circle btn-sm",
tabindex: 0,
role: "button",
dangerous_inner_html: r#"<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M6.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM12.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM18.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Z" /></svg>"#,
}
ul { class: "menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52",
tabindex: 0,
li {
button {
class: "btn btn-ghost btn-sm justify-start",
onclick: move |_| log::info!("{:#?}", mode),
"Dump"
}
}
}
}
}
div {
Description { tokens: mode.format() }
}
}
}
}
#[component]
pub fn Description(cx: Scope, tokens: Tokens) -> Element {
render! {
for token in &tokens.vec() {
match token {
Token::Text(text) => rsx! { "{text}" },
Token::NewLine => rsx! { br {} },
Token::Empty => rsx! { "" },
Token::Var(name) => rsx! {
span { class: "text-error", "[{name}]" }
},
Token::Error(text) => rsx! {
span { class: "text-error font-bold", "{text}" }
},
Token::Indent => rsx! {
br {}
" "
},
Token::Panic(text) => rsx! {
span { class: "text-error font-bold", "{text}" }
},
}
}
}
}