Skip to content

Commit 898a2fa

Browse files
committed
feat: Add support for className
1 parent 494dbe9 commit 898a2fa

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

Diff for: components/IndexSelector/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ class IndexSelector extends React.Component {
88
render() {
99
var currentIndex = this.props.currentIndex;
1010
var indices = this.props.indices;
11+
var cssClass = this.props.cssClass;
1112

1213
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+
})}
1722
</select>
1823
);
1924
}
2025
}
2126

2227
IndexSelector.propTypes = {
28+
cssClass: React.PropTypes.string,
2329
currentIndex: React.PropTypes.string,
2430
indices: React.PropTypes.array,
2531
setIndex: React.PropTypes.func

Diff for: example/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ search.addWidget(
2929
{'name': 'instant_search', 'label': 'Most relevant'},
3030
{'name': 'instant_search_price_asc', 'label': 'Lowest price'},
3131
{'name': 'instant_search_price_desc', 'label': 'Highest price'}
32-
]
32+
],
33+
cssClass: 'form-control'
3334
})
3435
);
3536

Diff for: example/index.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
4040
</div>
4141
<div class="col-md-9">
4242
<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>
4548
</div>
4649
<div id="hits"></div>
4750
<div id="pagination" class="text-center"></div>

Diff for: widgets/index-selector/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
var React = require('react');
2+
var cx = require('classnames');
23

34
var findIndex = require('lodash/array/findIndex');
45
var utils = require('../../lib/widgetUtils.js');
56

6-
function indexSelector({container = null, indices = null}) {
7+
function indexSelector({
8+
container = null,
9+
cssClass = null,
10+
indices = null
11+
}) {
712
var IndexSelector = require('../../components/IndexSelector');
813
var containerNode = utils.getContainerNode(container);
914

10-
var usage = 'Usage: indexSelector({container, indices})';
15+
var usage = 'Usage: indexSelector({container, indices[, cssClass]})';
1116
if (container === null || indices === null) {
1217
throw new Error(usage);
1318
}
@@ -20,9 +25,11 @@ function indexSelector({container = null, indices = null}) {
2025
throw new Error('[stats]: Index ' + currentIndex + ' not present in `indices`');
2126
}
2227
},
28+
2329
render: function(results, state, helper) {
2430
React.render(
2531
<IndexSelector
32+
cssClass={cx(cssClass)}
2633
currentIndex={helper.getIndex()}
2734
indices={indices}
2835
setIndex={helper.setIndex.bind(helper)}

0 commit comments

Comments
 (0)