leptos_bootstrap/v5/
list.rs

1use leptos::prelude::*;
2use std::fmt;
3
4#[component]
5pub fn ListGroup<'a>(
6    #[prop(default = false)] numbered: bool,
7    #[prop(default = false)] flush: bool,
8    #[prop(default = false)] horizontal: bool,
9    #[prop(optional, into)] class: &'a str,
10    children: Children,
11) -> impl IntoView {
12    let mut class = format!("list-group {}", class);
13    if flush {
14        class.push_str(" list-group-flush");
15    }
16    if numbered {
17        class.push_str(" list-group-numbered");
18    }
19    if horizontal {
20        class.push_str(" list-group-horizontal");
21    }
22    view! { <ul class=class>{children()}</ul> }
23}
24
25pub enum ListGroupItemKind {
26    Default,
27    Primary,
28    Secondary,
29    Success,
30    Danger,
31    Warning,
32    Info,
33    Light,
34    Dark,
35}
36
37impl fmt::Display for ListGroupItemKind {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        let s = match self {
40            Self::Default => "",
41            Self::Primary => "list-group-item-primary",
42            Self::Secondary => "list-group-item-secondary",
43            Self::Success => "list-group-item-success",
44            Self::Danger => "list-group-item-danger",
45            Self::Warning => "list-group-item-warning",
46            Self::Info => "list-group-item-info",
47            Self::Light => "list-group-item-light",
48            Self::Dark => "list-group-item-dark",
49        };
50        write!(f, "{}", s)
51    }
52}
53
54#[component]
55pub fn ListGroupItem<'a>(
56    #[prop(default = ListGroupItemKind::Default)] kind: ListGroupItemKind,
57    #[prop(default = false)] active: bool,
58    #[prop(optional, into)] class: &'a str,
59    children: Children,
60) -> impl IntoView {
61    let mut class = format!("list-group-item {} {}", kind, class);
62    if active {
63        class.push_str(" active");
64    }
65    view! { <li class=class>{children()}</li> }
66}