UNPKG

acud

Version:

acg react 组件库

49 lines • 1.68 kB
import _extends from "@babel/runtime/helpers/esm/extends"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import toArray from "rc-util/es/Children/toArray"; function convertNodeToOption(node) { var _a = node, key = _a.key, _b = _a.props, children = _b.children, value = _b.value, restProps = __rest(_b, ["children", "value"]); return _extends({ key: key, value: value !== undefined ? value : key, children: children }, restProps); } export function convertChildrenToData(nodes) { var optionOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return toArray(nodes).map(function (node, index) { if (! /*#__PURE__*/React.isValidElement(node) || !node.type) { return null; } var _a = node, isSelectOptGroup = _a.type.isSelectOptGroup, key = _a.key, _b = _a.props, children = _b.children, restProps = __rest(_b, ["children"]); if (optionOnly || !isSelectOptGroup) { return convertNodeToOption(node); } return _extends(_extends({ key: "".concat(key === null ? index : key), label: key }, restProps), { options: convertChildrenToData(children) }); }).filter(function (data) { return data; }); }