1
1
var React = require ( 'react' ) ;
2
2
var ReactDOM = require ( 'react-dom' ) ;
3
3
4
- var utils = require ( '../lib/utils.js' ) ;
5
- var autoHide = require ( '../decorators/autoHide' ) ;
6
- var headerFooter = require ( '../decorators/headerFooter' ) ;
7
- var RefinementList = autoHide ( headerFooter ( require ( '../components/RefinementList' ) ) ) ;
4
+ var utils = require ( '../../lib/utils.js' ) ;
5
+ var bem = utils . bemHelper ( 'ais-hierarchical-menu' ) ;
6
+ var cx = require ( 'classnames/dedupe' ) ;
7
+ var autoHide = require ( '../../decorators/autoHide' ) ;
8
+ var headerFooter = require ( '../../decorators/headerFooter' ) ;
9
+ var RefinementList = autoHide ( headerFooter ( require ( '../../components/RefinementList' ) ) ) ;
8
10
9
- var defaultTemplates = {
10
- header : '' ,
11
- item : '<a href="{{url}}">{{name}}</a> {{count}}' ,
12
- footer : ''
13
- } ;
11
+ var defaultTemplates = require ( './defaultTemplates.js' ) ;
14
12
15
13
/**
16
14
* Create a hierarchical menu using multiple attributes
@@ -20,28 +18,30 @@ var defaultTemplates = {
20
18
* @param {String[] } [options.sortBy=['count:desc']] How to sort refinements. Possible values: `count|isRefined|name:asc|desc`
21
19
* @param {Number } [options.limit=100] How much facet values to get
22
20
* @param {Object } [options.cssClasses] CSS classes to add to the wrapping elements: root, list, item
23
- * @param {String|String[] } [options.cssClasses.root] CSS class added to the root element
24
- * @param {String|String[] } [options.cssClasses.list] CSS class added to each list element
25
- * @param {String|String[] } [options.cssClasses.item] CSS class added to each item element
21
+ * @param {String|String[] } [options.cssClasses.root] CSS class to add to the root element
22
+ * @param {String|String[] } [options.cssClasses.header] CSS class to add to the header element
23
+ * @param {String|String[] } [options.cssClasses.body] CSS class to add to the body element
24
+ * @param {String|String[] } [options.cssClasses.footer] CSS class to add to the footer element
25
+ * @param {String|String[] } [options.cssClasses.list] CSS class to add to the list element
26
+ * @param {String|String[] } [options.cssClasses.item] CSS class to add to each item element
27
+ * @param {String|String[] } [options.cssClasses.active] CSS class to add to each active element
28
+ * @param {String|String[] } [options.cssClasses.link] CSS class to add to each link (when using the default template)
29
+ * @param {String|String[] } [options.cssClasses.count] CSS class to add to each count element (when using the default template)
26
30
* @param {Object } [options.templates] Templates to use for the widget
27
31
* @param {String|Function } [options.templates.header=''] Header template (root level only)
28
- * @param {String|Function } [options.templates.item='<a href="{{href}}">{{name}}</a> {{count}}' ] Item template, provided with `name`, `count`, `isRefined`, `path`
32
+ * @param {String|Function } [options.templates.item] Item template
29
33
* @param {String|Function } [options.templates.footer=''] Footer template (root level only)
30
34
* @param {Function } [options.transformData] Method to change the object passed to the item template
31
35
* @param {boolean } [hideWhenNoResults=true] Hide the container when there's no results
32
36
* @return {Object }
33
37
*/
34
38
function hierarchicalMenu ( {
35
- container = null ,
39
+ container,
36
40
attributes = [ ] ,
37
41
separator,
38
42
limit = 100 ,
39
43
sortBy = [ 'name:asc' ] ,
40
- cssClasses = {
41
- root : null ,
42
- list : null ,
43
- item : null
44
- } ,
44
+ cssClasses = { } ,
45
45
hideWhenNoResults = true ,
46
46
templates = defaultTemplates ,
47
47
transformData
@@ -76,6 +76,18 @@ function hierarchicalMenu({
76
76
templates
77
77
} ) ;
78
78
79
+ cssClasses = {
80
+ root : cx ( bem ( null ) , cssClasses . root ) ,
81
+ header : cx ( bem ( 'header' ) , cssClasses . header ) ,
82
+ body : cx ( bem ( 'body' ) , cssClasses . body ) ,
83
+ footer : cx ( bem ( 'footer' ) , cssClasses . footer ) ,
84
+ list : cx ( bem ( 'list' ) , cssClasses . list ) ,
85
+ item : cx ( bem ( 'item' ) , cssClasses . item ) ,
86
+ active : cx ( bem ( 'item' , 'active' ) , cssClasses . active ) ,
87
+ link : cx ( bem ( 'link' ) , cssClasses . link ) ,
88
+ count : cx ( bem ( 'count' ) , cssClasses . count )
89
+ } ;
90
+
79
91
ReactDOM . render (
80
92
< RefinementList
81
93
createURL = { ( facetValue ) => createURL ( state . toggleRefinement ( hierarchicalFacetName , facetValue ) ) }
0 commit comments