UNPKG

@viktorvojtek/react-native-simple-components

Version:

Collection of essential UI components based on react-native components

84 lines (83 loc) 2.85 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); function mapShortStyleProps(styleProps) { const { bgColor, m, ml, mt, mr, mb, mx, my, p, pl, pt, pr, pb, px, py } = styleProps, restStyleProps = __rest(styleProps, ["bgColor", "m", "ml", "mt", "mr", "mb", "mx", "my", "p", "pl", "pt", "pr", "pb", "px", "py"]); const marginProps = { m, ml, mt, mr, mb, mx, my }; const paddingProps = { p, pl, pt, pr, pb, px, py }; let result = {}; const isMarginProps = Object.values(marginProps).some((value) => typeof value !== "undefined"); const isPaddingProps = Object.values(paddingProps).some((value) => typeof value !== "undefined"); if (isMarginProps) { result = Object.assign(Object.assign({}, result), mapMarginProps(marginProps)); } if (isPaddingProps) { result = Object.assign(Object.assign({}, result), mapPaddingProps(paddingProps)); } return [ Object.assign(Object.assign({}, restStyleProps), result), ]; } exports.default = mapShortStyleProps; function mapMarginProps(props) { const { m, ml, mt, mr, mb, mx, my } = props; let result = {}; if (typeof m !== "undefined") { result.margin = m; } if (typeof ml !== "undefined") { result.marginLeft = ml; } if (typeof mt !== "undefined") { result.marginTop = mt; } if (typeof mr !== "undefined") { result.marginRight = mr; } if (typeof mb !== "undefined") { result.marginBottom = mb; } if (typeof mx !== "undefined") { result.marginHorizontal = mx; } if (typeof my !== "undefined") { result.marginVertical = my; } return result; } function mapPaddingProps(props) { const { p, pl, pt, pr, pb, px, py } = props; let result = {}; if (typeof p !== "undefined") { result.padding = p; } if (typeof pl !== "undefined") { result.paddingLeft = pl; } if (typeof pt !== "undefined") { result.paddingTop = pt; } if (typeof pr !== "undefined") { result.paddingRight = pr; } if (typeof pb !== "undefined") { result.paddingBottom = pb; } if (typeof px !== "undefined") { result.paddingHorizontal = px; } if (typeof py !== "undefined") { result.paddingVertical = py; } return result; }