import { TranslatedString } from "@gnu-taler/taler-util"; import { Fragment, VNode, h } from "preact"; import { LabelWithTooltipMaybeRequired, UIFormProps } from "./InputLine.js"; import { useField } from "./useField.js"; function classNames(...classes: string[]): string { return classes.filter(Boolean).join(" "); } const memoryOptions = [ { name: "4 GB", inStock: true }, { name: "8 GB", inStock: true }, { name: "16 GB", inStock: true }, { name: "32 GB", inStock: true }, { name: "64 GB", inStock: true }, { name: "128 GB", inStock: false }, ]; export interface Choice { label: TranslatedString; description?: TranslatedString; value: string; } export function InputChoiceStacked( props: { choices: Choice[]; } & UIFormProps, ): VNode { const { choices, name, label, tooltip, placeholder, required, before, after, converter, } = props; const { value, onChange, state, isDirty } = useField(name); if (state.hidden) { return ; } return (
{value !== undefined && !required && (
)}
{choices.map((choice) => { let clazz = "border relative block cursor-pointer rounded-lg bg-white px-6 py-4 shadow-sm focus:outline-none sm:flex sm:justify-between"; if (choice.value === value) { clazz += " border-transparent border-indigo-600 ring-2 ring-indigo-600"; } else { clazz += " border-gray-300"; } return ( ); })}
); }