yew_bootstrap/component/
line.rs1use crate::util::*;
2use yew::prelude::*;
3
4pub struct Line {}
22
23#[derive(Properties, Clone, PartialEq)]
25pub struct LineProps {
26 #[prop_or_default]
28 pub class: String,
29
30 #[prop_or_default]
32 pub height: Option<Size>,
33
34 #[prop_or_default]
36 pub vertical: bool,
37
38 #[prop_or_default]
40 pub style: Option<Color>,
41
42 #[prop_or_default]
44 pub width: Option<Size>,
45}
46
47impl Component for Line {
48 type Message = ();
49 type Properties = LineProps;
50
51 fn create(_ctx: &Context<Self>) -> Self {
52 Self {}
53 }
54
55 fn view(&self, ctx: &Context<Self>) -> Html {
56 let props = ctx.props();
57 let mut classes = Classes::new();
58 if props.vertical {
59 classes.push("vr");
60 }
61 if let Some(style) = props.style.clone() {
62 classes.push(format!("bg-{}", style));
63 }
64 classes.push(props.class.clone());
65
66 let mut css = String::new();
67 if let Some(height) = props.height.clone() {
68 css = format!("height: {}", height);
69 }
70 if let Some(width) = props.width.clone() {
71 css = format!("{}; width: {}", css, width);
72 }
73
74 if props.vertical {
75 html! {
76 <div class={classes} style={css} />
77 }
78 } else {
79 html! {
80 <hr class={classes} style={css} />
81 }
82 }
83 }
84}