UNPKG

glamorous

Version:

React component styling solved

3 lines (2 loc) 6.75 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("react"),require("glamor")):"function"==typeof define&&define.amd?define(["react","glamor"],r):e.glamorous=r(e.React,e.Glamor)}(this,function(e,r){"use strict";function t(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=t.noWarn,n=void 0!==o&&o,s=t.createElement,a=void 0===s||s,i=function(t){function o(){var e,r,t,s;m(this,o);for(var a=arguments.length,i=Array(a),p=0;p<a;p++)i[p]=arguments[p];return r=t=b(this,(e=o.__proto__||Object.getPrototypeOf(o)).call.apply(e,[this].concat(i))),t.warned=n,t.state={theme:{}},t.setTheme=function(e){return t.setState({theme:e})},s=r,b(t,s)}return v(o,t),h(o,[{key:"componentWillMount",value:function(){this.context[u];var e=this.props.theme;this.context[u]?this.setTheme(e||this.context[u].getState()):this.setTheme(e||{})}},{key:"componentWillReceiveProps",value:function(e){this.props.theme!==e.theme&&this.setTheme(e.theme)}},{key:"componentDidMount",value:function(){this.context[u]&&!this.props.theme&&(this.subscriptionId=this.context[u].subscribe(this.setTheme))}},{key:"componentWillUnmount",value:function(){this.subscriptionId&&this.context[u].unsubscribe(this.subscriptionId)}},{key:"render",value:function(){return a?e.createElement(r,d({},this.props,this.state)):r.call(this,d({},this.props,this.state),this.context)}}]),o}(e.Component);i.propTypes={theme:f.object};var p=y({},u,f.object),c=null;return Object.defineProperty(i,"contextTypes",{enumerable:!0,configurable:!0,set:function(e){c=e},get:function(){return c?d({},p,c):p}}),i}function o(e){var r=[],t=[];return e.toString().split(" ").forEach(function(e){if(0===e.indexOf("css-")){var o=n(e);t.push(o)}else r.push(e)}),{glamorlessClassName:r,glamorStyles:t}}function n(e){return y({},"data-"+e,"")}function s(e){var t=e.styles,o=e.props,n=e.cssOverrides,s=e.cssProp,i=e.context,p=(e.displayName,a([].concat(P(t),[o.className,n,s]),o,i)),c=p.mappedArgs,l=p.nonGlamorClassNames;return(r.css.apply(void 0,[null].concat(P(c))).toString()+" "+l.join(" ").trim()).trim()}function a(e,r,t){for(var n=void 0,s=[],i=[],p=0;p<e.length;p++)if("function"==typeof(n=e[p])){var c=n(r,t);if("string"==typeof c){var l=o(c),u=l.glamorStyles,f=l.glamorlessClassName;s.push.apply(s,P(u)),i.push.apply(i,P(f))}else s.push(c)}else if("string"==typeof n){var m=o(n),h=m.glamorStyles,y=m.glamorlessClassName;s.push.apply(s,P(h)),i.push.apply(i,P(y))}else if(Array.isArray(n)){var d=a(n,r,t);s.push.apply(s,P(d.mappedArgs)),i.push.apply(i,P(d.nonGlamorClassNames))}else s.push(n);return{mappedArgs:s,nonGlamorClassNames:i}}function i(e,r,t,o){return e.forEach(function(e){return"function"==typeof e?Object.assign(r,e(Object.assign({},r,t),o)):Array.isArray(e)?Object.assign(r,i(e,r,t,o)):Object.assign(r,e)}),Object.assign(r,t)}function p(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return Array.isArray(e)?e:[e]}function c(e,r){return e?e.concat(r):r}function l(e){return"string"==typeof e?e:e.displayName||e.name||"unknown"}e=e&&e.hasOwnProperty("default")?e.default:e;var u="__glamorous__",f=void 0;if(parseFloat(e.version.slice(0,4))>=15.5)try{f=("undefined"!=typeof window?window:global).PropTypes}catch(e){}f=f||e.PropTypes;var m=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},h=function(){function e(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(r,t,o){return t&&e(r.prototype,t),o&&e(r,o),r}}(),y=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},d=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},v=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},g=function(e,r){var t={};for(var o in e)r.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},b=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},P=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)};return function(r){function o(a){function p(e){return o(a,d({},l,e))}function c(){function c(e,r,t){if(!h)return!0;var o=!0;return t&&(h(t.props,e,t.context,r)||(o=!1)),o}for(var l=arguments.length,y=Array(l),b=0;b<l;b++)y[b]=arguments[b];var w=t(function(t,o){var n=c(t=i(w.propsToApply,{},t,o),o,this.previous);h&&(this.previous={props:t,context:o});var a=r(t,w),p=a.toForward,l=a.cssOverrides,u=a.cssProp;return this.className=n?s({styles:w.styles,props:t,cssOverrides:l,cssProp:u,context:o,displayName:w.displayName}):this.className,e.createElement(w.comp,d({ref:t.innerRef},p,{className:this.className}))},{noWarn:!0,createElement:!1});return w.propTypes={className:f.oneOfType([f.string,f.object]),cssOverrides:f.object,innerRef:f.func,glam:f.object},Object.assign(w,n({comp:a,styles:y,rootEl:u,filterProps:v,forwardProps:P,displayName:m,propsToApply:j}),{isGlamorousComponent:!0,propsAreCssOverrides:O,withComponent:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=w.forwardProps,n=w.filterProps,s=g(w,["forwardProps","filterProps"]);return o(d({},s,{comp:e}),d({forwardProps:t,filterProps:n},r))()},withProps:function(){for(var e=arguments.length,r=Array(e),t=0;t<e;t++)r[t]=arguments[t];return o(w,{withProps:r})()},withConfig:p}),w}var l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=l.rootEl,m=l.displayName,h=l.shouldClassNameUpdate,y=l.filterProps,v=void 0===y?[]:y,b=l.forwardProps,P=void 0===b?[]:b,w=l.propsAreCssOverrides,O=void 0===w?a.propsAreCssOverrides:w,j=l.withProps;return Object.assign(c,{withConfig:p}),c}function n(e){var r=e.comp,t=e.styles,o=e.rootEl,n=e.filterProps,s=e.forwardProps,a=e.displayName,i=e.propsToApply,u=r.comp?r.comp:r,f=r.propsToApply?[].concat(P(r.propsToApply),P(p(i))):p(i);return{styles:c(r.styles,t),comp:u,rootEl:o||u,forwardProps:c(r.forwardProps,s),filterProps:c(r.filterProps,n),displayName:a||"glamorous("+l(r)+")",propsToApply:f}}return o}(function(e){var r=e.css;return e.theme,e.className,e.innerRef,e.glam,{toForward:g(e,["css","theme","className","innerRef","glam"]),cssProp:r}})}); //# sourceMappingURL=glamorous.umd.min.tiny.js.map