11/* eslint-disable no-undef */
22import * as React from 'react'
3- import { getBreakpoints , Theme } from '@xstyled/system'
3+ import { getScreens , ITheme , Screens } from '@xstyled/system'
44
5- export function useThemeBreakpoints ( theme : Theme ) {
6- return getBreakpoints ( { theme } )
5+ export function useThemeScreens ( theme : ITheme ) : Screens {
6+ return getScreens ( { theme } )
77}
88
99/**
1010 * Minimum breakpoint width.
1111 * Null for the smallest breakpoint.
1212 */
13- function useThemeMinValue ( theme : Theme , key : string | number ) {
14- const breakpoints = useThemeBreakpoints ( theme )
15- const value = breakpoints [ key ]
13+ function useThemeMinValue ( theme : ITheme , key : string | number ) : number | null {
14+ const screens = useThemeScreens ( theme )
15+ const value = screens [ key ]
1616 return value === 0 ? null : value
1717}
1818
@@ -24,13 +24,13 @@ function useThemeMinValue(theme: Theme, key: string | number) {
2424 * Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
2525 * See https://bugs.webkit.org/show_bug.cgi?id=178261
2626 */
27- function useThemeMaxValue ( theme : Theme , key : string | number ) {
28- const breakpoints = useThemeBreakpoints ( theme )
29- const breakPoint = breakpoints [ key ]
27+ function useThemeMaxValue ( theme : ITheme , key : string | number ) : number | null {
28+ const screens = useThemeScreens ( theme )
29+ const breakPoint = screens [ key ]
3030 return breakPoint === 0 ? null : breakPoint - 0.02
3131}
3232
33- export function useViewportWidth ( ) {
33+ export function useViewportWidth ( ) : number | null {
3434 const [ width , setWidth ] = React . useState (
3535 typeof window === 'undefined' ? null : window . innerWidth ,
3636 )
@@ -50,27 +50,25 @@ export function useViewportWidth() {
5050 return width
5151}
5252
53- export function useThemeBreakpoint ( theme : Theme ) {
54- const breakpoints = useThemeBreakpoints ( theme )
53+ export function useThemeBreakpoint ( theme : ITheme ) : string | null {
54+ const screns = useThemeScreens ( theme )
5555 const width = useViewportWidth ( )
5656 return React . useMemo ( ( ) => {
5757 return (
58- Object . keys ( breakpoints )
58+ Object . keys ( screns )
5959 . reverse ( )
60- . find (
61- ( breakpoint ) => width !== null && width > breakpoints [ breakpoint ] ,
62- ) || null
60+ . find ( ( screen ) => width !== null && width > screns [ screen ] ) || null
6361 )
64- } , [ breakpoints , width ] )
62+ } , [ screns , width ] )
6563}
6664
67- export function useThemeUp ( theme : Theme , key : string | number ) {
65+ export function useThemeUp ( theme : ITheme , key : string | number ) : boolean {
6866 const value = useThemeMinValue ( theme , key )
6967 const width = useViewportWidth ( )
7068 return width !== null && value !== null && width >= value
7169}
7270
73- export function useThemeDown ( theme : Theme , key : string | number ) {
71+ export function useThemeDown ( theme : ITheme , key : string | number ) : boolean {
7472 const value = useThemeMaxValue ( theme , key )
7573 const width = useViewportWidth ( )
7674 return width !== null && value !== null && width < value
0 commit comments