-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
breakpoints.ts
56 lines (49 loc) · 1.21 KB
/
breakpoints.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/** @beta */
export interface ThemeBreakpointValues {
xs: number;
sm: number;
md: number;
lg: number;
xl: number;
xxl: number;
}
/** @beta */
export type ThemeBreakpointsKey = keyof ThemeBreakpointValues;
/** @beta */
export interface ThemeBreakpoints {
values: ThemeBreakpointValues;
keys: string[];
unit: string;
up: (key: ThemeBreakpointsKey | number) => string;
down: (key: ThemeBreakpointsKey | number) => string;
}
/** @internal */
export function createBreakpoints(): ThemeBreakpoints {
const step = 5;
const keys = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
const unit = 'px';
const values: ThemeBreakpointValues = {
xs: 0,
sm: 544,
md: 769, // 1 more than regular ipad in portrait
lg: 992,
xl: 1200,
xxl: 1440,
};
function up(key: ThemeBreakpointsKey | number) {
const value = typeof key === 'number' ? key : values[key];
return `@media (min-width:${value}${unit})`;
}
function down(key: ThemeBreakpointsKey | number) {
const value = typeof key === 'number' ? key : values[key];
return `@media (max-width:${value - step / 100}${unit})`;
}
// TODO add functions for between and only
return {
values,
up,
down,
keys,
unit,
};
}