summaryrefslogtreecommitdiff
path: root/webapp/src/components/card.rs
blob: 82d4fcbe03335801b14c1f4188a83f51a439deb3 (plain)
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
use crate::components::suit_css_class;
use protocol::card;
use yew::prelude::*;

#[function_component(Card)]
pub fn ccard(props: &CardProps) -> Html {
    let card::Card(suit, rank) = props.card;

    let onclick = {
        let card = props.card.clone();
        let onclick = props.onclick.clone();
        Callback::from(move |_| onclick.emit(card))
    };

    html! {
        <div class="card" {onclick}>
            <div class={ suit_css_class(suit) }>
                { rank }
            </div>
        </div>
    }
}

#[derive(PartialEq, Properties, Clone)]
pub struct CardProps {
    pub card: card::Card,
    #[prop_or_default]
    pub onclick: Callback<card::Card>,
}