2022-02-14 21:58:20 +03:00
|
|
|
import { FC, Children, isValidElement } from 'react';
|
2022-02-13 22:20:20 +03:00
|
|
|
import { Card, Nav, NavLink } from 'reactstrap';
|
|
|
|
import { NavLink as RouterNavLink } from 'react-router-dom';
|
|
|
|
import './NavPills.scss';
|
|
|
|
|
2022-02-14 21:58:20 +03:00
|
|
|
interface NavPillProps {
|
|
|
|
to: string;
|
|
|
|
replace?: boolean;
|
2022-02-13 22:20:20 +03:00
|
|
|
}
|
|
|
|
|
2022-02-14 21:58:20 +03:00
|
|
|
export const NavPillItem: FC<NavPillProps> = ({ children, ...rest }) => (
|
|
|
|
<NavLink className="nav-pills__nav-link" tag={RouterNavLink} {...rest}>
|
|
|
|
{children}
|
|
|
|
</NavLink>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const NavPills: FC = ({ children }) => (
|
2022-02-13 22:20:20 +03:00
|
|
|
<Card className="nav-pills__nav p-0 overflow-hidden mb-3" body>
|
|
|
|
<Nav pills fill>
|
2022-02-14 21:58:20 +03:00
|
|
|
{Children.map(children, (child) => {
|
|
|
|
if (!isValidElement(child) || child.type !== NavPillItem) {
|
|
|
|
throw new Error('Only NavPillItem children are allowed inside NavPills.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
})}
|
2022-02-13 22:20:20 +03:00
|
|
|
</Nav>
|
|
|
|
</Card>
|
|
|
|
);
|