UNPKG

@airplane/views

Version:

A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.

23 lines (22 loc) 782 B
import { Children, isValidElement, cloneElement } from "react"; import { isFragment } from "react-is"; function flattenChildren(children, depth = 0, keys = []) { return Children.toArray(children).reduce((acc, node, nodeIndex) => { if (isFragment(node)) { acc.push.apply(acc, flattenChildren(node.props.children, depth + 1, keys.concat(node.key || nodeIndex))); } else { if (/* @__PURE__ */ isValidElement(node)) { acc.push(/* @__PURE__ */ cloneElement(node, { key: keys.concat(String(node.key)).join(".") })); } else if (typeof node === "string" || typeof node === "number") { acc.push(node); } } return acc; }, []); } export { flattenChildren as default }; //# sourceMappingURL=flattenchildren.js.map