UNPKG

9.46 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _react = _interopRequireWildcard(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _withStyles = require("../helpers/withStyles");
13
14var _CinnectaTheme = _interopRequireDefault(require("../themes/CinnectaTheme"));
15
16var _Responsive = require("./Responsive");
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
21
22function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
23
24function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
26function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
28function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
29
30function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
32function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33
34function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
36function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
38function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
39
40function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
42var propTypes = {
43 bottom: _propTypes.default.number,
44 bottomLargeAndAbove: _propTypes.default.number,
45 bottomMediumAndAbove: _propTypes.default.number,
46 children: _propTypes.default.any,
47 horizontal: _propTypes.default.number,
48 horizontalLargeAndAbove: _propTypes.default.number,
49 horizontalMediumAndAbove: _propTypes.default.number,
50 inline: _propTypes.default.bool,
51 inside: _propTypes.default.bool,
52 left: _propTypes.default.number,
53 leftLargeAndAbove: _propTypes.default.number,
54 leftMediumAndAbove: _propTypes.default.number,
55 right: _propTypes.default.number,
56 rightLargeAndAbove: _propTypes.default.number,
57 rightMediumAndAbove: _propTypes.default.number,
58 top: _propTypes.default.number,
59 topLargeAndAbove: _propTypes.default.number,
60 topMediumAndAbove: _propTypes.default.number,
61 vertical: _propTypes.default.number,
62 verticalLargeAndAbove: _propTypes.default.number,
63 verticalMediumAndAbove: _propTypes.default.number,
64 isGreaterThan: _propTypes.default.func
65};
66
67var Spacing =
68/*#__PURE__*/
69function (_Component) {
70 _inherits(Spacing, _Component);
71
72 function Spacing() {
73 _classCallCheck(this, Spacing);
74
75 return _possibleConstructorReturn(this, _getPrototypeOf(Spacing).apply(this, arguments));
76 }
77
78 _createClass(Spacing, [{
79 key: "render",
80 value: function render() {
81 var _css, _css2;
82
83 var _this$props = this.props,
84 bottom = _this$props.bottom,
85 bottomLargeAndAbove = _this$props.bottomLargeAndAbove,
86 bottomMediumAndAbove = _this$props.bottomMediumAndAbove,
87 children = _this$props.children,
88 horizontal = _this$props.horizontal,
89 horizontalLargeAndAbove = _this$props.horizontalLargeAndAbove,
90 horizontalMediumAndAbove = _this$props.horizontalMediumAndAbove,
91 inline = _this$props.inline,
92 inside = _this$props.inside,
93 left = _this$props.left,
94 leftLargeAndAbove = _this$props.leftLargeAndAbove,
95 leftMediumAndAbove = _this$props.leftMediumAndAbove,
96 right = _this$props.right,
97 rightLargeAndAbove = _this$props.rightLargeAndAbove,
98 rightMediumAndAbove = _this$props.rightMediumAndAbove,
99 top = _this$props.top,
100 topLargeAndAbove = _this$props.topLargeAndAbove,
101 topMediumAndAbove = _this$props.topMediumAndAbove,
102 vertical = _this$props.vertical,
103 verticalLargeAndAbove = _this$props.verticalLargeAndAbove,
104 verticalMediumAndAbove = _this$props.verticalMediumAndAbove,
105 isGreaterThan = _this$props.isGreaterThan;
106
107 var getTopMargin = function getTopMargin() {
108 if ((topLargeAndAbove != null || verticalLargeAndAbove != null) && isGreaterThan('large')) {
109 return topLargeAndAbove || verticalLargeAndAbove;
110 } else if ((topMediumAndAbove != null || verticalMediumAndAbove != null) && isGreaterThan('medium')) {
111 return topMediumAndAbove || verticalMediumAndAbove;
112 } else {
113 return top || vertical;
114 }
115 };
116
117 var getRightMargin = function getRightMargin() {
118 if ((rightLargeAndAbove != null || horizontalLargeAndAbove != null) && isGreaterThan('large')) {
119 return rightLargeAndAbove || horizontalLargeAndAbove;
120 } else if ((rightMediumAndAbove != null || horizontalMediumAndAbove != null) && isGreaterThan('medium')) {
121 return rightMediumAndAbove || horizontalMediumAndAbove;
122 } else {
123 return right || horizontal;
124 }
125 };
126
127 var getBottomMargin = function getBottomMargin() {
128 if ((bottomLargeAndAbove != null || verticalLargeAndAbove != null) && isGreaterThan('large')) {
129 return bottomLargeAndAbove || verticalLargeAndAbove;
130 } else if ((bottomMediumAndAbove != null || verticalMediumAndAbove != null) && isGreaterThan('medium')) {
131 return bottomMediumAndAbove || verticalMediumAndAbove;
132 } else {
133 return bottom || vertical;
134 }
135 };
136
137 var getLeftMargin = function getLeftMargin() {
138 if ((leftLargeAndAbove != null || horizontalLargeAndAbove != null) && isGreaterThan('large')) {
139 return leftLargeAndAbove || horizontalLargeAndAbove;
140 } else if ((leftMediumAndAbove != null || horizontalMediumAndAbove != null) && isGreaterThan('medium')) {
141 return leftMediumAndAbove || horizontalMediumAndAbove;
142 } else {
143 return left || horizontal;
144 }
145 };
146
147 var topMargin = getTopMargin();
148 var rightMargin = getRightMargin();
149 var bottomMargin = getBottomMargin();
150 var leftMargin = getLeftMargin();
151 return inline ? _react.default.createElement("span", (0, _withStyles.css)((_css = {}, _defineProperty(_css, inside ? 'paddingTop' : 'marginTop', topMargin ? topMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css, inside ? 'paddingRight' : 'marginRight', rightMargin ? rightMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css, inside ? 'paddingBottom' : 'marginBottom', bottomMargin ? bottomMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css, inside ? 'paddingLeft' : 'marginLeft', leftMargin ? leftMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css, "display", 'inline-block'), _css)), children) : _react.default.createElement("div", (0, _withStyles.css)((_css2 = {}, _defineProperty(_css2, inside ? 'paddingTop' : 'marginTop', topMargin ? topMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css2, inside ? 'paddingRight' : 'marginRight', rightMargin ? rightMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css2, inside ? 'paddingBottom' : 'marginBottom', bottomMargin ? bottomMargin * _CinnectaTheme.default.unit : null), _defineProperty(_css2, inside ? 'paddingLeft' : 'marginLeft', leftMargin ? leftMargin * _CinnectaTheme.default.unit : null), _css2)), children);
152 }
153 }]);
154
155 return Spacing;
156}(_react.Component);
157
158Spacing.propTypes = propTypes;
159var SpacingWithBreakpoints = (0, _Responsive.withBreakpoints)(Spacing);
160var _default = SpacingWithBreakpoints;
161exports.default = _default;
\No newline at end of file