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

Function constructWithOptions

code/styling/public/app.js:21843–21867  ·  view source on GitHub ↗
(componentConstructor, tag)

Source from the content-addressed store, hash-verified

21841
21842var _constructWithOptions = (function (css) {
21843 var constructWithOptions = function constructWithOptions(componentConstructor, tag) {
21844 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
21845
21846 if (typeof tag !== 'string' && typeof tag !== 'function') {
21847 throw new Error(process.env.NODE_ENV !== 'production' ? 'Cannot create styled-component for component: ' + String(tag) : '');
21848 }
21849
21850 /* This is callable directly as a template function */
21851 // $FlowFixMe: Not typed to avoid destructuring arguments
21852 var templateFunction = function templateFunction() {
21853 return componentConstructor(tag, options, css.apply(undefined, arguments));
21854 };
21855
21856 /* If config methods are called, wrap up a new template function and merge options */
21857 templateFunction.withConfig = function (config) {
21858 return constructWithOptions(componentConstructor, tag, _extends({}, options, config));
21859 };
21860 templateFunction.attrs = function (attrs) {
21861 return constructWithOptions(componentConstructor, tag, _extends({}, options, {
21862 attrs: _extends({}, options.attrs || {}, attrs)
21863 }));
21864 };
21865
21866 return templateFunction;
21867 };
21868
21869 return constructWithOptions;
21870});

Callers 2

createStyledComponentFunction · 0.85
styledFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected