1+ 'use strict' ;
2+
3+ Object . defineProperty ( exports , "__esModule" , {
4+ value : true
5+ } ) ;
6+
7+ 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 ; } ; } ( ) ;
8+
9+ var _react = require ( 'react' ) ;
10+
11+ var _react2 = _interopRequireDefault ( _react ) ;
12+
13+ var _function = require ( 'react-pure-render/function' ) ;
14+
15+ var _function2 = _interopRequireDefault ( _function ) ;
16+
17+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
18+
19+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
20+
21+ 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 ; }
22+
23+ 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 ; }
24+
25+ /**
26+ * This HOC decorates a virtualized component and responds to arrow-key events by scrolling one row or column at a time.
27+ */
28+
29+ var ArrowKeyStepper = function ( _Component ) {
30+ _inherits ( ArrowKeyStepper , _Component ) ;
31+
32+ function ArrowKeyStepper ( props , context ) {
33+ _classCallCheck ( this , ArrowKeyStepper ) ;
34+
35+ var _this = _possibleConstructorReturn ( this , Object . getPrototypeOf ( ArrowKeyStepper ) . call ( this , props , context ) ) ;
36+
37+ _this . shouldComponentUpdate = _function2 . default ;
38+
39+
40+ _this . state = {
41+ scrollToColumn : 0 ,
42+ scrollToRow : 0
43+ } ;
44+
45+ _this . _columnStartIndex = 0 ;
46+ _this . _columnStopIndex = 0 ;
47+ _this . _rowStartIndex = 0 ;
48+ _this . _rowStopIndex = 0 ;
49+
50+ _this . _onKeyDown = _this . _onKeyDown . bind ( _this ) ;
51+ _this . _onSectionRendered = _this . _onSectionRendered . bind ( _this ) ;
52+ return _this ;
53+ }
54+
55+ _createClass ( ArrowKeyStepper , [ {
56+ key : 'render' ,
57+ value : function render ( ) {
58+ var _props = this . props ;
59+ var className = _props . className ;
60+ var children = _props . children ;
61+ var _state = this . state ;
62+ var scrollToColumn = _state . scrollToColumn ;
63+ var scrollToRow = _state . scrollToRow ;
64+
65+
66+ return _react2 . default . createElement (
67+ 'div' ,
68+ {
69+ className : className ,
70+ onKeyDown : this . _onKeyDown
71+ } ,
72+ children ( {
73+ onSectionRendered : this . _onSectionRendered ,
74+ scrollToColumn : scrollToColumn ,
75+ scrollToRow : scrollToRow
76+ } )
77+ ) ;
78+ }
79+ } , {
80+ key : '_onKeyDown' ,
81+ value : function _onKeyDown ( event ) {
82+ var _props2 = this . props ;
83+ var columnsCount = _props2 . columnsCount ;
84+ var rowsCount = _props2 . rowsCount ;
85+
86+ // The above cases all prevent default event event behavior.
87+ // This is to keep the grid from scrolling after the snap-to update.
88+
89+ switch ( event . key ) {
90+ case 'ArrowDown' :
91+ event . preventDefault ( ) ;
92+ this . setState ( {
93+ scrollToRow : Math . min ( this . _rowStopIndex + 1 , rowsCount - 1 )
94+ } ) ;
95+ break ;
96+ case 'ArrowLeft' :
97+ event . preventDefault ( ) ;
98+ this . setState ( {
99+ scrollToColumn : Math . max ( this . _columnStartIndex - 1 , 0 )
100+ } ) ;
101+ break ;
102+ case 'ArrowRight' :
103+ event . preventDefault ( ) ;
104+ this . setState ( {
105+ scrollToColumn : Math . min ( this . _columnStopIndex + 1 , columnsCount - 1 )
106+ } ) ;
107+ break ;
108+ case 'ArrowUp' :
109+ event . preventDefault ( ) ;
110+ this . setState ( {
111+ scrollToRow : Math . max ( this . _rowStartIndex - 1 , 0 )
112+ } ) ;
113+ break ;
114+ }
115+ }
116+ } , {
117+ key : '_onSectionRendered' ,
118+ value : function _onSectionRendered ( _ref ) {
119+ var columnStartIndex = _ref . columnStartIndex ;
120+ var columnStopIndex = _ref . columnStopIndex ;
121+ var rowStartIndex = _ref . rowStartIndex ;
122+ var rowStopIndex = _ref . rowStopIndex ;
123+
124+ this . _columnStartIndex = columnStartIndex ;
125+ this . _columnStopIndex = columnStopIndex ;
126+ this . _rowStartIndex = rowStartIndex ;
127+ this . _rowStopIndex = rowStopIndex ;
128+ }
129+ } ] ) ;
130+
131+ return ArrowKeyStepper ;
132+ } ( _react . Component ) ;
133+
134+ ArrowKeyStepper . propTypes = {
135+ children : _react . PropTypes . func . isRequired ,
136+ className : _react . PropTypes . string ,
137+ columnsCount : _react . PropTypes . number . isRequired ,
138+ rowsCount : _react . PropTypes . number . isRequired
139+ } ;
140+ exports . default = ArrowKeyStepper ;
0 commit comments