Skip to content

Commit

Permalink
fix: header navigation responsive (reactjs-id#51)
Browse files Browse the repository at this point in the history
* fix: header navigation responsive
* fix: resolve bun conflict
  • Loading branch information
andihaki authored and fikrialwan committed Jul 28, 2024
1 parent 3c86ce2 commit e7e646f
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/components/shared/navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from "@remix-run/react";

const navigationItems = [
export const navigationItems = [
{ path: "/about", text: "Tentang Kami" },
{ path: "/blog", text: "Blog" },
{ path: "/events", text: "Acara" },
Expand Down
33 changes: 28 additions & 5 deletions app/components/shared/site-navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import { Link } from "@remix-run/react";
import { Navigation } from "./navigation";
import { AlignRight } from "lucide-react";

import { Sheet, SheetContent, SheetTrigger } from "~/components/ui/sheet";
import { Navigation, navigationItems } from "./navigation";

export function SiteNavigation() {
return (
<div className="flex justify-center items-center">
<nav className="container">
<Link to="/">
<span className="text-xl font-bold">ReactJS ID</span>
<nav className="container !p-4 !lg:p-8 items-center">
<Link to="/" className="text-xl font-bold">
ReactJS ID
</Link>
<Navigation className="gap-[75px]" />
<div className="hidden lg:block">
<Navigation className="gap-[75px]" />
</div>
<div className="block lg:hidden">
<Sheet>
<SheetTrigger>
<AlignRight />
</SheetTrigger>
<SheetContent side="right" className="bg-[#15181D] text-slate-50">
<ul className={`flex flex-col gap-4 text-slate-400`}>
{navigationItems.map((navItem) => (
<li key={navItem.path}>
<Link to={navItem.path}>
<SheetTrigger>{navItem.text}</SheetTrigger>
</Link>
</li>
))}
</ul>
</SheetContent>
</Sheet>
</div>
</nav>
</div>
);
Expand Down
144 changes: 144 additions & 0 deletions app/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import * as React from "react";
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { cva, type VariantProps } from "class-variance-authority";
import { X } from "lucide-react";

import { cn } from "~/utils/cn";

const Sheet = SheetPrimitive.Root;

const SheetTrigger = SheetPrimitive.Trigger;

const SheetClose = SheetPrimitive.Close;

const SheetPortal = SheetPrimitive.Portal;

const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay> & {
className?: string;
}
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
ref={ref}
/>
));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;

const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
right:
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
},
);

interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}

const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
));
SheetContent.displayName = SheetPrimitive.Content.displayName;

const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement> & { className?: string }) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className,
)}
{...props}
/>
);
SheetHeader.displayName = "SheetHeader";

const SheetFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement> & { className?: string }) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className,
)}
{...props}
/>
);
SheetFooter.displayName = "SheetFooter";

const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title> & {
className?: string;
}
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold text-foreground", className)}
{...props}
/>
));
SheetTitle.displayName = SheetPrimitive.Title.displayName;

const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description> & {
className?: string;
}
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
SheetDescription.displayName = SheetPrimitive.Description.displayName;

export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
};
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 @@
},
"dependencies": {
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@remix-run/node": "^2.10.2",
"@remix-run/react": "^2.10.2",
Expand Down

0 comments on commit e7e646f

Please sign in to comment.