diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-09-06 22:07:28 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-09-06 22:07:28 -0400 |
commit | cab440c8a209ae92eba07d50f7b7127dadbd65c0 (patch) | |
tree | 95ad002ad00b6ae99baeb410cc23195286cf5d45 /webapp/src/components/hand.rs | |
parent | 77ed77bfa3480a06a3f36b072af5eb8712a1515c (diff) |
Move components to a separate module
Diffstat (limited to 'webapp/src/components/hand.rs')
-rw-r--r-- | webapp/src/components/hand.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/webapp/src/components/hand.rs b/webapp/src/components/hand.rs new file mode 100644 index 0000000..1a2727c --- /dev/null +++ b/webapp/src/components/hand.rs @@ -0,0 +1,38 @@ +use yew::prelude::*; +use crate::components::card::{Card, CardProps}; + +#[function_component(Hand)] +pub fn hand(props: &HandProps) -> Html { + let cards: Html = props + .cards + .iter() + .map(|c| { + html! { + <Card ..c.clone() /> + } + }) + .collect(); + + html! { + <div class="hand"> + { cards } + </div> + } +} + +#[derive(Clone, Default, PartialEq, Properties)] +pub struct HandProps { + #[prop_or_default] + cards: Vec<CardProps>, +} + +impl<C: Into<CardProps>> FromIterator<C> for HandProps { + fn from_iter<Cards>(cards: Cards) -> Self + where + Cards: std::iter::IntoIterator<Item = C>, + { + HandProps { + cards: cards.into_iter().map(Into::into).collect(), + } + } +} |