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/InputSelectMultiple.tsx | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 packages/exchange-backoffice-ui/src/forms/InputSelectMultiple.tsx (limited to 'packages/exchange-backoffice-ui/src/forms/InputSelectMultiple.tsx') diff --git a/packages/exchange-backoffice-ui/src/forms/InputSelectMultiple.tsx b/packages/exchange-backoffice-ui/src/forms/InputSelectMultiple.tsx new file mode 100644 index 000000000..375f8da93 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/forms/InputSelectMultiple.tsx @@ -0,0 +1,144 @@ +import { Fragment, VNode, h } from "preact"; +import { Choice } from "./InputChoice.js"; +import { LabelWithTooltipMaybeRequired, UIFormProps } from "./InputLine.js"; +import { useField } from "./useField.js"; +import { useState } from "preact/hooks"; + +export function InputSelectMultiple( + props: { + choices: Choice[]; + } & UIFormProps>, +): VNode { + const { name, label, choices, placeholder, tooltip, required } = props; + const { value, onChange } = useField<{ [s: string]: Array }>(name); + + const [filter, setFilter] = useState(undefined); + const regex = new RegExp(`.*${filter}.*`, "i"); + const choiceMap = choices.reduce((prev, curr) => { + return { ...prev, [curr.value]: curr.label }; + }, {} as Record); + + const list = value ?? []; + const filteredChoices = + filter === undefined + ? undefined + : choices.filter((v) => { + return regex.test(v.label); + }); + return ( +
+ + {list.map((v, idx) => { + return ( + + {choiceMap[v]} + + + ); + })} + +
+ { + setFilter(e.currentTarget.value); + }} + placeholder={placeholder} + class="w-full rounded-md border-0 bg-white py-1.5 pl-3 pr-12 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" + role="combobox" + aria-controls="options" + aria-expanded="false" + /> + + + {filteredChoices !== undefined && ( +
    + {filteredChoices.map((v, idx) => { + let clazz = + "relative flex border p-4 focus:outline-none disabled:text-grey"; + return ( +
  • { + const newValue = [...list]; + newValue.splice(0, 0, v.value); + onChange(newValue); + setFilter(undefined); + }} + + // tabindex="-1" + > + {/* */} + {v.label} + + {/* */} +
  • + ); + })} + + {/* */} + + {/* */} +
+ )} +
+
+ ); +} -- cgit v1.2.3