mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
60e96bcb72
* style: app sidebar, sidebar workspace dropdown and help section styling * style: consistent padding and spacing * feat: material icon global component * style: icons updated and tooltip added * style: project list spacing and project name truncate * style: sidebar padding and theming --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
220 lines
8.0 KiB
TypeScript
220 lines
8.0 KiB
TypeScript
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
|
|
// headless ui
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
|
// ui
|
|
import { CustomMenu, Icon, Tooltip } from "components/ui";
|
|
// icons
|
|
import { LinkIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline";
|
|
// helpers
|
|
import { truncateText } from "helpers/string.helper";
|
|
import { renderEmoji } from "helpers/emoji.helper";
|
|
// types
|
|
import { IProject } from "types";
|
|
|
|
type Props = {
|
|
project: IProject;
|
|
sidebarCollapse: boolean;
|
|
handleDeleteProject: () => void;
|
|
handleCopyText: () => void;
|
|
handleAddToFavorites?: () => void;
|
|
handleRemoveFromFavorites?: () => void;
|
|
};
|
|
|
|
const navigation = (workspaceSlug: string, projectId: string) => [
|
|
{
|
|
name: "Issues",
|
|
href: `/${workspaceSlug}/projects/${projectId}/issues`,
|
|
icon: "stack",
|
|
},
|
|
{
|
|
name: "Cycles",
|
|
href: `/${workspaceSlug}/projects/${projectId}/cycles`,
|
|
icon: "contrast",
|
|
},
|
|
{
|
|
name: "Modules",
|
|
href: `/${workspaceSlug}/projects/${projectId}/modules`,
|
|
icon: "dataset",
|
|
},
|
|
{
|
|
name: "Views",
|
|
href: `/${workspaceSlug}/projects/${projectId}/views`,
|
|
icon: "photo_filter",
|
|
},
|
|
{
|
|
name: "Pages",
|
|
href: `/${workspaceSlug}/projects/${projectId}/pages`,
|
|
icon: "article",
|
|
},
|
|
{
|
|
name: "Settings",
|
|
href: `/${workspaceSlug}/projects/${projectId}/settings`,
|
|
icon: "settings",
|
|
},
|
|
];
|
|
|
|
export const SingleSidebarProject: React.FC<Props> = ({
|
|
project,
|
|
sidebarCollapse,
|
|
handleDeleteProject,
|
|
handleCopyText,
|
|
handleAddToFavorites,
|
|
handleRemoveFromFavorites,
|
|
}) => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
return (
|
|
<Disclosure key={project?.id} defaultOpen={projectId === project?.id}>
|
|
{({ open }) => (
|
|
<>
|
|
<div className="flex items-center gap-x-1 text-custom-sidebar-text-100">
|
|
<Tooltip
|
|
tooltipContent={`${project?.name}`}
|
|
position="right"
|
|
className="ml-2"
|
|
disabled={!sidebarCollapse}
|
|
>
|
|
<Disclosure.Button
|
|
as="div"
|
|
className={`flex w-full cursor-pointer select-none items-center rounded-sm py-1 text-left text-sm font-medium ${
|
|
sidebarCollapse ? "justify-center" : "justify-between"
|
|
}`}
|
|
>
|
|
<div className="flex items-center gap-x-2">
|
|
{project.emoji ? (
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
{renderEmoji(project.emoji)}
|
|
</span>
|
|
) : project.icon_prop ? (
|
|
<div className="h-7 w-7 grid place-items-center">
|
|
<span
|
|
style={{ color: project.icon_prop.color }}
|
|
className="material-symbols-rounded text-lg"
|
|
>
|
|
{project.icon_prop.name}
|
|
</span>
|
|
</div>
|
|
) : (
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded bg-gray-700 uppercase text-white">
|
|
{project?.name.charAt(0)}
|
|
</span>
|
|
)}
|
|
|
|
{!sidebarCollapse && (
|
|
<p
|
|
className={`overflow-hidden text-ellipsis ${
|
|
open ? "" : "text-custom-sidebar-text-200"
|
|
}`}
|
|
>
|
|
{truncateText(project?.name, 14)}
|
|
</p>
|
|
)}
|
|
</div>
|
|
{!sidebarCollapse && (
|
|
<Icon
|
|
iconName="expand_more"
|
|
className={`${open ? "rotate-180" : ""} text-custom-text-200 duration-300`}
|
|
/>
|
|
)}
|
|
</Disclosure.Button>
|
|
</Tooltip>
|
|
|
|
{!sidebarCollapse && (
|
|
<CustomMenu ellipsis>
|
|
<CustomMenu.MenuItem onClick={handleDeleteProject}>
|
|
<span className="flex items-center justify-start gap-2 ">
|
|
<TrashIcon className="h-4 w-4" />
|
|
<span>Delete project</span>
|
|
</span>
|
|
</CustomMenu.MenuItem>
|
|
{handleAddToFavorites && (
|
|
<CustomMenu.MenuItem onClick={handleAddToFavorites}>
|
|
<span className="flex items-center justify-start gap-2">
|
|
<StarIcon className="h-4 w-4" />
|
|
<span>Add to favorites</span>
|
|
</span>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
{handleRemoveFromFavorites && (
|
|
<CustomMenu.MenuItem onClick={handleRemoveFromFavorites}>
|
|
<span className="flex items-center justify-start gap-2">
|
|
<StarIcon className="h-4 w-4" />
|
|
<span>Remove from favorites</span>
|
|
</span>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
<CustomMenu.MenuItem onClick={handleCopyText}>
|
|
<span className="flex items-center justify-start gap-2">
|
|
<LinkIcon className="h-4 w-4" />
|
|
<span>Copy project link</span>
|
|
</span>
|
|
</CustomMenu.MenuItem>
|
|
{project.archive_in > 0 && (
|
|
<CustomMenu.MenuItem
|
|
onClick={() =>
|
|
router.push(`/${workspaceSlug}/projects/${project?.id}/archived-issues/`)
|
|
}
|
|
>
|
|
<div className="flex items-center justify-start gap-2">
|
|
<Icon iconName="archive" className="h-4 w-4" />
|
|
<span>Archived Issues</span>
|
|
</div>
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
</CustomMenu>
|
|
)}
|
|
</div>
|
|
|
|
<Transition
|
|
enter="transition duration-100 ease-out"
|
|
enterFrom="transform scale-95 opacity-0"
|
|
enterTo="transform scale-100 opacity-100"
|
|
leave="transition duration-75 ease-out"
|
|
leaveFrom="transform scale-100 opacity-100"
|
|
leaveTo="transform scale-95 opacity-0"
|
|
>
|
|
<Disclosure.Panel className={`space-y-2 ${sidebarCollapse ? "" : "ml-[2.25rem]"}`}>
|
|
{navigation(workspaceSlug as string, project?.id).map((item) => {
|
|
if (
|
|
(item.name === "Cycles" && !project.cycle_view) ||
|
|
(item.name === "Modules" && !project.module_view) ||
|
|
(item.name === "Views" && !project.issue_views_view) ||
|
|
(item.name === "Pages" && !project.page_view)
|
|
)
|
|
return;
|
|
|
|
return (
|
|
<Link key={item.name} href={item.href}>
|
|
<a className="block w-full">
|
|
<Tooltip
|
|
tooltipContent={`${project?.name}: ${item.name}`}
|
|
position="right"
|
|
className="ml-2"
|
|
disabled={!sidebarCollapse}
|
|
>
|
|
<div
|
|
className={`group flex items-center rounded-md px-2 py-1.5 gap-2 text-xs font-medium outline-none ${
|
|
router.asPath.includes(item.href)
|
|
? "bg-custom-primary-100/10 text-custom-primary-100"
|
|
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80"
|
|
} ${sidebarCollapse ? "justify-center" : ""}`}
|
|
>
|
|
<Icon iconName={item.icon} />
|
|
{!sidebarCollapse && item.name}
|
|
</div>
|
|
</Tooltip>
|
|
</a>
|
|
</Link>
|
|
);
|
|
})}
|
|
</Disclosure.Panel>
|
|
</Transition>
|
|
</>
|
|
)}
|
|
</Disclosure>
|
|
);
|
|
};
|