UNPKG

2.26 kBJavaScriptView Raw
1"use strict";
2
3function _typeof(obj) { "@babel/helpers - typeof"; 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); }
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = asPrimaryExport;
9
10var React = _interopRequireWildcard(require("react"));
11
12function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
13
14function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
16/*
17Copyright (c) 2018-2020 Uber Technologies, Inc.
18
19This source code is licensed under the MIT license found in the
20LICENSE file in the root directory of this source tree.
21*/
22// transforms props for native styled components adding $ symbol to avoid to supported warning
23function asPrimaryExport(StyledComponent, propsTransformNames) {
24 return function withStyledPropsHOC(props) {
25 var styledProps = Object.keys(props).reduce(function (acc, key) {
26 if (key[0] === '$' || propsTransformNames.indexOf(key) < 0) {
27 acc[key] = props[key];
28 } else if (propsTransformNames.indexOf(key) >= 0) {
29 acc['$' + key] = props[key];
30 }
31
32 return acc;
33 }, {});
34 return React.createElement(StyledComponent, styledProps);
35 };
36}
\No newline at end of file