one
Version:
One is a new React Framework that makes Vite serve both native and web.
34 lines (33 loc) • 1.08 kB
JavaScript
import {
isValidElement
} from "react";
function isChildOfType(element, type) {
return isValidElement(element) && element.type === type;
}
function getFirstChildOfType(children, type) {
const childArray = Array.isArray(children) ? children : [children];
for (const child of childArray)
if (isChildOfType(child, type))
return child;
}
function getAllChildrenOfType(children, type) {
return (Array.isArray(children) ? children : [children]).filter(
(child) => isChildOfType(child, type)
);
}
function getAllChildrenNotOfType(children, type) {
return (Array.isArray(children) ? children : [children]).filter((child) => !isChildOfType(child, type));
}
function filterAllowedChildrenElements(children, allowedTypes) {
return (Array.isArray(children) ? children : [children]).filter(
(child) => isValidElement(child) && allowedTypes.some((type) => child.type === type)
);
}
export {
filterAllowedChildrenElements,
getAllChildrenNotOfType,
getAllChildrenOfType,
getFirstChildOfType,
isChildOfType
};
//# sourceMappingURL=children.js.map