add eslint, bug fixes
This commit is contained in:
33
src/libs/breakpoint.ts
Normal file
33
src/libs/breakpoint.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { TW_WIDTHS } from '@/constants/images'
|
||||
|
||||
type Breakpoint = keyof typeof TW_WIDTHS
|
||||
|
||||
export function getBreakpoint(): Breakpoint {
|
||||
if (typeof window === 'undefined') return 'XXS'
|
||||
|
||||
const width = window.innerWidth
|
||||
|
||||
if (width >= TW_WIDTHS._2XL) return '_2XL'
|
||||
if (width >= TW_WIDTHS.XL) return 'XL'
|
||||
if (width >= TW_WIDTHS.LG) return 'LG'
|
||||
if (width >= TW_WIDTHS.MD) return 'MD'
|
||||
if (width >= TW_WIDTHS.SM) return 'SM'
|
||||
if (width >= TW_WIDTHS.XS) return 'XS'
|
||||
return 'XXS'
|
||||
}
|
||||
|
||||
export function isAboveBreakpoint(size: Breakpoint): boolean {
|
||||
const currentBreakpoint = getBreakpoint()
|
||||
const breakpoints = Object.keys(TW_WIDTHS) as Breakpoint[]
|
||||
const currentIndex = breakpoints.indexOf(currentBreakpoint)
|
||||
const targetIndex = breakpoints.indexOf(size)
|
||||
return currentIndex >= targetIndex
|
||||
}
|
||||
|
||||
export function isBelowBreakpoint(size: Breakpoint): boolean {
|
||||
const currentBreakpoint = getBreakpoint()
|
||||
const breakpoints = Object.keys(TW_WIDTHS) as Breakpoint[]
|
||||
const currentIndex = breakpoints.indexOf(currentBreakpoint)
|
||||
const targetIndex = breakpoints.indexOf(size)
|
||||
return currentIndex < targetIndex
|
||||
}
|
||||
Reference in New Issue
Block a user