-
Notifications
You must be signed in to change notification settings - Fork 133
/
index.js
1 lines (1 loc) · 8.42 KB
/
index.js
1
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],e):"object"==typeof exports?exports["react-awesome-button"]=e(require("prop-types"),require("react")):t["react-awesome-button"]=e(t.PropTypes,t.React)}(this,function(t,e){return function(t){function e(o){if(n[o])return n[o].exports;var s=n[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=5)}([function(t,e,n){"use strict";(function(t){function o(t){return t&&t.__esModule?t:{default:t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},l=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),u=n(4),c=o(u),p=n(3),d=o(p),f=n(1),h=window||t,b="aws-btn",m=function(t){return c.default.createElement("a",t)},g=function(t){return c.default.createElement("button",t)},v=function(t){function e(t){s(this,e);var n=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.rootElement=t.rootElement||b,n.animationStage=0,n.extraProps={},n.state={disabled:t.disabled,loading:!1,loadingEnd:!1,loadingStart:!1,blocked:!1,clicked:!1},n.checkProps(t),n}return i(e,t),l(e,[{key:"componentDidMount",value:function(){(0,f.setCssEndEvent)(this.wrapper,"transition",this.clearStagedWrapperAnimation.bind(this))}},{key:"componentWillReceiveProps",value:function(t){this.checkProps(t)}},{key:"getRootClassName",value:function(){var t=[this.rootElement,this.props.type&&this.rootElement+"--"+this.props.type,this.props.size&&this.rootElement+"--"+this.props.size,this.props.visible&&this.rootElement+"--visible",this.state.loadingStart&&this.rootElement+"--start"||null,this.state.loadingEnd&&this.rootElement+"--end"||null,this.props.progress&&this.rootElement+"--progress"||null];return!0===this.state.disabled&&t.push(this.rootElement+"--disabled"),this.state.pressPosition&&t.push(this.state.pressPosition),this.props.cssModule&&this.props.cssModule["aws-btn"]?(0,f.classToModules)(t,this.props.cssModule):t.join(" ").trim()}},{key:"checkProps",value:function(t){this.extraProps.to=t.to||null,this.extraProps.href=t.href||null,this.extraProps.target=t.target||null,this.renderComponent=t.element||(this.props.href?m:g)}},{key:"endLoading",value:function(){this.setState({loadingEnd:!0}),this.animationStage=1}},{key:"startLoading",value:function(){this.setState({loading:!0,loadingStart:!0,blocked:!0})}},{key:"clearPress",value:function(){var t=this.state.loading?this.state.pressPosition:null;this.setState({pressPosition:t})}},{key:"clearLoading",value:function(){this.setState({loading:!1,loadingStart:!1,loadingEnd:!1})}},{key:"clearStagedWrapperAnimation",value:function(){var t=this;if(0!==this.animationStage){if(5===this.animationStage)return this.animationStage=0,void setTimeout(function(){h.requestAnimationFrame(function(){t.clearLoading(),t.clearPress(),setTimeout(function(){t.setState({blocked:!1})},500)})},350);this.animationStage+=1}}},{key:"action",value:function(){this.props.progress&&this.startLoading(),this.props.action&&this.props.action(this.button.parentNode,this.props.progress?this.endLoading.bind(this):null)}},{key:"createBubble",value:function(t){(0,f.createBubbleEffect)({event:t,button:this.button,content:this.content,className:(0,f.getClassName)(this.rootElement+"__bubble",this.props.cssModule)})}},{key:"moveEvents",value:function(){var t=this,e={onMouseLeave:function(){t.clearPress()},onMouseDown:function(e){!0!==t.state.disabled&&!0!==t.state.loading&&!0!==t.state.blocked&&1===e.nativeEvent.which&&(!1===t.props.progress&&!0===t.props.bubbles&&t.createBubble(e),t.setState({loading:t.props.progress,pressPosition:t.rootElement+"--active"}),h.requestAnimationFrame(function(){var e=new Event("action");t.button.dispatchEvent(e),t.action()}))},onMouseUp:function(e){if(!0===t.state.disabled||!0===t.state.loading||!0===t.state.blocked)return e.preventDefault(),void e.stopPropagation();t.clearPress()}};return!0===this.props.moveEvents?e.onMouseMove=function(e){if(!0!==t.state.disabled&&!0!==t.state.loading&&!0!==t.state.blocked){var n=t.button,o=n.getBoundingClientRect().left,s=n.offsetWidth;t.setState({pressPosition:e.pageX<o+.3*s?t.rootElement+"--left":e.pageX>o+.65*s?t.rootElement+"--right":t.rootElement+"--middle"})}}:e.onMouseEnter=function(){t.setState({pressPosition:t.rootElement+"--middle"})},e}},{key:"render",value:function(){var t=this,e=this.renderComponent;return c.default.createElement(e,a({style:this.props.style,className:this.getRootClassName(),role:"button"},this.extraProps,this.moveEvents()),c.default.createElement("span",{ref:function(e){t.button=e},className:(0,f.getClassName)(this.rootElement+"__container",this.props.cssModule)},c.default.createElement("span",{ref:function(e){t.wrapper=e},className:(0,f.getClassName)(this.rootElement+"__wrapper",this.props.cssModule)},c.default.createElement("span",{ref:function(e){t.content=e},"data-loading":this.props.progress&&this.props.loadingLabel||null,"data-status":this.props.progress&&this.props.resultLabel||null,className:(0,f.getClassName)(this.rootElement+"__content",this.props.cssModule)},c.default.createElement("span",null,this.props.children)))))}}]),e}(c.default.Component);v.propTypes={action:d.default.func,bubbles:d.default.bool,children:d.default.node.isRequired,disabled:d.default.bool,element:d.default.func,href:d.default.string,loadingLabel:d.default.string,progress:d.default.bool,resultLabel:d.default.string,rootElement:d.default.string,moveEvents:d.default.bool,size:d.default.string,style:d.default.object,cssModule:d.default.object,target:d.default.string,to:d.default.string,type:d.default.string,visible:d.default.bool},v.defaultProps={action:null,bubbles:!1,disabled:!1,element:null,href:null,loadingLabel:"Wait ..",moveEvents:!0,progress:!1,resultLabel:"Success!",rootElement:b,rounded:!0,size:null,style:{},target:null,to:null,type:"primary",visible:!0},e.default=v}).call(e,n(2))},function(t,e,n){"use strict";function o(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments[1],n=[],o=t.length;o--;)e[t[o]]&&n.push(e[t[o]]);return n.join(" ").trim()}function s(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments[1];return e?e[t]||t:t}function r(t,e,n){if(!t)return!1;var o=e.charAt(0).toUpperCase()+e.slice(1);return void 0!==t.style["Webkit"+o]?t.addEventListener("webkit"+o+"End",n):void 0!==t.style.OTransition?t.addEventListener("o"+e+"End",n):t.addEventListener(e+"End",n)}function i(t){var e=t.event,n=t.button,o=t.content,s=t.className,i=n.getBoundingClientRect(),a=window.pageYOffset||document.documentElement.scrolltop||0,l=document.createElement("span"),u=i.width<50?3*i.width:2*i.width;l.className=s,l.style.top="-"+(u/2-(e.pageY-i.top-a))+"px",l.style.left="-"+(u/2-(e.pageX-i.left))+"px",l.style.width=u+"px",l.style.height=u+"px",r(l,"animation",function(){o.removeChild(l)}),window.requestAnimationFrame(function(){o.appendChild(l)})}Object.defineProperty(e,"__esModule",{value:!0}),e.classToModules=o,e.getClassName=s,e.setCssEndEvent=r,e.createBubbleEffect=i},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(e,n){e.exports=t},function(t,n){t.exports=e},function(t,e,n){t.exports=n(0)}])});