use crate::assets::navbar_dropdown_styles::NAVBAR_DROPDOWN_STYLES;
use crate::assets::navbar_style::NAVBAR_STYLES;
use crate::enums::navbar_enums::NavbarConfig;
use crate::DropdownConfig;
use crate::{DropdownButtonConfig, DropdownMenu, DropdownMenuButton, Orientation};
use dioxus::prelude::*;
#[component]
pub fn Navbar(navbar_config: NavbarConfig) -> Element {
let mut menu_open = use_signal(|| false);
let orientation_class = match navbar_config
.orientation
.clone()
.unwrap_or(Orientation::Right)
{
Orientation::Left => "menu-items left",
Orientation::Center => "menu-items center",
Orientation::Right => "menu-items right",
};
rsx! {
div {
style { "{NAVBAR_STYLES}" }
nav {
class: "navbar",
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "nav-div",
div { class: "",
match &navbar_config.nav_header {
Some(header) => rsx! {
div {
class: "nav-header-wrapper",
style: "color: {navbar_config.header_color.as_css_class()};",
Link { to: "/", "{header}" }
}
},
None => rsx! {
div { class: "no-nav-header",
span { "" }
}
},
}
}
button {
class: "hamburger",
onclick: move |_| menu_open.set(!menu_open()),
match menu_open() {
true => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M18 6L6 18M6 6L18 18" }
}
}
}
false => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M4 6h16M4 12h16M4 18h16" }
}
}
}
}
}
}
div {
class: match menu_open() {
true => "menu open",
false => "menu",
},
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "{orientation_class}",
for (item , link) in navbar_config.nav_items.iter().zip(navbar_config.nav_links.iter()) {
Link {
class: "menu-item",
to: "{link}",
style: "color: {navbar_config.nav_item_color.as_css_class()};",
onclick: move |_| menu_open.set(false),
"{item}"
}
}
}
}
}
}
}
}
#[component]
pub fn NavbarDropdown(navbar_config: NavbarConfig, config_dropdown: DropdownConfig) -> Element {
let mut menu_open = use_signal(|| false);
let _dropdown_open = use_signal(|| None::<usize>);
let orientation_class = match navbar_config
.orientation
.clone()
.unwrap_or(Orientation::Right)
{
Orientation::Left => "menu-items left",
Orientation::Center => "menu-items center",
Orientation::Right => "menu-items right",
};
let has_header = navbar_config.nav_header.is_some();
let navbar_class = if has_header {
"navbar"
} else {
"navbar no-header"
};
rsx! {
div {
style { "{NAVBAR_DROPDOWN_STYLES}" }
nav {
class: "{navbar_class}",
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "nav-div",
div { class: "",
match &navbar_config.nav_header {
Some(header) => rsx! {
div {
class: "nav-header-wrapper",
style: "color: {navbar_config.header_color.as_css_class()};",
Link { to: "/", "{header}" }
}
},
None => rsx! {
div { class: "no-nav-header",
span { "" }
}
},
}
}
button {
class: "hamburger",
onclick: move |_| menu_open.set(!menu_open()),
match menu_open() {
true => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M18 6L6 18M6 6L18 18" }
}
}
}
false => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M4 6h16M4 12h16M4 18h16" }
}
}
}
}
}
}
div {
class: match menu_open() {
true => "menu open",
false => "menu",
},
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "{orientation_class}",
for (item , link) in navbar_config.nav_items.iter().zip(navbar_config.nav_links.iter()) {
Link {
class: "menu-item",
to: "{link}",
style: "color: {navbar_config.nav_item_color.as_css_class()};",
onclick: move |_| menu_open.set(false),
"{item}"
}
}
div { class: "dropdown-navbar",
DropdownMenu { config_dropdown: config_dropdown.clone() }
}
}
}
}
}
}
}
#[component]
pub fn NavbarDropdownButtons(
navbar_config: NavbarConfig,
config_dropdown: DropdownButtonConfig,
) -> Element {
let mut menu_open = use_signal(|| false);
let _dropdown_open = use_signal(|| None::<usize>);
let orientation_class = match navbar_config
.orientation
.clone()
.unwrap_or(Orientation::Right)
{
Orientation::Left => "menu-items left",
Orientation::Center => "menu-items center",
Orientation::Right => "menu-items right",
};
rsx! {
div {
style { "{NAVBAR_DROPDOWN_STYLES}" }
nav {
class: "navbar",
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "nav-div",
div { class: "",
match &navbar_config.nav_header {
Some(header) => rsx! {
div {
class: "nav-header-wrapper",
style: "color: {navbar_config.header_color.as_css_class()};",
Link { to: "/", "{header}" }
}
},
None => rsx! {
div { class: "no-nav-header",
span { "" }
}
},
}
}
button {
class: "hamburger",
onclick: move |_| menu_open.set(!menu_open()),
match menu_open() {
true => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M18 6L6 18M6 6L18 18" }
}
}
}
false => {
rsx! {
svg {
xmlns: "http://www.w3.org/2000/svg",
width: "32",
height: "32",
view_box: "0 0 24 24",
fill: "none",
stroke: "{navbar_config.icon_color.as_css_class()}",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: "M4 6h16M4 12h16M4 18h16" }
}
}
}
}
}
}
div {
class: match menu_open() {
true => "menu open",
false => "menu",
},
style: "background-color: {navbar_config.background_color.as_css_class()};",
div { class: "{orientation_class}",
for (item , link) in navbar_config.nav_items.iter().zip(navbar_config.nav_links.iter()) {
Link {
class: "menu-item",
to: "{link}",
style: "color: {navbar_config.nav_item_color.as_css_class()};",
onclick: move |_| menu_open.set(false),
"{item}"
}
}
div { class: "dropdown-navbar",
DropdownMenuButton { config_dropdown: config_dropdown.clone() }
}
}
}
}
}
}
}