UNPKG

1.82 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _templateObject = _taggedTemplateLiteral(['\n ', '\n @media (min-width: ', ') {\n ', '\n }\n '], ['\n ', '\n @media (min-width: ', ') {\n ', '\n }\n ']);
8
9var _styledComponents = require('styled-components');
10
11var _config = require('./config');
12
13function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } /* eslint no-param-reassign: 0 */
14
15
16/**
17 * This method generates spacing as defined in the theme file.
18 * You can use this method like this:
19 * ${spacing.small`margin-top`}
20 * This applies the small spacing for all the breakpoints for the margin-top property.
21 *
22 * It works by exporting an object with all the spacing variations
23 * (e.g. small, medium, large) as css functions that generate all the media
24 * queries for the breakpoints.
25 */
26exports.default = Object.keys(_config.spacingPerBreakpoint).reduce(function (accumulator, label) {
27 accumulator[label] = function () {
28 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
29 args[_key] = arguments[_key];
30 }
31
32 return Object.keys(_config.spacingPerBreakpoint[label]).reduce(function (styledAccumulator, breakpoint) {
33 return (0, _styledComponents.css)(_templateObject, styledAccumulator, _config.breakpoints[breakpoint], function () {
34 // Get the styles
35 var styles = _styledComponents.css.apply(undefined, args);
36 // Replace {value} with the actual value
37 return styles.map(function (style) {
38 return style.replace(/{value}/g, _config.spacingPerBreakpoint[label][breakpoint]);
39 });
40 });
41 }, {});
42 };
43 return accumulator;
44}, {});
\No newline at end of file