Files
grafana/public/app/core/hooks/useMediaQueryMinWidth.ts
Torkel Ödegaard b9bc069fb9 AppChrome/MegaMenu: Fixes issue with default state being initialised to undocked (#103507)
* AppChrome/MegaMenu: Fixes default mega menu docked state

* AppChrome/MegaMenu: Fixes default mega menu docked state

* Update thresholds

* Update

* pa11y fix

* remove unnessary css

* fixed pa11y config

* try fix pa11y config + unit tests

* just increase thresholds again...

---------

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
2025-04-07 16:00:05 +01:00

22 lines
725 B
TypeScript

import { useEffect, useMemo, useState } from 'react';
import { ThemeBreakpointsKey } from '@grafana/data';
import { useTheme2 } from '@grafana/ui';
export function useMediaQueryMinWidth(breakpoint: ThemeBreakpointsKey): boolean {
const theme = useTheme2();
const mediaQuery = useMemo(
() => window.matchMedia(`(min-width: ${theme.breakpoints.values[breakpoint]}px)`),
[theme, breakpoint]
);
const [isMatch, setIsMatch] = useState(mediaQuery.matches);
useEffect(() => {
const onChange = (e: MediaQueryListEvent) => setIsMatch(e.matches);
mediaQuery.addEventListener('change', onChange);
return () => mediaQuery.removeEventListener('change', onChange);
}, [mediaQuery]);
return isMatch;
}