Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXED: Implement Dropdown for Hidden Breadcrumb Paths Across the Platform #9413

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 83 additions & 63 deletions src/components/Common/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ import { useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbList,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

import useAppHistory from "@/hooks/useAppHistory";

Expand Down Expand Up @@ -70,76 +82,84 @@ export default function Breadcrumbs({
className={classNames("text-sm font-normal", crumb.style)}
>
<div className="flex items-center">
<CareIcon icon="l-angle-right" className="h-4 text-gray-400" />
{isLastItem ? (
<span className="text-gray-600">{crumb.name}</span>
) : (
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 underline underline-offset-2 hover:text-gray-700"
>
<Link href={crumb.uri}>{crumb.name}</Link>
</Button>
)}
<BreadcrumbSeparator className="text-gray-400" />
{isLastItem && <span className="text-gray-600">{crumb.name}</span>}
modamaan marked this conversation as resolved.
Show resolved Hide resolved
</div>
</li>
);
};

return (
<nav className={classNames("w-full", className)} aria-label="Breadcrumb">
<ol className="flex flex-wrap items-center">
{!hideBack && (
<li className="mr-3 flex items-center">
<Button
variant="link"
className="rounded bg-gray-200/50 px-1 text-sm font-normal text-gray-800 transition hover:bg-gray-200/75 hover:no-underline"
size="xs"
onClick={() => {
if (onBackClick && onBackClick() === false) return;
goBack(backUrl);
}}
>
<CareIcon icon="l-arrow-left" className="h-5 text-gray-700" />
<span className="pr-2">Back</span>
</Button>
</li>
)}
<li>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 underline underline-offset-2 hover:text-gray-700"
>
<Link href="/">Home</Link>
</Button>
</li>
{crumbs && crumbs.length > 1 && (
<>
{!showFullPath && (
<li>
<div className="flex items-center">
<CareIcon
icon="l-angle-right"
className="h-4 text-gray-400"
/>
<Button
variant="link"
className="h-auto p-0 font-light text-gray-500 hover:text-gray-700"
onClick={() => setShowFullPath(true)}
>
•••
</Button>
</div>
<Breadcrumb>
<nav className={classNames("w-full", className)} aria-label="Breadcrumb">
<BreadcrumbList>
<ol className="flex flex-wrap items-center">
{!hideBack && (
<li className="mr-3 flex items-center">
<Button
variant="link"
className="rounded bg-gray-200/50 px-1 text-sm font-normal text-gray-800 transition hover:bg-gray-200/75 hover:no-underline"
size="xs"
onClick={() => {
if (onBackClick && onBackClick() === false) return;
goBack(backUrl);
}}
>
<CareIcon icon="l-arrow-left" className="h-5 text-gray-700" />
<span className="pr-2">Back</span>
</Button>
</li>
)}
{showFullPath && crumbs.slice(0, -1).map(renderCrumb)}
</>
)}
{crumbs?.length &&
renderCrumb(crumbs[crumbs.length - 1], crumbs.length - 1)}
</ol>
</nav>
<BreadcrumbItem>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 hover:text-gray-700"
>
<Link href="/">Home</Link>
</Button>
</BreadcrumbItem>
{crumbs && crumbs.length > 1 && (
<>
{!showFullPath && (
<li>
<div className="flex items-center ml-[-2px]">
<BreadcrumbSeparator className="text-gray-400" />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="link"
className="h-auto p-0 font-light text-gray-500 hover:text-gray-700"
onClick={() => setShowFullPath(true)}
>
•••
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
{crumbs.slice(0, -1).map((crumb, index) => (
<DropdownMenuItem key={index}>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 underline underline-offset-2 hover:text-gray-700"
modamaan marked this conversation as resolved.
Show resolved Hide resolved
>
<Link href={crumb.uri}>{crumb.name}</Link>
</Button>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
modamaan marked this conversation as resolved.
Show resolved Hide resolved
</div>
</li>
)}
{showFullPath && crumbs.slice(0, -1).map(renderCrumb)}
</>
)}
{crumbs?.length &&
renderCrumb(crumbs[crumbs.length - 1], crumbs.length - 1)}
</ol>
</BreadcrumbList>
</nav>
</Breadcrumb>
modamaan marked this conversation as resolved.
Show resolved Hide resolved
);
}
118 changes: 118 additions & 0 deletions src/components/ui/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { ChevronRightIcon, DotsHorizontalIcon } from "@radix-ui/react-icons";
import { Slot } from "@radix-ui/react-slot";
import * as React from "react";

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

const Breadcrumb = React.forwardRef<
HTMLElement,
React.ComponentPropsWithoutRef<"nav"> & {
separator?: React.ReactNode;
}
>(({ ...props }, ref) => <nav ref={ref} aria-label="breadcrumb" {...props} />);
Breadcrumb.displayName = "Breadcrumb";

const BreadcrumbList = React.forwardRef<
HTMLOListElement,
React.ComponentPropsWithoutRef<"ol">
>(({ className, ...props }, ref) => (
<ol
ref={ref}
className={cn(
"flex flex-wrap items-center gap-1.5 break-words text-sm text-gray-500 sm:gap-2.5 dark:text-gray-400",
className,
)}
{...props}
/>
));
BreadcrumbList.displayName = "BreadcrumbList";

const BreadcrumbItem = React.forwardRef<
HTMLLIElement,
React.ComponentPropsWithoutRef<"li">
>(({ className, ...props }, ref) => (
<li
ref={ref}
className={cn("inline-flex items-center gap-1.5", className)}
{...props}
/>
));
BreadcrumbItem.displayName = "BreadcrumbItem";

const BreadcrumbLink = React.forwardRef<
HTMLAnchorElement,
React.ComponentPropsWithoutRef<"a"> & {
asChild?: boolean;
}
>(({ asChild, className, ...props }, ref) => {
const Comp = asChild ? Slot : "a";

return (
<Comp
ref={ref}
className={cn(
"transition-colors hover:text-gray-950 dark:hover:text-gray-50",
className,
)}
{...props}
/>
);
});
BreadcrumbLink.displayName = "BreadcrumbLink";

const BreadcrumbPage = React.forwardRef<
HTMLSpanElement,
React.ComponentPropsWithoutRef<"span">
>(({ className, ...props }, ref) => (
<span
ref={ref}
role="link"
aria-disabled="true"
aria-current="page"
className={cn("font-normal text-gray-950 dark:text-gray-50", className)}
{...props}
/>
));
BreadcrumbPage.displayName = "BreadcrumbPage";

const BreadcrumbSeparator = ({
children,
className,
...props
}: React.ComponentProps<"li">) => (
<li
role="presentation"
aria-hidden="true"
className={cn("[&>svg]:w-3.5 [&>svg]:h-3.5", className)}
{...props}
>
{children ?? <ChevronRightIcon />}
</li>
);
BreadcrumbSeparator.displayName = "BreadcrumbSeparator";

const BreadcrumbEllipsis = ({
className,
...props
}: React.ComponentProps<"span">) => (
<span
role="presentation"
aria-hidden="true"
className={cn("flex h-9 w-9 items-center justify-center", className)}
{...props}
>
<DotsHorizontalIcon className="h-4 w-4" />
<span className="sr-only">More</span>
</span>
);
BreadcrumbEllipsis.displayName = "BreadcrumbElipssis";

export {
Breadcrumb,
BreadcrumbList,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbPage,
BreadcrumbSeparator,
BreadcrumbEllipsis,
};
Loading