Skip to content

Commit

Permalink
feat(widgets): default design for disabled states (#1929)
Browse files Browse the repository at this point in the history
When widgets are no more relevant/have no refinements, we were already
adding specific CSS classes. Now the default theme also define more
precise rendering states for widgets (greyed out)

Basically noRefine panels will get an opacity of 0.7.

Also did some fixes so that MultiRange is working with Panel feature.
  • Loading branch information
vvo authored Feb 6, 2017
1 parent f6fc378 commit 31f010b
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@

.ais-MultiRange__itemLabelSelected{
}

.ais-MultiRange__itemNoRefinement {
opacity: .7;
}
8 changes: 6 additions & 2 deletions packages/react-instantsearch-theme-algolia/styles/_Panel.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.ais-Panel__title{
.ais-Panel__title {
margin: 0 0 6px;
padding: 0 0 6px;
text-transform: uppercase;
border-bottom: 2px solid #eee;
}
}

.ais-Panel__noRefinement {
opacity: .7;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
.ais-RangeInput__root {
}

.ais-RangeInput__fieldset {
border: 0;
margin: 0;
padding: 0;
}

.ais-RangeInput__labelMin,
.ais-RangeInput__labelMax {
min-width: 80px;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-instantsearch/src/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Menu extends Component {

export default translatable({
showMore: extended => extended ? 'Show less' : 'Show more',
noResults: 'No Results',
noResults: 'No results',
submit: null,
reset: null,
resetTitle: 'Clear the search query.',
Expand Down
13 changes: 13 additions & 0 deletions packages/react-instantsearch/src/components/MultiRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ class MultiRange extends Component {
canRefine: PropTypes.bool.isRequired,
};

static contextTypes = {
canRefine: PropTypes.func,
};

componentWillMount() {
if (this.context.canRefine) this.context.canRefine(this.props.canRefine);
}

componentWillReceiveProps(props) {
if (this.context.canRefine) this.context.canRefine(props.canRefine);
}

renderItem = item => {
const {refine} = this.props;

Expand All @@ -26,6 +38,7 @@ class MultiRange extends Component {
{...cx('itemRadio', item.isRefined && 'itemRadioSelected')}
type="radio"
checked={item.isRefined}
disabled={item.noRefinement}
onChange={refine.bind(null, item.value)}
/>
<span {...cx('itemBox', 'itemBox', item.isRefined && 'itemBoxSelected')}></span>
Expand Down
28 changes: 15 additions & 13 deletions packages/react-instantsearch/src/components/RangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ class RangeInput extends Component {
const {translate, canRefine} = this.props;
return (
<form {...cx('root', !canRefine && 'noRefinement')} onSubmit={this.onSubmit}>
<label {...cx('labelMin')}>
<input {...cx('inputMin')}
type="number" value={this.state.from} onChange={e => this.setState({from: e.target.value})}
/>
</label>
<span {...cx('separator')}>{translate('separator')}</span>
<label {...cx('labelMax')}>
<input {...cx('inputMax')}
type="number" value={this.state.to} onChange={e => this.setState({to: e.target.value})}
/>
</label>
<button {...cx('submit')} type="submit">{translate('submit')}
</button>
<fieldset disabled={!canRefine} {...cx('fieldset')}>
<label {...cx('labelMin')}>
<input {...cx('inputMin')}
type="number" value={this.state.from} onChange={e => this.setState({from: e.target.value})}
/>
</label>
<span {...cx('separator')}>{translate('separator')}</span>
<label {...cx('labelMax')}>
<input {...cx('inputMax')}
type="number" value={this.state.to} onChange={e => this.setState({to: e.target.value})}
/>
</label>
<button {...cx('submit')} type="submit">{translate('submit')}
</button>
</fieldset>
</form>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ class RefinementList extends Component {

export default translatable({
showMore: extended => extended ? 'Show less' : 'Show more',
noResults: 'No Results',
noResults: 'No results',
submit: null,
reset: null,
resetTitle: 'Clear the search query.',
submitTitle: 'Submit your search query.',
placeholder: 'Search here…',
})(RefinementList);

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`MultiRange supports having a selected item 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -25,6 +26,7 @@ exports[`MultiRange supports having a selected item 1`] = `
<input
checked={true}
className="ais-MultiRange__itemRadio ais-MultiRange__itemRadioSelected"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -41,6 +43,7 @@ exports[`MultiRange supports having a selected item 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -57,6 +60,7 @@ exports[`MultiRange supports having a selected item 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -82,6 +86,7 @@ exports[`MultiRange supports passing items values 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -98,6 +103,7 @@ exports[`MultiRange supports passing items values 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -114,6 +120,7 @@ exports[`MultiRange supports passing items values 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand All @@ -130,6 +137,7 @@ exports[`MultiRange supports passing items values 1`] = `
<input
checked={false}
className="ais-MultiRange__itemRadio"
disabled={false}
onChange={[Function]}
type="radio" />
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,70 @@ exports[`RangeInput applies translations 1`] = `
<form
className="ais-RangeInput__root"
onSubmit={[Function]}>
<label
className="ais-RangeInput__labelMin">
<input
className="ais-RangeInput__inputMin"
onChange={[Function]}
type="number"
value={0} />
</label>
<span
className="ais-RangeInput__separator">
SEPARATOR
</span>
<label
className="ais-RangeInput__labelMax">
<input
className="ais-RangeInput__inputMax"
onChange={[Function]}
type="number"
value={100} />
</label>
<button
className="ais-RangeInput__submit"
type="submit">
SUBMIT
</button>
<fieldset
className="ais-RangeInput__fieldset"
disabled={false}>
<label
className="ais-RangeInput__labelMin">
<input
className="ais-RangeInput__inputMin"
onChange={[Function]}
type="number"
value={0} />
</label>
<span
className="ais-RangeInput__separator">
SEPARATOR
</span>
<label
className="ais-RangeInput__labelMax">
<input
className="ais-RangeInput__inputMax"
onChange={[Function]}
type="number"
value={100} />
</label>
<button
className="ais-RangeInput__submit"
type="submit">
SUBMIT
</button>
</fieldset>
</form>
`;

exports[`RangeInput supports passing max/min values 1`] = `
<form
className="ais-RangeInput__root"
onSubmit={[Function]}>
<label
className="ais-RangeInput__labelMin">
<input
className="ais-RangeInput__inputMin"
onChange={[Function]}
type="number"
value={0} />
</label>
<span
className="ais-RangeInput__separator">
to
</span>
<label
className="ais-RangeInput__labelMax">
<input
className="ais-RangeInput__inputMax"
onChange={[Function]}
type="number"
value={100} />
</label>
<button
className="ais-RangeInput__submit"
type="submit">
ok
</button>
<fieldset
className="ais-RangeInput__fieldset"
disabled={false}>
<label
className="ais-RangeInput__labelMin">
<input
className="ais-RangeInput__inputMin"
onChange={[Function]}
type="number"
value={0} />
</label>
<span
className="ais-RangeInput__separator">
to
</span>
<label
className="ais-RangeInput__labelMax">
<input
className="ais-RangeInput__inputMax"
onChange={[Function]}
type="number"
value={100} />
</label>
<button
className="ais-RangeInput__submit"
type="submit">
ok
</button>
</fieldset>
</form>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default createConnector({
return {
items: props.transformItems ? props.transformItems(items) : items,
currentRefinement,
canRefine: !items.reduce((noRefinement, item) => noRefinement && item.noRefinement, true),
canRefine: items.length > 0 && items.some(item => item.noRefinement === false),
};
},

Expand Down
8 changes: 7 additions & 1 deletion stories/ClearAll.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const stories = storiesOf('ClearAll', module);

stories.addDecorator(withKnobs);

stories.add('default', () =>
stories.add('with refinements to clear', () =>
<WrapWithHits linkedStoryGroup="ClearAll">
<div>
<ClearAll />
Expand All @@ -21,3 +21,9 @@ stories.add('default', () =>
</div>
</WrapWithHits>
);

stories.add('nothing to clear', () =>
<WrapWithHits linkedStoryGroup="ClearAll">
<ClearAll />
</WrapWithHits>
);
19 changes: 15 additions & 4 deletions stories/HitsPerPage.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {storiesOf} from '@kadira/storybook';
import {HitsPerPage} from '../packages/react-instantsearch/dom';
import {HitsPerPage, Panel} from '../packages/react-instantsearch/dom';
import {withKnobs, number} from '@kadira/storybook-addon-knobs';
import {WrapWithHits} from './util';

Expand All @@ -27,12 +27,23 @@ stories.add('default', () =>
{value: 8}]}/>
</WrapWithHits>
).add('playground', () =>
<WrapWithHits >
<WrapWithHits >
<HitsPerPage
defaultRefinement={number('default hits per page', 4)}
items={[{value: 2, label: '2 hits per page'},
{value: 4, label: '4 hits per page'},
{value: 6, label: '6 hits per page'},
{value: 8, label: '8 hits per page'}]}/>
</WrapWithHits>
).add('inside a panel', () =>
<WrapWithHits>
<Panel title="Hits to display">
<HitsPerPage
defaultRefinement={number('default hits per page', 4)}
items={[{value: 2, label: '2 hits per page'},
{value: 4, label: '4 hits per page'},
{value: 6, label: '6 hits per page'},
{value: 8, label: '8 hits per page'}]}/>
</WrapWithHits>
);
</Panel>
</WrapWithHits>
);
4 changes: 2 additions & 2 deletions stories/Menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ stories.add('default', () =>
/>
</Panel>
</WrapWithHits>
).add('with panel but no refinement', () =>
).add('with panel but no available refinement', () =>
<WrapWithHits searchBox={false}>
<Panel title="Category">
<Menu
attributeName="category"
/>
<div style={{display: 'none'}}>
<SearchBox defaultRefinement="ds" />
<SearchBox defaultRefinement="dkjsakdjskajdksjakdjaskj" />
</div>
</Panel>
</WrapWithHits>
Expand Down
Loading

0 comments on commit 31f010b

Please sign in to comment.