UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components for the NEXT UI Kit.

42 lines (41 loc) 1.32 kB
import { jsx } from "react/jsx-runtime"; import { useState } from "react"; import { HvDropdown } from "@hitachivantara/uikit-react-core"; import { useFlowNodeUtils } from "../../hooks/useFlowNode.js"; const 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; const optionLabel = typeof option === "string" ? option : option.label; return { id: optionId, label: optionLabel, selected: !!opts?.find((opt) => opt === optionId) }; }), onChange: handleChange, maxHeight: 100, multiSelect: multiple } ); }; export { Select as default };