mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
22 lines
626 B
TypeScript
22 lines
626 B
TypeScript
export const SIZE_TO_MEDIA: any = {
|
|
xs: '(min-width: 0px)',
|
|
sm: '(min-width: 576px)',
|
|
md: '(min-width: 768px)',
|
|
lg: '(min-width: 992px)',
|
|
xl: '(min-width: 1200px)',
|
|
};
|
|
|
|
// Check if the window matches the media query
|
|
// at the breakpoint passed
|
|
// e.g. matchBreakpoint('sm') => true if screen width exceeds 576px
|
|
export const matchBreakpoint = (breakpoint: string | undefined) => {
|
|
if (breakpoint === undefined || breakpoint === '') {
|
|
return true;
|
|
}
|
|
if ((window as any).matchMedia) {
|
|
const mediaQuery = SIZE_TO_MEDIA[breakpoint];
|
|
return window.matchMedia(mediaQuery).matches;
|
|
}
|
|
return false;
|
|
};
|