(breakpointKey: K)
| 14 | type ScreensConfig = typeof breakpoints; |
| 15 | |
| 16 | export function useBreakpoint<K extends string>(breakpointKey: K) { |
| 17 | const breakpointValue = breakpoints[breakpointKey as keyof ScreensConfig]; |
| 18 | const bool = useMediaQuery({ |
| 19 | query: `(max-width: ${breakpointValue as string})`, |
| 20 | }); |
| 21 | const capitalizedKey = |
| 22 | breakpointKey[0]?.toUpperCase() + breakpointKey.substring(1); |
| 23 | |
| 24 | type KeyAbove = `isAbove${Capitalize<K>}`; |
| 25 | type KeyBelow = `isBelow${Capitalize<K>}`; |
| 26 | |
| 27 | return { |
| 28 | [breakpointKey]: Number(String(breakpointValue).replace(/[^0-9]/g, '')), |
| 29 | [`isAbove${capitalizedKey}`]: !bool, |
| 30 | [`isBelow${capitalizedKey}`]: bool, |
| 31 | } as Record<K, number> & Record<KeyAbove | KeyBelow, boolean>; |
| 32 | } |
no test coverage detected