Skip to main content

orbital_base_components/navigation/toolbar/
base.rs

1use leptos::prelude::*;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
4pub enum ToolbarSize {
5    Small,
6    #[default]
7    Medium,
8    Large,
9}
10
11impl ToolbarSize {
12    pub fn as_str(&self) -> &'static str {
13        match self {
14            Self::Small => "small",
15            Self::Medium => "medium",
16            Self::Large => "large",
17        }
18    }
19}
20
21#[component]
22pub fn BaseToolbar(
23    #[prop(optional, into)] class: MaybeProp<String>,
24    #[prop(optional)] vertical: bool,
25    #[prop(optional, into)] size: Signal<ToolbarSize>,
26    children: Children,
27) -> impl IntoView {
28    let orientation = move || if vertical { "vertical" } else { "horizontal" };
29
30    view! {
31        <div
32            class=move || {
33                let mut parts = vec![
34                    "orbital-toolbar".to_string(),
35                    format!("orbital-toolbar--{}", size.get().as_str()),
36                    format!("orbital-toolbar--{}", orientation()),
37                ];
38                if let Some(extra) = class.get() {
39                    if !extra.is_empty() {
40                        parts.push(extra);
41                    }
42                }
43                parts.join(" ")
44            }
45            role="toolbar"
46            aria-orientation=orientation
47        >
48            {children()}
49        </div>
50    }
51}