Files
sigpro-ui/components/Select.js
natxocc 16afea2768
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s
Rebuild all components
2026-04-21 18:00:17 +02:00

25 lines
946 B
JavaScript

// components/Select.js
import { Tag, For } from "sigpro";
export const Select = (props, children) => {
children === undefined && (children = props, props = {});
return Tag("select", { ...props, class: `select ${props.class ?? ''}` }, children);
};
export const Options = (props) => {
const placeholderOption = props.placeholder
? Tag("option", { disabled: props.placeholderDisabled ?? true, selected: true }, props.placeholder)
: null;
const dynamicOptions = For(
() => [...(typeof props.items === "function" ? props.items() : props.items || [])],
(item) => {
const val = typeof item === "string" ? item : item.value;
const label = typeof item === "string" ? item : item.label;
return Tag("option", { value: val }, label);
},
props.keyFn || ((item) => (typeof item === "string" ? item : item.value))
);
return placeholderOption ? [placeholderOption, dynamicOptions] : dynamicOptions;
};