File tree 4 files changed +26
-9
lines changed
4 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -8,18 +8,24 @@ class IndexSelector extends React.Component {
8
8
render ( ) {
9
9
var currentIndex = this . props . currentIndex ;
10
10
var indices = this . props . indices ;
11
+ var cssClass = this . props . cssClass ;
11
12
12
13
return (
13
- < select onChange = { this . handleChange . bind ( this ) } value = { currentIndex } >
14
- { indices . map ( function ( index ) {
15
- return < option key = { index . name } value = { index . name } > { index . label } </ option > ;
16
- } ) }
14
+ < select
15
+ className = { cssClass }
16
+ onChange = { this . handleChange . bind ( this ) }
17
+ value = { currentIndex }
18
+ >
19
+ { indices . map ( function ( index ) {
20
+ return < option key = { index . name } value = { index . name } > { index . label } </ option > ;
21
+ } ) }
17
22
</ select >
18
23
) ;
19
24
}
20
25
}
21
26
22
27
IndexSelector . propTypes = {
28
+ cssClass : React . PropTypes . string ,
23
29
currentIndex : React . PropTypes . string ,
24
30
indices : React . PropTypes . array ,
25
31
setIndex : React . PropTypes . func
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ search.addWidget(
29
29
{ 'name' : 'instant_search' , 'label' : 'Most relevant' } ,
30
30
{ 'name' : 'instant_search_price_asc' , 'label' : 'Lowest price' } ,
31
31
{ 'name' : 'instant_search_price_desc' , 'label' : 'Highest price' }
32
- ]
32
+ ] ,
33
+ cssClass : 'form-control'
33
34
} )
34
35
) ;
35
36
Original file line number Diff line number Diff line change @@ -40,8 +40,11 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
40
40
</ div >
41
41
< div class ="col-md-9 ">
42
42
< div id ="stats "> </ div >
43
- < div >
44
- Sort by: < span id ="index-selector "> </ span >
43
+ < div class ="form-inline ">
44
+ < div class ="form-group ">
45
+ < label > Sort by:</ label >
46
+ < span id ="index-selector "> </ span >
47
+ </ div >
45
48
</ div >
46
49
< div id ="hits "> </ div >
47
50
< div id ="pagination " class ="text-center "> </ div >
Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
+ var cx = require ( 'classnames' ) ;
2
3
3
4
var findIndex = require ( 'lodash/array/findIndex' ) ;
4
5
var utils = require ( '../../lib/widgetUtils.js' ) ;
5
6
6
- function indexSelector ( { container = null , indices = null } ) {
7
+ function indexSelector ( {
8
+ container = null ,
9
+ cssClass = null ,
10
+ indices = null
11
+ } ) {
7
12
var IndexSelector = require ( '../../components/IndexSelector' ) ;
8
13
var containerNode = utils . getContainerNode ( container ) ;
9
14
10
- var usage = 'Usage: indexSelector({container, indices})' ;
15
+ var usage = 'Usage: indexSelector({container, indices[, cssClass] })' ;
11
16
if ( container === null || indices === null ) {
12
17
throw new Error ( usage ) ;
13
18
}
@@ -20,9 +25,11 @@ function indexSelector({container = null, indices = null}) {
20
25
throw new Error ( '[stats]: Index ' + currentIndex + ' not present in `indices`' ) ;
21
26
}
22
27
} ,
28
+
23
29
render : function ( results , state , helper ) {
24
30
React . render (
25
31
< IndexSelector
32
+ cssClass = { cx ( cssClass ) }
26
33
currentIndex = { helper . getIndex ( ) }
27
34
indices = { indices }
28
35
setIndex = { helper . setIndex . bind ( helper ) }
You can’t perform that action at this time.
0 commit comments