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! {
23        <ul class=class>
24            {children()}
25        </ul>
26    }
27}
28
29pub enum ListGroupItemKind {
30    Default,
31    Primary,
32    Secondary,
33    Success,
34    Danger,
35    Warning,
36    Info,
37    Light,
38    Dark,
39}
40
41impl fmt::Display for ListGroupItemKind {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        let s = match self {
44            Self::Default => "",
45            Self::Primary => "list-group-item-primary",
46            Self::Secondary => "list-group-item-secondary",
47            Self::Success => "list-group-item-success",
48            Self::Danger => "list-group-item-danger",
49            Self::Warning => "list-group-item-warning",
50            Self::Info => "list-group-item-info",
51            Self::Light => "list-group-item-light",
52            Self::Dark => "list-group-item-dark",
53        };
54        write!(f, "{}", s)
55    }
56}
57
58#[component]
59pub fn ListGroupItem<'a>(
60    #[prop(default = ListGroupItemKind::Default)] kind: ListGroupItemKind,
61    #[prop(default = false)] active: bool,
62    #[prop(optional, into)] class: &'a str,
63    children: Children,
64) -> impl IntoView {
65    let mut class = format!("list-group-item {} {}", kind, class);
66    if active {
67        class.push_str(" active");
68    }
69    view! {
70        <li class=class>
71            {children()}
72        </li>
73    }
74}