add eslint, bug fixes

This commit is contained in:
Salam-vsem
2025-05-18 00:56:02 +03:00
parent bc645a8261
commit 33a432cbd1
18 changed files with 3264 additions and 32 deletions

33
src/libs/breakpoint.ts Normal file
View 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
}