Skip to content

Commit 9671715

Browse files
authored
Create NavItem component (#5972)
feat: create NavItem component
1 parent 7e90b95 commit 9671715

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.navItem {
2+
@apply inline-flex
3+
items-center
4+
gap-2
5+
rounded
6+
px-3
7+
py-2;
8+
9+
.label {
10+
@apply text-sm
11+
font-medium
12+
leading-5;
13+
}
14+
15+
.icon {
16+
@apply h-3
17+
w-3
18+
text-neutral-500
19+
dark:text-neutral-200;
20+
}
21+
22+
&.nav {
23+
.label {
24+
@apply text-neutral-900
25+
dark:text-white;
26+
}
27+
28+
&:active {
29+
@apply bg-green-600;
30+
31+
.label {
32+
@apply text-white;
33+
}
34+
35+
.icon {
36+
@apply text-white
37+
opacity-50;
38+
}
39+
}
40+
}
41+
42+
&.footer {
43+
.label {
44+
@apply text-neutral-800
45+
dark:text-white;
46+
}
47+
48+
&:hover {
49+
@apply dark:bg-neutral-900;
50+
}
51+
}
52+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2+
3+
import NavItem from './index';
4+
5+
type Story = StoryObj<typeof NavItem>;
6+
type Meta = MetaObj<typeof NavItem>;
7+
8+
export const Default: Story = {
9+
args: {
10+
href: '/learn',
11+
label: 'Learn',
12+
},
13+
};
14+
15+
export const WithExternalLink: Story = {
16+
args: {
17+
href: 'https://nodejs.org/en',
18+
label: 'Learn',
19+
},
20+
};
21+
22+
export const FooterItem: Story = {
23+
args: {
24+
href: '/about',
25+
label: 'Trademark Policy',
26+
type: 'footer',
27+
},
28+
};
29+
30+
export default { component: NavItem } as Meta;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ArrowUpRightIcon } from '@heroicons/react/24/solid';
2+
import classNames from 'classnames';
3+
import type { FC } from 'react';
4+
import { useMemo } from 'react';
5+
6+
import LocalizedLink from '@/components/LocalizedLink';
7+
8+
import styles from './index.module.css';
9+
10+
type NavItemType = 'nav' | 'footer';
11+
12+
type NavItemProps = {
13+
href: string;
14+
label?: string;
15+
type?: NavItemType;
16+
};
17+
18+
const NavItem: FC<NavItemProps> = ({ href, label, type = 'nav' }) => {
19+
const showIcon = useMemo(
20+
() => type === 'nav' && /^https?:\/\//.test(href),
21+
[href, type]
22+
);
23+
24+
return (
25+
<LocalizedLink
26+
href={href}
27+
className={classNames(styles.navItem, styles[type])}
28+
>
29+
<span className={styles.label}>{label}</span>
30+
{showIcon && <ArrowUpRightIcon className={styles.icon} />}
31+
</LocalizedLink>
32+
);
33+
};
34+
35+
export default NavItem;

0 commit comments

Comments
 (0)