-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(queryRules): add connectQueryRules connector (#3597)
* feat(queryRules): add connectQueryRules connector * chore(storybook): add support for playgrounds (#3599) * feat(queryRules): add queryRuleCustomData widget (#3600)
- Loading branch information
1 parent
ab84c57
commit 924cd99
Showing
23 changed files
with
1,019 additions
and
203 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import algoliasearch from 'algoliasearch/lite'; | ||
import instantsearch from '../src/index'; | ||
import defaultPlayground from './playgrounds/default'; | ||
|
||
export const withHits = ( | ||
storyFn: ({ | ||
container, | ||
instantsearch, | ||
search, | ||
}: { | ||
container: HTMLElement; | ||
instantsearch: any; | ||
search: any; | ||
}) => void, | ||
searchOptions: any | ||
) => () => { | ||
const { | ||
appId = 'latency', | ||
apiKey = '6be0576ff61c053d5f9a3225e2a90f76', | ||
indexName = 'instant_search', | ||
searchParameters = {}, | ||
playground = defaultPlayground, | ||
...instantsearchOptions | ||
} = searchOptions || {}; | ||
|
||
const urlLogger = action('Routing state'); | ||
const search = instantsearch({ | ||
indexName, | ||
searchClient: algoliasearch(appId, apiKey), | ||
searchParameters: { | ||
hitsPerPage: 4, | ||
attributesToSnippet: ['description:15'], | ||
snippetEllipsisText: '[…]', | ||
...searchParameters, | ||
}, | ||
routing: { | ||
router: { | ||
write: (routeState: object) => { | ||
urlLogger(JSON.stringify(routeState, null, 2)); | ||
}, | ||
read: () => ({}), | ||
createURL: () => '', | ||
onUpdate: () => {}, | ||
}, | ||
}, | ||
...instantsearchOptions, | ||
}); | ||
|
||
const containerElement = document.createElement('div'); | ||
|
||
// Add the preview container to add the stories in | ||
const previewElement = document.createElement('div'); | ||
previewElement.classList.add('container', 'container-preview'); | ||
containerElement.appendChild(previewElement); | ||
|
||
// Add the playground container to add widgets into | ||
const playgroundElement = document.createElement('div'); | ||
playgroundElement.classList.add('container', 'container-playground'); | ||
containerElement.appendChild(playgroundElement); | ||
|
||
const leftPanelPlaygroundElement = document.createElement('div'); | ||
leftPanelPlaygroundElement.classList.add('panel-left'); | ||
playgroundElement.appendChild(leftPanelPlaygroundElement); | ||
|
||
const rightPanelPlaygroundElement = document.createElement('div'); | ||
rightPanelPlaygroundElement.classList.add('panel-right'); | ||
playgroundElement.appendChild(rightPanelPlaygroundElement); | ||
|
||
playground({ | ||
search, | ||
leftPanel: leftPanelPlaygroundElement, | ||
rightPanel: rightPanelPlaygroundElement, | ||
}); | ||
|
||
storyFn({ | ||
container: previewElement, | ||
instantsearch, | ||
search, | ||
}); | ||
|
||
search.start(); | ||
|
||
return containerElement; | ||
}; |
Oops, something went wrong.