Files
Homarr/src/components/Dashboard/Wrappers/Sidebar/Sidebar.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-12-04 17:36:30 +01:00
import { Card } from '@mantine/core';
import { RefObject } from 'react';
import { useGridstack } from '../gridstack/use-gridstack';
import { WrapperContent } from '../WrapperContent';
2022-12-04 17:36:30 +01:00
2023-01-06 23:50:08 +01:00
interface DashboardSidebarProps extends DashboardSidebarInnerProps {
2022-12-04 17:36:30 +01:00
location: 'right' | 'left';
2023-01-06 23:50:08 +01:00
isGridstackReady: boolean;
2022-12-04 17:36:30 +01:00
}
2023-01-06 23:50:08 +01:00
export const DashboardSidebar = ({ location, isGridstackReady }: DashboardSidebarProps) => (
2022-12-04 17:36:30 +01:00
<Card
withBorder
w={300}
style={{
background: 'none',
borderStyle: 'dashed',
}}
>
2023-01-06 23:50:08 +01:00
{isGridstackReady && <SidebarInner location={location} />}
2022-12-04 17:36:30 +01:00
</Card>
);
2023-01-06 23:50:08 +01:00
interface DashboardSidebarInnerProps {
location: 'right' | 'left';
}
// Is Required because of the gridstack main area width.
const SidebarInner = ({ location }: DashboardSidebarInnerProps) => {
const { refs, apps, widgets } = useGridstack('sidebar', location);
const minRow = useMinRowForFullHeight(refs.wrapper);
return (
<div
className="grid-stack grid-stack-sidebar"
style={{ transitionDuration: '0s', height: '100%' }}
data-sidebar={location}
// eslint-disable-next-line react/no-unknown-property
gs-min-row={minRow}
ref={refs.wrapper}
>
<WrapperContent apps={apps} refs={refs} widgets={widgets} />
</div>);
2022-12-04 17:36:30 +01:00
};
2022-12-20 11:45:33 +09:00
const useMinRowForFullHeight = (wrapperRef: RefObject<HTMLDivElement>) =>
2023-01-06 23:50:08 +01:00
wrapperRef.current ? Math.floor(wrapperRef.current!.offsetHeight / 128) : 2;