UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components to UI Kit by the community.

37 lines (36 loc) 1.23 kB
import { useFlowNodeUtils } from "../../hooks/useFlowNode.js"; import { useState } from "react"; import { HvDropdown } from "@hitachivantara/uikit-react-core"; import { jsx } from "react/jsx-runtime"; //#region src/Flow/Node/Parameters/Select.tsx var Select = ({ param, data }) => { const { id, label, multiple = false, options } = param; const { setNodeData } = useFlowNodeUtils(); const [opts, setOpts] = useState(data[id] ? Array.isArray(data[id]) ? data[id] : [data[id]] : void 0); const handleChange = (item) => { const newOpts = Array.isArray(item) ? item.map((x) => x.id) : item?.id ?? void 0; setNodeData((prev) => ({ ...prev, [id]: newOpts })); setOpts(newOpts ? Array.isArray(newOpts) ? newOpts : [newOpts] : void 0); }; return /* @__PURE__ */ jsx(HvDropdown, { className: "nodrag", disablePortal: true, label, values: options?.map((option) => { const optionId = typeof option === "string" ? option : option.id; return { id: optionId, label: typeof option === "string" ? option : option.label, selected: !!opts?.find((opt) => opt === optionId) }; }), onChange: handleChange, maxHeight: 100, multiSelect: multiple }); }; //#endregion export { Select as default };