1+ 'use strict' ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+
7+ var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
8+
9+ var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
10+
11+ var _react = require ( 'react' ) ;
12+
13+ var _react2 = _interopRequireDefault ( _react ) ;
14+
15+ var _propTypes = require ( 'prop-types' ) ;
16+
17+ var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
18+
19+ var _ladda = require ( 'ladda' ) ;
20+
21+ var _ladda2 = _interopRequireDefault ( _ladda ) ;
22+
23+ var _constants = require ( './constants' ) ;
24+
25+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
26+
27+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
28+
29+ function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
30+
31+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . __proto__ = superClass ; }
32+
33+ var isUndefined = function isUndefined ( value ) {
34+ return typeof value === 'undefined' ;
35+ } ;
36+
37+ var OMITTED_PROPS = [ 'loading' , 'progress' ] ;
38+
39+ var omit = function omit ( data , keys ) {
40+ var result = { } ;
41+ Object . keys ( data ) . forEach ( function ( key ) {
42+ if ( keys . indexOf ( key ) === - 1 ) {
43+ result [ key ] = data [ key ] ;
44+ }
45+ } ) ;
46+
47+ return result ;
48+ } ;
49+
50+ var LaddaButton = function ( _Component ) {
51+ _inherits ( LaddaButton , _Component ) ;
52+
53+ function LaddaButton ( ) {
54+ var _ref ;
55+
56+ var _temp , _this , _ret ;
57+
58+ _classCallCheck ( this , LaddaButton ) ;
59+
60+ for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
61+ args [ _key ] = arguments [ _key ] ;
62+ }
63+
64+ return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _ref = LaddaButton . __proto__ || Object . getPrototypeOf ( LaddaButton ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this ) , _this . setNode = function ( node ) {
65+ _this . node = node ;
66+ } , _this . updateLaddaInstance = function ( props ) {
67+ if ( props . loading !== _this . props . loading ) {
68+ if ( props . loading ) {
69+ _this . laddaInstance . start ( ) ;
70+ } else if ( props . disabled ) {
71+ // .stop removes the attribute "disabled"
72+ // .disable calls .stop then adds the attribute "disabled"
73+ // see https://github.com/hakimel/Ladda/blob/master/js/ladda.js
74+ _this . laddaInstance . disable ( ) ;
75+ } else {
76+ _this . laddaInstance . stop ( ) ;
77+ }
78+ }
79+
80+ if ( props . progress !== _this . props . progress ) {
81+ _this . laddaInstance . setProgress ( props . progress ) ;
82+ }
83+ } , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
84+ }
85+
86+ _createClass ( LaddaButton , [ {
87+ key : 'componentDidMount' ,
88+ value : function componentDidMount ( ) {
89+ this . laddaInstance = _ladda2 . default . create ( this . node ) ;
90+
91+ if ( this . props . loading ) {
92+ this . laddaInstance . start ( ) ;
93+ }
94+
95+ if ( ! isUndefined ( this . props . progress ) ) {
96+ this . laddaInstance . setProgress ( this . props . progress ) ;
97+ }
98+ }
99+ } , {
100+ key : 'shouldComponentUpdate' ,
101+ value : function shouldComponentUpdate ( nextProps ) {
102+ this . updateLaddaInstance ( nextProps ) ;
103+ }
104+ } , {
105+ key : 'componentWillUnmount' ,
106+ value : function componentWillUnmount ( ) {
107+ this . laddaInstance . remove ( ) ;
108+ }
109+ } , {
110+ key : 'render' ,
111+ value : function render ( ) {
112+ return _react2 . default . createElement (
113+ 'button' ,
114+ _extends ( { } , omit ( this . props , OMITTED_PROPS ) , {
115+ className : 'ladda-button ' + ( this . props . className || '' ) ,
116+ ref : this . setNode ,
117+ disabled : this . props . disabled || this . props . loading
118+ } ) ,
119+ _react2 . default . createElement (
120+ 'span' ,
121+ { className : 'ladda-label' } ,
122+ this . props . children
123+ )
124+ ) ;
125+ }
126+ } ] ) ;
127+
128+ return LaddaButton ;
129+ } ( _react . Component ) ;
130+
131+ LaddaButton . propTypes = {
132+ children : _propTypes2 . default . node ,
133+ className : _propTypes2 . default . string ,
134+ progress : _propTypes2 . default . number ,
135+ loading : _propTypes2 . default . bool ,
136+ disabled : _propTypes2 . default . bool ,
137+
138+ // Ladda props
139+ // eslint-disable-next-line react/no-unused-prop-types
140+ 'data-color' : _propTypes2 . default . oneOf ( [ 'green' , 'red' , 'blue' , 'purple' , 'mint' ] ) ,
141+ // eslint-disable-next-line react/no-unused-prop-types
142+ 'data-size' : _propTypes2 . default . oneOf ( _constants . SIZES ) ,
143+ // eslint-disable-next-line react/no-unused-prop-types
144+ 'data-style' : _propTypes2 . default . oneOf ( _constants . STYLES ) ,
145+ // eslint-disable-next-line react/no-unused-prop-types
146+ 'data-spinner-size' : _propTypes2 . default . number ,
147+ // eslint-disable-next-line react/no-unused-prop-types
148+ 'data-spinner-color' : _propTypes2 . default . string ,
149+ // eslint-disable-next-line react/no-unused-prop-types
150+ 'data-spinner-lines' : _propTypes2 . default . number
151+ } ;
152+ exports . default = LaddaButton ;
0 commit comments