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

59 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-12-10 22:14:31 +01:00
import { WrapperType } from '../../../../types/wrapper';
import Widgets from '../../../../widgets';
import { IWidget, IWidgetDefinition } from '../../../../widgets/widgets';
2022-12-10 22:14:31 +01:00
import { Tiles } from '../../Tiles/tilesDefinitions';
import { GridstackTileWrapper } from '../../Tiles/TileWrapper';
import { useGridstack } from '../gridstack/use-gridstack';
interface DashboardWrapperProps {
wrapper: WrapperType;
}
export const DashboardWrapper = ({ wrapper }: DashboardWrapperProps) => {
const { refs, items, integrations } = useGridstack('wrapper', wrapper.id);
return (
<div
className="grid-stack grid-stack-wrapper"
style={{ transitionDuration: '0s' }}
data-wrapper={wrapper.id}
ref={refs.wrapper}
>
{items?.map((app) => {
const { component: TileComponent, ...tile } = Tiles['app'];
2022-12-10 22:14:31 +01:00
return (
<GridstackTileWrapper
id={app.id}
type="app"
key={app.id}
itemRef={refs.items.current[app.id]}
2022-12-10 22:14:31 +01:00
{...tile}
{...app.shape.location}
{...app.shape.size}
2022-12-10 22:14:31 +01:00
>
<TileComponent className="grid-stack-item-content" app={app} />
2022-12-10 22:14:31 +01:00
</GridstackTileWrapper>
);
})}
{Object.entries(integrations).map(([k, v]) => {
const widget = Widgets[k as keyof typeof Widgets] as IWidgetDefinition | undefined;
if (!widget) return null;
2022-12-10 22:14:31 +01:00
return (
<GridstackTileWrapper
type="module"
key={k}
itemRef={refs.items.current[k]}
id={widget.id}
{...widget.gridstack}
2022-12-10 22:14:31 +01:00
{...v.shape.location}
{...v.shape.size}
>
<widget.component className="grid-stack-item-content" module={v} />
2022-12-10 22:14:31 +01:00
</GridstackTileWrapper>
);
})}
</div>
);
};