domain-watchdog/assets/hooks/useBreakpoint.tsx

21 lines
580 B
TypeScript
Raw Normal View History

2024-12-31 13:55:42 +01:00
import type {Breakpoint} from 'antd'
import { theme} from 'antd'
2024-12-30 23:50:15 +01:00
import {useMediaQuery} from 'react-responsive'
2024-07-30 06:13:31 +02:00
2024-12-30 23:50:15 +01:00
const {useToken} = theme
2024-07-30 06:13:31 +02:00
2024-12-30 23:50:15 +01:00
type ScreenProperty = 'screenXXL' | 'screenXL' | 'screenLG' | 'screenMD' | 'screenSM' | 'screenXS'
2024-07-30 06:13:31 +02:00
const propertyName = (breakpoint: Breakpoint): ScreenProperty => {
2024-07-31 12:37:43 +02:00
return 'screen' + breakpoint.toUpperCase() as ScreenProperty
2024-12-30 23:50:15 +01:00
}
2024-07-30 06:13:31 +02:00
export default function useBreakpoint(
2024-07-31 12:37:43 +02:00
breakpoint: Breakpoint
2024-07-30 06:13:31 +02:00
) {
2024-07-31 12:37:43 +02:00
const {token} = useToken()
const width: number = token[propertyName(breakpoint)]
2024-07-30 06:13:31 +02:00
2024-07-31 12:37:43 +02:00
return useMediaQuery({maxWidth: width})
2024-07-30 06:13:31 +02:00
}