File tree 8 files changed +72
-3
lines changed
components/MultipleChoiceList
widgets/multiple-choice-list
8 files changed +72
-3
lines changed Original file line number Diff line number Diff line change
1
+ var React = require ( 'react' ) ;
2
+
3
+ var Template = require ( '../Template/' ) ;
4
+
5
+ class MultipleChoiceList extends React . Component {
6
+ render ( ) {
7
+ var facetValues = this . props . facetValues ;
8
+ var template = this . props . template ;
9
+
10
+ return (
11
+ < ul >
12
+ { facetValues . map ( function ( facetValue ) {
13
+ return < Template key = { facetValue . name } data = { facetValue } template = { template } /> ;
14
+ } ) }
15
+ </ ul >
16
+ ) ;
17
+ }
18
+ }
19
+
20
+ MultipleChoiceList . propTypes = {
21
+ facetValues : React . PropTypes . array ,
22
+ template : React . PropTypes . oneOfType ( [
23
+ React . PropTypes . string ,
24
+ React . PropTypes . func
25
+ ] ) . isRequired ,
26
+ toggleRefine : React . PropTypes . fn
27
+ } ;
28
+
29
+ module . exports = MultipleChoiceList ;
Original file line number Diff line number Diff line change @@ -35,4 +35,11 @@ search.addWidget(
35
35
} )
36
36
) ;
37
37
38
+ search . addWidget (
39
+ instantsearch . widgets . multipleChoiceList ( {
40
+ container : '#brands' ,
41
+ facetName : 'brand'
42
+ } )
43
+ ) ;
44
+
38
45
search . start ( ) ;
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
14
14
15
15
< div class ="row ">
16
16
< div class ="col-md-3 ">
17
-
18
17
< div id ="search-box "> </ div >
18
+ < div id ="brands "> </ div >
19
19
</ div >
20
20
< div class ="col-md-9 ">
21
21
< div id ="hits "> </ div >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module.exports = {
3
3
widgets : {
4
4
searchBox : require ( './widgets/search-box/' ) ,
5
5
hits : require ( './widgets/hits/' ) ,
6
- pagination : require ( './widgets/pagination/' )
6
+ pagination : require ( './widgets/pagination/' ) ,
7
+ multipleChoiceList : require ( './widgets/multiple-choice-list/' )
7
8
}
8
9
} ;
Original file line number Diff line number Diff line change 35
35
"onchange" : " 2.0.0" ,
36
36
"pretty-bytes" : " 2.0.1" ,
37
37
"proxyquire" : " 1.7.1" ,
38
- "raw-loader" : " 0.5.1" ,
39
38
"sinon" : " 1.16.1" ,
40
39
"style-loader" : " 0.12.3" ,
41
40
"tap-spec" : " 4.1.0" ,
50
49
"classnames" : " 2.1.3" ,
51
50
"hogan.js" : " 3.0.2" ,
52
51
"lodash" : " 3.10.1" ,
52
+ "raw-loader" : " 0.5.1" ,
53
53
"react" : " 0.13.3"
54
54
},
55
55
"license" : " MIT"
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ module.exports = {
9
9
module : {
10
10
loaders : [ {
11
11
test : / \. j s $ / , exclude : / n o d e _ m o d u l e s / , loader : 'babel-loader'
12
+ } , {
13
+ test : / \. h t m l $ / , exclude : / n o d e _ m o d u l e s / , loader : 'raw'
12
14
} ]
13
15
}
14
16
} ;
Original file line number Diff line number Diff line change
1
+ var React = require ( 'react' ) ;
2
+
3
+ var utils = require ( '../../lib/widgetUtils.js' ) ;
4
+ var defaultTemplate = require ( './template.html' ) ;
5
+
6
+ function multipleChoiceList ( { container = null , facetName = null , template = defaultTemplate } ) {
7
+ var MultipleChoiceList = require ( '../../components/MultipleChoiceList' ) ;
8
+ var containerNode = utils . getContainerNode ( container ) ;
9
+
10
+ if ( container === null || facetName === null ) {
11
+ throw new Error ( 'Usage: multipleChoiceList({container, facetName[, template]})' ) ;
12
+ }
13
+
14
+ return {
15
+ getConfiguration : ( ) => ( { disjunctiveFacets : [ facetName ] } ) ,
16
+ render : function ( results , state , helper ) {
17
+ React . render (
18
+ < MultipleChoiceList
19
+ facetValues = { results . getFacetValues ( facetName , { sortBy : [ 'name:asc' ] } ) }
20
+ toggleRefine = { helper . toggleRefine . bind ( helper , facetName ) }
21
+ template = { template }
22
+ /> ,
23
+ containerNode
24
+ ) ;
25
+ }
26
+ } ;
27
+ }
28
+
29
+ module . exports = multipleChoiceList ;
Original file line number Diff line number Diff line change
1
+ < label > < input type ="checkbox " value ="{{name}} " {{#selected}}checked{{ /selected}} /> {{name}} < span > {{count}}</ span > </ label >
You can’t perform that action at this time.
0 commit comments