Skip to content

Commit

Permalink
feat(nav): Add Nav progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
USER authored and USER committed Nov 5, 2023
1 parent c860086 commit 65c7af0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from 'next/link';
import { useRouter } from 'next/router';
import { FunctionComponent, useEffect, useState } from 'react';

import { AvatarImage } from './Avatar';
import { AvatarImage } from '../Avatar';

interface NavTextProps {
text: string;
Expand Down
28 changes: 28 additions & 0 deletions apps/blog/src/features/shared/components/nav/Progress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FunctionComponent, useEffect, useState } from 'react';

const NavProgress: FunctionComponent = () => {
const [progress, setProgress] = useState(0);
const [max, setMax] = useState(1);

useEffect(() => {
const { scrollHeight, clientHeight } = document.documentElement;
const documentMax = scrollHeight - clientHeight;
setMax(documentMax);

const handleScroll = () => {
setProgress(window.scrollY % documentMax);
};
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

return (
<div className="nav-progress">
<progress value={progress} max={max}></progress>
</div>
);
};

export default NavProgress;
20 changes: 20 additions & 0 deletions apps/blog/src/features/styles/ui/navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
var(--tw-ring-shadow, 0 0 #fff0), var(--tw-shadow);
}

.nav-progress {
progress {
position: fixed;
top: 0;
left: 0;
z-index: 101;
width: 100%;
height: 3px;
accent-color: red;
}

::-webkit-progress-bar {
background-color: $dark-color;
}

::-webkit-progress-value {
background: #28bc97;
}
}

/* MOBILE */
@media (width <= 700px) {
.post-nav-trans {
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FunctionComponent } from 'react';
import NotFoundContainer from '~/404/Container';
import Footer from '~/shared/components/Footer';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import { ImageUrl, MetaDescription, MetaTitle } from '~/shared/constants/blog';

const NotFound: FunctionComponent = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextPage } from 'next';
import AboutContainer from '~/about/Container';
import Footer from '~/shared/components/Footer';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import { ImageUrl, MetaDescription, MetaTitle } from '~/shared/constants/blog';

const About: NextPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextPage } from 'next';

import HomeContainer from '~/home/Container';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import { ImageUrl, MetaDescription, MetaTitle } from '~/shared/constants/blog';

const Home: NextPage = () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/blog/src/pages/posts/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import PostContainer from '~/posts/Container';
import { PostType } from '~/posts/models';
import Footer from '~/shared/components/Footer';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import NavProgress from '~/shared/components/nav/Progress';
import { MetaTitle } from '~/shared/constants/blog';
import markdownToHtml from '~/shared/helpers/markdown';
import { getAllPosts, getPostBySlug } from '~/shared/helpers/post';
Expand Down Expand Up @@ -34,6 +35,7 @@ const Posts: NextPage<PostsProps> = ({ post }) => {
description={post.description}
/>
<main className="post-layout">
<NavProgress />
<Navbar />
<PostContainer post={post} />
<Footer />
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/posts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PostListContainer from '~/posts/ListContainer';
import { PostType } from '~/posts/models';
import Footer from '~/shared/components/Footer';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import { ImageUrl, MetaDescription, MetaTitle } from '~/shared/constants/blog';
import { getAllPosts, getPostBySlug } from '~/shared/helpers/post';

Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/tags/[tag].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from 'next/router';
import ErrorPage from 'next/error';

import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import Footer from '~/shared/components/Footer';
import { getAllPosts } from '~/shared/helpers/post';
import { PostType } from '~/posts/models';
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/src/pages/tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextPage } from 'next';

import Footer from '~/shared/components/Footer';
import MetaHeader from '~/shared/components/MetaHeader';
import Navbar from '~/shared/components/Navbar';
import Navbar from '~/shared/components/nav/Navbar';
import { ImageUrl, MetaDescription, MetaTitle } from '~/shared/constants/blog';
import { getAllPosts, getPostBySlug } from '~/shared/helpers/post';
import TagListContainer from '~/tags/tagList/Container';
Expand Down

0 comments on commit 65c7af0

Please sign in to comment.