nes_yew/components/
checkbox.rs1use std::borrow::Cow;
2use yew::prelude::*;
3
4#[derive(Properties, PartialEq)]
5pub struct CheckboxProps {
6 #[prop_or_default]
7 pub checked: bool,
8 #[prop_or_default]
9 pub label: Option<AttrValue>,
10 #[prop_or_default]
11 pub on_select: Callback<()>,
12 pub class: Option<Cow<'static, str>>,
13 pub style: Option<AttrValue>,
14}
15
16#[function_component(Checkbox)]
17pub fn checkbox(
18 CheckboxProps {
19 label,
20 on_select,
21 checked,
22 class,
23 style,
24 }: &CheckboxProps,
25) -> Html {
26 let on_select = on_select.clone();
27 html! {
28 <div>
29 <label class="nes-checkbox-parent">
30 <input
31 type="checkbox"
32 class={classes!(class, "nes-checkbox")}
33 style={style.clone()}
34 checked={*checked}
35 onchange={Callback::from(move |_| on_select.emit(()))}
36 />
37 {label.as_ref().map(|l| html!{<span>{l}</span>})}
38 </label>
39 </div>
40 }
41}