12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- "use strict";
- exports.__esModule = true;
- exports["default"] = directionalProperty;
- var _capitalizeString = _interopRequireDefault(require("../internalHelpers/_capitalizeString"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
- var positionMap = ['Top', 'Right', 'Bottom', 'Left'];
- function generateProperty(property, position) {
- if (!property) return position.toLowerCase();
- var splitProperty = property.split('-');
- if (splitProperty.length > 1) {
- splitProperty.splice(1, 0, position);
- return splitProperty.reduce(function (acc, val) {
- return "" + acc + (0, _capitalizeString["default"])(val);
- });
- }
- var joinedProperty = property.replace(/([a-z])([A-Z])/g, "$1" + position + "$2");
- return property === joinedProperty ? "" + property + position : joinedProperty;
- }
- function generateStyles(property, valuesWithDefaults) {
- var styles = {};
- for (var i = 0; i < valuesWithDefaults.length; i += 1) {
- if (valuesWithDefaults[i] || valuesWithDefaults[i] === 0) {
- styles[generateProperty(property, positionMap[i])] = valuesWithDefaults[i];
- }
- }
- return styles;
- }
- function directionalProperty(property) {
- for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- values[_key - 1] = arguments[_key];
- }
-
- var firstValue = values[0],
- _values$ = values[1],
- secondValue = _values$ === void 0 ? firstValue : _values$,
- _values$2 = values[2],
- thirdValue = _values$2 === void 0 ? firstValue : _values$2,
- _values$3 = values[3],
- fourthValue = _values$3 === void 0 ? secondValue : _values$3;
- var valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue];
- return generateStyles(property, valuesWithDefaults);
- }
- module.exports = exports.default;
|