import React from 'react';
import PropTypes from 'prop-types';
import { storiesOf } from '@storybook/react';
import {
InfiniteHits,
Highlight,
Panel,
Snippet,
Configure,
connectInfiniteHits,
createInfiniteHitsSessionStorageCache,
} from 'react-instantsearch-dom';
import { WrapWithHits } from './util';
import { action } from '@storybook/addon-actions';
import { connectHitInsights } from 'react-instantsearch-core';
const stories = storiesOf('InfiniteHits', module);
stories
.add('default', () => (
))
.add('with previous button', () => {
const urlLogger = action('Routing state');
return (
{
urlLogger(JSON.stringify(searchState, null, 2));
}}
>
);
})
.add('with custom rendering', () => {
const urlLogger = action('Routing state');
const MyInfiniteHits = ({
hits,
hasMore,
hasPrevious,
refine,
refinePrevious,
}) => (
{hits.map((hit) => (
- {hit.name}
))}
);
MyInfiniteHits.propTypes = {
hits: PropTypes.array.isRequired,
hasMore: PropTypes.bool.isRequired,
hasPrevious: PropTypes.bool.isRequired,
refine: PropTypes.func.isRequired,
refinePrevious: PropTypes.func.isRequired,
};
const CustomInfiniteHits = connectInfiniteHits(MyInfiniteHits);
return (
{
urlLogger(JSON.stringify(searchState, null, 2));
}}
>
);
})
.add('with custom hitComponent', () => {
function Product({ hit }) {
return (
);
}
Product.propTypes = {
hit: PropTypes.object.isRequired,
};
return (
);
})
.add('with Panel', () => (
))
.add('with Insights', () => {
const insightsClient = (method, payload) =>
action(`[InsightsClient] sent ${method} with payload`)(payload);
const ProductWithInsights = connectHitInsights(insightsClient)(Product);
function Product({ hit, insights }) {
return (
);
}
Product.propTypes = {
hit: PropTypes.object.isRequired,
insights: PropTypes.func.isRequired,
};
return (
);
})
.add('with sessionStorage cache', () => {
function Product({ hit }) {
return (
);
}
Product.propTypes = {
hit: PropTypes.object.isRequired,
};
return (
);
});