This commit is contained in:
rizky 2024-08-02 04:36:16 -07:00
parent 75a5ff497f
commit f2fb7ed35a
1 changed files with 76 additions and 43 deletions

View File

@ -1,6 +1,7 @@
import { useLocal } from "@/utils/use-local"; import { useLocal } from "@/utils/use-local";
import { FC, ReactNode, useEffect } from "react"; import { FC, ReactNode, useEffect } from "react";
import { FieldLoading } from "../ui/field-loading"; import { FieldLoading } from "../ui/field-loading";
import { ChevronLeft } from "lucide-react";
export type BreadItem = { export type BreadItem = {
label: React.ReactNode; label: React.ReactNode;
@ -39,10 +40,13 @@ export const Breadcrumb: FC<BreadcrumbProps> = ({ value, className }) => {
local.value = value; local.value = value;
} }
const list = Array.isArray(local.value) ? local.value : [];
return ( return (
<div <div
className={cx( className={cx(
"breadcrumb c-w-full c-flex c-items-center c-flex-wrap", "breadcrumb c-w-full c-flex c-flex-wrap",
isMobile ? "c-items-stretch" : "c-items-center",
className className
)} )}
> >
@ -53,8 +57,9 @@ export const Breadcrumb: FC<BreadcrumbProps> = ({ value, className }) => {
{(!local.value || local.value.length === 0) && {(!local.value || local.value.length === 0) &&
isEditor && isEditor &&
"Breadcrumb"} "Breadcrumb"}
{(Array.isArray(local.value) ? local.value : []).map( {isDesktop && (
(cur, index): ReactNode => { <>
{list.map((cur, index): ReactNode => {
const lastIndex = (local.value || []).length - 1; const lastIndex = (local.value || []).length - 1;
return ( return (
@ -96,7 +101,35 @@ export const Breadcrumb: FC<BreadcrumbProps> = ({ value, className }) => {
)} )}
</> </>
); );
} })}
</>
)}
{isMobile && (
<>
{list.length > 1 && (
<div className={cx("c-flex c-items-stretch")}>
<div
className="breadcrumb-back c-flex c-items-center c-px-2 c-border-r "
onClick={(ev) => {
const cur = list[list.length - 2];
if (isEditor) return;
if (cur.url) navigate(cur.url || "");
if (cur.onClick) cur.onClick(ev);
}}
>
<ChevronLeft />
</div>
<h1 className="bredcrumb-label c-flex c-font-semibold c-items-center c-pl-2 c-text-xs md:c-text-base">
{list[list.length - 1].label}
</h1>
</div>
)}
{list.length === 1 && (
<h1 className="bredcrumb-label c-font-semibold c-flex c-px-3 c-items-center c-text-xs md:c-text-base">
{list[0].label}
</h1>
)}
</>
)} )}
</> </>
)} )}