menu animation

This commit is contained in:
Timur Ercan
2022-12-06 20:44:21 +01:00
parent 926e9f0c17
commit d66e53880b
6 changed files with 75 additions and 32 deletions

View File

@ -1,5 +1,8 @@
import { Fragment } from "react"; import { Fragment } from "react";
import { Disclosure, Menu, Transition } from "@headlessui/react"; import { Disclosure, Menu, Transition } from "@headlessui/react";
import Link from "next/link";
import { useRouter } from "next/router";
import { import {
Bars3Icon, Bars3Icon,
BellIcon, BellIcon,
@ -15,12 +18,12 @@ const user = {
"https://pbs.twimg.com/profile_images/1382036502390181888/4BT30oTM_400x400.jpg", "https://pbs.twimg.com/profile_images/1382036502390181888/4BT30oTM_400x400.jpg",
}; };
const navigation = [ const navigation = [
{ name: "Dashboard", href: "/", current: true }, { name: "Dashboard", href: "/dashboard", current: true },
{ name: "Team", href: "/", current: false }, { name: "Team", href: "/team", current: false },
{ name: "Settings", href: "settings" }, { name: "Settings", href: "/settings" },
]; ];
const userNavigation = [ const userNavigation = [
{ name: "Your Profile", href: "#" }, { name: "Your Profile", href: "/settings" },
{ name: "Sign out", href: "/login" }, { name: "Sign out", href: "/login" },
]; ];
@ -29,6 +32,12 @@ function classNames(...classes: any) {
} }
export default function Layout({ children }: any) { export default function Layout({ children }: any) {
const router = useRouter();
navigation.forEach((element) => {
element.current = element.href == router.route;
});
return ( return (
<> <>
<div className="min-h-full"> <div className="min-h-full">
@ -43,7 +52,7 @@ export default function Layout({ children }: any) {
</div> </div>
<div className="hidden sm:-my-px sm:ml-6 sm:flex sm:space-x-8"> <div className="hidden sm:-my-px sm:ml-6 sm:flex sm:space-x-8">
{navigation.map((item) => ( {navigation.map((item) => (
<a <Link
key={item.name} key={item.name}
href={item.href} href={item.href}
className={classNames( className={classNames(
@ -55,7 +64,7 @@ export default function Layout({ children }: any) {
aria-current={item.current ? "page" : undefined} aria-current={item.current ? "page" : undefined}
> >
{item.name} {item.name}
</a> </Link>
))} ))}
</div> </div>
{/* Search section */} {/* Search section */}
@ -116,7 +125,7 @@ export default function Layout({ children }: any) {
{userNavigation.map((item) => ( {userNavigation.map((item) => (
<Menu.Item key={item.name}> <Menu.Item key={item.name}>
{({ active }) => ( {({ active }) => (
<a <Link
href={item.href} href={item.href}
className={classNames( className={classNames(
active ? "bg-gray-100" : "", active ? "bg-gray-100" : "",
@ -124,7 +133,7 @@ export default function Layout({ children }: any) {
)} )}
> >
{item.name} {item.name}
</a> </Link>
)} )}
</Menu.Item> </Menu.Item>
))} ))}

View File

@ -1,6 +1,9 @@
import Link from "next/link";
export default function Logo(props: any) { export default function Logo(props: any) {
return ( return (
<> <>
<Link href="/dashboard">
<svg <svg
className="w-12" className="w-12"
viewBox="0 0 88.6758041381836 32.18000030517578" viewBox="0 0 88.6758041381836 32.18000030517578"
@ -18,6 +21,7 @@ export default function Logo(props: any) {
></path> ></path>
</g> </g>
</svg> </svg>
</Link>
</> </>
); );
} }

View File

@ -24,15 +24,8 @@ const subNavigation = [
{ name: "Profile", href: "#", icon: UserCircleIcon, current: true }, { name: "Profile", href: "#", icon: UserCircleIcon, current: true },
{ name: "Account", href: "#", icon: CogIcon, current: false }, { name: "Account", href: "#", icon: CogIcon, current: false },
{ name: "Password", href: "#", icon: KeyIcon, current: false }, { name: "Password", href: "#", icon: KeyIcon, current: false },
{ name: "Notifications", href: "#", icon: BellIcon, current: false },
{ name: "Billing", href: "#", icon: CreditCardIcon, current: false },
{ name: "Integrations", href: "#", icon: SquaresPlusIcon, current: false }, { name: "Integrations", href: "#", icon: SquaresPlusIcon, current: false },
]; ];
const userNavigation = [
{ name: "Your Profile", href: "#" },
{ name: "Settings", href: "#" },
{ name: "Sign out", href: "#" },
];
function classNames(...classes: any) { function classNames(...classes: any) {
return classes.filter(Boolean).join(" "); return classes.filter(Boolean).join(" ");

View File

@ -1,5 +1,14 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
async redirects() {
return [
{
source: "/",
destination: "/dashboard",
permanent: true,
},
];
},
reactStrictMode: true, reactStrictMode: true,
swcMinify: true, swcMinify: true,
distDir: "build", distDir: "build",

View File

@ -0,0 +1,14 @@
import type { ReactElement } from "react";
import Layout from "../components/layout";
import Settings from "../components/settings";
import type { NextPageWithLayout } from "./_app";
const DashboardPage: NextPageWithLayout = () => {
return <>This is the dashboard page.</>;
};
DashboardPage.getLayout = function getLayout(page: ReactElement) {
return <Layout>{page}</Layout>;
};
export default DashboardPage;

14
apps/web/pages/team.tsx Normal file
View File

@ -0,0 +1,14 @@
import type { ReactElement } from "react";
import Layout from "../components/layout";
import Settings from "../components/settings";
import type { NextPageWithLayout } from "./_app";
const TeamPage: NextPageWithLayout = () => {
return <>This is the team page</>;
};
TeamPage.getLayout = function getLayout(page: ReactElement) {
return <Layout>{page}</Layout>;
};
export default TeamPage;