Skip to main content

orbital_base_components/floating_button/
base.rs

1use leptos::{ev, prelude::*};
2
3use crate::Handler;
4
5/// Headless floating action button — semantics and fixed positioning only.
6#[component]
7pub fn BaseFloatingButton(
8    #[prop(optional, into)] class: MaybeProp<String>,
9    #[prop(optional, into)] style: MaybeProp<String>,
10    #[prop(optional, into)] aria_label: MaybeProp<String>,
11    #[prop(default = false.into(), into)] disabled: Signal<bool>,
12    #[prop(optional)] on_click: Option<Handler<ev::MouseEvent>>,
13    #[prop(optional, into)] testid: MaybeProp<String>,
14    children: Children,
15) -> impl IntoView {
16    let on_click = move |event: ev::MouseEvent| {
17        if disabled.get_untracked() {
18            return;
19        }
20        if let Some(on_click) = on_click.as_ref() {
21            on_click.run(event);
22        }
23    };
24
25    view! {
26        <button
27            type="button"
28            class=class
29            style=style
30            aria-label=move || aria_label.get()
31            disabled=move || disabled.get().then_some("")
32            data-testid=move || testid.get()
33            on:click=on_click
34        >
35            {children()}
36        </button>
37    }
38}