yew_bootstrap/component/
column.rs1use gloo_console::warn;
2use yew::prelude::*;
3
4pub struct Column {}
23
24#[derive(Properties, Clone, PartialEq)]
26pub struct ColumnProps {
27 #[prop_or_default]
29 pub class: String,
30
31 #[prop_or_default]
33 pub children: Children,
34
35 #[prop_or(Some(0))]
37 pub size: Option<u8>,
38
39 #[prop_or_default]
41 pub sm: Option<u8>,
42
43 #[prop_or_default]
45 pub md: Option<u8>,
46
47 #[prop_or_default]
49 pub lg: Option<u8>,
50
51 #[prop_or_default]
53 pub xl: Option<u8>,
54
55 #[prop_or_default]
57 pub xxl: Option<u8>,
58
59 #[prop_or_default]
61 pub onclick: Callback<MouseEvent>,
62}
63
64impl Component for Column {
65 type Message = ();
66 type Properties = ColumnProps;
67
68 fn create(_ctx: &Context<Self>) -> Self {
69 Self {}
70 }
71
72 fn view(&self, ctx: &Context<Self>) -> Html {
73 let props = ctx.props();
74 if props.size.unwrap_or(0) > 12 {
75 warn!("Column `size` cannot be greater than 12");
76 }
77 if props.sm.unwrap_or(0) > 12 {
78 warn!("Column `sm` size cannot be greater than 12");
79 }
80 if props.md.unwrap_or(0) > 12 {
81 warn!("Column `md` size cannot be greater than 12");
82 }
83 if props.lg.unwrap_or(0) > 12 {
84 warn!("Column `lg` size cannot be greater than 12");
85 }
86 if props.xl.unwrap_or(0) > 12 {
87 warn!("Column `xl` size cannot be greater than 12");
88 }
89 if props.xxl.unwrap_or(0) > 12 {
90 warn!("Column `xxl` size cannot be greater than 12");
91 }
92 let mut classes = Classes::new();
93 if let Some(size) = props.size {
94 if size == 0 {
95 classes.push("col");
96 } else {
97 classes.push("col-".to_string() + &size.to_string());
98 }
99 }
100 if let Some(sm) = props.sm {
101 classes.push("col-sm-".to_string() + &sm.to_string());
102 }
103 if let Some(md) = props.md {
104 classes.push("col-md-".to_string() + &md.to_string());
105 }
106 if let Some(lg) = props.lg {
107 classes.push("col-lg-".to_string() + &lg.to_string());
108 }
109 if let Some(xl) = props.xl {
110 classes.push("col-xl-".to_string() + &xl.to_string());
111 }
112 if let Some(xxl) = props.xxl {
113 classes.push("col-xxl-".to_string() + &xxl.to_string());
114 }
115 classes.push(props.class.clone());
116
117 html! {
118 <div
119 class={classes}
120 onclick={props.onclick.clone()}
121 >
122 { for props.children.iter() }
123 </div>
124 }
125 }
126}