import React, { Component } from 'react'; import { storiesOf } from '@storybook/react'; import { object, boolean } from '@storybook/addon-knobs'; import { action } from '@storybook/addon-actions'; import { Panel, SearchBox } from 'react-instantsearch-dom'; import { WrapWithHits } from './util'; const stories = storiesOf('SearchBox', module); stories .add('default', () => ( )) .add('with a default query', () => ( )) .add('with submit and reset components', () => ( 🔍} reset={ } /> )) .add('Display feedback when search is stalled (custom component)', () => ( ✨} /> )) .add('without search as you type', () => ( )) .add('with Panel', () => ( )) .add('playground', () => ( )); // with event listeners // -------------------- class SearchBoxContainer extends Component { state = { selectedEvents: { onChange: true } }; get supportedEvents() { return [ 'onChange', 'onFocus', 'onBlur', 'onSelect', 'onKeyDown', 'onKeyPress', 'onSubmit', 'onReset', ]; } handleSelectedEvent = (eventName) => ({ target: { checked } }) => { const { selectedEvents } = this.state; this.setState({ selectedEvents: { ...selectedEvents, [eventName]: checked }, }); }; handleSubmit = (event) => { // we dont want the page to reload after the submit event event.preventDefault(); event.stopPropagation(); this.logAction('onSubmit')(event); }; logAction = (eventName) => (event) => { // we dont want to log unselected event if (this.state.selectedEvents[eventName]) { action(eventName)(event); } }; render() { return ( {/* events checkboxes */} {this.supportedEvents.map((eventName) => ( {eventName} ))} (Click on the action logger tab of the right sidebar to see event logs) ); } } stories.add('with event listeners', () => );