Spaces:
Sleeping
Sleeping
File size: 1,426 Bytes
dbcdc7c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import { useLocation } from 'react-router-dom';
import { useOptions } from '/src/utils/optionsContext';
import clsx from 'clsx';
import { preload } from '/src/utils/preload';
import { memo } from 'react';
const NavItem = ({ items }) => {
const loc = useLocation();
const { options } = useOptions();
const active = options.navItemActive || '#c1d4f1';
const scale = Number(options.navScale || 1);
return (
<>
{items.map((item) => {
const Icon = item.type;
return (
<span
key={item.id}
className={clsx(
'flex gap-1 items-center h-full cursor-pointer',
loc.pathname !== item.route && 'hover:opacity-80 duration-100',
)}
style={{
...(loc.pathname == item.route
? { color: active, boxShadow: `inset 0 -2px 0 0 ${active}` }
: null),
fontSize: `${16 * scale}px`,
}}
onClick={item.onClick}
onMouseEnter={() => preload(item.route)}
onFocus={() => preload(item.route)}
>
{Icon && (
<Icon
color={loc.pathname == item.route ? active : undefined}
size={Math.round(item.size * scale)}
/>
)}
<span>{item.name}</span>
</span>
);
})}
</>
);
};
export default memo(NavItem);
|