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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crate::styles::{get_palette, get_size, get_style, Palette, Size, Style};
use stylist::{css, StyleSource};
use wasm_bindgen_test::*;
use yew::prelude::*;
use yew::{utils, App};
pub struct FormSubmit {
props: Props,
}
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
pub value: String,
#[prop_or(Palette::Standard)]
pub submit_palette: Palette,
#[prop_or(Style::Regular)]
pub submit_style: Style,
#[prop_or(Size::Medium)]
pub size: Size,
#[prop_or(false)]
pub disabled: bool,
#[prop_or_default]
pub code_ref: NodeRef,
#[prop_or_default]
pub key: String,
#[prop_or_default]
pub class_name: String,
#[prop_or_default]
pub id: String,
#[prop_or(css!(""))]
pub styles: StyleSource<'static>,
}
impl Component for FormSubmit {
type Message = ();
type Properties = Props;
fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self { props }
}
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
false
}
fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props != props {
self.props = props;
true
} else {
false
}
}
fn view(&self) -> Html {
html! {
<input
type="submit"
key=self.props.key.clone()
ref=self.props.code_ref.clone()
class=classes!(
"form-submit",
get_style(self.props.submit_style.clone()),
get_palette(self.props.submit_palette.clone()),
get_size(self.props.size.clone()),
self.props.class_name.clone())
disabled=self.props.disabled
id=self.props.id.clone()
value=self.props.value.clone()
/>
}
}
}
#[wasm_bindgen_test]
fn should_create_form_submit() {
let props = Props {
value: "submit".to_string(),
disabled: false,
key: "".to_string(),
code_ref: NodeRef::default(),
id: "result".to_string(),
class_name: "form-submit-test".to_string(),
submit_style: Style::Regular,
submit_palette: Palette::Standard,
size: Size::Medium,
styles: css!("background-color: #918d94;"),
};
let form_submit: App<FormSubmit> = App::new();
form_submit.mount_with_props(
utils::document().get_element_by_id("output").unwrap(),
props,
);
let form_submit_element = utils::document().get_element_by_id("result").unwrap();
assert_eq!(form_submit_element.tag_name(), "INPUT");
}