glamorous
Version:
React component styling solved
3 lines (2 loc) • 7.14 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("preact"),require("glamor")):"function"==typeof define&&define.amd?define(["preact","glamor"],r):e.glamorous=r(e.preact,e.Glamor)}(this,function(e,r){"use strict";function t(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.noWarn,o=void 0!==n&&n,s=t.createElement,a=void 0===s||s,i=function(e){function t(){var e,r,n,s;m(this,t);for(var a=arguments.length,i=Array(a),p=0;p<a;p++)i[p]=arguments[p];return r=n=P(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i))),n.warned=o,n.state={theme:{}},n.setTheme=function(e){return n.setState({theme:e})},s=r,P(n,s)}return b(t,e),d(t,[{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?h(r,g({},this.props,this.state)):r.call(this,g({},this.props,this.state),this.context)}}]),t}(e.Component),p=v({},u,f.object),l=null;return Object.defineProperty(i,"contextTypes",{enumerable:!0,configurable:!0,set:function(e){l=e},get:function(){return l?g({},p,l):p}}),i}function n(e){var r=[],t=[];return e.toString().split(" ").forEach(function(e){if(0===e.indexOf("css-")){var n=o(e);t.push(n)}else r.push(e)}),{glamorlessClassName:r,glamorStyles:t}}function o(e){return v({},"data-"+e,"")}function s(e){var t=e.styles,n=e.props,o=e.cssOverrides,s=e.cssProp,i=e.context,p=(e.displayName,a([].concat(w(t),[n.className,o,s]),n,i)),l=p.mappedArgs,c=p.nonGlamorClassNames;return(r.css.apply(void 0,[null].concat(w(l))).toString()+" "+c.join(" ").trim()).trim()}function a(e,r,t){for(var o=void 0,s=[],i=[],p=0;p<e.length;p++)if("function"==typeof(o=e[p])){var l=o(r,t);if("string"==typeof l){var c=n(l),u=c.glamorStyles,f=c.glamorlessClassName;s.push.apply(s,w(u)),i.push.apply(i,w(f))}else s.push(l)}else if("string"==typeof o){var h=n(o),y=h.glamorStyles,m=h.glamorlessClassName;s.push.apply(s,w(y)),i.push.apply(i,w(m))}else if(Array.isArray(o)){var d=a(o,r,t);s.push.apply(s,w(d.mappedArgs)),i.push.apply(i,w(d.nonGlamorClassNames))}else s.push(o);return{mappedArgs:s,nonGlamorClassNames:i}}function i(e,r,t,n){return e.forEach(function(e){return"function"==typeof e?Object.assign(r,e(Object.assign({},r,t),n)):Array.isArray(e)?Object.assign(r,i(e,r,t,n)):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 l(e,r){return e?e.concat(r):r}function c(e){return"string"==typeof e?e:e.displayName||e.name||"unknown"}var u="__glamorous__",f=void 0;if((e=e&&e.hasOwnProperty("default")?e.default:e).PropTypes||(f=function(){return f},["array","bool","func","number","object","string","symbol","any","arrayOf","element","instanceOf","node","objectOf","oneOf","oneOfType","shape","exact"].forEach(function(e){f[e]=f})),!e.Children){var y={map:function(e,r,t){return null==e?null:(e=y.toArray(e),t&&t!==e&&(r=r.bind(t)),e.map(r))},forEach:function(e,r,t){if(null==e)return null;e=y.toArray(e),t&&t!==e&&(r=r.bind(t)),e.forEach(r)},count:function(e){return e&&e.length||0},only:function(e){if(1!==(e=y.toArray(e)).length)throw new Error("Children.only() expects only one child.");return e[0]},toArray:function(e){return null==e?[]:[].concat(e)}};e.Children=y}f=f||e.PropTypes;var m=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},d=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),v=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},g=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},b=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)},O=function(e,r){var t={};for(var n in e)r.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},P=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},w=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 n(a){function p(e){return n(a,g({},c,e))}function l(){function l(e,r,t){if(!h)return!0;var n=!0;return t&&(h(t.props,e,t.context,r)||(n=!1)),n}for(var c=arguments.length,y=Array(c),d=0;d<c;d++)y[d]=arguments[d];var b=t(function(t,n){var o=l(t=i(b.propsToApply,{},t,n),n,this.previous);h&&(this.previous={props:t,context:n});var a=r(t,b),p=a.toForward,c=a.cssOverrides,u=a.cssProp;return this.className=o?s({styles:b.styles,props:t,cssOverrides:c,cssProp:u,context:n,displayName:b.displayName}):this.className,e.createElement(b.comp,g({ref:t.innerRef},p,{className:this.className}))},{noWarn:!0,createElement:!1});return Object.assign(b,o({comp:a,styles:y,rootEl:u,filterProps:m,forwardProps:v,displayName:f,propsToApply:w}),{isGlamorousComponent:!0,propsAreCssOverrides:P,withComponent:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=b.forwardProps,o=b.filterProps,s=O(b,["forwardProps","filterProps"]);return n(g({},s,{comp:e}),g({forwardProps:t,filterProps:o},r))()},withProps:function(){for(var e=arguments.length,r=Array(e),t=0;t<e;t++)r[t]=arguments[t];return n(b,{withProps:r})()},withConfig:p}),b}var c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=c.rootEl,f=c.displayName,h=c.shouldClassNameUpdate,y=c.filterProps,m=void 0===y?[]:y,d=c.forwardProps,v=void 0===d?[]:d,b=c.propsAreCssOverrides,P=void 0===b?a.propsAreCssOverrides:b,w=c.withProps;return Object.assign(l,{withConfig:p}),l}function o(e){var r=e.comp,t=e.styles,n=e.rootEl,o=e.filterProps,s=e.forwardProps,a=e.displayName,i=e.propsToApply,u=r.comp?r.comp:r,f=r.propsToApply?[].concat(w(r.propsToApply),w(p(i))):p(i);return{styles:l(r.styles,t),comp:u,rootEl:n||u,forwardProps:l(r.forwardProps,s),filterProps:l(r.filterProps,o),displayName:a||"glamorous("+c(r)+")",propsToApply:f}}return n}(function(e){var r=e.css;return e.theme,e.className,e.innerRef,e.glam,{toForward:O(e,["css","theme","className","innerRef","glam"]),cssProp:r}})});
//# sourceMappingURL=glamorous.umd.min.tiny.js.map