Skip to content

Commit

Permalink
feat: 🎨remove hooks and update active link component
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiy Khvala committed Oct 10, 2023
1 parent a6960d1 commit 667c7ed
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
15 changes: 5 additions & 10 deletions internal/ActiveLink/ActiveLink.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useRouter } from 'next/router';
import Link from 'next/link';
import { useState, useEffect } from 'react';
import styles from './activeLink.module.css';
import clsx from 'clsx';

const ActiveLink = ({ children, ...props }) => {
const ActiveLink = ({ children, className, activeClassName, ...props }) => {
const { asPath, isReady } = useRouter();
const [computedClassName, setComputedClassName] = useState(
styles.navigationLink
);
const [computedClassName, setComputedClassName] = useState(className);

useEffect(() => {
if (isReady) {
Expand All @@ -20,11 +17,9 @@ const ActiveLink = ({ children, ...props }) => {
''
);

const newClassName = clsx(
linkPathname === activePathname
? `${styles.activeLink} ${styles.navigationLink}`
: styles.navigationLink
);
const newClassName = clsx(className, {
[activeClassName]: linkPathname === activePathname,
});

if (newClassName !== computedClassName) {
setComputedClassName(newClassName);
Expand Down
11 changes: 0 additions & 11 deletions internal/ActiveLink/activeLink.module.css

This file was deleted.

14 changes: 12 additions & 2 deletions internal/MobileNavigation/MobileNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ const MobileNavigation = () => {
className={styles.dropdown}
>
<DropdownItem>
<ActiveLink href='/docs'>Installation</ActiveLink>
<ActiveLink
href='/docs'
className={styles.navigationLink}
activeClassName={styles.activeLink}
>
Installation
</ActiveLink>
</DropdownItem>
{pages.map((link) => (
<DropdownItem key={link}>
<ActiveLink href={`/docs/${link}`}>
<ActiveLink
href={`/docs/${link}`}
className={styles.navigationLink}
activeClassName={styles.activeLink}
>
{link.replace('-', ' ')}
</ActiveLink>
</DropdownItem>
Expand Down
12 changes: 12 additions & 0 deletions internal/MobileNavigation/mobileNavigation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
cursor: pointer;
}

.navigationLink {
margin: 8px 0;
display: block;
color: #000;
text-decoration: none;
text-transform: capitalize;
}

.activeLink {
color: #5093ff;
}

@media screen and (max-width: 1280px) {
.container {
display: flex;
Expand Down
12 changes: 12 additions & 0 deletions internal/Navigation/Navigation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
padding: 6px 12px;
}

.navigationLink {
margin: 8px 0;
display: block;
color: #000;
text-decoration: none;
text-transform: capitalize;
}

.activeLink {
color: #5093ff;
}

@media screen and (max-width: 1280px) {
.navigation {
display: none;
Expand Down
7 changes: 0 additions & 7 deletions internal/hooks/useGetFormattedPathname.js

This file was deleted.

0 comments on commit 667c7ed

Please sign in to comment.