Skip to content

Commit

Permalink
feat : add mobile menu navigation , feat : add more breadcrumb examples
Browse files Browse the repository at this point in the history
  • Loading branch information
BelkacemYerfa committed Mar 29, 2024
1 parent d6eea84 commit e0d3053
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 7 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"**/.lintstagedrc.mjs": true,
"**/.markdownlint.json": true,
"**/.markdownlintignore": true,
"**/.next": true,
"**/.prettierignore": true,
"**/.svn": true,
"**/.todo.md": true,
Expand Down
10 changes: 10 additions & 0 deletions content/docs/breadcrumb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ import { Link } from "next/link";

## Examples

### Orientation

<ComponentPreview name="breadcrumb-orientation" />

### BreadCrumb Separator

<ComponentPreview name="breadcrumb-separator" />
Expand All @@ -228,6 +232,12 @@ By default, the Breadcrumb component uses the `default` variant for each item. Y

<ComponentPreview name="breadcrumb-variants" />

### BreadCrumb Active Item

You can indicate the active item by passing the `isActive` prop to the `BreadcrumbItem` component.

<ComponentPreview name="breadcrumb-active" />

<Alert className="mt-4" variant="info">
<MdxIcons.Info className="size-4" />
<AlertTitle>Good to know</AlertTitle>
Expand Down
14 changes: 14 additions & 0 deletions src/__registry__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ export const Index: Record<string, any> = {
component: React.lazy(() => import("@/registry/default/example/breadcrumb/breadcrumb-popover.tsx")),
files: ["src/registry/default/example/breadcrumb/breadcrumb-popover.tsx"],
},
"breadcrumb-active": {
name: "breadcrumb-active",
type: "components:example",
registryDependencies: ["breadcrumb"],
component: React.lazy(() => import("@/registry/default/example/breadcrumb/breadcrumb-active.tsx")),
files: ["src/registry/default/example/breadcrumb/breadcrumb-active.tsx"],
},
"breadcrumb-orientation": {
name: "breadcrumb-orientation",
type: "components:example",
registryDependencies: ["breadcrumb"],
component: React.lazy(() => import("@/registry/default/example/breadcrumb/breadcrumb-orientation.tsx")),
files: ["src/registry/default/example/breadcrumb/breadcrumb-orientation.tsx"],
},
"image-carousel-upload-example": {
name: "image-carousel-upload-example",
type: "components:example",
Expand Down
22 changes: 22 additions & 0 deletions src/components/layouts/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { Pages } from "@/config/docs-config";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import { Banner } from "@/components/banner";
import { useState } from "react";
import { Sheet, SheetContent, SheetTrigger } from "../ui/sheet";
import { Menu } from "lucide-react";
import { SideBar } from "../side-bar";

export const SiteHeader = () => {
const pathname = usePathname();
Expand All @@ -20,6 +24,7 @@ export const SiteHeader = () => {
<div className="flex items-center justify-between px-4 py-2 h-12 border-b border-border bg-background">
<nav className="mx-auto max-w-screen-2xl flex items-center justify-between w-full">
<div className="flex items-center gap-4">
<MobileMenu />
<Link href="/" className="flex items-center gap-2 truncate">
<Icons.logo className="h-5 w-5 fill-current" />
<Balancer as={"span"} className=" font-bold truncate ">
Expand Down Expand Up @@ -56,3 +61,20 @@ export const SiteHeader = () => {
</header>
);
};

const MobileMenu = () => {
const [open, setOpen] = useState(false);
return (
<div className="md:hidden">
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger>
<Menu className="size-4" />
<span className="sr-only">menu</span>
</SheetTrigger>
<SheetContent side={"left"}>
<SideBar setOpen={setOpen} />
</SheetContent>
</Sheet>
</div>
);
};
7 changes: 6 additions & 1 deletion src/components/side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import Link from "next/link";
import { buttonVariants } from "./ui/button";
import { usePathname } from "next/navigation";

export const SideBar = () => {
type SideBarProps = {
setOpen?: (open: boolean) => void;
};

export const SideBar = ({ setOpen }: SideBarProps) => {
const pathname = usePathname();
return (
<div className="flex flex-col py-2 gap-5 ">
Expand All @@ -19,6 +23,7 @@ export const SideBar = () => {
<Link
href={page?.path || "/"}
key={page.title}
onClick={() => setOpen?.(false)}
className={cn(
buttonVariants({
variant: "ghost",
Expand Down
140 changes: 140 additions & 0 deletions src/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"use client"

import * as React from "react"
import * as SheetPrimitive from "@radix-ui/react-dialog"
import { Cross2Icon } from "@radix-ui/react-icons"
import { cva, type VariantProps } from "class-variance-authority"

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

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, ...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">
<Cross2Icon 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>) => (
<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>) => (
<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, ...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, ...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,
}
12 changes: 12 additions & 0 deletions src/registry/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ const examples: Registry = [
registryDependencies: ["breadcrumb"],
files: ["example/breadcrumb/breadcrumb-popover.tsx"],
},
{
name: "breadcrumb-active",
type: "components:example",
registryDependencies: ["breadcrumb"],
files: ["example/breadcrumb/breadcrumb-active.tsx"],
},
{
name: "breadcrumb-orientation",
type: "components:example",
registryDependencies: ["breadcrumb"],
files: ["example/breadcrumb/breadcrumb-orientation.tsx"],
},
// Under development
{
name: "image-carousel-upload-example",
Expand Down
59 changes: 59 additions & 0 deletions src/registry/default/example/breadcrumb/breadcrumb-active.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use client";

import {
BreadCrumb,
BreadCrumbItem,
BreadCrumbSeparator,
} from "@/registry/default/extension/breadcrumb";
import Link from "next/link";
import { useSearchParams } from "next/navigation";

const Pages = [
{
title: "Home",
path: "home",
},
{
title: "Settings",
path: "settings",
},
{
title: "Account",
path: "account",
},
];

const BreadCrumbTest = () => {
const searchParams = useSearchParams();
const path = searchParams.get("path");
return (
<BreadCrumb
orientation="horizontal"
variant={"ghost"}
className="gap-1 bg-background rounded-lg p-2"
>
{Pages.map((page, index) => {
const isActive = path === page.path;
return (
<div key={`${page.title}-path`} className="flex items-center gap-1">
<BreadCrumbItem
isActive={isActive}
index={index}
className="h-8 px-2 "
activeVariant={{
variant: "default",
}}
>
<Link scroll={false} href={`?path=${page.path}`}>
{page.title}
</Link>
</BreadCrumbItem>
{index !== Pages.length - 1 && <BreadCrumbSeparator />}
</div>
);
})}
</BreadCrumb>
);
};

export default BreadCrumbTest;
46 changes: 46 additions & 0 deletions src/registry/default/example/breadcrumb/breadcrumb-orientation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
BreadCrumb,
BreadCrumbItem,
BreadCrumbSeparator,
} from "@/registry/default/extension/breadcrumb";
import Link from "next/link";

const Pages = [
{
title: "Home",
path: "home",
},
{
title: "Settings",
path: "settings",
},
{
title: "Account",
path: "account",
},
];

const BreadCrumbTest = () => {
return (
<BreadCrumb
orientation="vertical"
variant={"ghost"}
className="gap-1 bg-background rounded-lg p-2"
>
{Pages.map((page, index) => {
return (
<div key={`${page.title}-path`} className="flex items-center gap-1">
<BreadCrumbItem index={index} className="h-8 px-2 ">
<Link scroll={false} href={`#`}>
{page.title}
</Link>
</BreadCrumbItem>
{index !== Pages.length - 1 && <BreadCrumbSeparator />}
</div>
);
})}
</BreadCrumb>
);
};

export default BreadCrumbTest;
Loading

0 comments on commit e0d3053

Please sign in to comment.