@@ -23,16 +23,25 @@ class FilteredIsotope extends React.Component {
2323 const { getSortData, sortBy, sortOrder, wholeWord, searchTerm, filterList } = this . props ;
2424 const { isotope } = this . state ;
2525
26- const reg = wholeWord ? RegExp ( `\\b${ searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' ) : RegExp ( `${ searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
26+ const reg = wholeWord
27+ ? RegExp ( `\\b${ searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' )
28+ : RegExp ( `${ searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
2729
2830 if ( ! isotope ) {
29- this . setState ( { isotope : new Isotope ( ReactDOM . findDOMNode ( this ) , {
30- layoutMode : 'fitRows' ,
31- getSortData,
32- sortBy : sortBy || 'original-order' ,
33- sortAscending : sortOrder ? sortOrder === 'asc' : true ,
34- filter : itemElem => ( ! filterList || filterList . length === 0 || filterList . every ( filter => filter ( itemElem ) ) ) && reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ,
35- } ) } ) ;
31+ this . setState ( {
32+ isotope : new Isotope ( ReactDOM . findDOMNode ( this ) , {
33+ itemSelector : '.wfui-isotope-element' ,
34+ layoutMode : 'fitRows' ,
35+ getSortData,
36+ sortBy : sortBy || 'original-order' ,
37+ sortAscending : sortOrder ? sortOrder === 'asc' : true ,
38+ filter : itemElem =>
39+ ( ! filterList ||
40+ filterList . length === 0 ||
41+ filterList . every ( filter => filter ( itemElem ) ) ) &&
42+ reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ,
43+ } ) ,
44+ } ) ;
3645 } else {
3746 this . state . isotope . reloadItems ( ) ;
3847 }
@@ -50,11 +59,17 @@ class FilteredIsotope extends React.Component {
5059
5160 if ( JSON . stringify ( this . props . getSortData ) !== JSON . stringify ( nextProps . getSortData ) ) {
5261 this . state . isotope . destroy ( ) ;
53- const reg = nextProps . wholeWord ? RegExp ( `\\b${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' ) : RegExp ( `${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
62+ const reg = nextProps . wholeWord
63+ ? RegExp ( `\\b${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' )
64+ : RegExp ( `${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
5465 options . getSortData = nextProps . getSortData ;
5566 options . sortBy = nextProps . sortBy || 'original-order' ;
5667 options . sortAscending = nextProps . sortOrder ? nextProps . sortOrder === 'asc' : true ;
57- options . filter = itemElem => ( ! nextProps . filterList || nextProps . filterList . length === 0 || nextProps . filterList . every ( filter => filter ( itemElem ) ) ) && reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ;
68+ options . filter = itemElem =>
69+ ( ! nextProps . filterList ||
70+ nextProps . filterList . length === 0 ||
71+ nextProps . filterList . every ( filter => filter ( itemElem ) ) ) &&
72+ reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ;
5873 if ( reload !== this . state . reload ) {
5974 this . setState ( {
6075 isotope : new Isotope ( ReactDOM . findDOMNode ( this ) , {
@@ -74,18 +89,31 @@ class FilteredIsotope extends React.Component {
7489 } ) ;
7590 }
7691 } else {
77- if ( this . props . sortBy !== nextProps . sortBy ) options . sortBy = nextProps . sortBy || 'original-order' ;
78- if ( this . props . sortOrder !== nextProps . sortOrder ) options . sortAscending = nextProps . sortOrder ? nextProps . sortOrder === 'asc' : true ;
79- if ( this . props . searchTerm . toLowerCase ( ) . trim ( ) !== nextProps . searchTerm . toLowerCase ( ) . trim ( ) ||
80- JSON . stringify ( this . props . filterList ) !== JSON . stringify ( nextProps . filterList ) ) {
81- const reg = nextProps . wholeWord ? RegExp ( `\\b${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' ) : RegExp ( `${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
82- options . filter = itemElem => ( ! nextProps . filterList || nextProps . filterList . length === 0 || nextProps . filterList . every ( filter => filter ( itemElem ) ) ) && reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ;
92+ if ( this . props . sortBy !== nextProps . sortBy ) {
93+ options . sortBy = nextProps . sortBy || 'original-order' ;
94+ }
95+ if ( this . props . sortOrder !== nextProps . sortOrder ) {
96+ options . sortAscending = nextProps . sortOrder ? nextProps . sortOrder === 'asc' : true ;
97+ }
98+ if (
99+ this . props . searchTerm . toLowerCase ( ) . trim ( ) !==
100+ nextProps . searchTerm . toLowerCase ( ) . trim ( ) ||
101+ JSON . stringify ( this . props . filterList ) !== JSON . stringify ( nextProps . filterList )
102+ ) {
103+ const reg = nextProps . wholeWord
104+ ? RegExp ( `\\b${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } \\b` , 'i' )
105+ : RegExp ( `${ nextProps . searchTerm . toLowerCase ( ) . trim ( ) } ` , 'i' ) ;
106+ options . filter = itemElem =>
107+ ( ! nextProps . filterList ||
108+ nextProps . filterList . length === 0 ||
109+ nextProps . filterList . every ( filter => filter ( itemElem ) ) ) &&
110+ reg . test ( itemElem . querySelector ( '.isotope-search' ) . innerText ) ;
83111 }
84112
85113 if ( reload !== this . state . reload ) this . setState ( { reload } ) ;
86114 if ( options ) this . state . isotope . arrange ( { ...options } ) ;
87115 }
88- /*
116+ /*
89117 if (JSON.stringify(this.props.data) !== JSON.stringify(nextProps.data)) {
90118 this.setState({ reload: true });
91119 } else if (this.state.reload) {
@@ -140,11 +168,14 @@ class FilteredIsotope extends React.Component {
140168
141169 return (
142170 < div className = { classNames ( className , 'wfui-isotope-grid' ) } >
143- {
144- data . map ( ( item , idx ) => (
145- < Element className = { itemClassName } item = { item } itemDisplay = { itemDisplay } key = { idx } />
146- ) )
147- }
171+ { data . map ( ( item , idx ) => (
172+ < Element
173+ className = { itemClassName }
174+ item = { item }
175+ itemDisplay = { itemDisplay }
176+ key = { idx }
177+ />
178+ ) ) }
148179 </ div >
149180 ) ;
150181 }
@@ -154,10 +185,7 @@ FilteredIsotope.propTypes = {
154185 itemDisplay : PropTypes . element . isRequired ,
155186 data : PropTypes . arrayOf ( PropTypes . any ) . isRequired ,
156187 className : PropTypes . string ,
157- getSortData : PropTypes . objectOf ( PropTypes . oneOfType ( [
158- PropTypes . string ,
159- PropTypes . func ,
160- ] ) ) ,
188+ getSortData : PropTypes . objectOf ( PropTypes . oneOfType ( [ PropTypes . string , PropTypes . func ] ) ) ,
161189 sortBy : PropTypes . string ,
162190 sortOrder : PropTypes . string ,
163191 searchTerm : PropTypes . string ,
0 commit comments