🍞 Improved path breadcrumb (#62)

This commit is contained in:
Montassar Ghanmy
2023-06-02 10:08:39 +01:00
committed by GitHub
parent 5e49f78436
commit 78caea4e92
2 changed files with 80 additions and 41 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [14.x] node-version: [16.x]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@@ -1,4 +1,3 @@
import { Button } from '@atoms/button/button';
import { Title } from '@atoms/text'; import { Title } from '@atoms/text';
import { DriveItem } from '@features/drive/types'; import { DriveItem } from '@features/drive/types';
import { ChevronDownIcon } from '@heroicons/react/solid'; import { ChevronDownIcon } from '@heroicons/react/solid';
@@ -33,9 +32,11 @@ export const PathRender = ({
inTrash: boolean; inTrash: boolean;
onClick: (id: string) => void; onClick: (id: string) => void;
}) => { }) => {
const pathLength = (path || []).reduce((acc, curr) => acc + curr.name.length, 0);
return ( return (
<Title className="overflow-hidden whitespace-nowrap mr-2 pl-px inline-flex"> <nav className="overflow-hidden whitespace-nowrap mr-2 pl-px inline-flex">
{(path || [])?.map((a, i) => ( {pathLength < 70 ? (
(path || [])?.map((a, i) => (
<PathItem <PathItem
key={a.id} key={a.id}
item={a} item={a}
@@ -43,8 +44,36 @@ export const PathRender = ({
last={i + 1 === path?.length} last={i + 1 === path?.length}
onClick={onClick} onClick={onClick}
/> />
))} ))
</Title> ) : (
<>
<PathItem
key={path[path.length - 3]?.id}
item={{
...path[path?.length - 3],
name: '...',
}}
first={true}
last={false}
onClick={onClick}
/>
<PathItem
key={path[path.length - 2]?.id}
item={path[path?.length - 2]}
first={false}
last={false}
onClick={onClick}
/>
<PathItem
key={path[path.length - 1]?.id}
item={path[path?.length - 1]}
first={false}
last={true}
onClick={onClick}
/>
</>
)}
</nav>
); );
}; };
@@ -61,14 +90,10 @@ const PathItem = ({
}) => { }) => {
const { user } = useCurrentUser(); const { user } = useCurrentUser();
return ( return (
<Button <div className="flex items-center">
theme={last ? 'primary' : 'default'} <a
className={ href="#"
'-ml-px shrink overflow-hidden whitespace-nowrap last:flex-[1_0_auto_!important] first:flex-[0_0_auto] first:flex-shrink-0 ' + className="text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white"
(!first ? 'rounded-l-none ' : '') +
(!last ? 'rounded-r-none ' : '') +
(!first && !last ? 'max-w-[15ch] ' : '')
}
onClick={evt => { onClick={evt => {
if (first) { if (first) {
MenusManager.openMenu( MenusManager.openMenu(
@@ -84,17 +109,31 @@ const PathItem = ({
} }
}} }}
> >
<span className="text-ellipsis overflow-hidden whitespace-nowrap" style={{ maxWidth: 120 }}> <Title>{item?.name || ''}</Title>
{item?.name || ''} </a>
</span>
{item?.access_info?.public?.level && item?.access_info?.public?.level !== 'none' && ( {item?.access_info?.public?.level && item?.access_info?.public?.level !== 'none' && (
<PublicIcon className="h-5 w-5 ml-2" /> <PublicIcon className="h-5 w-5 ml-2" />
)} )}
{first && ( {first && (
<span className="ml-2 -mr-1"> <span className="ml-2 -mr-1 text-gray-700">
<ChevronDownIcon className="w-4 h-4" /> <ChevronDownIcon className="w-4 h-4" />
</span> </span>
)} )}
</Button> {!last && (
<svg
aria-hidden="true"
className="w-6 h-6 text-gray-400 mx-1"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
clipRule="evenodd"
></path>
</svg>
)}
</div>
); );
}; };