forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia.ts
More file actions
31 lines (24 loc) · 801 Bytes
/
Copy pathmedia.ts
File metadata and controls
31 lines (24 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import weakMemo from '@emotion/weak-memoize';
import facepaint from 'facepaint';
type BREAKPOINTSTYPE = {
xs: number;
sm: number;
md: number;
lg: number;
};
export const BREAK_POINTS: BREAKPOINTSTYPE = { xs: 586, sm: 768, md: 992, lg: 1200 };
const minWidth = (width: number, m: boolean = true) =>
`${m ? '@media ' : ''}(min-width: ${width}px)`;
type MediaType = {
[P in keyof BREAKPOINTSTYPE]: string;
};
export const media: MediaType = Object.entries(BREAK_POINTS).reduce(
(obj, [key, value]) => ({ ...obj, [key]: minWidth(value) }),
{} as Record<keyof MediaType, string>
);
const paint = weakMemo(breakpoints =>
facepaint(Object.entries(breakpoints).map(([, width]) => `@media (min-width: ${width}px)`))
);
export function useMediaQuery() {
return paint(BREAK_POINTS);
}