You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
2.0 KiB

  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  8. var _responsivePropType = _interopRequireDefault(require("./responsivePropType"));
  9. var _breakpoints = require("./breakpoints");
  10. function getPath(obj, path) {
  11. if (!path || typeof path !== 'string') {
  12. return null;
  13. }
  14. return path.split('.').reduce(function (acc, item) {
  15. return acc && acc[item] ? acc[item] : null;
  16. }, obj);
  17. }
  18. function style(options) {
  19. var prop = options.prop,
  20. _options$cssProperty = options.cssProperty,
  21. cssProperty = _options$cssProperty === void 0 ? options.prop : _options$cssProperty,
  22. themeKey = options.themeKey,
  23. transform = options.transform;
  24. var fn = function fn(props) {
  25. if (props[prop] == null) {
  26. return null;
  27. }
  28. var propValue = props[prop];
  29. var theme = props.theme;
  30. var themeMapping = getPath(theme, themeKey) || {};
  31. var styleFromPropValue = function styleFromPropValue(propValueFinal) {
  32. var value;
  33. if (typeof themeMapping === 'function') {
  34. value = themeMapping(propValueFinal);
  35. } else if (Array.isArray(themeMapping)) {
  36. value = themeMapping[propValueFinal];
  37. } else {
  38. value = getPath(themeMapping, propValueFinal) || propValueFinal;
  39. if (transform) {
  40. value = transform(value);
  41. }
  42. }
  43. if (cssProperty === false) {
  44. return value;
  45. }
  46. return (0, _defineProperty2.default)({}, cssProperty, value);
  47. };
  48. return (0, _breakpoints.handleBreakpoints)(props, propValue, styleFromPropValue);
  49. };
  50. fn.propTypes = process.env.NODE_ENV !== 'production' ? (0, _defineProperty2.default)({}, prop, _responsivePropType.default) : {};
  51. fn.filterProps = [prop];
  52. return fn;
  53. }
  54. var _default = style;
  55. exports.default = _default;