pub struct ButtonProps {
pub color: Color,
pub outline: bool,
pub size: Size,
pub disabled: bool,
pub href: Option<String>,
pub target: Option<String>,
pub download: Option<String>,
pub type: String,
pub onclick: Option<EventHandler<MouseEvent>>,
pub active: bool,
pub class: String,
pub children: Element,
/* private fields */
}Expand description
Bootstrap Button component.
Renders a <button> by default. When href is set, renders an <a> element
instead (Bootstrap link-button pattern).
Accepts all standard HTML attributes via extends = GlobalAttributes.
This means title, data-bs-toggle, aria-label, id, etc. all work.
§Bootstrap HTML → Dioxus
| HTML | Dioxus |
|---|---|
<button class="btn btn-primary"> | Button { color: Color::Primary, "Text" } |
<button class="btn btn-outline-danger btn-sm"> | Button { color: Color::Danger, outline: true, size: Size::Sm, "Text" } |
<button class="btn btn-success btn-lg" disabled> | Button { color: Color::Success, size: Size::Lg, disabled: true, "Text" } |
<a class="btn btn-primary" href="/page"> | Button { color: Color::Primary, href: "/page", "Link" } |
<a class="btn btn-sm" href="f.json" target="_blank" download="f.json"> | Button { size: Size::Sm, href: "f.json", target: "_blank", download: "f.json", "DL" } |
<button class="btn btn-primary" title="Tip"> | Button { color: Color::Primary, title: "Tip", "Text" } |
rsx! {
Button { color: Color::Primary, "Click me" }
Button { color: Color::Danger, outline: true, size: Size::Sm, "Delete" }
Button { color: Color::Success, disabled: true, "Saved" }
Button { color: Color::Warning, onclick: move |_| { /* handler */ }, "Action" }
// Link button — renders <a> instead of <button>:
Button { color: Color::Primary, href: "/page", "Go to Page" }
// HTML attributes work directly:
Button { color: Color::Secondary, title: "Tooltip text", "Hover me" }
Button { color: Color::Primary, "data-bs-toggle": "modal", "Open Modal" }
}Fields§
§color: ColorButton color variant.
outline: boolUse outline style instead of filled.
size: SizeButton size.
disabled: boolWhether the button is disabled.
href: Option<String>When set, renders an <a> element instead of <button> (link-button pattern).
target: Option<String>Link target (e.g., "_blank"). Only used when href is set.
download: Option<String>Download filename. Only used when href is set.
type: StringHTML button type attribute (ignored when href is set).
onclick: Option<EventHandler<MouseEvent>>Click event handler.
active: boolActive (pressed) state.
class: StringAdditional CSS classes.
children: ElementChild elements.
Implementations§
Source§impl ButtonProps
impl ButtonProps
Sourcepub fn builder() -> ButtonPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), ())>
pub fn builder() -> ButtonPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), ())>
Create a builder for building ButtonProps.
On the builder, call .color(...)(optional), .outline(...)(optional), .size(...)(optional), .disabled(...)(optional), .href(...)(optional), .target(...)(optional), .download(...)(optional), .r#type(...)(optional), .onclick(...)(optional), .active(...)(optional), .class(...)(optional), .attributes(...)(optional), .children(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of ButtonProps.
Trait Implementations§
Source§impl Clone for ButtonProps
impl Clone for ButtonProps
Source§fn clone(&self) -> ButtonProps
fn clone(&self) -> ButtonProps
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more