From cb535460350bd510dd4b2b7d6bc3c6ec5f5bcdf1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 10 May 2023 00:53:37 -0300 Subject: almost first document --- .../src/forms/InputChoice.tsx | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 packages/exchange-backoffice-ui/src/forms/InputChoice.tsx (limited to 'packages/exchange-backoffice-ui/src/forms/InputChoice.tsx') diff --git a/packages/exchange-backoffice-ui/src/forms/InputChoice.tsx b/packages/exchange-backoffice-ui/src/forms/InputChoice.tsx new file mode 100644 index 000000000..dae5ff34a --- /dev/null +++ b/packages/exchange-backoffice-ui/src/forms/InputChoice.tsx @@ -0,0 +1,119 @@ +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 ( + + ); + })} +
+
+
+ ); +} -- cgit v1.2.3