feishin/src/renderer/hooks/use-container-query.ts

22 lines
557 B
TypeScript
Raw Normal View History

2022-12-19 15:59:14 -08:00
import { useElementSize } from '@mantine/hooks';
interface UseContainerQueryProps {
lg?: number;
md?: number;
sm?: number;
xl?: number;
}
export const useContainerQuery = (props?: UseContainerQueryProps) => {
const { lg, md, sm, xl } = props || {};
const { ref, width, height } = useElementSize();
const isXs = width >= 0;
const isSm = width >= (sm || 600);
2022-12-26 05:11:45 -08:00
const isMd = width >= (md || 768);
2022-12-19 15:59:14 -08:00
const isLg = width >= (lg || 1200);
const isXl = width >= (xl || 1500);
return { height, isLg, isMd, isSm, isXl, isXs, ref, width };
};