Skip to content

Commit ecb6756

Browse files
committed
fix(autohide): Rename attribute to hideContainerWhenNoResults
BREAKING CHANGE: Widget attribute is now named `hideContainerWhenNoResults` instead of `hideWhenNoResults` to be more explicit on what it is really doing. Also internally renamed the `autoHide` decorator to `autoHideContainer` Fixes #325
1 parent 24122a2 commit ecb6756

File tree

19 files changed

+104
-104
lines changed

19 files changed

+104
-104
lines changed

Diff for: README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ search.addWidget(
386386
* @param {String|Function} [options.templates.body] Body template
387387
* @param {String|Function} [options.templates.footer=''] Footer template
388388
* @param {Function} [options.transformData] Function to change the object passed to the `body` template
389-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
389+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
390390
* @return {Object}
391391
*/
392392
```
@@ -455,7 +455,7 @@ you'll need several indices. This widget lets you easily change it.
455455
* @param {Object} [options.cssClasses] CSS classes to be added
456456
* @param {String} [options.cssClasses.root] CSS classes added to the parent <select>
457457
* @param {String} [options.cssClasses.item] CSS classes added to each <option>
458-
* @param {boolean} [hideWhenNoResults=false] Hide the container when no results match
458+
* @param {boolean} [hideContainerWhenNoResults=false] Hide the container when no results match
459459
* @return {Object}
460460
*/
461461
```
@@ -518,7 +518,7 @@ search.addWidget(
518518
* @param {Number} [maxPages=20] The max number of pages to browse
519519
* @param {String|DOMElement|boolean} [scrollTo='body'] Where to scroll after a click, set to `false` to disable
520520
* @param {boolean} [showFirstLast=true] Define if the First and Last links should be displayed
521-
* @param {boolean} [hideWhenNoResults=true] Hide the container when no results match
521+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when no results match
522522
* @return {Object}
523523
*/
524524
```
@@ -660,7 +660,7 @@ Note that we are not toggling from `true` to `false` here, but from `true` to
660660
* @param {String|Function} [options.templates.item] Item template
661661
* @param {String|Function} [options.templates.footer=''] Footer template
662662
* @param {Function} [options.transformData] Function to change the object passed to the item template
663-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
663+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
664664
* @return {Object}
665665
*/
666666
```
@@ -755,7 +755,7 @@ search.addWidget(
755755
* @param {String|Function} [options.templates.item] Item template, provided with `name`, `count`, `isRefined`
756756
* @param {String|Function} [options.templates.footer] Footer template
757757
* @param {Function} [options.transformData] Function to change the object passed to the item template
758-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
758+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
759759
* @return {Object}
760760
*/
761761
```
@@ -851,7 +851,7 @@ search.addWidget(
851851
* @param {String|Function} [options.templates.item] Item template, provided with `name`, `count`, `isRefined`
852852
* @param {String|Function} [options.templates.footer=''] Footer template
853853
* @param {Function} [options.transformData] Method to change the object passed to the item template
854-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
854+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
855855
* @return {Object}
856856
*/
857857
```
@@ -940,7 +940,7 @@ search.addWidget(
940940
* @param {Object} [options.cssClasses] CSS classes to add to the wrapping elements: root, body
941941
* @param {String|String[]} [options.cssClasses.root] CSS class to add to the root element
942942
* @param {String|String[]} [options.cssClasses.body] CSS class to add to the body element
943-
* @param {boolean} [hideWhenNoResults=true] Hide the container when no results match
943+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when no results match
944944
* @return {Object}
945945
*/
946946
```
@@ -990,7 +990,7 @@ search.addWidget(
990990
* @param {String|Function} [options.labels.button] Button label
991991
* @param {String|Function} [options.labels.currency] Currency label
992992
* @param {String|Function} [options.labels.to] To label
993-
* @param {boolean} [hideWhenNoResults=true] Hide the container when no results match
993+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when no results match
994994
* @return {Object}
995995
*/
996996
```
@@ -1045,7 +1045,7 @@ search.addWidget(
10451045
* @param {String|Function} [options.templates.item] Item template
10461046
* @param {String|Function} [options.templates.footer=''] Footer template (root level only)
10471047
* @param {Function} [options.transformData] Method to change the object passed to the item template
1048-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
1048+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
10491049
* @return {Object}
10501050
*/
10511051
```

Diff for: components/RefinementList/__tests__/RefinementList-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('RefinementList', () => {
5555
});
5656

5757
context('sublist', () => {
58-
it('uses autoHide() and headerFooter()', () => {
58+
it('uses autoHideContainer() and headerFooter()', () => {
5959
var customProps = {
6060
cssClasses: {
6161
depth: 'depth',

Diff for: decorators/__tests__/autoHide-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
import React from 'react';
44
import expect from 'expect';
55
import TestUtils from 'react-addons-test-utils';
6-
import autoHide from '../autoHide';
6+
import autoHideContainer from '../autoHideContainer';
77

88
import expectJSX from 'expect-jsx';
99
expect.extend(expectJSX);
1010

11-
describe('autoHide', () => {
11+
describe('autoHideContainer', () => {
1212
var renderer;
1313

1414
beforeEach(() => {
1515
let {createRenderer} = TestUtils;
1616
renderer = createRenderer();
1717
});
1818

19-
it('should render autoHide(<span />)', () => {
19+
it('should render autoHideContainer(<span />)', () => {
2020
var out = render();
2121
expect(out).toEqualJSX(<span />);
2222
});
2323

24-
it('should not render autoHide(<span />)', () => {
25-
var out = render({hasResults: false, hideWhenNoResults: true});
24+
it('should not render autoHideContainer(<span />)', () => {
25+
var out = render({hasResults: false, hideContainerWhenNoResults: true});
2626
expect(out).toEqualJSX(<div />);
2727
});
2828

2929
function render(props = {}) {
30-
var AutoHide = autoHide(<span />);
30+
var AutoHide = autoHideContainer(<span />);
3131
renderer.render(<AutoHide {...props} />);
3232
return renderer.getRenderOutput();
3333
}

Diff for: decorators/autoHide.js renamed to decorators/autoHideContainer.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var React = require('react');
22
var ReactDOM = require('react-dom');
33

4-
function autoHide(ComposedComponent) {
4+
function autoHideContainer(ComposedComponent) {
55
class AutoHide extends React.Component {
66
componentDidMount() {
77
this._hideOrShowContainer(this.props);
@@ -13,16 +13,16 @@ function autoHide(ComposedComponent) {
1313

1414
_hideOrShowContainer(props) {
1515
var container = ReactDOM.findDOMNode(this).parentNode;
16-
if (props.hideWhenNoResults === true && props.hasResults === false) {
16+
if (props.hideContainerWhenNoResults === true && props.hasResults === false) {
1717
container.style.display = 'none';
18-
} else if (props.hideWhenNoResults === true) {
18+
} else if (props.hideContainerWhenNoResults === true) {
1919
container.style.display = '';
2020
}
2121
}
2222

2323
render() {
2424
if (this.props.hasResults === false &&
25-
this.props.hideWhenNoResults === true) {
25+
this.props.hideContainerWhenNoResults === true) {
2626
return <div />;
2727
}
2828

@@ -32,7 +32,7 @@ function autoHide(ComposedComponent) {
3232

3333
AutoHide.propTypes = {
3434
hasResults: React.PropTypes.bool.isRequired,
35-
hideWhenNoResults: React.PropTypes.bool.isRequired
35+
hideContainerWhenNoResults: React.PropTypes.bool.isRequired
3636
};
3737

3838
// precise displayName for ease of debugging (react dev tool, react warnings)
@@ -41,4 +41,4 @@ function autoHide(ComposedComponent) {
4141
return AutoHide;
4242
}
4343

44-
module.exports = autoHide;
44+
module.exports = autoHideContainer;

Diff for: widgets/hierarchical-menu/hierarchical-menu.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var ReactDOM = require('react-dom');
44
var utils = require('../../lib/utils.js');
55
var bem = utils.bemHelper('ais-hierarchical-menu');
66
var cx = require('classnames/dedupe');
7-
var autoHide = require('../../decorators/autoHide');
7+
var autoHideContainer = require('../../decorators/autoHideContainer');
88
var headerFooter = require('../../decorators/headerFooter');
9-
var RefinementList = autoHide(headerFooter(require('../../components/RefinementList/RefinementList.js')));
9+
var RefinementList = autoHideContainer(headerFooter(require('../../components/RefinementList/RefinementList.js')));
1010

1111
var defaultTemplates = require('./defaultTemplates.js');
1212

@@ -32,7 +32,7 @@ var defaultTemplates = require('./defaultTemplates.js');
3232
* @param {String|Function} [options.templates.item] Item template
3333
* @param {String|Function} [options.templates.footer=''] Footer template (root level only)
3434
* @param {Function} [options.transformData] Method to change the object passed to the item template
35-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
35+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
3636
* @return {Object}
3737
*/
3838
function hierarchicalMenu({
@@ -42,7 +42,7 @@ function hierarchicalMenu({
4242
limit = 100,
4343
sortBy = ['name:asc'],
4444
cssClasses = {},
45-
hideWhenNoResults = true,
45+
hideContainerWhenNoResults = true,
4646
templates = defaultTemplates,
4747
transformData
4848
}) {
@@ -96,7 +96,7 @@ function hierarchicalMenu({
9696
facetNameKey="path"
9797
facetValues={facetValues}
9898
hasResults={facetValues.length > 0}
99-
hideWhenNoResults={hideWhenNoResults}
99+
hideContainerWhenNoResults={hideContainerWhenNoResults}
100100
limit={limit}
101101
templateProps={templateProps}
102102
toggleRefinement={toggleRefinement.bind(null, helper, hierarchicalFacetName)}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ describe('indexSelector()', () => {
2222
var props;
2323
var helper;
2424
var results;
25-
var autoHide;
25+
var autoHideContainer;
2626

2727
beforeEach(() => {
28-
autoHide = sinon.stub().returns(IndexSelector);
28+
autoHideContainer = sinon.stub().returns(IndexSelector);
2929

3030
ReactDOM = {render: sinon.spy()};
3131
indexSelector.__Rewire__('ReactDOM', ReactDOM);
32-
indexSelector.__Rewire__('autoHide', autoHide);
32+
indexSelector.__Rewire__('autoHideContainer', autoHideContainer);
3333

3434
container = document.createElement('div');
3535
indices = ['index-a', 'index-b'];
@@ -61,7 +61,7 @@ describe('indexSelector()', () => {
6161
},
6262
currentIndex: 'index-a',
6363
hasResults: false,
64-
hideWhenNoResults: false,
64+
hideContainerWhenNoResults: false,
6565
indices: ['index-a', 'index-b'],
6666
setIndex: () => {}
6767
};
@@ -85,6 +85,6 @@ describe('indexSelector()', () => {
8585

8686
afterEach(() => {
8787
indexSelector.__ResetDependency__('ReactDOM');
88-
indexSelector.__ResetDependency__('autoHide');
88+
indexSelector.__ResetDependency__('autoHideContainer');
8989
});
9090
});

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var findIndex = require('lodash/array/findIndex');
55
var utils = require('../../lib/utils.js');
66
var bem = utils.bemHelper('ais-index-selector');
77
var cx = require('classnames');
8-
var autoHide = require('../../decorators/autoHide');
8+
var autoHideContainer = require('../../decorators/autoHideContainer');
99

1010
/**
1111
* Instantiate a dropdown element to choose the current targeted index
@@ -16,18 +16,18 @@ var autoHide = require('../../decorators/autoHide');
1616
* @param {Object} [options.cssClasses] CSS classes to be added
1717
* @param {String} [options.cssClasses.root] CSS classes added to the parent <select>
1818
* @param {String} [options.cssClasses.item] CSS classes added to each <option>
19-
* @param {boolean} [hideWhenNoResults=false] Hide the container when no results match
19+
* @param {boolean} [hideContainerWhenNoResults=false] Hide the container when no results match
2020
* @return {Object}
2121
*/
2222
function indexSelector({
2323
container,
2424
indices,
2525
cssClasses = {},
26-
hideWhenNoResults = false
26+
hideContainerWhenNoResults = false
2727
}) {
2828
var containerNode = utils.getContainerNode(container);
2929

30-
var usage = 'Usage: indexSelector({container, indices[, cssClasses.{select,option}, hideWhenNoResults]})';
30+
var usage = 'Usage: indexSelector({container, indices[, cssClasses.{select,option}, hideContainerWhenNoResults]})';
3131
if (!container || !indices) {
3232
throw new Error(usage);
3333
}
@@ -50,7 +50,7 @@ function indexSelector({
5050
let currentIndex = helper.getIndex();
5151
let hasResults = results.hits.length > 0;
5252
let setIndex = this.setIndex.bind(this, helper);
53-
var IndexSelector = autoHide(require('../../components/IndexSelector'));
53+
var IndexSelector = autoHideContainer(require('../../components/IndexSelector'));
5454

5555
cssClasses = {
5656
root: cx(bem(null), cssClasses.root),
@@ -61,7 +61,7 @@ function indexSelector({
6161
cssClasses={cssClasses}
6262
currentIndex={currentIndex}
6363
hasResults={hasResults}
64-
hideWhenNoResults={hideWhenNoResults}
64+
hideContainerWhenNoResults={hideContainerWhenNoResults}
6565
indices={indices}
6666
setIndex={setIndex}
6767
/>,

Diff for: widgets/menu/menu.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var ReactDOM = require('react-dom');
44
var utils = require('../../lib/utils.js');
55
var bem = utils.bemHelper('ais-menu');
66
var cx = require('classnames/dedupe');
7-
var autoHide = require('../../decorators/autoHide');
7+
var autoHideContainer = require('../../decorators/autoHideContainer');
88
var headerFooter = require('../../decorators/headerFooter');
9-
var RefinementList = autoHide(headerFooter(require('../../components/RefinementList/RefinementList.js')));
9+
var RefinementList = autoHideContainer(headerFooter(require('../../components/RefinementList/RefinementList.js')));
1010

1111
var defaultTemplates = require('./defaultTemplates.js');
1212

@@ -31,7 +31,7 @@ var defaultTemplates = require('./defaultTemplates.js');
3131
* @param {String|Function} [options.templates.item] Item template, provided with `name`, `count`, `isRefined`
3232
* @param {String|Function} [options.templates.footer=''] Footer template
3333
* @param {Function} [options.transformData] Method to change the object passed to the item template
34-
* @param {boolean} [hideWhenNoResults=true] Hide the container when there's no results
34+
* @param {boolean} [hideContainerWhenNoResults=true] Hide the container when there's no results
3535
* @return {Object}
3636
*/
3737
function menu({
@@ -42,7 +42,7 @@ function menu({
4242
cssClasses = {},
4343
templates = defaultTemplates,
4444
transformData,
45-
hideWhenNoResults = true
45+
hideContainerWhenNoResults = true
4646
}) {
4747
var containerNode = utils.getContainerNode(container);
4848
var usage = 'Usage: menu({container, facetName, [sortBy, limit, cssClasses.{root,list,item}, templates.{header,item,footer}, transformData, hideWhenResults]})';
@@ -90,7 +90,7 @@ function menu({
9090
cssClasses={cssClasses}
9191
facetValues={facetValues}
9292
hasResults={facetValues.length > 0}
93-
hideWhenNoResults={hideWhenNoResults}
93+
hideContainerWhenNoResults={hideContainerWhenNoResults}
9494
templateProps={templateProps}
9595
toggleRefinement={toggleRefinement.bind(null, helper, hierarchicalFacetName)}
9696
/>,

Diff for: widgets/pagination/__tests__/pagination-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('pagination()', () => {
2323
beforeEach(() => {
2424
ReactDOM = {render: sinon.spy()};
2525
pagination.__Rewire__('ReactDOM', ReactDOM);
26-
pagination.__Rewire__('autoHide', sinon.stub().returns(Pagination));
26+
pagination.__Rewire__('autoHideContainer', sinon.stub().returns(Pagination));
2727

2828
container = document.createElement('div');
2929
widget = pagination({container, scrollTo: false});
@@ -84,15 +84,15 @@ describe('pagination()', () => {
8484

8585
afterEach(() => {
8686
pagination.__ResetDependency__('ReactDOM');
87-
pagination.__ResetDependency__('autoHide');
87+
pagination.__ResetDependency__('autoHideContainer');
8888
});
8989

9090
function getProps(extraProps = {}) {
9191
return {
9292
cssClasses: {},
9393
currentPage: 0,
9494
hasResults: true,
95-
hideWhenNoResults: true,
95+
hideContainerWhenNoResults: true,
9696
labels: {first: '«', last: '»', next: '›', previous: '‹'},
9797
nbHits: results.nbHits,
9898
nbPages: results.nbPages,

0 commit comments

Comments
 (0)