@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
35 lines (34 loc) • 1.13 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef } from "react";
import classNames from "classnames";
import Icon from "../Icon/Icon.js";
// used to determine if anything is gonna render
// falsy elements do not render,
// but child arrays are truthy even though their items are falsy
const hasTruthyChildren = (children)=>{
if (Array.isArray(children)) {
return children.some(hasTruthyChildren);
}
return !!children;
};
/**
* Item for Nav component
*/ const NavItem = /*#__PURE__*/ forwardRef(({ children, icon, className, ...props }, ref)=>{
return /*#__PURE__*/ _jsxs("div", {
...props,
className: classNames("bf-nav-item bf-break-word", className, {
"bf-nav-item-icon-only": icon && !hasTruthyChildren(children)
}),
ref: ref,
children: [
icon && /*#__PURE__*/ _jsx(Icon, {
icon: icon,
fixedWidth: true,
className: "bf-nav-item-icon"
}),
children
]
});
});
NavItem.displayName = "Nav.Item";
export default NavItem;