forked from algolia/instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): migrate dev-novel to storybook (algolia#3376)
- Loading branch information
1 parent
0e33c76
commit 21b1ef9
Showing
78 changed files
with
6,123 additions
and
6,176 deletions.
There are no files selected for viewing
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,2 @@ | ||
import '@storybook/addon-options/register'; | ||
import '@storybook/addon-actions/register'; |
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,18 @@ | ||
import { addDecorator, configure } from '@storybook/html'; | ||
import { withOptions } from '@storybook/addon-options'; | ||
import './style.css'; | ||
|
||
addDecorator( | ||
withOptions({ | ||
name: 'instantsearch.js', | ||
url: 'https://github.com/algolia/instantsearch.js', | ||
}) | ||
); | ||
|
||
// automatically import all files ending in *.stories.js | ||
const req = require.context('../stories', true, /.stories.js$/); | ||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)); | ||
} | ||
|
||
configure(loadStories, module); |
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,186 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import algoliasearch from 'algoliasearch/lite'; | ||
import instantsearch from '../src/index'; | ||
|
||
export const withHits = (storyFn, searchOptions = {}) => () => { | ||
const { | ||
appId = 'latency', | ||
apiKey = '6be0576ff61c053d5f9a3225e2a90f76', | ||
indexName = 'instant_search', | ||
searchParameters = {}, | ||
...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 => { | ||
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); | ||
|
||
// Add widgets to the playground | ||
const refinementList = document.createElement('div'); | ||
leftPanelPlaygroundElement.appendChild(refinementList); | ||
|
||
const brandList = instantsearch.widgets.panel({ | ||
templates: { | ||
header: 'Brands', | ||
}, | ||
})(instantsearch.widgets.refinementList); | ||
|
||
search.addWidget( | ||
brandList({ | ||
container: refinementList, | ||
attribute: 'brand', | ||
}) | ||
); | ||
|
||
const numericMenu = document.createElement('div'); | ||
leftPanelPlaygroundElement.appendChild(numericMenu); | ||
|
||
const priceMenu = instantsearch.widgets.panel({ | ||
templates: { | ||
header: 'Price', | ||
}, | ||
})(instantsearch.widgets.numericMenu); | ||
|
||
search.addWidget( | ||
priceMenu({ | ||
container: numericMenu, | ||
attribute: 'price', | ||
items: [ | ||
{ label: 'All' }, | ||
{ label: '≤ 10$', end: 10 }, | ||
{ label: '10–100$', start: 10, end: 100 }, | ||
{ label: '100–500$', start: 100, end: 500 }, | ||
{ label: '≥ 500$', start: 500 }, | ||
], | ||
}) | ||
); | ||
|
||
const ratingMenu = document.createElement('div'); | ||
leftPanelPlaygroundElement.appendChild(ratingMenu); | ||
|
||
const ratingList = instantsearch.widgets.panel({ | ||
templates: { | ||
header: 'Rating', | ||
}, | ||
})(instantsearch.widgets.ratingMenu); | ||
|
||
search.addWidget( | ||
ratingList({ | ||
container: ratingMenu, | ||
attribute: 'rating', | ||
}) | ||
); | ||
|
||
const searchBox = document.createElement('div'); | ||
searchBox.classList.add('searchbox'); | ||
rightPanelPlaygroundElement.appendChild(searchBox); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.searchBox({ | ||
container: searchBox, | ||
placeholder: 'Search here…', | ||
}) | ||
); | ||
|
||
const stats = document.createElement('div'); | ||
stats.classList.add('stats'); | ||
rightPanelPlaygroundElement.appendChild(stats); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.stats({ | ||
container: stats, | ||
}) | ||
); | ||
|
||
const hits = document.createElement('div'); | ||
hits.classList.add('hits'); | ||
rightPanelPlaygroundElement.appendChild(hits); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.hits({ | ||
container: hits, | ||
templates: { | ||
item: ` | ||
<div | ||
class="hits-image" | ||
style="background-image: url({{image}})" | ||
></div> | ||
<article> | ||
<header> | ||
<strong>{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}</strong> | ||
</header> | ||
<p> | ||
{{#helpers.snippet}}{ "attribute": "description" }{{/helpers.snippet}} | ||
</p> | ||
<footer> | ||
<p> | ||
<strong>{{price}}$</strong> | ||
</p> | ||
</footer> | ||
</article> | ||
`, | ||
}, | ||
cssClasses: { | ||
item: 'hits-item', | ||
}, | ||
}) | ||
); | ||
|
||
const pagination = document.createElement('div'); | ||
rightPanelPlaygroundElement.appendChild(pagination); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.pagination({ | ||
container: pagination, | ||
}) | ||
); | ||
|
||
storyFn({ | ||
container: previewElement, | ||
instantsearch, | ||
search, | ||
}); | ||
|
||
search.start(); | ||
|
||
return containerElement; | ||
}; |
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 @@ | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/algolia.min.css"> |
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
Oops, something went wrong.