import { Breakpoint , useMatchedBreakpoints } from "./BreakpointProvider" ; import { isNil , isObject } from "../../shared" ; export type ResponsiveValue < T > = Partial < Record < Breakpoint , T > > & { base ? : T ; } ; export type ResponsiveProp < T > = T | ResponsiveValue < T > ; export function parseResponsiveValue < T > ( value , matchedBreakpoints ) { if ( isObject ( value ) ) { for ( let i = 0 ; i < matchedBreakpoints . length ; i ++ ) { const responsiveValue = value [ matchedBreakpoints [ i ] ] ; if ( ! isNil ( responsiveValue ) ) { return responsiveValue as T ; } } return value [ "base" ] as T ; } return value as T ; } export function useResponsiveValue < T > ( value ) { const matchedBreakpoints = useMatchedBreakpoints ( ) ; return parseResponsiveValue ( value , matchedBreakpoints ) ; }