Skip to content

Commit 7a30468

Browse files
authored
feat: ✨ adding sticky section (#163)
1 parent a42ab15 commit 7a30468

7 files changed

Lines changed: 48 additions & 48 deletions

File tree

site.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CONFIG = {
2020
blog: {
2121
title: "morethan-log",
2222
description: "welcome to morethan-log!",
23-
theme: "light", // ['light', 'dark', 'auto']
23+
theme: "auto", // ['light', 'dark', 'auto']
2424
},
2525

2626
// CONFIG configration (required)

src/components/Layout/Header/NavBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import Link from 'next/link'
1+
import Link from "next/link"
22

33
const NavBar: React.FC = () => {
4-
const links = [{ id: 1, name: 'About', to: '/about' }]
4+
const links = [{ id: 1, name: "About", to: "/about" }]
55
return (
66
<div className="flex-shrink-0">
77
<ul className="flex flex-row">
88
{links.map((link) => (
99
<li
1010
key={link.id}
11-
className="block ml-4 text-black dark:text-gray-50 nav"
11+
className="block ml-4 text-black text-gray-500 dark:text-white nav"
1212
>
1313
<Link href={link.to}>
1414
<a>{link.name}</a>

src/components/Layout/Header/index.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { useRef } from "react"
2-
import CONFIG from "site.config"
31
import NavBar from "./NavBar"
42
import Logo from "./Logo"
53
import ThemeToggle from "./ThemeToggle"
@@ -9,20 +7,18 @@ type Props = {
97
}
108

119
const Header: React.FC<Props> = ({ fullWidth }) => {
12-
const navRef = useRef(null)
13-
1410
return (
15-
<div
16-
className={`sticky-nav m-auto w-full h-6 flex flex-row justify-between items-center mb-2 md:mb-6 py-8 bg-opacity-60 max-w-6xl px-4 ${
17-
fullWidth && "px-4 md:px-24"
18-
}`}
19-
id="sticky-nav"
20-
ref={navRef}
21-
>
22-
<Logo />
23-
<div className={`flex gap-3 items-center`}>
24-
<ThemeToggle />
25-
<NavBar />
11+
<div className="shadow-sm transition sticky bg-white dark:bg-zinc-700 mb-2 md:mb-6 border-b-[1px] z-[40] border-gray-100 dark:border-gray-800 top-0">
12+
<div
13+
className={`m-auto px-4 h-12 w-full max-w-6xl flex justify-between items-center ${
14+
fullWidth && "md:px-24"
15+
}`}
16+
>
17+
<Logo />
18+
<div className={`flex gap-3 items-center `}>
19+
<ThemeToggle />
20+
<NavBar />
21+
</div>
2622
</div>
2723
</div>
2824
)

src/containers/Feed/components/cards/ProfileCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ProfileCard: React.FC<Props> = ({ className }) => {
1010
return (
1111
<div className={className}>
1212
<div className="p-1 mb-3 dark:text-white">💻 Profile</div>
13-
<div className="w-full md:p-4 lg:p-4 rounded-2xl bg-white dark:bg-zinc-700 mb-9">
13+
<div className="rounded-2xl bg-white dark:bg-zinc-700 w-full md:p-4 lg:p-4 mb-9">
1414
<div className="relative w-full after:content-[''] after:block after:pb-[100%]">
1515
<Image src={CONFIG.profile.image} layout="fill" alt="" />
1616
</div>

src/containers/Feed/components/lists/TagList.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TTags } from '@customTypes/index'
2-
import { useRouter } from 'next/router'
3-
import React from 'react'
1+
import { TTags } from "@customTypes/index"
2+
import { useRouter } from "next/router"
3+
import React from "react"
44

55
type Props = {
66
className?: string
@@ -35,11 +35,11 @@ const TagList: React.FC<Props> = ({ className, data }) => {
3535
return (
3636
<div className={className}>
3737
<div className="hidden lg:block p-1 mb-3 dark:text-white">🏷️ Tags</div>
38-
<ul className="cursor-pointer gap-1 flex mobile-x-scroll lg:block mb-6">
38+
<ul className="gap-1 flex mobile-x-scroll lg:block mb-6">
3939
{Object.keys(data).map((key) => (
4040
<li
4141
key={key}
42-
className={`text-sm p-1 px-4 my-1 flex-shrink-0 rounded-xl text-gray-500 dark:text-white hover:bg-gray-200 dark:hover:bg-zinc-800 ${
42+
className={`cursor-pointer text-sm p-1 px-4 my-1 flex-shrink-0 rounded-xl text-gray-500 dark:text-white hover:bg-gray-200 dark:hover:bg-zinc-800 ${
4343
key === currentTag &&
4444
"text-black bg-white dark:bg-zinc-700 hover:bg-white dark:hover:bg-zinc-700"
4545
}`}

src/containers/Feed/index.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ type Props = {
1717
const Feed: React.FC<Props> = ({ categories, tags, posts }) => {
1818
const [q, setQ] = useState("")
1919

20+
// .box {
21+
// -ms-overflow-style: none;
22+
// scrollbar-width: none;
23+
// }
24+
// .box::-webkit-scrollbar {
25+
// display: none;
26+
// }
2027
return (
2128
<div className="block md:grid grid-cols-12 gap-6">
22-
<div className="hidden lg:block col-span-2">
29+
<div
30+
className="common-no-scroll-bar sticky top-[73px] hidden lg:block col-span-2 overflow-scroll"
31+
style={{
32+
height: "calc(100vh - 73px)",
33+
}}
34+
>
2335
{/* <Lists.CategoryList data={categories} /> */}
2436
<Lists.TagList data={tags} />
2537
</div>
@@ -31,7 +43,12 @@ const Feed: React.FC<Props> = ({ categories, tags, posts }) => {
3143
<Lists.PostList q={q} posts={posts} />
3244
<Footer className="block lg:hidden flex justify-center pb-8" />
3345
</div>
34-
<div className="hidden lg:block lg:col-span-3">
46+
<div
47+
className="common-no-scroll-bar sticky top-[73px] hidden lg:block lg:col-span-3 overflow-scroll"
48+
style={{
49+
height: "calc(100vh - 73px)",
50+
}}
51+
>
3552
<Cards.ProfileCard />
3653
<Cards.ServiceCard />
3754
<Cards.ContactCard />

src/styles/globals.css

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ body::-webkit-scrollbar-thumb {
2525
background: rgba(45, 170, 219, 0.3);
2626
}
2727

28+
.common-no-scroll-bar {
29+
scrollbar-width: none;
30+
-ms-overflow-style: none;
31+
}
32+
.common-no-scroll-bar::-webkit-scrollbar {
33+
display: none;
34+
}
35+
2836
.wrapper {
2937
min-height: 100vh;
3038
display: flex;
@@ -34,34 +42,13 @@ body::-webkit-scrollbar-thumb {
3442
flex-direction: column;
3543
}
3644

37-
.sticky-nav {
38-
position: sticky;
39-
z-index: 40;
40-
top: -1px;
41-
backdrop-filter: blur(5px);
42-
transition: all 0.5s cubic-bezier(0.4, 0, 0, 1);
43-
border-bottom-color: transparent;
44-
}
45-
46-
.remove-sticky {
47-
position: unset;
48-
}
49-
50-
.sticky-nav-full {
51-
@apply border-b border-opacity-50 border-gray-200 dark:border-gray-600 dark:border-opacity-50;
52-
}
53-
5445
.header-name {
5546
/* display: none; */
5647
opacity: 1;
5748
/* opacity: 0; */
5849
overflow: hidden;
5950
}
6051

61-
.sticky-nav-full .nav {
62-
@apply text-gray-600 dark:text-gray-300;
63-
}
64-
6552
nav {
6653
flex-wrap: wrap;
6754
line-height: 1.5em;

0 commit comments

Comments
 (0)