@@ -36,6 +36,8 @@ var _reactRedux = require('react-redux');
3636
3737var _reactBootstrap = require ( 'react-bootstrap' ) ;
3838
39+ var _stringifyValues = require ( '../util/stringifyValues' ) ;
40+
3941function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
4042
4143function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
@@ -46,10 +48,6 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
4648
4749var columnProps = _propTypes2 . default . oneOfType ( [ _propTypes2 . default . string , _propTypes2 . default . number , _propTypes2 . default . bool , _propTypes2 . default . shape ( {
4850 size : _propTypes2 . default . oneOfType ( [ _propTypes2 . default . bool , _propTypes2 . default . number , _propTypes2 . default . string ] ) ,
49- // example size values:
50- // 12 || "12" => col-12 or col-`width`-12
51- // auto => col-auto or col-`width`-auto
52- // true => col or col-`width`
5351 order : _propTypes2 . default . oneOfType ( [ _propTypes2 . default . number , _propTypes2 . default . string ] ) ,
5452 offset : _propTypes2 . default . oneOfType ( [ _propTypes2 . default . number , _propTypes2 . default . string ] )
5553} ) ] ) ;
@@ -62,13 +60,15 @@ var IsotopeItem = function IsotopeItem(_ref) {
6260 sm = _ref . sm ,
6361 md = _ref . md ,
6462 lg = _ref . lg ,
65- children = _ref . children ;
63+ children = _ref . children ,
64+ item = _ref . item ;
6665 return width ? _react2 . default . createElement (
6766 'div' ,
6867 {
6968 key : key ,
7069 className : ( 0 , _classnames2 . default ) ( id + '-item' , 'wfui-isotope-item' ) ,
71- style : { width : width + 'px' }
70+ style : { width : width + 'px' } ,
71+ 'data-item' : ( 0 , _stringifyValues . stringifyValues ) ( item )
7272 } ,
7373 children
7474 ) : _react2 . default . createElement (
@@ -79,7 +79,8 @@ var IsotopeItem = function IsotopeItem(_ref) {
7979 xs : xs ,
8080 sm : sm ,
8181 md : md ,
82- lg : lg
82+ lg : lg ,
83+ 'data-item' : ( 0 , _stringifyValues . stringifyValues ) ( item )
8384 } ,
8485 children
8586 ) ;
@@ -93,7 +94,8 @@ IsotopeItem.propTypes = {
9394 sm : columnProps ,
9495 md : columnProps ,
9596 lg : columnProps ,
96- children : _propTypes2 . default . node
97+ children : _propTypes2 . default . node ,
98+ item : _propTypes2 . default . any
9799} ;
98100
99101IsotopeItem . defaultProps = {
@@ -125,7 +127,10 @@ var IsotopeGrid = function (_React$Component) {
125127 id = _props . id ,
126128 wholeWord = _props . wholeWord ,
127129 searchTerm = _props . searchTerm ,
128- filterList = _props . filterList ;
130+ filterList = _props . filterList ,
131+ sortBy = _props . sortBy ,
132+ sortAscending = _props . sortAscending ,
133+ getSortData = _props . getSortData ;
129134 var isotope = this . state . isotope ;
130135
131136
@@ -136,13 +141,16 @@ var IsotopeGrid = function (_React$Component) {
136141 isotope : new _isotopeLayout2 . default ( _reactDom2 . default . findDOMNode ( this ) , {
137142 itemSelector : '.' + id + '-item' ,
138143 layoutMode : 'fitRows' ,
144+ sortBy : sortBy ,
145+ sortAscending : sortAscending ,
146+ getSortData : getSortData ,
139147 filter : function filter ( itemElem ) {
140148 var _this2 = this ;
141149
142- var isoSearch = itemElem ? itemElem . querySelector ( '.isotope-search' ) : this . querySelector ( '.isotope-search' ) ;
150+ var isoSearch = itemElem ? itemElem . dataset . item : this . dataset . item ;
143151 return ( ! filterList || filterList . length === 0 || filterList . every ( function ( filter ) {
144152 return filter ( itemElem || _this2 ) ;
145- } ) ) && reg . test ( isoSearch ? isoSearch . innerText : '' ) ;
153+ } ) ) && reg . test ( isoSearch || '' ) ;
146154 }
147155 } )
148156 } ) ;
@@ -188,17 +196,26 @@ var IsotopeGrid = function (_React$Component) {
188196 options . filter = function ( itemElem ) {
189197 var _this3 = this ;
190198
191- var isoSearch = itemElem ? itemElem . querySelector ( '.isotope-search' ) : this . querySelector ( '.isotope-search' ) ;
199+ var isoSearch = itemElem ? itemElem . dataset . item : this . dataset . item ;
192200 return ( ! nextProps . filterList || nextProps . filterList . length === 0 || nextProps . filterList . every ( function ( filter ) {
193201 return filter ( itemElem || _this3 ) ;
194- } ) ) && reg . test ( isoSearch ? isoSearch . innerText : '' ) ;
202+ } ) ) && reg . test ( isoSearch || '' ) ;
195203 } ;
196204 }
205+ if ( this . props . sortBy !== nextProps . sortBy ) {
206+ options . sortBy = nextProps . sortBy ;
207+ }
208+ if ( this . props . sortAscending !== nextProps . sortAscending ) {
209+ options . sortAscending = nextProps . sortAscending ;
210+ }
211+ if ( JSON . stringify ( this . props . getSortData ) !== JSON . stringify ( nextProps . getSortData ) ) {
212+ options . getSortData = nextProps . getSortData ;
213+ }
197214
198215 if ( reload !== this . state . reload ) this . setState ( { reload : reload } ) ;
199- if ( options && this . state . isotope ) {
216+ if ( Object . keys ( options ) . length && this . state . isotope ) {
200217 this . state . isotope . arrange ( _extends ( { } , options ) ) ;
201- } else if ( options ) {
218+ } else if ( ! Object . keys ( options ) . length ) {
202219 this . createIsotope ( ) ;
203220 }
204221 }
@@ -314,26 +331,24 @@ IsotopeGrid.propTypes = {
314331 md : columnProps ,
315332 lg : columnProps ,
316333 children : _propTypes2 . default . node ,
317- sortBy : _propTypes2 . default . string ,
318- sortOrder : _propTypes2 . default . string ,
334+ sortBy : _propTypes2 . default . oneOf ( _propTypes2 . default . string , _propTypes2 . default . arrayOf ( _propTypes2 . default . string ) ) ,
335+ sortAscending : _propTypes2 . default . bool ,
336+ getSortData : _propTypes2 . default . object ,
319337 searchTerm : _propTypes2 . default . string ,
320338 wholeWord : _propTypes2 . default . bool ,
321- filterList : _propTypes2 . default . arrayOf ( _propTypes2 . default . func ) ,
322- category : _propTypes2 . default . object
339+ filterList : _propTypes2 . default . arrayOf ( _propTypes2 . default . func )
323340} ;
324341
325342IsotopeGrid . defaultProps = {
326343 searchTerm : '' ,
327344 xs : 12 ,
328345 sm : 6 ,
329346 md : 4 ,
330- lg : 4
347+ lg : 4 ,
348+ sortBy : 'original-order' ,
349+ sortAscending : true
331350} ;
332351
333352IsotopeGrid . Item = IsotopeItem ;
334353
335- exports . default = ( 0 , _reactRedux . connect ) ( function ( state ) {
336- return {
337- category : state . visibilityFilter && state . visibilityFilter . category
338- } ;
339- } ) ( IsotopeGrid ) ;
354+ exports . default = IsotopeGrid ;
0 commit comments