From 0365641a3af0bee88597c1ee137948d36ca4268c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Tue, 9 Oct 2018 10:10:46 -0700 Subject: [PATCH] feat(refinement-list): implement InstantSearch.css (2) (#3179) * Flattens the templates to the top-level `templates` option. --- .../stories/refinement-list.stories.js | 45 ++---- docgen/src/guides/v3-migration.md | 44 +++--- .../RefinementList/RefinementList.js | 10 +- .../__tests__/RefinementList-test.js | 12 +- .../refinement-list-test.js.snap | 11 +- .../__tests__/refinement-list-test.js | 40 +++++- .../refinement-list/defaultTemplates.js | 1 + .../defaultTemplates.searchForFacetValue.js | 3 - .../refinement-list/refinement-list.js | 129 ++++++------------ 9 files changed, 131 insertions(+), 164 deletions(-) delete mode 100644 src/widgets/refinement-list/defaultTemplates.searchForFacetValue.js diff --git a/dev/app/builtin/stories/refinement-list.stories.js b/dev/app/builtin/stories/refinement-list.stories.js index 5ceee805ce..f56e009ac5 100644 --- a/dev/app/builtin/stories/refinement-list.stories.js +++ b/dev/app/builtin/stories/refinement-list.stories.js @@ -15,8 +15,6 @@ export default () => { instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', - limit: 10, }) ); }) @@ -28,14 +26,12 @@ export default () => { instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', limit: 3, - showMore: { - templates: { - active: 'Show less', - inactive: 'Show more', - }, - limit: 10, + showMore: true, + showMoreLimit: 10, + templates: { + showMoreActive: 'Show way less', + showMoreInactive: 'Show way less', }, }) ); @@ -48,29 +44,22 @@ export default () => { instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', - limit: 10, - searchable: { - placeholder: 'Find other brands...', - templates: { - noResults: 'No results', - }, - }, + searchable: true, }) ); }) ) .add( - 'with search inside items (using the default noResults template)', + 'with search inside items (using a custom searchableNoResults template)', wrapWithHits(container => { window.search.addWidget( instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', - limit: 10, - searchable: { - placeholder: 'Find other brands...', + searchable: true, + searchablePlaceholder: 'Find other brands...', + templates: { + searchableNoResults: 'No results found', }, }) ); @@ -84,7 +73,6 @@ export default () => { container, attribute: 'price_range', operator: 'and', - limit: 10, cssClasses: { item: 'facet-value checkbox', count: 'facet-count pull-right', @@ -107,8 +95,6 @@ export default () => { instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', - limit: 10, transformItems: items => items.map(item => ({ ...item, @@ -126,14 +112,7 @@ export default () => { instantsearch.widgets.refinementList({ container, attribute: 'brand', - operator: 'or', - limit: 10, - searchable: { - placeholder: 'Find other brands...', - templates: { - noResults: 'No results', - }, - }, + searchable: true, transformItems: items => items.map(item => ({ ...item, diff --git a/docgen/src/guides/v3-migration.md b/docgen/src/guides/v3-migration.md index 79d890e8b5..f627b433f4 100644 --- a/docgen/src/guides/v3-migration.md +++ b/docgen/src/guides/v3-migration.md @@ -10,11 +10,11 @@ If you were previously using the `urlSync` option, you should now migrate to the Here are the elements you need to migrate: -* `urlSync: true` becomes `routing: true` -* `threshold` becomes `routing: {router: instantsearch.routers.history({writeDelay: 400})} -* `mapping` and `trackedParameters` are replaced with `stateMapping`. Read [User friendly urls](routing.html#user-friendly-urls) to know how to configure it -* `useHash` is removed but can be achieved using an advanced configuration of the [history router](routing.html#history-router-api) -* `getHistoryState` is removed but can be achieved using an advanced configuration of the [history router](routing.html#history-router-api) +- `urlSync: true` becomes `routing: true` +- `threshold` becomes `routing: {router: instantsearch.routers.history({writeDelay: 400})} +- `mapping` and `trackedParameters` are replaced with `stateMapping`. Read [User friendly urls](routing.html#user-friendly-urls) to know how to configure it +- `useHash` is removed but can be achieved using an advanced configuration of the [history router](routing.html#history-router-api) +- `getHistoryState` is removed but can be achieved using an advanced configuration of the [history router](routing.html#history-router-api) ## Widgets @@ -150,8 +150,8 @@ With the redo button: | `escapeHits` | `escapeHTML` | | `showMoreLabel` | `loadMoreLabel` | -* `escapeHTML` becomes `true` by default. -* `allItems` template has been removed in favor of `connectHits` +- `escapeHTML` becomes `true` by default. +- `allItems` template has been removed in favor of `connectHits` #### CSS classes @@ -499,6 +499,24 @@ Widget removed. ### RefinementList +#### Options + +| Before | After | +| ------------------------------------------ | ------------------------------- | +| `attributeName` | `attribute` | +| `searchForFacetValues` | `searchable` | +| `searchForFacetValues.placeholder` | `searchablePlaceholder` | +| `searchForFacetValues.isAlwaysActive` | `searchableIsAlwaysActive` | +| `searchForFacetValues.escapeFacetValues` | `searchableEscapeFacetValues` | +| `searchForFacetValues.templates.noResults` | `templates.searchableNoResults` | +| `showMore.templates.active` | `templates.showMoreActive` | +| `showMore.templates.inactive` | `templates.showMoreInactive` | + +- `searchablePlaceholder` defaults to `"Search..."` +- `searchableEscapeFacetValues` defaults to `true` +- `searchableIsAlwaysActive` defaults to `true` +- `showMore` is now a boolean option (`searchForFacetValues.templates` and `showMore.templates` are now in `templates`) + #### CSS classes | Before | After | @@ -519,16 +537,6 @@ Widget removed. | | `ais-RefinementList-showMore` | | | `ais-RefinementList-showMore--disabled` | -#### Options - -| Before | After | -| ---------------------- | ------------ | -| `attributeName` | `attribute` | -| `searchForFacetValues` | `searchable` | - -* `escapeFacetValues` defaults to `true` -* `isAlwaysActive` defaults to `true` - #### Markup ##### Default @@ -741,4 +749,4 @@ We've moved the `label` into the `templates.labelText` template to make it consi | --------------- | ----------- | | `attributeName` | `attribute` | -* `escapeFacetValues` defaults to `true` +- `escapeFacetValues` defaults to `true` diff --git a/src/components/RefinementList/RefinementList.js b/src/components/RefinementList/RefinementList.js index 117b5472be..a9d11f5908 100644 --- a/src/components/RefinementList/RefinementList.js +++ b/src/components/RefinementList/RefinementList.js @@ -155,9 +155,9 @@ class RefinementList extends Component { const showMoreButton = this.props.showMore === true && (