dropdownAutoComplete.stories.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React from 'react';
  2. import {withInfo} from '@storybook/addon-info';
  3. import Button from 'app/components/button';
  4. import DropdownAutoComplete from 'app/components/dropdownAutoComplete';
  5. import DropdownButton from 'app/components/dropdownButton';
  6. const items = [
  7. {
  8. value: 'apple',
  9. label: '🍎 Apple',
  10. },
  11. {
  12. value: 'bacon',
  13. label: 'πŸ₯“ Bacon',
  14. },
  15. {
  16. value: 'corn',
  17. label: '🌽 Corn',
  18. },
  19. ];
  20. const groupedItems = [
  21. {
  22. value: 'defaults',
  23. hideGroupLabel: true,
  24. items: [
  25. {
  26. value: 'recent thing',
  27. label: 'recent thing',
  28. },
  29. {
  30. value: 'other recent thing',
  31. label: 'other recent thing',
  32. },
  33. {
  34. value: 'yet another recent thing',
  35. label: 'yet another recent thing',
  36. },
  37. ],
  38. },
  39. {
  40. value: 'countries',
  41. label: (
  42. <div>
  43. Countries{' '}
  44. <a style={{float: 'right'}} href="#">
  45. + Add
  46. </a>
  47. </div>
  48. ),
  49. items: [
  50. {
  51. value: 'new zealand',
  52. label: <div>πŸ‡¨πŸ‡· New Zealand</div>,
  53. },
  54. {
  55. value: 'australia',
  56. label: <div>πŸ‡¦πŸ‡Ί Australia</div>,
  57. },
  58. {
  59. value: 'brazil',
  60. label: <div>πŸ‡§πŸ‡· Brazil</div>,
  61. },
  62. ],
  63. },
  64. {
  65. value: 'foods',
  66. label: 'Foods',
  67. items: [
  68. {
  69. value: 'apple',
  70. label: <div>🍎 Apple</div>,
  71. },
  72. {
  73. value: 'bacon',
  74. label: <div>πŸ₯“ Bacon</div>,
  75. },
  76. {
  77. value: 'corn',
  78. label: <div>🌽 Corn</div>,
  79. },
  80. ],
  81. },
  82. ];
  83. export default {
  84. title: 'UI/Dropdowns/DropdownAutoComplete',
  85. };
  86. export const Ungrouped = withInfo('The item label can be a component or a string')(() => (
  87. <DropdownAutoComplete items={items}>
  88. {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
  89. </DropdownAutoComplete>
  90. ));
  91. Ungrouped.story = {
  92. name: 'ungrouped',
  93. };
  94. export const Grouped = withInfo('Group labels can receive a component too')(() => (
  95. <DropdownAutoComplete
  96. items={groupedItems}
  97. virtualizedHeight={44}
  98. virtualizedLabelHeight={28}
  99. >
  100. {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
  101. </DropdownAutoComplete>
  102. ));
  103. Grouped.story = {
  104. name: 'grouped',
  105. };
  106. export const WithDropdownButton = withInfo(
  107. 'Use it with dropdownbutton for maximum fun'
  108. )(() => (
  109. <DropdownAutoComplete items={groupedItems}>
  110. {({isOpen, selectedItem}) => (
  111. <DropdownButton isOpen={isOpen}>
  112. {selectedItem ? selectedItem.label : 'Click me!'}
  113. </DropdownButton>
  114. )}
  115. </DropdownAutoComplete>
  116. ));
  117. WithDropdownButton.story = {
  118. name: 'with dropdownButton',
  119. };
  120. export const WithExtraAction = withInfo('Add a call to action button')(() => (
  121. <DropdownAutoComplete
  122. items={items}
  123. action={<Button priority="primary">Now click me!</Button>}
  124. >
  125. {({isOpen, selectedItem}) => (
  126. <DropdownButton isOpen={isOpen}>
  127. {selectedItem ? selectedItem.label : 'Click me!'}
  128. </DropdownButton>
  129. )}
  130. </DropdownAutoComplete>
  131. ));
  132. WithExtraAction.story = {
  133. name: 'with extra action',
  134. };