UNPKG

2.78 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = createBreakpoints;
9exports.keys = void 0;
10
11var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
13var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
14
15// Sorted ASC by size. That's important.
16// It can't be configured as it's used statically for propTypes.
17var keys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
18
19exports.keys = keys;
20
21function createBreakpoints(breakpoints) {
22 var _breakpoints$values = breakpoints.values,
23 values = _breakpoints$values === void 0 ? {
24 xs: 0,
25 sm: 600,
26 md: 960,
27 lg: 1280,
28 xl: 1920
29 } : _breakpoints$values,
30 _breakpoints$unit = breakpoints.unit,
31 unit = _breakpoints$unit === void 0 ? 'px' : _breakpoints$unit,
32 _breakpoints$step = breakpoints.step,
33 step = _breakpoints$step === void 0 ? 5 : _breakpoints$step,
34 other = (0, _objectWithoutProperties2.default)(breakpoints, ["values", "unit", "step"]);
35
36 function up(key) {
37 var value = typeof values[key] === 'number' ? values[key] : key;
38 return "@media (min-width:".concat(value).concat(unit, ")");
39 }
40
41 function down(key) {
42 var endIndex = keys.indexOf(key) + 1;
43 var upperbound = values[keys[endIndex]];
44
45 if (endIndex === keys.length) {
46 // xl down applies to all sizes
47 return up('xs');
48 }
49
50 var value = typeof upperbound === 'number' && endIndex > 0 ? upperbound : key;
51 return "@media (max-width:".concat(value - step / 100).concat(unit, ")");
52 }
53
54 function between(start, end) {
55 var endIndex = keys.indexOf(end);
56
57 if (endIndex === keys.length - 1) {
58 return up(start);
59 }
60
61 return "@media (min-width:".concat(typeof values[start] === 'number' ? values[start] : start).concat(unit, ") and ") + "(max-width:".concat((endIndex !== -1 && typeof values[keys[endIndex + 1]] === 'number' ? values[keys[endIndex + 1]] : end) - step / 100).concat(unit, ")");
62 }
63
64 function only(key) {
65 return between(key, key);
66 }
67
68 var warnedOnce = false;
69
70 function width(key) {
71 if (process.env.NODE_ENV !== 'production') {
72 if (!warnedOnce) {
73 warnedOnce = true;
74 console.warn(["Material-UI: The `theme.breakpoints.width` utility is deprecated because it's redundant.", 'Use the `theme.breakpoints.values` instead.'].join('\n'));
75 }
76 }
77
78 return values[key];
79 }
80
81 return (0, _extends2.default)({
82 keys: keys,
83 values: values,
84 up: up,
85 down: down,
86 between: between,
87 only: only,
88 width: width
89 }, other);
90}
\No newline at end of file