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
use css_in_rust_next::Style;
use yew::{html, Children, Component, Context, Html, Properties};
#[derive(PartialEq, Properties)]
pub struct FieldProperties {
pub label: String,
#[prop_or_default]
pub children: Children,
}
pub struct Field {
style: Style,
}
impl Component for Field {
type Message = ();
type Properties = FieldProperties;
fn create(_ctx: &Context<Self>) -> Self {
let style = Style::create(
"Component",
r#"
label.fieldTitle,
span.fieldInner {
vertical-align: bottom;
line-height: 23px;
padding: 3px;
}
label.fieldTitle {
display: inline-block;
width: 200px;
overflow: hidden;
}
"#,
)
.unwrap();
Self { style }
}
fn view(&self, ctx: &Context<Self>) -> Html {
html!(
<div class={self.style.clone()}>
<label class="fieldTitle">
{&ctx.props().label}
</label>
<span class="fieldInner">
{ for ctx.props().children.iter() }
</span>
</div>
)
}
}