use crate::assets::tabs_styles::{TABS_SECONDARY_STYLES, TABS_STYLES};
use crate::enums::tabs_enums::{TabsColor, TabsProps};
use crate::TabsSecondaryProps;
use dioxus::prelude::*;
#[component]
pub fn TabsPrimary(props: TabsProps) -> Element {
let mut active_tab_idx = use_signal(|| 0);
let text = match &props.custom_texts {
Some(custom_texts) => custom_texts.get(active_tab_idx()).cloned(),
None => Some(rsx! {}),
};
let custom_styles = if let Some(TabsColor::Custom(color)) = &props.custom_color {
format!(
r#"
.custom-tab-item {{
color: {color};
border-bottom-color: transparent;
}}
.custom-tab-item:hover {{
color: {color};
border-bottom-color: {color};
}}
.custom-tab-item.active-tab {{
color: {color};
border-bottom-color: {color};
}}
"#
)
} else {
String::new()
};
let style_tag = rsx! {
style {
"{TABS_STYLES}"
"{custom_styles}"
}
};
rsx! {
div {
{style_tag}
div { id: "tabs", class: "tabs-container",
div { class: "tabs-navigation",
for (idx , tab_name) in props.tabs_names.iter().enumerate() {
div {
class: format!(
"tab-item {} {} {}",
if matches!(&props.custom_color, Some(TabsColor::Custom(_))) {
"custom-tab-item"
} else {
""
},
props.custom_color.as_ref().map_or("", |color| color.to_css_class()),
if active_tab_idx() == idx { "active-tab" } else { "" },
),
onclick: move |_| active_tab_idx.set(idx),
"{tab_name}"
}
}
}
div { class: "tab-content", {text} }
}
}
}
}
#[component]
pub fn TabsSecondary(props: TabsSecondaryProps) -> Element {
let custom_style = format!(
r#"
:root {{
--tab-max-width: {};
--tab-header-hover: {};
--tab-header-bg: {};
--tab-header-text: {};
--tab-active-bg: {};
--tab-active-text: {};
--tab-radius: {};
--tab-shadow: {};
}}
"#,
props
.tab_max_width
.clone()
.unwrap_or_else(|| "700px".to_string()),
props
.tab_header_hover
.clone()
.unwrap_or_else(|| "#e5e5e5".to_string()),
props
.header_bg_color
.clone()
.unwrap_or_else(|| "#e5e5e5".to_string()),
props
.header_text_color
.clone()
.unwrap_or_else(|| "#7f7f7f".to_string()),
props
.active_bg_color
.clone()
.unwrap_or_else(|| "#ffffff".to_string()),
props
.active_text_color
.clone()
.unwrap_or_else(|| "#000000".to_string()),
props
.tab_radius
.clone()
.unwrap_or_else(|| "1em 1em 1em 1em)".to_string()),
props.tab_shadow.clone().unwrap_or_else(|| "".to_string()),
);
let style_tag = rsx! {
style { "{TABS_SECONDARY_STYLES}" }
style { "{custom_style}" }
};
let texts = props.custom_texts.clone().unwrap_or_default();
rsx! {
div {
{style_tag}
div { class: "tabs",
for (idx , name) in props.tabs_names.iter().enumerate() {
input {
r#type: "radio",
class: "input",
id: format!("tab-{idx}"),
name: "tabs",
checked: idx == 0,
}
label {
class: "label label-default",
r#for: format!("tab-{idx}"),
"{name}"
}
div { class: "panel",
{texts.get(idx).cloned().unwrap_or(rsx! {
div {}
})}
}
}
}
}
}
}