2022-06-23 07:25:56 +00:00
|
|
|
import { PropsWithChildren, ReactNode } from 'react';
|
|
|
|
|
2022-06-28 07:42:42 +00:00
|
|
|
import { useSidebarState } from './useSidebarState';
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
interface Props {
|
2022-07-06 05:09:14 +00:00
|
|
|
title: ReactNode;
|
|
|
|
showTitleWhenOpen?: boolean;
|
|
|
|
'aria-label'?: string;
|
2022-06-23 07:25:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function SidebarSection({
|
|
|
|
title,
|
|
|
|
children,
|
2022-07-06 05:09:14 +00:00
|
|
|
showTitleWhenOpen,
|
|
|
|
'aria-label': ariaLabel,
|
2022-06-23 07:25:56 +00:00
|
|
|
}: PropsWithChildren<Props>) {
|
|
|
|
return (
|
2022-06-28 07:42:42 +00:00
|
|
|
<div>
|
2022-07-06 05:09:14 +00:00
|
|
|
<SidebarSectionTitle showWhenOpen={showTitleWhenOpen}>
|
|
|
|
{title}
|
|
|
|
</SidebarSectionTitle>
|
2022-06-23 07:25:56 +00:00
|
|
|
|
2022-07-06 05:09:14 +00:00
|
|
|
<nav
|
|
|
|
aria-label={typeof title === 'string' ? title : ariaLabel}
|
|
|
|
className="mt-4"
|
|
|
|
>
|
2022-06-23 07:25:56 +00:00
|
|
|
<ul>{children}</ul>
|
|
|
|
</nav>
|
2022-06-28 07:42:42 +00:00
|
|
|
</div>
|
2022-06-23 07:25:56 +00:00
|
|
|
);
|
|
|
|
}
|
2022-07-06 05:09:14 +00:00
|
|
|
|
|
|
|
interface TitleProps {
|
|
|
|
showWhenOpen?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function SidebarSectionTitle({
|
|
|
|
showWhenOpen,
|
|
|
|
children,
|
|
|
|
}: PropsWithChildren<TitleProps>) {
|
|
|
|
const { isOpen } = useSidebarState();
|
|
|
|
|
|
|
|
if (!isOpen && !showWhenOpen) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-02-12 21:04:24 +00:00
|
|
|
<li className="ml-3 text-sm text-gray-3 transition-all duration-500 ease-in-out be:text-gray-6">
|
2022-07-06 05:09:14 +00:00
|
|
|
{children}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|