Skip to main content

basecoat_core/props/
tabs.rs

1use crate::{AttrMap, BasecoatProps};
2use std::borrow::Cow;
3
4/// Tabs orientation — upstream uses `aria-orientation` on the tablist `<nav>`.
5#[derive(Clone, Debug, PartialEq, Eq, Default)]
6pub enum TabsOrientation {
7    #[default]
8    Horizontal,
9    Vertical,
10}
11
12impl std::fmt::Display for TabsOrientation {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            TabsOrientation::Horizontal => f.write_str("horizontal"),
16            TabsOrientation::Vertical => f.write_str("vertical"),
17        }
18    }
19}
20
21/// A single tab within a `TabsProps`.
22#[derive(Clone, Debug, Default)]
23pub struct TabSet {
24    /// Tab button content (HTML).
25    pub tab: Cow<'static, str>,
26    /// Tab panel content (HTML), optional.
27    pub panel: Option<Cow<'static, str>>,
28}
29
30/// Tabs — maps to CSS class `.tabs`.
31#[derive(BasecoatProps, Default, Clone, Debug)]
32pub struct TabsProps {
33    /// Unique DOM id — required for the WASM controller.
34    #[prop(optional, into)]
35    pub id: Option<Cow<'static, str>>,
36    /// The tab sets (tab buttons + panels).
37    #[prop(default)]
38    pub tabsets: Vec<TabSet>,
39    /// 1-based index of the initially active tab.
40    #[prop(default = 1usize)]
41    pub default_tab_index: usize,
42    #[prop(default)]
43    pub orientation: TabsOrientation,
44    #[prop(optional, into)]
45    pub class: Option<Cow<'static, str>>,
46    #[prop(extend)]
47    pub attrs: AttrMap,
48}