2023-01-06 22:46:07 +01:00
|
|
|
import { useMantineTheme } from '@mantine/core';
|
|
|
|
|
import create from 'zustand';
|
2023-01-13 10:57:57 +09:00
|
|
|
import { useConfigContext } from '../../../../config/provider';
|
2023-01-06 22:46:07 +01:00
|
|
|
|
|
|
|
|
export const useGridstackStore = create<GridstackStoreType>((set, get) => ({
|
|
|
|
|
mainAreaWidth: null,
|
|
|
|
|
currentShapeSize: null,
|
|
|
|
|
setMainAreaWidth: (w: number) =>
|
|
|
|
|
set((v) => ({ ...v, mainAreaWidth: w, currentShapeSize: getCurrentShapeSize(w) })),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
interface GridstackStoreType {
|
|
|
|
|
mainAreaWidth: null | number;
|
|
|
|
|
currentShapeSize: null | 'sm' | 'md' | 'lg';
|
|
|
|
|
setMainAreaWidth: (width: number) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 20:37:46 +01:00
|
|
|
export const useNamedWrapperColumnCount = (): 'small' | 'medium' | 'large' | null => {
|
2023-01-06 22:46:07 +01:00
|
|
|
const mainAreaWidth = useGridstackStore((x) => x.mainAreaWidth);
|
|
|
|
|
const { sm, xl } = useMantineTheme().breakpoints;
|
|
|
|
|
if (!mainAreaWidth) return null;
|
|
|
|
|
|
2023-01-11 20:37:46 +01:00
|
|
|
if (mainAreaWidth >= xl) return 'large';
|
|
|
|
|
|
|
|
|
|
if (mainAreaWidth >= sm) return 'medium';
|
2023-01-06 22:46:07 +01:00
|
|
|
|
2023-01-11 20:37:46 +01:00
|
|
|
return 'small';
|
|
|
|
|
};
|
2023-01-06 22:46:07 +01:00
|
|
|
|
2023-01-11 20:37:46 +01:00
|
|
|
export const useWrapperColumnCount = () => {
|
2023-01-13 10:57:57 +09:00
|
|
|
const { config } = useConfigContext();
|
|
|
|
|
const numberOfSidebars =
|
|
|
|
|
(config?.settings.customization.layout.enabledLeftSidebar ? 1 : 0) +
|
|
|
|
|
(config?.settings.customization.layout.enabledRightSidebar ? 1 : 0);
|
|
|
|
|
|
2023-01-11 20:37:46 +01:00
|
|
|
switch (useNamedWrapperColumnCount()) {
|
|
|
|
|
case 'large':
|
2023-01-13 10:57:57 +09:00
|
|
|
return 15 - numberOfSidebars * 2;
|
2023-01-11 20:37:46 +01:00
|
|
|
case 'medium':
|
2023-01-13 10:57:57 +09:00
|
|
|
return 9 - numberOfSidebars * 2;
|
2023-01-11 20:37:46 +01:00
|
|
|
case 'small':
|
|
|
|
|
return 3;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-01-06 22:46:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getCurrentShapeSize(size: number) {
|
|
|
|
|
return size >= 1400 ? 'lg' : size >= 768 ? 'md' : 'sm';
|
|
|
|
|
}
|