From 10a3f971d9939e6c7d6701b2e896412506c40841 Mon Sep 17 00:00:00 2001 From: Natxo <1172351+natxocc@users.noreply.github.com> Date: Tue, 31 Mar 2026 12:05:22 +0200 Subject: [PATCH] Add Button component with badge and tooltip support Implement a Button component with optional badge and tooltip. --- src/components/button.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/components/button.js diff --git a/src/components/button.js b/src/components/button.js new file mode 100644 index 0000000..1222680 --- /dev/null +++ b/src/components/button.js @@ -0,0 +1,39 @@ +import { $html } from "sigpro"; +import { val, joinClass } from "../core/utils.js"; + +/** BUTTON */ +export const Button = (props, children) => { + const { badge, badgeClass, tooltip, icon, loading, ...rest } = props; + + const btn = $html( + "button", + { + ...rest, + // Usamos props.class directamente + class: joinClass("btn", props.class), + disabled: () => val(loading) || val(props.disabled), + }, + [ + () => (val(loading) ? $html("span", { class: "loading loading-spinner" }) : null), + icon ? $html("span", { class: "mr-1" }, icon) : null, + children, + ] + ); + + let out = btn; + + if (badge) { + out = $html("div", { class: "indicator" }, [ + $html( + "span", + { class: joinClass("indicator-item badge", badgeClass || "badge-secondary") }, + badge + ), + out, + ]); + } + + return tooltip + ? $html("div", { class: "tooltip", "data-tip": tooltip }, out) + : out; +};