Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/router/src/components/history_buttons.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dioxus_core::{Element, VNode};
use dioxus_core::{Attribute, Element, VNode};
use dioxus_core_macro::{rsx, Props};
use dioxus_html as dioxus_elements;

Expand All @@ -11,6 +11,10 @@ use crate::utils::use_router_internal::use_router_internal;
pub struct HistoryButtonProps {
/// The children to render within the generated HTML button tag.
pub children: Element,

/// Additional attributes to pass to the button element.
#[props(extends = GlobalAttributes)]
attributes: Vec<Attribute>,
}

/// A button to go back through the navigation history. Similar to a browsers back button.
Expand Down Expand Up @@ -43,6 +47,7 @@ pub struct HistoryButtonProps {
/// fn Index() -> Element {
/// rsx! {
/// GoBackButton {
/// class: "btn btn-primary",
/// "go back"
/// }
/// }
Expand All @@ -52,11 +57,14 @@ pub struct HistoryButtonProps {
/// # vdom.rebuild_in_place();
/// # assert_eq!(
/// # dioxus_ssr::render(&vdom),
/// # r#"<button disabled="true">go back</button>"#
/// # r#"<button disabled="true" class="btn btn-primary">go back</button>"#
/// # );
/// ```
pub fn GoBackButton(props: HistoryButtonProps) -> Element {
let HistoryButtonProps { children } = props;
let HistoryButtonProps {
children,
attributes,
} = props;

// hook up to router
let router = match use_router_internal() {
Expand All @@ -80,6 +88,7 @@ pub fn GoBackButton(props: HistoryButtonProps) -> Element {
evt.prevent_default();
router.go_back()
},
..attributes,
{children}
}
}
Expand Down Expand Up @@ -115,6 +124,7 @@ pub fn GoBackButton(props: HistoryButtonProps) -> Element {
/// fn Index() -> Element {
/// rsx! {
/// GoForwardButton {
/// class: "btn btn-primary",
/// "go forward"
/// }
/// }
Expand All @@ -124,11 +134,14 @@ pub fn GoBackButton(props: HistoryButtonProps) -> Element {
/// # vdom.rebuild_in_place();
/// # assert_eq!(
/// # dioxus_ssr::render(&vdom),
/// # r#"<button disabled="true">go forward</button>"#
/// # r#"<button disabled="true" class="btn btn-primary">go forward</button>"#
/// # );
/// ```
pub fn GoForwardButton(props: HistoryButtonProps) -> Element {
let HistoryButtonProps { children } = props;
let HistoryButtonProps {
children,
attributes,
} = props;

// hook up to router
let router = match use_router_internal() {
Expand All @@ -152,6 +165,7 @@ pub fn GoForwardButton(props: HistoryButtonProps) -> Element {
evt.prevent_default();
router.go_forward()
},
..attributes,
{children}
}
}
Expand Down
Loading