UNPKG

glamorous

Version:

React component styling solved

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