Skip to content

Commit

Permalink
docs(stories): real dynamic widgets example
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Aug 4, 2021
1 parent 598a27b commit 585e38f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions stories/dynamic-widgets.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { withHits } from '../.storybook/decorators';
storiesOf('Basics/DynamicWidgets', module).add(
'default',
withHits(({ search, container: rootContainer, instantsearch }) => {
const dynamicWidgetsContainer = document.createElement('div');
const disclaimer = document.createTextNode(
'try the queries: "dog" or "lego"'
);
rootContainer.appendChild(disclaimer);
rootContainer.appendChild(dynamicWidgetsContainer);

search.addWidgets([
instantsearch.widgets.EXPERIMENTAL_dynamicWidgets({
transformItems(_attributes, { results }) {
if (results._state.query === 'dog') {
return ['categories'];
}
if (results._state.query === 'lego') {
return ['categories', 'brand'];
}
return ['brand', 'hierarchicalCategories.lvl0', 'categories'];
},
container: rootContainer,
container: dynamicWidgetsContainer,
widgets: [
container =>
instantsearch.widgets.menu({ container, attribute: 'categories' }),
Expand Down

0 comments on commit 585e38f

Please sign in to comment.