1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

fix(sidebar): sort issues [EE-3447] (#7147)

This commit is contained in:
Chaim Lev-Ari 2022-07-06 08:09:14 +03:00 committed by GitHub
parent d32793e84e
commit b004b33935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 65 deletions

View file

@ -3,28 +3,50 @@ import { PropsWithChildren, ReactNode } from 'react';
import { useSidebarState } from './useSidebarState';
interface Props {
title: string;
renderTitle?: (className: string) => ReactNode;
title: ReactNode;
showTitleWhenOpen?: boolean;
'aria-label'?: string;
}
export function SidebarSection({
title,
renderTitle,
children,
showTitleWhenOpen,
'aria-label': ariaLabel,
}: PropsWithChildren<Props>) {
const { isOpen } = useSidebarState();
const titleClassName =
'ml-3 text-sm text-gray-3 be:text-gray-6 transition-all duration-500 ease-in-out';
return (
<div>
{renderTitle
? renderTitle(titleClassName)
: isOpen && <li className={titleClassName}>{title}</li>}
<SidebarSectionTitle showWhenOpen={showTitleWhenOpen}>
{title}
</SidebarSectionTitle>
<nav aria-label={title} className="mt-4">
<nav
aria-label={typeof title === 'string' ? title : ariaLabel}
className="mt-4"
>
<ul>{children}</ul>
</nav>
</div>
);
}
interface TitleProps {
showWhenOpen?: boolean;
}
export function SidebarSectionTitle({
showWhenOpen,
children,
}: PropsWithChildren<TitleProps>) {
const { isOpen } = useSidebarState();
if (!isOpen && !showWhenOpen) {
return null;
}
return (
<li className="ml-3 text-sm text-gray-3 be:text-gray-6 transition-all duration-500 ease-in-out">
{children}
</li>
);
}