Skip to main content

dioxus_bulma/components/
container.rs

1use dioxus::prelude::*;
2use crate::utils::build_class;
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum ContainerBreakpoint {
6    Widescreen,
7    FullHD,
8    MaxDesktop,
9    MaxWidescreen,
10}
11
12impl ContainerBreakpoint {
13    pub fn as_str(&self) -> &'static str {
14        match self {
15            ContainerBreakpoint::Widescreen => "is-widescreen",
16            ContainerBreakpoint::FullHD => "is-fullhd", 
17            ContainerBreakpoint::MaxDesktop => "is-max-desktop",
18            ContainerBreakpoint::MaxWidescreen => "is-max-widescreen",
19        }
20    }
21}
22
23#[derive(Props, Clone, PartialEq)]
24pub struct ContainerProps {
25    #[props(default)]
26    pub fluid: Option<bool>,
27    #[props(default)]
28    pub breakpoint: Option<ContainerBreakpoint>,
29    #[props(default)]
30    pub id: Option<String>,
31    #[props(default)]
32    pub class: Option<String>,
33    #[props(default)]
34    pub style: Option<String>,
35    pub children: Element,
36}
37
38#[component]
39pub fn Container(props: ContainerProps) -> Element {
40    let fluid = props.fluid.unwrap_or(false);
41    
42    let base_classes = vec!["container"];
43    
44    let optional_classes = vec![
45        if fluid { Some("is-fluid".to_string()) } else { None },
46        props.breakpoint.map(|bp| bp.as_str().to_string()),
47        props.class.clone(),
48    ];
49    
50    let final_class = build_class(&base_classes, &optional_classes);
51    let container_style = props.style.as_deref().unwrap_or("");
52
53    rsx! {
54        div {
55            class: "{final_class}",
56            style: "{container_style}",
57            id: props.id.clone(),
58            {props.children}
59        }
60    }
61}