react-form-package
Version:
A declarative form component with inbuilt validation and state management
45 lines (36 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getNestedChilds = void 0;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var getNestedChilds = function getNestedChilds(children, data) {
var flatChilds = data;
var arr = Array.isArray(children) && _typeof(children) === 'object' ? children : [children];
arr = _typeof(children) === 'object' ? arr : [];
arr.forEach(function (child) {
// eslint-disable-line
if (!child) {
return null;
}
var type = child.type;
if (typeof type === 'function') {
if (type.displayName === 'Field' || type.displayName === 'FieldWrapper' || type.displayName === 'Select' || type.displayName === 'RadioGroup') {
flatChilds.push(child);
}
}
if (Array.isArray(child)) {
return child.forEach(function (c) {
return getNestedChilds(c, flatChilds);
});
}
if (_typeof(child) !== 'object') {
return flatChilds;
}
if (child.props.children) {
return getNestedChilds(child.props.children, flatChilds);
}
});
return flatChilds;
};
exports.getNestedChilds = getNestedChilds;