UNPKG

@gechiui/components

Version:
49 lines (44 loc) 1.18 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@gechiui/element"; /** * External dependencies */ import { unescape as unescapeString, repeat, flatMap, compact } from 'lodash'; /** * GeChiUI dependencies */ import { useMemo } from '@gechiui/element'; /** * Internal dependencies */ import { SelectControl } from '../'; function getSelectOptions(tree) { let level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; return flatMap(tree, treeNode => [{ value: treeNode.id, label: repeat('\u00A0', level * 3) + unescapeString(treeNode.name) }, ...getSelectOptions(treeNode.children || [], level + 1)]); } export default function TreeSelect(_ref) { let { label, noOptionLabel, onChange, selectedId, tree, ...props } = _ref; const options = useMemo(() => { return compact([noOptionLabel && { value: '', label: noOptionLabel }, ...getSelectOptions(tree)]); }, [noOptionLabel, tree]); return createElement(SelectControl, _extends({ label, options, onChange, value: selectedId }, props)); } //# sourceMappingURL=index.js.map