@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
7
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
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
+
9
11
var _react = require ( 'react' ) ;
10
12
11
13
var _react2 = _interopRequireDefault ( _react ) ;
@@ -22,100 +24,121 @@ var _x = require('./x');
22
24
23
25
var _x2 = _interopRequireDefault ( _x ) ;
24
26
25
- var _reactAddonsPureRenderMixin = require ( 'react-addons-pure-render-mixin ' ) ;
27
+ var _reactAddonsShallowCompare = require ( 'react-addons-shallow-compare ' ) ;
26
28
27
- var _reactAddonsPureRenderMixin2 = _interopRequireDefault ( _reactAddonsPureRenderMixin ) ;
29
+ var _reactAddonsShallowCompare2 = _interopRequireDefault ( _reactAddonsShallowCompare ) ;
28
30
29
31
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
30
32
31
- exports . default = _react2 . default . createClass ( {
32
- mixins : [ _reactAddonsPureRenderMixin2 . default ] ,
33
-
34
- displayName : 'Toggle' ,
35
-
36
- propTypes : {
37
- checked : _react2 . default . PropTypes . bool ,
38
- defaultChecked : _react2 . default . PropTypes . bool ,
39
- onChange : _react2 . default . PropTypes . func ,
40
- name : _react2 . default . PropTypes . string ,
41
- value : _react2 . default . PropTypes . string ,
42
- id : _react2 . default . PropTypes . string ,
43
- 'aria-labelledby' : _react2 . default . PropTypes . string ,
44
- 'aria-label' : _react2 . default . PropTypes . string
45
- } ,
46
-
47
- getInitialState : function getInitialState ( ) {
48
- var checked = false ;
49
- if ( 'checked' in this . props ) {
50
- checked = this . props . checked ;
51
- } else if ( 'defaultChecked' in this . props ) {
52
- checked = this . props . defaultChecked ;
53
- }
54
- return {
55
- checked : ! ! checked ,
33
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
34
+
35
+ 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 ; }
36
+
37
+ 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 ; }
38
+
39
+ var Toggle = function ( _Component ) {
40
+ _inherits ( Toggle , _Component ) ;
41
+
42
+ function Toggle ( props ) {
43
+ _classCallCheck ( this , Toggle ) ;
44
+
45
+ var _this = _possibleConstructorReturn ( this , ( Toggle . __proto__ || Object . getPrototypeOf ( Toggle ) ) . call ( this , props ) ) ;
46
+
47
+ _this . handleClick = _this . handleClick . bind ( _this ) ;
48
+ _this . handleFocus = _this . setState . bind ( _this , { hasFocus : true } ) ;
49
+ _this . handleBlur = _this . setState . bind ( _this , { hasFocus : false } ) ;
50
+ _this . state = {
51
+ checked : ! ! ( props . checked || props . defaultChecked ) ,
56
52
hasFocus : false
57
53
} ;
58
- } ,
59
- componentWillReceiveProps : function componentWillReceiveProps ( nextProps ) {
60
- if ( 'checked' in nextProps ) {
61
- this . setState ( { checked : ! ! nextProps . checked } ) ;
54
+ return _this ;
55
+ }
56
+
57
+ _createClass ( Toggle , [ {
58
+ key : 'componentWillReceiveProps' ,
59
+ value : function componentWillReceiveProps ( nextProps ) {
60
+ if ( 'checked' in nextProps ) {
61
+ this . setState ( { checked : ! ! nextProps . checked } ) ;
62
+ }
62
63
}
63
- } ,
64
- handleClick : function handleClick ( event ) {
65
- var checkbox = this . input ;
66
- if ( event . target !== checkbox ) {
67
- event . preventDefault ( ) ;
68
- checkbox . focus ( ) ;
69
- checkbox . click ( ) ;
70
- return ;
64
+ } , {
65
+ key : 'handleClick' ,
66
+ value : function handleClick ( event ) {
67
+ var checkbox = this . input ;
68
+ if ( event . target !== checkbox ) {
69
+ event . preventDefault ( ) ;
70
+ checkbox . focus ( ) ;
71
+ checkbox . click ( ) ;
72
+ return ;
73
+ }
74
+
75
+ if ( ! ( 'checked' in this . props ) ) {
76
+ this . setState ( { checked : checkbox . checked } ) ;
77
+ }
71
78
}
72
-
73
- if ( ! ( 'checked' in this . props ) ) {
74
- this . setState ( { checked : checkbox . checked } ) ;
79
+ } , {
80
+ key : 'shouldComponentUpdate' ,
81
+ value : function shouldComponentUpdate ( nextProps , nextState ) {
82
+ return ( 0 , _reactAddonsShallowCompare2 . default ) ( this , nextProps , nextState ) ;
75
83
}
76
- } ,
77
- handleFocus : function handleFocus ( ) {
78
- this . setState ( { hasFocus : true } ) ;
79
- } ,
80
- handleBlur : function handleBlur ( ) {
81
- this . setState ( { hasFocus : false } ) ;
82
- } ,
83
- render : function render ( ) {
84
- var _this = this ;
85
-
86
- var classes = ( 0 , _classnames2 . default ) ( 'react-toggle' , {
87
- 'react-toggle--checked' : this . state . checked ,
88
- 'react-toggle--focus' : this . state . hasFocus ,
89
- 'react-toggle--disabled' : this . props . disabled
90
- } ) ;
91
-
92
- return _react2 . default . createElement (
93
- 'div' ,
94
- { className : classes , onClick : this . handleClick } ,
95
- _react2 . default . createElement (
84
+ } , {
85
+ key : 'render' ,
86
+ value : function render ( ) {
87
+ var _this2 = this ;
88
+
89
+ var classes = ( 0 , _classnames2 . default ) ( 'react-toggle' , {
90
+ 'react-toggle--checked' : this . state . checked ,
91
+ 'react-toggle--focus' : this . state . hasFocus ,
92
+ 'react-toggle--disabled' : this . props . disabled
93
+ } ) ;
94
+
95
+ return _react2 . default . createElement (
96
96
'div' ,
97
- { className : 'react-toggle-track' } ,
97
+ { className : classes , onClick : this . handleClick } ,
98
98
_react2 . default . createElement (
99
99
'div' ,
100
- { className : 'react-toggle-track-check' } ,
101
- _react2 . default . createElement ( _check2 . default , null )
100
+ { className : 'react-toggle-track' } ,
101
+ _react2 . default . createElement (
102
+ 'div' ,
103
+ { className : 'react-toggle-track-check' } ,
104
+ _react2 . default . createElement ( _check2 . default , null )
105
+ ) ,
106
+ _react2 . default . createElement (
107
+ 'div' ,
108
+ { className : 'react-toggle-track-x' } ,
109
+ _react2 . default . createElement ( _x2 . default , null )
110
+ )
102
111
) ,
103
- _react2 . default . createElement (
104
- 'div' ,
105
- { className : 'react-toggle-track-x' } ,
106
- _react2 . default . createElement ( _x2 . default , null )
107
- )
108
- ) ,
109
- _react2 . default . createElement ( 'div' , { className : 'react-toggle-thumb' } ) ,
110
- _react2 . default . createElement ( 'input' , _extends ( {
111
- ref : function ref ( _ref ) {
112
- _this . input = _ref ;
113
- } ,
114
- onFocus : this . handleFocus ,
115
- onBlur : this . handleBlur ,
116
- className : 'react-toggle-screenreader-only' ,
117
- type : 'checkbox'
118
- } , this . props ) )
119
- ) ;
120
- }
121
- } ) ;
112
+ _react2 . default . createElement ( 'div' , { className : 'react-toggle-thumb' } ) ,
113
+ _react2 . default . createElement ( 'input' , _extends ( {
114
+ ref : function ref ( _ref ) {
115
+ _this2 . input = _ref ;
116
+ } ,
117
+ onFocus : this . handleFocus ,
118
+ onBlur : this . handleBlur ,
119
+ className : 'react-toggle-screenreader-only' ,
120
+ type : 'checkbox'
121
+ } , this . props ) )
122
+ ) ;
123
+ }
124
+ } ] ) ;
125
+
126
+ return Toggle ;
127
+ } ( _react . Component ) ;
128
+
129
+ exports . default = Toggle ;
130
+
131
+
132
+ Toggle . displayName = 'Toggle' ;
133
+
134
+ Toggle . propTypes = {
135
+ checked : _react . PropTypes . bool ,
136
+ disabled : _react . PropTypes . bool ,
137
+ defaultChecked : _react . PropTypes . bool ,
138
+ onChange : _react . PropTypes . func ,
139
+ name : _react . PropTypes . string ,
140
+ value : _react . PropTypes . string ,
141
+ id : _react . PropTypes . string ,
142
+ 'aria-labelledby' : _react . PropTypes . string ,
143
+ 'aria-label' : _react . PropTypes . string
144
+ } ;
0 commit comments