@gravity-ui/uikit
Version:
Gravity UI base styling and components
39 lines (38 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTabComponentProps = isTabComponentProps;
exports.isTabLinkProps = isTabLinkProps;
exports.getTabNodePropsFromReactNode = getTabNodePropsFromReactNode;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const polymorphic_1 = require("../utils/polymorphic.js");
const Tab_1 = require("./Tab.js");
function isTabComponentProps(p) {
return (0, polymorphic_1.isPolymorphicComponentProps)(p);
}
function isTabLinkProps(p) {
return (0, polymorphic_1.isPolymorphicLinkProps)(p);
}
/**
* Finds the first Tab in the subtree (e.g. Tab wrapped in Tooltip) and returns it.
*/
function getTabNodePropsFromReactNode(node) {
if (!React.isValidElement(node)) {
return undefined;
}
if (node.type === Tab_1.Tab) {
return node.props;
}
const props = node.props;
if (props.children === null) {
return undefined;
}
for (const child of React.Children.toArray(props.children)) {
const nested = getTabNodePropsFromReactNode(child);
if (nested !== undefined) {
return nested;
}
}
return undefined;
}
//# sourceMappingURL=utils.js.map