summaryrefslogtreecommitdiff
path: root/webapp/src/components/hand.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-09-06 22:07:28 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-09-06 22:07:28 -0400
commitcab440c8a209ae92eba07d50f7b7127dadbd65c0 (patch)
tree95ad002ad00b6ae99baeb410cc23195286cf5d45 /webapp/src/components/hand.rs
parent77ed77bfa3480a06a3f36b072af5eb8712a1515c (diff)
Move components to a separate module
Diffstat (limited to 'webapp/src/components/hand.rs')
-rw-r--r--webapp/src/components/hand.rs38
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(),
+ }
+ }
+}