MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / createStyledComponent

Function createStyledComponent

code/styling/public/app.js:21570–21645  ·  view source on GitHub ↗
(target, options, rules)

Source from the content-addressed store, hash-verified

21568 }(React.Component);
21569
21570 var createStyledComponent = function createStyledComponent(target, options, rules) {
21571 var _StyledComponent$cont;
21572
21573 var _options$displayName = options.displayName,
21574 displayName = _options$displayName === undefined ? isTag(target) ? 'styled.' + target : 'Styled(' + getComponentName(target) + ')' : _options$displayName,
21575 _options$componentId = options.componentId,
21576 componentId = _options$componentId === undefined ? generateId(options.displayName, options.parentComponentId) : _options$componentId,
21577 _options$ParentCompon = options.ParentComponent,
21578 ParentComponent = _options$ParentCompon === undefined ? BaseStyledComponent : _options$ParentCompon,
21579 extendingRules = options.rules,
21580 attrs = options.attrs;
21581
21582
21583 var styledComponentId = options.displayName && options.componentId ? escape(options.displayName) + '-' + options.componentId : componentId;
21584
21585 var componentStyle = new ComponentStyle(extendingRules === undefined ? rules : extendingRules.concat(rules), attrs, styledComponentId);
21586
21587 var StyledComponent = function (_ParentComponent) {
21588 inherits(StyledComponent, _ParentComponent);
21589
21590 function StyledComponent() {
21591 classCallCheck(this, StyledComponent);
21592 return possibleConstructorReturn(this, _ParentComponent.apply(this, arguments));
21593 }
21594
21595 StyledComponent.withComponent = function withComponent(tag) {
21596 var previousComponentId = options.componentId,
21597 optionsToCopy = objectWithoutProperties(options, ['componentId']);
21598
21599
21600 var newComponentId = previousComponentId && previousComponentId + '-' + (isTag(tag) ? tag : escape(getComponentName(tag)));
21601
21602 var newOptions = _extends({}, optionsToCopy, {
21603 componentId: newComponentId,
21604 ParentComponent: StyledComponent
21605 });
21606
21607 return createStyledComponent(tag, newOptions, rules);
21608 };
21609
21610 createClass(StyledComponent, null, [{
21611 key: 'extend',
21612 get: function get$$1() {
21613 var rulesFromOptions = options.rules,
21614 parentComponentId = options.componentId,
21615 optionsToCopy = objectWithoutProperties(options, ['rules', 'componentId']);
21616
21617
21618 var newRules = rulesFromOptions === undefined ? rules : rulesFromOptions.concat(rules);
21619
21620 var newOptions = _extends({}, optionsToCopy, {
21621 rules: newRules,
21622 parentComponentId: parentComponentId,
21623 ParentComponent: StyledComponent
21624 });
21625
21626 return constructWithOptions(createStyledComponent, target, newOptions);
21627 }

Callers

nothing calls this directly

Calls 7

isTagFunction · 0.85
generateIdFunction · 0.85
inheritsFunction · 0.85
objectWithoutPropertiesFunction · 0.85
constructWithOptionsFunction · 0.85
getComponentNameFunction · 0.70
escapeFunction · 0.70

Tested by

no test coverage detected