|
- "use strict";
-
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
-
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
-
- var _responsivePropType = _interopRequireDefault(require("./responsivePropType"));
-
- var _breakpoints = require("./breakpoints");
-
- function getPath(obj, path) {
- if (!path || typeof path !== 'string') {
- return null;
- }
-
- return path.split('.').reduce(function (acc, item) {
- return acc && acc[item] ? acc[item] : null;
- }, obj);
- }
-
- function style(options) {
- var prop = options.prop,
- _options$cssProperty = options.cssProperty,
- cssProperty = _options$cssProperty === void 0 ? options.prop : _options$cssProperty,
- themeKey = options.themeKey,
- transform = options.transform;
-
- var fn = function fn(props) {
- if (props[prop] == null) {
- return null;
- }
-
- var propValue = props[prop];
- var theme = props.theme;
- var themeMapping = getPath(theme, themeKey) || {};
-
- var styleFromPropValue = function styleFromPropValue(propValueFinal) {
- var value;
-
- if (typeof themeMapping === 'function') {
- value = themeMapping(propValueFinal);
- } else if (Array.isArray(themeMapping)) {
- value = themeMapping[propValueFinal];
- } else {
- value = getPath(themeMapping, propValueFinal) || propValueFinal;
-
- if (transform) {
- value = transform(value);
- }
- }
-
- if (cssProperty === false) {
- return value;
- }
-
- return (0, _defineProperty2.default)({}, cssProperty, value);
- };
-
- return (0, _breakpoints.handleBreakpoints)(props, propValue, styleFromPropValue);
- };
-
- fn.propTypes = process.env.NODE_ENV !== 'production' ? (0, _defineProperty2.default)({}, prop, _responsivePropType.default) : {};
- fn.filterProps = [prop];
- return fn;
- }
-
- var _default = style;
- exports.default = _default;
|