mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
* fix: tailwind xl breakpoint mismatch * fix: use lg breakpoint for ContributingToC --------- Co-authored-by: Ali Waseem <waseema393@gmail.com>
40 lines
992 B
TypeScript
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
|
|
}
|