Skip to content

Commit

Permalink
animate in and out back arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
jewlexx committed Dec 19, 2024
1 parent 29ffb0d commit bf34311
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@next/mdx": "^15.1.1",
"@types/mdx": "^2.0.13",
"gray-matter": "^4.0.3",
"motion": "^11.15.0",
"next": "^15.1.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
32 changes: 22 additions & 10 deletions src/app/_components/Back.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
'use client';

import { AnimatePresence, motion } from 'motion/react';
import { useRouter, usePathname } from 'next/navigation';
import { IoArrowBack } from 'react-icons/io5';

export function Back({}) {
export function Back() {
const router = useRouter();
const pathname = usePathname();

return (
<button
className="btn btn-ghost btn-lg btn-circle fixed left-5 top-5"
title="Go back"
onClick={() => {
window.history.back();
}}
>
<IoArrowBack />
</button>
<AnimatePresence>
{pathname !== '/' && (
<motion.button
className="btn btn-ghost btn-lg btn-circle fixed left-5 top-5"
title="Go back"
onClick={() => {
router.back();
}}
initial={{ opacity: 0 }}
whileInView={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
<IoArrowBack />
</motion.button>
)}
</AnimatePresence>
);
}
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from 'next';
import { Roboto, Roboto_Mono } from 'next/font/google';
import { Back } from './_components/Back';
import './globals.scss';

const roboto = Roboto({
Expand Down Expand Up @@ -27,6 +28,7 @@ export default function RootLayout({
<body
className={`${roboto.className} ${robotoMono.className} box-border min-h-full w-full pb-12 text-lg antialiased`}
>
<Back />
{children}
</body>
</html>
Expand Down
10 changes: 0 additions & 10 deletions src/app/projects/layout.tsx

This file was deleted.

0 comments on commit bf34311

Please sign in to comment.