use leptos::prelude::*;
use leptos_router::hooks::use_navigate;
use phosphor_leptos::CARET_LEFT;
use crate::components::button::{BtnVariant, ButtonIcon};
use crate::components::Button;
#[component]
pub fn NavigationBackButton(#[prop(optional)] class: Option<&'static str>) -> impl IntoView {
let navigate = use_navigate();
let on_click = Callback::new(move |_| {
#[cfg(not(feature = "ssr"))]
{
if let Some(window) = web_sys::window() {
if let Ok(history) = window.history() {
if let Ok(length) = history.length() {
if length > 1 {
let _ = history.back();
return;
}
}
}
}
}
let navigate = navigate.clone();
navigate("/", Default::default());
});
view! {
<Button
variant=BtnVariant::Square
icon=ButtonIcon::Icon(&CARET_LEFT)
on_click=on_click
class=class.unwrap_or("")
/>
}
}