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

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-01-13 18:56:00 +09:00
import { Card } from '@mantine/core';
2022-12-04 17:36:30 +01:00
import { RefObject } from 'react';
2023-01-04 23:54:34 +09:00
import { useCardStyles } from '../../../layout/useCardStyles';
2022-12-04 17:36:30 +01:00
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-13 14:12:09 +09:00
export const DashboardSidebar = ({ location, isGridstackReady }: DashboardSidebarProps) => {
const {
cx,
classes: { card: cardClass },
2023-01-17 13:17:48 +09:00
} = useCardStyles(true);
2023-01-13 14:12:09 +09:00
return (
2023-01-17 13:17:48 +09:00
<Card p={0} m={0} radius="lg" className={cardClass} withBorder>
2023-01-13 14:12:09 +09:00
{isGridstackReady && <SidebarInner location={location} />}
</Card>
);
};
2023-01-06 23:50:08 +01:00
2023-01-07 09:45:00 +01:00
interface DashboardSidebarInnerProps {
location: 'right' | 'left';
}
2023-01-06 23:50:08 +01:00
// 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 (
2023-01-13 14:12:09 +09:00
<div
ref={refs.wrapper}
className="grid-stack grid-stack-sidebar"
style={{
transitionDuration: '0s',
2023-01-17 13:17:48 +09:00
minWidth: 256,
height: '100%',
2023-01-17 13:17:48 +09:00
width: '100%',
2023-01-13 14:12:09 +09:00
}}
data-sidebar={location}
// eslint-disable-next-line react/no-unknown-property
gs-min-row={minRow}
>
<WrapperContent apps={apps} refs={refs} widgets={widgets} />
</div>
2023-01-07 09:45:00 +01:00
);
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;