Files
supabase/packages/common/hooks/useBreakpoint.tsx
Marouane Souda 84126faa0a fix: tailwind xl breakpoint mismatch (#39814)
* fix: tailwind xl breakpoint mismatch

* fix: use lg breakpoint for ContributingToC

---------

Co-authored-by: Ali Waseem <waseema393@gmail.com>
2025-11-04 10:24:45 -07:00

40 lines
992 B
TypeScript

'use client'
import { useState } from 'react'
import { useIsomorphicLayoutEffect, useWindowSize } from 'react-use'
/**
* Map of Tailwind default breakpoint values. Allows setting a value by
* Tailwind breakpoint, so that it syncs up with CSS changes.
*
* Note Tailwind uses `min-width` logic, whereas we use `max-width` logic, so
* the values are offset by 1px.
*
* Source:
* https://tailwindcss.com/docs/responsive-design
*/
const twBreakpointMap = {
sm: 639,
md: 767,
lg: 1023,
xl: 1279,
'2xl': 1535,
}
export function useBreakpoint(breakpoint: number | keyof typeof twBreakpointMap = 'lg') {
const [isBreakpoint, setIsBreakpoint] = useState(false)
const { width } = useWindowSize()
const _breakpoint = typeof breakpoint === 'string' ? twBreakpointMap[breakpoint] : breakpoint
useIsomorphicLayoutEffect(() => {
if (width <= _breakpoint) {
setIsBreakpoint(true)
} else {
setIsBreakpoint(false)
}
}, [width])
return isBreakpoint
}