use dioxus::prelude::*;
const BOOTSTRAP_CSS: Asset = asset!("/assets/bootstrap.min.css");
const BOOTSTRAP_ICONS_CSS: Asset = asset!("/assets/bootstrap-icons.min.css");
#[derive(Clone, PartialEq, Default)]
pub enum BootstrapCss {
#[default]
Bundled,
Url(String),
Cdn(String),
None,
}
#[derive(Clone, PartialEq, Default)]
pub enum BootstrapIcons {
#[default]
Bundled,
Url(String),
None,
}
#[derive(Clone, PartialEq, Props)]
pub struct BootstrapHeadProps {
#[props(default)]
pub css: BootstrapCss,
#[props(default)]
pub icons: BootstrapIcons,
}
#[component]
pub fn BootstrapHead(props: BootstrapHeadProps) -> Element {
let css_element = match &props.css {
BootstrapCss::Bundled => rsx! {
document::Link { rel: "stylesheet", href: BOOTSTRAP_CSS }
},
BootstrapCss::Url(url) => {
let url = url.clone();
rsx! { link { rel: "stylesheet", href: "{url}" } }
}
BootstrapCss::Cdn(version) => {
let href = format!(
"https://cdn.jsdelivr.net/npm/bootstrap@{version}/dist/css/bootstrap.min.css"
);
rsx! { link { rel: "stylesheet", href: "{href}" } }
}
BootstrapCss::None => rsx! {},
};
let icons_element = match &props.icons {
BootstrapIcons::Bundled => rsx! {
document::Link { rel: "stylesheet", href: BOOTSTRAP_ICONS_CSS }
},
BootstrapIcons::Url(url) => {
let url = url.clone();
rsx! { link { rel: "stylesheet", href: "{url}" } }
}
BootstrapIcons::None => rsx! {},
};
rsx! {
{css_element}
{icons_element}
}
}