Skip to content

Commit

Permalink
feat: multipleChoiceList first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo committed Sep 2, 2015
1 parent 63b4b50 commit bc91bfb
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
29 changes: 29 additions & 0 deletions components/MultipleChoiceList/index.js
@@ -0,0 +1,29 @@
var React = require('react');

var Template = require('../Template/');

class MultipleChoiceList extends React.Component {
render() {
var facetValues = this.props.facetValues;
var template = this.props.template;

return (
<ul>
{facetValues.map(function(facetValue) {
return <Template key={facetValue.name} data={facetValue} template={template} />;
})}
</ul>
);
}
}

MultipleChoiceList.propTypes = {
facetValues: React.PropTypes.array,
template: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.func
]).isRequired,
toggleRefine: React.PropTypes.fn
};

module.exports = MultipleChoiceList;
7 changes: 7 additions & 0 deletions example/app.js
Expand Up @@ -35,4 +35,11 @@ search.addWidget(
})
);

search.addWidget(
instantsearch.widgets.multipleChoiceList({
container: '#brands',
facetName: 'brand'
})
);

search.start();
2 changes: 1 addition & 1 deletion example/index.html
Expand Up @@ -14,8 +14,8 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>

<div class="row">
<div class="col-md-3">

<div id="search-box"></div>
<div id="brands"></div>
</div>
<div class="col-md-9">
<div id="hits"></div>
Expand Down
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -3,6 +3,7 @@ module.exports = {
widgets: {
searchBox: require('./widgets/search-box/'),
hits: require('./widgets/hits/'),
pagination: require('./widgets/pagination/')
pagination: require('./widgets/pagination/'),
multipleChoiceList: require('./widgets/multiple-choice-list/')
}
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -35,7 +35,6 @@
"onchange": "2.0.0",
"pretty-bytes": "2.0.1",
"proxyquire": "1.7.1",
"raw-loader": "0.5.1",
"sinon": "1.16.1",
"style-loader": "0.12.3",
"tap-spec": "4.1.0",
Expand All @@ -50,6 +49,7 @@
"classnames": "2.1.3",
"hogan.js": "3.0.2",
"lodash": "3.10.1",
"raw-loader": "0.5.1",
"react": "0.13.3"
},
"license": "MIT"
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.js
Expand Up @@ -9,6 +9,8 @@ module.exports = {
module: {
loaders: [{
test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'
}, {
test: /\.html$/, exclude: /node_modules/, loader: 'raw'
}]
}
};
29 changes: 29 additions & 0 deletions widgets/multiple-choice-list/index.js
@@ -0,0 +1,29 @@
var React = require('react');

var utils = require('../../lib/widgetUtils.js');
var defaultTemplate = require('./template.html');

function multipleChoiceList({container = null, facetName = null, template = defaultTemplate}) {
var MultipleChoiceList = require('../../components/MultipleChoiceList');
var containerNode = utils.getContainerNode(container);

if (container === null || facetName === null) {
throw new Error('Usage: multipleChoiceList({container, facetName[, template]})');
}

return {
getConfiguration: () => ({disjunctiveFacets: [facetName]}),
render: function(results, state, helper) {
React.render(
<MultipleChoiceList
facetValues={results.getFacetValues(facetName, {sortBy: ['name:asc']})}
toggleRefine={helper.toggleRefine.bind(helper, facetName)}
template={template}
/>,
containerNode
);
}
};
}

module.exports = multipleChoiceList;
1 change: 1 addition & 0 deletions widgets/multiple-choice-list/template.html
@@ -0,0 +1 @@
<label><input type="checkbox" value="{{name}}" {{#selected}}checked{{/selected}} />{{name}} <span>{{count}}</span></label>

0 comments on commit bc91bfb

Please sign in to comment.