shelving
Version:
Toolkit for using data in JavaScript.
14 lines (13 loc) • 871 B
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { getProps } from "../../util/object.js";
import { Flex } from "../style/Flex.js";
import { RadioInput } from "./RadioInput.js";
/** Maximum number of options to show in a row. */
const MAX_ROW_OPTIONS = 2;
export function ChoiceRadioInputs({ required = false, value = "", onValue, wrap = false, column, options, ...props }) {
const entries = getProps(options);
const hasMany = entries.length > MAX_ROW_OPTIONS;
return (_jsxs(Flex, { wrap: wrap, column: column ?? hasMany, children: [entries.map(([k, t]) => (_jsx(RadioInput //
, { value: value === k, onValue: () => onValue(k), required: required, ...props, children: t }, k))), !required ? (_jsx(RadioInput //
, { value: !value, onValue: () => onValue(undefined), required: required, ...props })) : null] }));
}