based/src/ui/container.rs
2025-01-14 22:56:07 +01:00

37 lines
912 B
Rust

use maud::{Markup, Render, html};
use super::UIWidget;
#[allow(non_snake_case)]
/// A component for fixing an element's width to the current breakpoint.
pub fn Container<T: UIWidget + 'static>(inner: T) -> ContainerWidget {
ContainerWidget(Box::new(inner))
}
pub struct ContainerWidget(Box<dyn UIWidget>);
impl Render for ContainerWidget {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl UIWidget for ContainerWidget {
fn can_inherit(&self) -> bool {
true
}
fn render_with_class(&self, class: &str) -> Markup {
if self.0.as_ref().can_inherit() {
self.0
.as_ref()
.render_with_class(&format!("container {class}"))
} else {
html! {
div class=(format!("container {class}")) {
(self.0.as_ref())
}
}
}
}
}