story.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import React from 'react'
  16. import { storiesOf } from '@storybook/react'
  17. import AutocompleteDropdown from '.'
  18. const generateItem = (item: string, value?: string) => {
  19. return {
  20. value: value || item.replace(/ /g, '_').toLowerCase(),
  21. label: item,
  22. }
  23. }
  24. const items = [
  25. generateItem('Item 1'),
  26. generateItem('Item 2'),
  27. generateItem('Item 3'),
  28. generateItem('Item 4'),
  29. generateItem('Item 5'),
  30. generateItem('Item 6'),
  31. generateItem('Item 7'),
  32. generateItem('Item 8'),
  33. generateItem('Item 8', 'item_8_2'),
  34. ]
  35. type State = {
  36. selectedItem: string,
  37. }
  38. class Wrapper extends React.Component<{}, State> {
  39. state = {
  40. selectedItem: '',
  41. }
  42. render() {
  43. return (
  44. <AutocompleteDropdown
  45. items={items}
  46. selectedItem={this.state.selectedItem}
  47. onChange={selectedItem => { this.setState({ selectedItem }) }}
  48. onInputChange={(value, filteredItems) => {
  49. if (filteredItems.length === 0) {
  50. console.log('input value', value)
  51. }
  52. }}
  53. />
  54. )
  55. }
  56. }
  57. storiesOf('AutocompleteDropdown', module)
  58. .add('default', () => (
  59. <Wrapper />
  60. ))