Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from Dungeon-MASSters/nav-menu
Browse files Browse the repository at this point in the history
navbar
  • Loading branch information
NikonP authored Oct 14, 2023
2 parents 667d742 + c592b39 commit 0a8918d
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 33 deletions.
37 changes: 37 additions & 0 deletions frontend/MASSter-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/MASSter-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@hookform/resolvers": "^3.3.2",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
Expand Down
98 changes: 65 additions & 33 deletions frontend/MASSter-frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import { Link, Redirect, Route, Switch } from "wouter";
import { Link, Redirect, Route, Switch } from "wouter";
import { AuthPage } from "./pages/auth";
import { invalidateUser, logoutUser, useUser } from "./lib/use-user";
import { Button } from "./components/ui/button";
import { useQueryClient } from "react-query";
import { FullscreenLoader } from "./components/loaders";
import { MainPage } from "./pages/main";
import { GridPage } from "./pages/grid";
import { AddPromptPage } from "./pages/add-prompt";
import {
NavigationMenu,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
navigationMenuTriggerStyle
} from "./components/ui/navigation-menu";
import {
IconBrush,
IconLogout,
IconPhoto,
IconUser
} from "@tabler/icons-react";
import clsx from "clsx";

function App() {
const {
isSuccess: isAuthed,
refetch: refetchUser,
isLoading
isLoading,
data: user
} = useUser(false);
const qc = useQueryClient();

Expand All @@ -37,36 +51,54 @@ function App() {

return (
<div className="container">
{/* TODO: nav menu from shadcn */}
<div className="flex gap-2 items-center">
<Link
href="some page"
className="bg-primary p-2 rounded text-input"
>
Some page
</Link>
<Link
href="/grid"
className="bg-primary p-2 rounded text-input"
>
Grid
</Link>
<Link
href="/generate"
className="bg-primary p-2 rounded text-input"
>
Add
</Link>
<Button
onClick={() => {
console.log("logout");
logoutUser();
invalidateUser(qc).then(() => refetchUser());
}}
>
Logout
</Button>
</div>
<NavigationMenu className="mx-auto">
<NavigationMenuList className="justify-between flex">
<NavigationMenuItem
className={clsx(navigationMenuTriggerStyle())}
>
<Link href="/grid">
<NavigationMenuLink className="flex gap-1">
<IconPhoto />
<span>результаты генерации</span>
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
<NavigationMenuItem
className={clsx(navigationMenuTriggerStyle())}
>
<Link href="/generate">
<NavigationMenuLink className="flex gap-1">
<IconBrush />
<span>создать дизайн</span>
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
<NavigationMenuItem
className={clsx(navigationMenuTriggerStyle())}
>
<NavigationMenuLink className="flex gap-1">
<IconUser />
<span>{user.record["username"]}</span>
</NavigationMenuLink>
</NavigationMenuItem>

<NavigationMenuItem
className={clsx(navigationMenuTriggerStyle())}
>
<NavigationMenuLink
className="flex gap-1"
onClick={() => {
console.log("logout");
logoutUser();
invalidateUser(qc).then(() => refetchUser());
}}
>
<IconLogout />
<span>выйти</span>
</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>

<Switch>
<Route path="/" component={MainPage} />
Expand Down
128 changes: 128 additions & 0 deletions frontend/MASSter-frontend/src/components/ui/navigation-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import * as React from "react"
import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"
import { cva } from "class-variance-authority"
import { ChevronDown } from "lucide-react"

import { cn } from "@/lib/utils"

const NavigationMenu = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Root
ref={ref}
className={cn(
"relative z-10 flex max-w-max flex-1 items-center justify-center",
className
)}
{...props}
>
{children}
<NavigationMenuViewport />
</NavigationMenuPrimitive.Root>
))
NavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName

const NavigationMenuList = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.List>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.List
ref={ref}
className={cn(
"group flex flex-1 list-none items-center justify-center space-x-1",
className
)}
{...props}
/>
))
NavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName

const NavigationMenuItem = NavigationMenuPrimitive.Item

const navigationMenuTriggerStyle = cva(
"group inline-flex h-10 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[state=open]:bg-accent/50"
)

const NavigationMenuTrigger = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Trigger
ref={ref}
className={cn(navigationMenuTriggerStyle(), "group", className)}
{...props}
>
{children}{" "}
<ChevronDown
className="relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180"
aria-hidden="true"
/>
</NavigationMenuPrimitive.Trigger>
))
NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName

const NavigationMenuContent = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Content
ref={ref}
className={cn(
"left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto ",
className
)}
{...props}
/>
))
NavigationMenuContent.displayName = NavigationMenuPrimitive.Content.displayName

const NavigationMenuLink = NavigationMenuPrimitive.Link

const NavigationMenuViewport = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Viewport>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport>
>(({ className, ...props }, ref) => (
<div className={cn("absolute left-0 top-full flex justify-center")}>
<NavigationMenuPrimitive.Viewport
className={cn(
"origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 md:w-[var(--radix-navigation-menu-viewport-width)]",
className
)}
ref={ref}
{...props}
/>
</div>
))
NavigationMenuViewport.displayName =
NavigationMenuPrimitive.Viewport.displayName

const NavigationMenuIndicator = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Indicator>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Indicator>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Indicator
ref={ref}
className={cn(
"top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in",
className
)}
{...props}
>
<div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
</NavigationMenuPrimitive.Indicator>
))
NavigationMenuIndicator.displayName =
NavigationMenuPrimitive.Indicator.displayName

export {
navigationMenuTriggerStyle,
NavigationMenu,
NavigationMenuList,
NavigationMenuItem,
NavigationMenuContent,
NavigationMenuTrigger,
NavigationMenuLink,
NavigationMenuIndicator,
NavigationMenuViewport,
}

0 comments on commit 0a8918d

Please sign in to comment.