37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
// components/Radio.js
|
|
import { $html } from "sigpro";
|
|
import { val, ui } from "../core/utils.js";
|
|
|
|
/**
|
|
* Radio component
|
|
*
|
|
* daisyUI classes used:
|
|
* - radio, radio-primary, radio-secondary, radio-accent
|
|
* - radio-info, radio-success, radio-warning, radio-error
|
|
* - radio-xs, radio-sm, radio-md, radio-lg
|
|
* - label, label-text, cursor-pointer, justify-start, gap-3
|
|
* - tooltip, tooltip-top, tooltip-bottom, tooltip-left, tooltip-right
|
|
*/
|
|
export const Radio = (props) => {
|
|
const { class: className, label, tooltip, value, inputValue, name, ...rest } = props;
|
|
|
|
const radioEl = $html("input", {
|
|
...rest,
|
|
type: "radio",
|
|
name: name,
|
|
class: ui('radio', className),
|
|
checked: () => val(value) === inputValue,
|
|
onclick: () => {
|
|
if (typeof value === "function") value(inputValue);
|
|
},
|
|
});
|
|
|
|
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;
|
|
}; |