import { useLocal } from "@/utils/use-local"; import { FC, ReactNode, useEffect } from "react"; import { Skeleton } from "../ui/skeleton"; export type BreadItem = { label: React.ReactNode; url?: string; onClick?: (ev: any) => void; }; type BreadcrumbProps = { on_load?: () => Promise; className?: string; props?: any; value?: BreadItem[]; }; export const Breadcrumb: FC = (_arg) => { const { on_load } = _arg; const local = useLocal({ list: _arg.value || ([] as BreadItem[]), status: "init" as "init" | "loading" | "ready", params: {}, }); if (_arg.value) { local.list = _arg.value; } useEffect(() => { (async () => { if (_arg.value) { local.status = "ready"; local.render(); return; } if (local.status === "init" && typeof on_load === "function") { local.status = "loading"; local.render(); local.list = await on_load(); local.status = "ready"; local.render(); } })(); }, [on_load]); return (
{local.status !== "ready" ? ( ) : ( <> {local.list === null ? ( <>

Null Breadcrumb

) : ( (local.list || []).map((item, index): ReactNode => { const lastIndex = local.list.length - 1; return ( <> {index === lastIndex ? (

{item?.label}

) : (

{ if (item.url) navigate(item.url || ""); if (item.onClick) item.onClick(ev); }} > {item?.label}

)} {index !== lastIndex && (
)} ); }) )} )}
); };