yew_bs/components/
float.rs

1use yew::prelude::*;
2use crate::components::common::Breakpoint;
3#[derive(Clone, Copy, PartialEq, Debug)]
4pub enum FloatDirection {
5    Start,
6    End,
7    None,
8}
9impl FloatDirection {
10    pub fn as_str(&self) -> &'static str {
11        match self {
12            FloatDirection::Start => "start",
13            FloatDirection::End => "end",
14            FloatDirection::None => "none",
15        }
16    }
17}
18/// Props for the Float component
19#[derive(Properties, PartialEq)]
20pub struct FloatProps {
21    /// The float direction to apply
22    pub direction: FloatDirection,
23    /// Optional breakpoint for responsive float
24    #[prop_or_default]
25    pub breakpoint: Option<Breakpoint>,
26    /// The child elements to be floated
27    #[prop_or_default]
28    pub children: Children,
29    /// Additional CSS classes to apply
30    #[prop_or_default]
31    pub class: Option<AttrValue>,
32    /// The HTML element to use (defaults to div)
33    #[prop_or("div".into())]
34    pub tag: AttrValue,
35}
36/// A utility component for applying Bootstrap float utility classes
37///
38/// The Float component provides easy access to Bootstrap's float utilities,
39#[function_component(Float)]
40pub fn float(props: &FloatProps) -> Html {
41    let mut classes = Classes::new();
42    let class_name = if let Some(breakpoint) = &props.breakpoint {
43        format!("float-{}-{}", breakpoint.as_str(), props.direction.as_str())
44    } else {
45        format!("float-{}", props.direction.as_str())
46    };
47    classes.push(class_name);
48    if let Some(custom_class) = &props.class {
49        classes.push(custom_class.to_string());
50    }
51    let tag = props.tag.clone();
52    html! {
53        <@ { tag.to_string() } class = { classes } > { for props.children.iter() } </@>
54    }
55}
56#[derive(Properties, PartialEq)]
57pub struct ClearfixProps {
58    #[prop_or_default]
59    pub children: Children,
60    #[prop_or_default]
61    pub class: Option<AttrValue>,
62}
63#[function_component(Clearfix)]
64pub fn clearfix(props: &ClearfixProps) -> Html {
65    let mut classes = Classes::new();
66    classes.push("clearfix");
67    if let Some(custom_class) = &props.class {
68        classes.push(custom_class.to_string());
69    }
70    html! {
71        < div class = { classes } > { for props.children.iter() } </ div >
72    }
73}