Skip to content

Commit

Permalink
completed navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag3003 committed Jan 23, 2024
1 parent a2b0790 commit 401fc73
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 50 deletions.
125 changes: 76 additions & 49 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@import url('https://fonts.googleapis.com/css2?family=Inconsolata:wght@200;300;400;500;600;700;800;900&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

/* @layer base {
:root {
--background: 0 0% 100%;
Expand Down Expand Up @@ -67,57 +69,82 @@
}
*/
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}

@layer base {
:root {
--background: 180 30% 96%;
--foreground: 195 17% 9%;
--card: 180 30% 96%;
--card-foreground: 195 17% 9%;
--popover: 180 30% 96%;
--popover-foreground: 195 17% 9%;
--primary: 189 36% 29%;
--primary-foreground: 180 30% 96%;
--secondary: 189 46% 69%;
--secondary-foreground: 195 17% 9%;
--muted: 180 29% 20%;
--muted-foreground: 196 18% 70%;
--accent: 189 56% 47%;
--accent-foreground: 195 17% 9%;
--destructive: 0 85% 60%;
--destructive-foreground: 195 17% 9%;
--border: 180 29% 20%;
--input: 180 29% 20%;
--ring: 189 56% 40%;
--radius: 0.5rem;
--background: 180 30% 96%;
--foreground: 195 17% 9%;
--card: 180 30% 96%;
--card-foreground: 195 17% 9%;
--popover: 180 30% 96%;
--popover-foreground: 195 17% 9%;
--primary: 189 36% 29%;
--primary-foreground: 180 30% 96%;
--secondary: 189 46% 69%;
--secondary-foreground: 195 17% 9%;
--muted: 180 29% 20%;
--muted-foreground: 196 18% 70%;
--accent: 189 56% 47%;
--accent-foreground: 195 17% 9%;
--destructive: 0 85% 60%;
--destructive-foreground: 195 17% 9%;
--border: 180 29% 20%;
--input: 180 29% 20%;
--ring: 189 56% 40%;
--radius: 0.5rem;
}

.dark {
--background: 180 27% 4%;
--foreground: 195 17% 91%;
--card: 180 27% 4%;
--card-foreground: 195 17% 91%;
--popover: 180 27% 4%;
--popover-foreground: 195 17% 91%;
--primary: 189 36% 71%;
--primary-foreground: 180 27% 4%;
--secondary: 189 46% 31%;
--secondary-foreground: 195 17% 91%;
--muted: 180 27% 80%;
--muted-foreground: 195 17% 91%;
--accent: 189 56% 53%;
--accent-foreground: 180 27% 4%;
--destructive: 0 62% 30%;
--destructive-foreground: 193 18% 10%;
--border: 180 27% 60%;
--input: 180 27% 80%;
--ring: 189 56% 60%;
--background: 180 27% 4%;
--foreground: 195 17% 91%;
--card: 180 27% 4%;
--card-foreground: 195 17% 91%;
--popover: 180 27% 4%;
--popover-foreground: 195 17% 91%;
--primary: 189 36% 71%;
--primary-foreground: 180 27% 4%;
--secondary: 189 46% 31%;
--secondary-foreground: 195 17% 91%;
--muted: 180 27% 80%;
--muted-foreground: 195 17% 91%;
--accent: 189 56% 53%;
--accent-foreground: 180 27% 4%;
--destructive: 0 62% 30%;
--destructive-foreground: 193 18% 10%;
--border: 180 27% 60%;
--input: 180 27% 80%;
--ring: 189 56% 60%;
}
}
}

:root {
--font: 'Inconsolata', monospace;
}

* {
font-family: 'Inconsolata', monospace;
box-sizing: border-box;
}

::-webkit-scrollbar-track {
background-color: hsl(var(--background));
width: 2px;
display: none;
}
::-webkit-scrollbar {
width: 5px;
background-color: #f5f5f5;
}

::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
background-color: #555;
}
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Inter } from 'next/font/google'

import './globals.css'
import { Toaster } from 'react-hot-toast'
import Navbar from '@/components/Navbar'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -19,6 +20,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
return (
<html lang="en">
<body className={`${inter.className} text-text bg-background dark`}>
<Navbar />
{children}
<Toaster />
</body>
Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export default function Home() {
return (
<main className="flex min-h-screen bg-background p-24">
<main className="flex min-h-[300vh] bg-background p-24">
</main>
);
}
112 changes: 112 additions & 0 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use client'

import React, { useState } from 'react'
import { motion, useMotionValue, useScroll, useTransform } from 'framer-motion'
import Link from 'next/link'
import { Button } from './ui/button'
import { MenuIcon } from 'lucide-react'
import { Card, CardContent } from './ui/card'

const navLinks = [
{
name: 'Link 1',
link: '#about',
},
{
name: 'Link 2',
link: '#',
},
{
name: 'Link 3',
link: '#',
},
]

function Navbar() {
const { scrollY } = useScroll()
const borderRadius = useTransform(
scrollY,
[0, 200, 200],
['0rem', '0rem', '3rem']
)
const top = useTransform(scrollY, [0, 200, 200], ['0rem', '0rem', '1rem'])
const width = useTransform(scrollY, [0, 200, 200], ['100%', '100%', '95%'])
const height = useMotionValue<'0' | '1000px'>('1000px')
const opacity = useMotionValue<'0' | '1'>('1')

function toggleNav() {
if (height.get() === '1000px') {
height.set('0')
opacity.set('0')
} else {
height.set('1000px')
opacity.set('1')
}
}

return (
<motion.div
className="bg-primary/10 shadow-sm mx-auto fixed left-0 right-0 transition-all"
style={{
borderRadius: borderRadius,
top: top,
width: width,
}}
>
<div className="wrapper px-10 py-5 w-full relative">
<div className="max-w-7xl mx-auto flex items-center justify-between">
<header className="flex items-center gap-1">
<span>{'< '}</span>
<h1 className="text-2xl font-medium"> {'Chirag'}</h1>
<span>{' />'}</span>
</header>
<nav className="text-muted gap-8 hidden items-center lg:flex">
{navLinks.map(({ name, link }, index) => {
return (
<Link
key={index}
href={link}
className="hover:text-foreground hover:scale-110 transition-all"
>
{name}
</Link>
)
})}
</nav>
<Button
onClick={toggleNav}
variant={'ghost'}
className="lg:hidden"
>
<MenuIcon />
</Button>
</div>
<motion.div
style={{
opacity,
maxHeight: height,
}}
className="mobile-nav absolute lg:hidden top-[120%] mx-auto w-[95vw] left-0 right-0 transition-all overflow-hidden"
>
<Card className="p-4">
<nav className="flex flex-col gap-4">
{navLinks.map(({ name, link }, index) => {
return (
<Link
key={index}
href={link}
className="text-lg"
>
{name}
</Link>
)
})}
</nav>
</Card>
</motion.div>
</div>
</motion.div>
)
}

export default Navbar

0 comments on commit 401fc73

Please sign in to comment.