import { useRouterStore } from '@l-clutch/core';
import { FC, useMemo } from 'react';
export const Menu = () => {
const items = lClutchCoreSettings.menuItems;
const basicId = lClutchCoreSettings.basicId;
return (
{items.map((item, index) => {
if (item.path) {
return (
);
} else if (item.href && basicId) {
const href = item.href.replace('%s', basicId);
return (
{item.title}
);
}
})}
);
};
type MenuItemProps = {
children: React.ReactNode;
path: string;
className?: string;
};
const MenuItem: FC = ({ children, path, className: aditionalClass }) => {
const { getPath, setPath } = useRouterStore();
const nowPath = getPath(0) ?? '';
const isCurrent = useMemo(() => path.replace(/^\//, '') === nowPath, [path, nowPath]);
const className = useMemo(() => {
const classes = isCurrent ? ['current'] : [];
if (aditionalClass) classes.push(aditionalClass);
return classes.join(' ');
}, [isCurrent]);
return (
{
e.preventDefault();
setPath(path);
}}
>
{children}
);
};
type MenuLinkProps = {
href: string;
children: React.ReactNode;
};
const MenuLink: FC = ({ href, children }) => (
{children}
);