Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 16s
CodeQL / Analyze (python) (push) Failing after 3s
i18n sync check / check:sync (push) Failing after 3s
React Doctor / react-doctor (push) Failing after 16s
Branch Build CE / Build-Push Admin Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Admin Manifest (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Web Manifest (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Proxy Manifest (push) Has been cancelled
Branch Build CE / Merge Space Manifest (push) Has been cancelled
Branch Build CE / Prepare AIO Assets (push) Has been cancelled
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge Live Collaboration Manifest (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge API Server Manifest (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (${{ matrix.arch }}) (push) Has been cancelled
Branch Build CE / Merge AIO Manifest (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
/**
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
import React, { useMemo } from "react";
|
|
import { observer } from "mobx-react";
|
|
import Link from "next/link";
|
|
import { Breadcrumbs } from "@plane/ui";
|
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
|
|
|
type Props = {
|
|
label?: string;
|
|
href?: string;
|
|
icon?: React.ReactNode;
|
|
disableTooltip?: boolean;
|
|
isLast?: boolean;
|
|
};
|
|
|
|
const IconWrapper = React.memo(function IconWrapper({ icon }: { icon: React.ReactNode }) {
|
|
return <div className="flex size-4 items-center justify-center overflow-hidden !text-16">{icon}</div>;
|
|
});
|
|
|
|
IconWrapper.displayName = "IconWrapper";
|
|
|
|
const LabelWrapper = React.memo(function LabelWrapper({ label }: { label: React.ReactNode }) {
|
|
return <div className="relative line-clamp-1 block max-w-[150px] truncate overflow-hidden text-primary">{label}</div>;
|
|
});
|
|
|
|
LabelWrapper.displayName = "LabelWrapper";
|
|
|
|
const BreadcrumbContent = React.memo(function BreadcrumbContent({
|
|
icon,
|
|
label,
|
|
}: {
|
|
icon?: React.ReactNode;
|
|
label?: React.ReactNode;
|
|
}) {
|
|
if (!icon && !label) return null;
|
|
|
|
return (
|
|
<>
|
|
{icon && <IconWrapper icon={icon} />}
|
|
{label && <LabelWrapper label={label} />}
|
|
</>
|
|
);
|
|
});
|
|
|
|
BreadcrumbContent.displayName = "BreadcrumbContent";
|
|
|
|
const ItemWrapper = React.memo(function ItemWrapper({
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof Breadcrumbs.ItemWrapper>) {
|
|
return <Breadcrumbs.ItemWrapper {...props}>{children}</Breadcrumbs.ItemWrapper>;
|
|
});
|
|
|
|
ItemWrapper.displayName = "ItemWrapper";
|
|
|
|
export const BreadcrumbLink = observer(function BreadcrumbLink(props: Props) {
|
|
const { href, label, icon, disableTooltip = false, isLast = false } = props;
|
|
const { isMobile } = usePlatformOS();
|
|
|
|
const itemWrapperProps = useMemo(
|
|
(): Omit<React.ComponentProps<typeof ItemWrapper>, "children"> => ({
|
|
label: label?.toString(),
|
|
disableTooltip: isMobile || disableTooltip,
|
|
type: href && href !== "" ? "link" : "text",
|
|
isLast,
|
|
}),
|
|
[href, label, isMobile, disableTooltip, isLast]
|
|
);
|
|
|
|
const content = useMemo(() => <BreadcrumbContent icon={icon} label={label} />, [icon, label]);
|
|
|
|
if (href) {
|
|
return (
|
|
<Link href={href}>
|
|
<ItemWrapper {...itemWrapperProps}>{content}</ItemWrapper>
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
return <ItemWrapper {...itemWrapperProps}>{content}</ItemWrapper>;
|
|
});
|