Skip to content

Commit

Permalink
feat: Add support for className
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelastic committed Sep 8, 2015
1 parent 494dbe9 commit 898a2fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
14 changes: 10 additions & 4 deletions components/IndexSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ class IndexSelector extends React.Component {
render() {
var currentIndex = this.props.currentIndex;
var indices = this.props.indices;
var cssClass = this.props.cssClass;

return (
<select onChange={this.handleChange.bind(this)} value={currentIndex}>
{indices.map(function(index) {
return <option key={index.name} value={index.name}>{index.label}</option>;
})}
<select
className={cssClass}
onChange={this.handleChange.bind(this)}
value={currentIndex}
>
{indices.map(function(index) {
return <option key={index.name} value={index.name}>{index.label}</option>;
})}
</select>
);
}
}

IndexSelector.propTypes = {
cssClass: React.PropTypes.string,
currentIndex: React.PropTypes.string,
indices: React.PropTypes.array,
setIndex: React.PropTypes.func
Expand Down
3 changes: 2 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ search.addWidget(
{'name': 'instant_search', 'label': 'Most relevant'},
{'name': 'instant_search_price_asc', 'label': 'Lowest price'},
{'name': 'instant_search_price_desc', 'label': 'Highest price'}
]
],
cssClass: 'form-control'
})
);

Expand Down
7 changes: 5 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
</div>
<div class="col-md-9">
<div id="stats"></div>
<div>
Sort by: <span id="index-selector"></span>
<div class="form-inline">
<div class="form-group">
<label>Sort by:</label>
<span id="index-selector"></span>
</div>
</div>
<div id="hits"></div>
<div id="pagination" class="text-center"></div>
Expand Down
11 changes: 9 additions & 2 deletions widgets/index-selector/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var React = require('react');
var cx = require('classnames');

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

function indexSelector({container = null, indices = null}) {
function indexSelector({
container = null,
cssClass = null,
indices = null
}) {
var IndexSelector = require('../../components/IndexSelector');
var containerNode = utils.getContainerNode(container);

var usage = 'Usage: indexSelector({container, indices})';
var usage = 'Usage: indexSelector({container, indices[, cssClass]})';
if (container === null || indices === null) {
throw new Error(usage);
}
Expand All @@ -20,9 +25,11 @@ function indexSelector({container = null, indices = null}) {
throw new Error('[stats]: Index ' + currentIndex + ' not present in `indices`');
}
},

render: function(results, state, helper) {
React.render(
<IndexSelector
cssClass={cx(cssClass)}
currentIndex={helper.getIndex()}
indices={indices}
setIndex={helper.setIndex.bind(helper)}
Expand Down

0 comments on commit 898a2fa

Please sign in to comment.