1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use yew::prelude::*;

/// # Button group
/// [ButtonGroup] is used to group several [crate::component::Button] instances together.
/// Buttons can be arranged vertically.
/// 
/// See [ButtonGroupProps] for a listing of properties.
/// 
/// ## Example
/// Example of a simple button group:
/// 
/// ```rust
/// use yew::prelude::*;
/// use yew_bootstrap::component::{Button, ButtonGroup};
/// use yew_bootstrap::util::Color;
/// fn test() -> Html {
///     html!{
///         <ButtonGroup class={ "class" }>
///             <Button style={Color::Primary} text={ "First button" }/>
///             <Button style={Color::Secondary} text={ "Second button" }/>
///         </ButtonGroup>
///     }
/// }
/// ```
pub struct ButtonGroup {}

/// Properties for [ButtonGroup]
#[derive(Properties, Clone, PartialEq)]
pub struct ButtonGroupProps {
    /// CSS class
    #[prop_or_default]
    pub class: String,

    /// Children for the group (Button instances)
    #[prop_or_default]
    pub children: Children,

    /// Aria label used for assistive technologies
    #[prop_or_default]
    pub label: String,

    /// Role, used for assistive technoligies to describe the purpose of the group.
    #[prop_or_default]
    pub role: String,

    /// If true, disposition is vertical (Default horizontal)
    #[prop_or_default]
    pub vertical: bool,
}

impl Component for ButtonGroup {
    type Message = ();
    type Properties = ButtonGroupProps;

    fn create(_ctx: &Context<Self>) -> Self {
        Self {}
    }

    fn view(&self, ctx: &Context<Self>) -> Html {
        let props = ctx.props();
        let mut classes = Classes::new();
        if props.vertical {
            classes.push("btn-group-vertical");
        } else {
            classes.push("btn-group");
        }
        classes.push(props.class.clone());

        html! {
            <div
                class={classes}
                role={props.role.clone()}
                aria-label={props.label.clone()}
            >
                { for props.children.iter() }
            </div>
        }
    }
}