Skip to content

Commit

Permalink
Merge pull request #5 from Hkaar/animations
Browse files Browse the repository at this point in the history
Updated next.js & imporved animations
  • Loading branch information
Hkaar authored Oct 22, 2024
2 parents e80d176 + 39d05d0 commit 73b1f21
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 100 deletions.
10 changes: 7 additions & 3 deletions app/(dynamic)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import Profile from "@/components/Profile";
import Badge from "@/components/Badge";
import { Icon } from "@iconify/react";

export default function BlogPage({ params }: {
params: { slug: string };
}) {
interface BlogPageProps {
params: Promise<{slug: string}>
}

export default async function BlogPage(props: BlogPageProps) {
const params = await props.params;

return (
<>
<ArticleContainer>
Expand Down
10 changes: 7 additions & 3 deletions app/(dynamic)/projects/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import Profile from "@/components/Profile";
import { Icon } from "@iconify/react";
import Image from "next/image";

export default function ProjectPage({ params }: {
params: { slug: string };
}) {
interface ProjectPageProps {
params: Promise<{slug: string}>
}

export default async function ProjectPage(props: ProjectPageProps) {
const params = await props.params;

return (
<>
<ArticleContainer>
Expand Down
13 changes: 13 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
@tailwind components;
@tailwind utilities;

body {
transition-property: opacity, filter;
transition-timing-function: ease-in-out;
transition-duration: 350ms;
}

@layer components {
.page-transition {
opacity: 0;
filter: blur(12px);
}
}

@layer utilities {
.text-balance {
text-wrap: balance;
Expand Down
36 changes: 29 additions & 7 deletions components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Icon } from "@iconify/react";
import { usePathname } from "next/navigation";
import { loadStoredTheme } from "@/lib/themeUtils";
import { useEffect, useState } from "react";
import Link from "next/link";

export default function Header() {
const path = usePathname();
Expand Down Expand Up @@ -37,18 +38,30 @@ export default function Header() {
className={`py-4 bg-base-light dark:bg-base-dark border-b border-gray-200 dark:border-gray-800 sticky top-0 z-40
${
isScrolled
? "" // (THIS IS CURRENTLY DISABLED 'KAY?) bg-opacity-20 dark:bg-base-light dark:bg-opacity-[7%] backdrop-blur-lg drop-shadow-lg
? "" // (THIS IS CURRENTLY DISABLED 'KAY?) bg-opacity-20 dark:bg-base-light dark:bg-opacity-[7%] backdrop-blur-lg drop-shadow-lg
: ""
}`}
>
<div className="container flex items-center flex-col gap-4 lg:flex-row justify-between">
<div className="flex justify-between w-full lg:w-fit lg:justify-start">
<div className="flex lg:items-center justify-center lg:justify-start gap-2">
<Icon icon="material-symbols-light:code" fontSize={32} fontWeight={300}></Icon>
<h5 className="font-semibold text-2xl">Shava Jaya</h5>
</div>
<Link href="/" className="flex lg:items-center justify-center lg:justify-start gap-2">
<Icon
icon="material-symbols-light:code"
fontSize={32}
fontWeight={300}
>
</Icon>

<h5 className="font-semibold text-2xl">
Shava Jaya
</h5>
</Link>

<Button className="lg:hidden" icon="mdi-light:menu" onClick={handleCollapse} />
<Button
className="lg:hidden"
icon="mdi-light:menu"
onClick={handleCollapse}
/>
</div>

<div
Expand All @@ -58,21 +71,30 @@ export default function Header() {
}`}
>
<nav className="flex lg:items-center flex-col lg:flex-row gap-2">
<Menu href="/" active={path === "/"} icon="material-symbols-light:home-outline">Home</Menu>
<Menu
href="/"
active={path === "/"}
icon="material-symbols-light:home-outline"
>
Home
</Menu>

<Menu
href="/projects"
active={path.startsWith("/projects")}
icon="material-symbols-light:deployed-code-outline"
>
Projects
</Menu>

<Menu
href="/blog"
active={path.startsWith("/blog")}
icon="material-symbols-light:newspaper"
>
Blog
</Menu>

<Menu
href="/contact"
active={path.startsWith("/contact")}
Expand Down
6 changes: 3 additions & 3 deletions components/Header/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from "next/link";
import { Icon } from "@iconify/react";
import TransitionLink from "@/components/TransitionLink";

interface MenuProps {
href: string;
Expand All @@ -10,7 +10,7 @@ interface MenuProps {

export default function Menu({ href, icon, active, children }: MenuProps) {
return (
<Link
<TransitionLink
href={href}
passHref
className={`${
Expand All @@ -22,6 +22,6 @@ export default function Menu({ href, icon, active, children }: MenuProps) {
>
{icon ? <Icon icon={icon} fontSize={24} fontWeight={600}></Icon> : null}
{children}
</Link>
</TransitionLink>
);
}
48 changes: 48 additions & 0 deletions components/TransitionLink/TransitionLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client";

import Link, { LinkProps } from "next/link";
import { useRouter } from "next/navigation";

interface TransitionLinkProps extends LinkProps {
href: string;
children?: React.ReactNode;
className?: string;
}

function sleep(duration: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, duration));
}

export default function TransitionLink(
{ href, children, className, ...props }: TransitionLinkProps,
) {
const router = useRouter();

const handleTransition = async (
e: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
) => {
e.preventDefault();

const body = document.querySelector("body");
body?.classList.add("page-transition");

await sleep(300);

router.push(href);

await sleep(350);

body?.classList.remove("page-transition");
};

return (
<Link
href={href}
onClick={handleTransition}
{...props}
className={className}
>
{children}
</Link>
);
}
1 change: 1 addition & 0 deletions components/TransitionLink/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './TransitionLink';
2 changes: 1 addition & 1 deletion components/Transitions/SlideDown/SlideDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function SlideDown(
) {
return (
<motion.div
initial={{ y: -200, opacity: 0, z: 30 }}
initial={{ y: -50, opacity: 0, z: 30 }}
whileInView={{ y: 0, opacity: 1, z: 0, transition: { duration: delay ? delay : 1.2 } }}
viewport={{ once: true }}
>
Expand Down
3 changes: 2 additions & 1 deletion components/Transitions/SlideLeft/SlideLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export default function SlideLeft(
) {
return (
<motion.div
initial={{ x: 100, opacity: 0 }}
initial={{ x: 100, opacity: 0, z: 30 }}
whileInView={{
x: 0,
opacity: 1,
z: 0,
transition: { duration: delay ? delay : 1.2 },
}}
viewport={{ once: true }}
Expand Down
3 changes: 2 additions & 1 deletion components/Transitions/SlideRight/SlideRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export default function SlideRight(
) {
return (
<motion.div
initial={{ x: -100, opacity: 0 }}
initial={{ x: -50, opacity: 0, z: 30 }}
whileInView={{
x: 0,
opacity: 1,
z: 0,
transition: { duration: delay ? delay : 1.2 },
}}
viewport={{ once: true }}
Expand Down
2 changes: 1 addition & 1 deletion components/Transitions/SlideUp/SlideUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function SlideUp(
) {
return (
<motion.div
initial={{ y: 200, opacity: 0, z: 30 }}
initial={{ y: 50, opacity: 0, z: 30 }}
whileInView={{ y: 0, opacity: 1, z: 0, transition: { duration: delay ? delay : 1.2 } }}
viewport={{ once: true }}
>
Expand Down
2 changes: 1 addition & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createClient } from "@sanity/client";

const client = createClient({

Check failure on line 3 in lib/client.ts

View workflow job for this annotation

GitHub Actions / Tests

__tests__/page.test.tsx

Error: Configuration must contain `projectId` ❯ initConfig node_modules/.deno/@sanity[email protected]/node_modules/@sanity/client/src/config.ts:74:11 ❯ SanityClient.config node_modules/.deno/@sanity[email protected]/node_modules/@sanity/client/src/SanityClient.ts:797:26 ❯ new SanityClient node_modules/.deno/@sanity[email protected]/node_modules/@sanity/client/src/SanityClient.ts:754:10 ❯ Proxy.createClient node_modules/.deno/@sanity[email protected]/node_modules/@sanity/client/src/defineCreateClient.ts:30:5 ❯ lib/client.ts:3:16 ❯ app/(main)/page.tsx:13:32
projectId: process.env.SANITY_PROJECT_ID,
apiVersion: process.env.SANITY_API_VERSION,
apiVersion: process.env.SANITY_API_VERSION ? process.env.SANITY_API_VERSION : "v2022-03-07",
dataset: process.env.SANITY_DATASET,
token: process.env.SANITY_API_TOKEN,
useCdn: false,
Expand Down
Loading

0 comments on commit 73b1f21

Please sign in to comment.