UNPKG

2.27 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = createSpacing;
7
8var _system = require("@material-ui/system");
9
10var warnOnce;
11
12function createSpacing() {
13 var spacingInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8;
14
15 // Already transformed.
16 if (spacingInput.mui) {
17 return spacingInput;
18 } // Material Design layouts are visually balanced. Most measurements align to an 8dp grid applied, which aligns both spacing and the overall layout.
19 // Smaller components, such as icons and type, can align to a 4dp grid.
20 // https://material.io/design/layout/understanding-layout.html#usage
21
22
23 var transform = (0, _system.createUnarySpacing)({
24 spacing: spacingInput
25 });
26
27 var spacing = function spacing() {
28 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29 args[_key] = arguments[_key];
30 }
31
32 if (process.env.NODE_ENV !== 'production') {
33 if (!(args.length <= 4)) {
34 console.error("Material-UI: Too many arguments provided, expected between 0 and 4, got ".concat(args.length));
35 }
36 }
37
38 if (args.length === 0) {
39 return transform(1);
40 }
41
42 if (args.length === 1) {
43 return transform(args[0]);
44 }
45
46 return args.map(function (argument) {
47 if (typeof argument === 'string') {
48 return argument;
49 }
50
51 var output = transform(argument);
52 return typeof output === 'number' ? "".concat(output, "px") : output;
53 }).join(' ');
54 }; // Backward compatibility, to remove in v5.
55
56
57 Object.defineProperty(spacing, 'unit', {
58 get: function get() {
59 if (process.env.NODE_ENV !== 'production') {
60 if (!warnOnce || process.env.NODE_ENV === 'test') {
61 console.error(['Material-UI: theme.spacing.unit usage has been deprecated.', 'It will be removed in v5.', 'You can replace `theme.spacing.unit * y` with `theme.spacing(y)`.', '', 'You can use the `https://github.com/mui-org/material-ui/tree/master/packages/material-ui-codemod/README.md#theme-spacing-api` migration helper to make the process smoother.'].join('\n'));
62 }
63
64 warnOnce = true;
65 }
66
67 return spacingInput;
68 }
69 });
70 spacing.mui = true;
71 return spacing;
72}
\No newline at end of file