mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 13:39:40 +08:00
27 lines
663 B
TypeScript
27 lines
663 B
TypeScript
import type { VNodeTypes } from '@vue/runtime-core';
|
|
import { isFragment } from '../../_util/props-util';
|
|
|
|
export interface Option {
|
|
keepEmpty?: boolean;
|
|
}
|
|
|
|
export default function toArray(children: any[], option: Option = {}): any[] {
|
|
let ret: VNodeTypes[] = [];
|
|
|
|
children.forEach((child: any) => {
|
|
if ((child === undefined || child === null) && !option.keepEmpty) {
|
|
return;
|
|
}
|
|
debugger;
|
|
if (Array.isArray(child)) {
|
|
ret = ret.concat(toArray(child));
|
|
} else if (isFragment(child) && child.props) {
|
|
ret = ret.concat(toArray(child.props.children, option));
|
|
} else {
|
|
ret.push(child);
|
|
}
|
|
});
|
|
|
|
return ret;
|
|
}
|