forked from yewstack/yew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.rs
54 lines (48 loc) · 1.25 KB
/
item.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
use crate::Hovered;
use yew::prelude::*;
#[derive(PartialEq, Clone, Properties)]
pub struct Props {
#[prop_or_default]
pub hide: bool,
pub on_hover: Callback<Hovered>,
pub name: String,
#[prop_or_default]
pub children: Children,
}
pub struct ListItem;
impl Component for ListItem {
type Message = ();
type Properties = Props;
fn create(_ctx: &Context<Self>) -> Self {
Self
}
fn view(&self, ctx: &Context<Self>) -> Html {
let onmouseover = {
let name = ctx.props().name.clone();
let on_hover = ctx.props().on_hover.clone();
move |e: MouseEvent| {
e.stop_propagation();
on_hover.emit(Hovered::Item(name.clone()))
}
};
html! {
<div class="list-item" {onmouseover}>
{ &ctx.props().name }
{ Self::view_details(&ctx.props().children) }
</div>
}
}
}
impl ListItem {
fn view_details(children: &Children) -> Html {
if children.is_empty() {
html! {}
} else {
html! {
<div class="list-item-details">
{ children.clone() }
</div>
}
}
}
}