Skip to content

Commit 19090c3

Browse files
author
vvo
committed
feat(rangeSlider): add headerFooter decorator
1 parent 8a70c7d commit 19090c3

File tree

6 files changed

+53
-18
lines changed

6 files changed

+53
-18
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,12 @@ search.addWidget(
498498
* You can also provide
499499
* tooltips: {format: function(formattedValue, rawValue) {return '$' + formattedValue}}
500500
* So that you can format the tooltip display value as you want
501+
* @param {Object} [options.cssClasses] Css classes to add to the wrapping elements: root, body
502+
* @param {String|String[]} [options.cssClasses.root]
503+
* @param {String|String[]} [options.cssClasses.body]
504+
* @param {Object} [options.templates] Templates to use for the widget
505+
* @param {String|Function} [options.templates.header=''] Header template
506+
* @param {String|Function} [options.templates.footer=''] Footer template
501507
* @param {boolean} [hideWhenNoResults=true] Hide the container when no results match
502508
* @return {Object}
503509
*/

components/Slider/index.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
var cx = require('classnames');
12
var React = require('react');
23

34
var Nouislider = require('react-nouislider');
45
var autoHide = require('../../decorators/autoHide');
6+
var headerFooter = require('../../decorators/headerFooter');
57

68
require('style?prepend!raw!./index.css');
79

@@ -16,14 +18,16 @@ class Slider extends React.Component {
1618

1719
render() {
1820
return (
19-
<Nouislider
20-
{...this.props}
21-
onChange={this.handleChange.bind(this)}
22-
animate={false}
23-
behaviour={'snap'}
24-
connect
25-
cssPrefix={cssPrefix}
26-
/>
21+
<div className={cx(this.props.cssClasses.body)}>
22+
<Nouislider
23+
{...this.props}
24+
onChange={this.handleChange.bind(this)}
25+
animate={false}
26+
behaviour={'snap'}
27+
connect
28+
cssPrefix={cssPrefix}
29+
/>
30+
</div>
2731
);
2832
}
2933
}
@@ -36,7 +40,13 @@ Slider.propTypes = {
3640
tooltips: React.PropTypes.oneOfType([
3741
React.PropTypes.bool,
3842
React.PropTypes.object
39-
])
43+
]),
44+
cssClasses: React.PropTypes.shape({
45+
body: React.PropTypes.oneOfType([
46+
React.PropTypes.string,
47+
React.PropTypes.arrayOf(React.PropTypes.string)
48+
])
49+
})
4050
};
4151

42-
module.exports = autoHide(Slider);
52+
module.exports = autoHide(headerFooter(Slider));

example/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ search.addWidget(
128128
instantsearch.widgets.rangeSlider({
129129
container: '#price',
130130
facetName: 'price',
131+
cssClasses: {
132+
body: 'panel-body'
133+
},
134+
templates: {
135+
header: '<div class="panel-heading">Price</div>'
136+
},
131137
tooltips: {
132138
format: function(formattedValue) {
133139
return '$' + formattedValue;

example/index.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
3131

3232
<div class="panel panel-default" id="free-shipping"></div>
3333

34-
<div class="panel panel-default">
35-
<div class="panel-heading">Price</div>
36-
<div class="panel-body">
37-
<div id="price"></div>
38-
</div>
39-
</div>
34+
<div class="panel panel-default" id="price"></div>
4035

4136
</div>
4237
<div class="col-md-9">

example/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ body {
3636
height: 125px;
3737
}
3838

39-
#price {
40-
padding: 30px 0;
39+
#price .panel-body {
40+
padding: 45px 15px;
4141
}
4242

4343
.panel-heading {

widgets/range-slider.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ var React = require('react');
22

33
var utils = require('../lib/utils.js');
44

5+
var defaultTemplates = {
6+
header: '',
7+
footer: ''
8+
};
9+
510
/**
611
* Instantiate a slider based on a numeric attribute
712
* @param {String|DOMElement} options.container CSS Selector or DOMElement to insert the widget
@@ -11,13 +16,24 @@ var utils = require('../lib/utils.js');
1116
* You can also provide
1217
* tooltips: {format: function(formattedValue, rawValue) {return '$' + formattedValue}}
1318
* So that you can format the tooltip display value as you want
19+
* @param {Object} [options.cssClasses] Css classes to add to the wrapping elements: root, body
20+
* @param {String|String[]} [options.cssClasses.root]
21+
* @param {String|String[]} [options.cssClasses.body]
22+
* @param {Object} [options.templates] Templates to use for the widget
23+
* @param {String|Function} [options.templates.header=''] Header template
24+
* @param {String|Function} [options.templates.footer=''] Footer template
1425
* @param {boolean} [hideWhenNoResults=true] Hide the container when no results match
1526
* @return {Object}
1627
*/
1728
function rangeSlider({
1829
container = null,
1930
facetName = null,
2031
tooltips = true,
32+
templates = defaultTemplates,
33+
cssClasses = {
34+
root: null,
35+
body: null
36+
},
2137
hideWhenNoResults = true
2238
}) {
2339
var Slider = require('../components/Slider');
@@ -71,6 +87,8 @@ function rangeSlider({
7187
<Slider
7288
start={[currentRefinement.min, currentRefinement.max]}
7389
range={{min: stats.min, max: stats.max}}
90+
cssClasses={cssClasses}
91+
templates={templates}
7492
hideWhenNoResults={hideWhenNoResults}
7593
hasResults={stats.min !== null && stats.max !== null}
7694
onChange={this._refine.bind(this, helper)}

0 commit comments

Comments
 (0)