Button
Buttons trigger actions or events.
Basic Usage
#![allow(unused)]
fn main() {
use blinc_cn::prelude::*;
button("Click me")
.on_click(|| println!("Clicked!"))
}
Variants
Buttons come in several visual variants:
#![allow(unused)]
fn main() {
// Primary (default) - Main actions
button("Save").variant(ButtonVariant::Primary)
// Secondary - Alternative actions
button("Cancel").variant(ButtonVariant::Secondary)
// Destructive - Dangerous actions
button("Delete").variant(ButtonVariant::Destructive)
// Outline - Bordered style
button("Edit").variant(ButtonVariant::Outline)
// Ghost - Minimal style
button("More").variant(ButtonVariant::Ghost)
// Link - Looks like a link
button("Learn more").variant(ButtonVariant::Link)
}
Sizes
#![allow(unused)]
fn main() {
// Small
button("Small").size(ButtonSize::Sm)
// Default
button("Default").size(ButtonSize::Default)
// Large
button("Large").size(ButtonSize::Lg)
// Icon only (square)
button("").size(ButtonSize::Icon).icon(icons::SETTINGS)
}
With Icons
#![allow(unused)]
fn main() {
use blinc_icons::icons;
// Icon before text
button("Settings")
.icon(icons::SETTINGS)
// Icon after text
button("Next")
.icon_right(icons::ARROW_RIGHT)
// Icon only
button("")
.size(ButtonSize::Icon)
.icon(icons::PLUS)
}
States
#![allow(unused)]
fn main() {
// Disabled
button("Disabled")
.disabled(true)
// Loading
button("Saving...")
.loading(true)
// Full width
button("Submit")
.full_width(true)
}
Event Handling
#![allow(unused)]
fn main() {
button("Submit")
.on_click(|| {
// Handle click
submit_form();
})
.on_hover(|hovering| {
// Handle hover state
if hovering {
show_tooltip();
}
})
}
Button Groups
#![allow(unused)]
fn main() {
div()
.flex_row()
.gap(8.0)
.child(button("Save").variant(ButtonVariant::Primary))
.child(button("Cancel").variant(ButtonVariant::Outline))
}
Examples
Form Submit Button
#![allow(unused)]
fn main() {
button("Create Account")
.variant(ButtonVariant::Primary)
.size(ButtonSize::Lg)
.full_width(true)
.on_click(|| handle_submit())
}
Icon Button
#![allow(unused)]
fn main() {
button("")
.size(ButtonSize::Icon)
.variant(ButtonVariant::Ghost)
.icon(icons::X)
.on_click(|| close_dialog())
}
Loading Button
#![allow(unused)]
fn main() {
let is_loading = use_state(false);
button(if is_loading { "Saving..." } else { "Save" })
.loading(is_loading)
.disabled(is_loading)
.on_click(|| {
set_loading(true);
save_data().then(|| set_loading(false));
})
}
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | ButtonVariant | Primary | Visual style |
size | ButtonSize | Default | Button size |
disabled | bool | false | Disable interaction |
loading | bool | false | Show loading state |
full_width | bool | false | Expand to full width |
icon | &str | None | Icon before text |
icon_right | &str | None | Icon after text |
Events
| Event | Type | Description |
|---|---|---|
on_click | Fn() | Called when clicked |
on_hover | Fn(bool) | Called on hover change |