1
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
import React from 'react';
|
||||
export interface Option {
|
||||
keepEmpty?: boolean;
|
||||
}
|
||||
export default function toArray(children: React.ReactNode, option?: Option): React.ReactElement[];
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = toArray;
|
||||
var _isFragment = _interopRequireDefault(require("../React/isFragment"));
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function toArray(children, option = {}) {
|
||||
let ret = [];
|
||||
_react.default.Children.forEach(children, child => {
|
||||
if ((child === undefined || child === null) && !option.keepEmpty) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(child)) {
|
||||
ret = ret.concat(toArray(child));
|
||||
} else if ((0, _isFragment.default)(child) && child.props) {
|
||||
ret = ret.concat(toArray(child.props.children, option));
|
||||
} else {
|
||||
ret.push(child);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user