mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* remove ToHtml trait * re-add display impls * make Vec::clone expilit * fix doc * fix conflicting impls Into<Html> and Display can't be implemented on the same type * update docs * blanket impl won't work here * bring back `Vec<VNode>: IntoPropValue<VNode>` * macro tests * Revert "fix conflicting impls" This reverts commit 52f3c1fa8174489ba9cc783d708a49cc7b9c90a4. These impls are fine now * make examples compile * .clone() should be before .into() * Rc VList * Make use of ImplicitClone and AttrValue in example (There is more work to do but it's complicated so I will do it in another PR) * Impl ImplicitClone on VChild --------- Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
use yew::prelude::*;
|
|
|
|
use crate::Hovered;
|
|
|
|
#[derive(PartialEq, Clone, Properties)]
|
|
pub struct Props {
|
|
#[prop_or_default]
|
|
pub hide: bool,
|
|
pub on_hover: Callback<Hovered>,
|
|
pub name: AttrValue,
|
|
#[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();
|
|
ctx.props().on_hover.reform(move |e: MouseEvent| {
|
|
e.stop_propagation();
|
|
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>
|
|
}
|
|
}
|
|
}
|
|
}
|