From 361101a4638b9b885bb3fcc9604447f9c94278d1 Mon Sep 17 00:00:00 2001 From: Natxo <1172351+natxocc@users.noreply.github.com> Date: Tue, 31 Mar 2026 12:13:24 +0200 Subject: [PATCH] Add Radio component for radio input functionality --- src/components/Radio.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/components/Radio.js diff --git a/src/components/Radio.js b/src/components/Radio.js new file mode 100644 index 0000000..12c4b88 --- /dev/null +++ b/src/components/Radio.js @@ -0,0 +1,25 @@ +import { $html } from "sigpro"; +import { val, joinClass } from "../core/utils.js"; + +/** RADIO */ +export const Radio = (props) => { + const { label, tooltip, value, ...rest } = props; + + const radioEl = $html("input", { + ...rest, + type: "radio", + class: joinClass("radio", props.class), + checked: () => val(value) === props.value, + disabled: () => val(props.disabled), + onclick: () => typeof value === "function" && value(props.value), + }); + + if (!label && !tooltip) return radioEl; + + const layout = $html("label", { class: "label cursor-pointer justify-start gap-3" }, [ + radioEl, + label ? $html("span", { class: "label-text" }, label) : null, + ]); + + return tooltip ? $html("div", { class: "tooltip", "data-tip": tooltip }, layout) : layout; +};