Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding NavItem #5973

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/nodejs.org.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions components/sections/NavItem/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.navItem {
@apply inline-flex items-center gap-2 rounded px-3 py-2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay Sir 😅


.label {
@apply text-sm font-medium leading-5;
}

.icon {
@apply h-3 w-3 text-neutral-500 dark:text-neutral-200;
}

&.nav {
.label {
@apply text-neutral-900 dark:text-white;
}

&:active {
@apply bg-green-600;

.label {
@apply text-white;
}

.icon {
@apply text-white opacity-50;
}
}
}

&.footer {
.label {
@apply text-neutral-800 dark:text-white;
}

&:hover {
@apply dark:bg-neutral-900;
}
}
}
30 changes: 30 additions & 0 deletions components/sections/NavItem/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import NavItem, { NavItemType } from './index';

type Story = StoryObj<typeof NavItem>;
type Meta = MetaObj<typeof NavItem>;

export const Default: Story = {
args: {
href: '/about',
label: 'Learn',
},
};

export const WithExternalLink: Story = {
args: {
href: 'https://nodejs.org/en',
label: 'Learn',
},
};

export const FooterItem: Story = {
args: {
href: '/about',
label: 'Trademark Policy',
type: NavItemType.footer,
},
};

export default { component: NavItem } as Meta;
31 changes: 31 additions & 0 deletions components/sections/NavItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ArrowUpRightIcon } from '@heroicons/react/24/solid';
import classNames from 'classnames';
import Link from 'next/link';
import { useMemo, type FC } from 'react';

import styles from './index.module.css';

export enum NavItemType {
nav = 'nav',
footer = 'footer',
}

type NavItemProps = {
href: string;
label?: string;
type?: NavItemType;
};

const NavItem: FC<NavItemProps> = ({ href, label, type = NavItemType.nav }) => {
const showIcon = useMemo(() => {
return href.startsWith('http') && type === NavItemType.nav;
}, [href, type]);

return (
<Link href={href} className={classNames(styles.navItem, styles[type])}>
<span className={styles.label}>{label}</span>
{showIcon && <ArrowUpRightIcon className={styles.icon} />}
</Link>
);
};
export default NavItem;
Loading