File tree Expand file tree Collapse file tree
components/sections/NavItem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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' && / ^ h t t p s ? : \/ \/ / . 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 ;
You can’t perform that action at this time.
0 commit comments