Open menu dropdown
useBreakpoints
Reactive responsive breakpoints in JavaScript (isSmallScreen, isMediumScreen, isLargeScreen) from your breakpoint list, to change the behavior or the rendered components by screen size when CSS media queries are not enough. Built on useWindowSize.
Basic usage
ts
const breakpoints = {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
}
const {
isLargeScreen,
isMediumScreen,
isSmallScreen,
} = useBreakpoints({
breakpoints,
initialWidth: 0,
mediumBreakPoint: 'md',
largeBreakPoint: 'lg',
})Use the maz-ui breakpoints
To use the same thresholds as the mob-*, tab-* and lap-* Tailwind variants, feed the composable with screens (the scale of maz-ui, in px strings). getNumericScreensFromTailwind converts such a scale to numbers: useBreakpoints calls it for you, use it only when you need the numeric values yourself.
ts
import { useBreakpoints } from 'maz-ui/composables/useBreakpoints'
import { getNumericScreensFromTailwind, screens } from 'maz-ui/tailwindcss'
const { isSmallScreen, isMediumScreen, isLargeScreen, numericBreakpoints } = useBreakpoints({
breakpoints: screens,
mediumBreakPoint: 'tab-m',
largeBreakPoint: 'lap-s',
})
const thresholds = getNumericScreensFromTailwind(screens)
// { 'mob-s': 320, 'mob-m': 425, ..., 'tab-m': 768, 'lap-s': 1024, ... }See Breakpoints for the scale.
WARNING
More documentation to come