dropdownAutoComplete.stories.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import Button from 'sentry/components/button';
  2. import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete';
  3. import DropdownButton from 'sentry/components/dropdownButton';
  4. const items = [
  5. {
  6. value: 'apple',
  7. label: '🍎 Apple',
  8. },
  9. {
  10. value: 'bacon',
  11. label: '🥓 Bacon',
  12. },
  13. {
  14. value: 'corn',
  15. label: '🌽 Corn',
  16. },
  17. ];
  18. const groupedItems = [
  19. {
  20. value: 'defaults',
  21. hideGroupLabel: true,
  22. items: [
  23. {
  24. value: 'recent thing',
  25. label: 'recent thing',
  26. },
  27. {
  28. value: 'other recent thing',
  29. label: 'other recent thing',
  30. },
  31. {
  32. value: 'yet another recent thing',
  33. label: 'yet another recent thing',
  34. },
  35. ],
  36. },
  37. {
  38. value: 'countries',
  39. label: (
  40. <div>
  41. Countries{' '}
  42. <a style={{float: 'right'}} href="#">
  43. + Add
  44. </a>
  45. </div>
  46. ),
  47. items: [
  48. {
  49. value: 'new zealand',
  50. label: <div>🇨🇷 New Zealand</div>,
  51. },
  52. {
  53. value: 'australia',
  54. label: <div>🇦🇺 Australia</div>,
  55. },
  56. {
  57. value: 'brazil',
  58. label: <div>🇧🇷 Brazil</div>,
  59. },
  60. ],
  61. },
  62. {
  63. value: 'foods',
  64. label: 'Foods',
  65. items: [
  66. {
  67. value: 'apple',
  68. label: <div>🍎 Apple</div>,
  69. },
  70. {
  71. value: 'bacon',
  72. label: <div>🥓 Bacon</div>,
  73. },
  74. {
  75. value: 'corn',
  76. label: <div>🌽 Corn</div>,
  77. },
  78. ],
  79. },
  80. ];
  81. export default {
  82. title: 'Components/Buttons/Dropdowns/Dropdown Auto Complete',
  83. component: DropdownAutoComplete,
  84. };
  85. export const Ungrouped = () => (
  86. <DropdownAutoComplete items={items}>
  87. {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
  88. </DropdownAutoComplete>
  89. );
  90. Ungrouped.storyName = 'Ungrouped';
  91. Ungrouped.parameters = {
  92. docs: {
  93. description: {
  94. story: 'The item label can be a component or a string',
  95. },
  96. },
  97. };
  98. export const Grouped = () => (
  99. <DropdownAutoComplete
  100. items={groupedItems}
  101. virtualizedHeight={44}
  102. virtualizedLabelHeight={28}
  103. >
  104. {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
  105. </DropdownAutoComplete>
  106. );
  107. Grouped.storyName = 'Grouped';
  108. Grouped.parameters = {
  109. docs: {
  110. description: {
  111. story: 'Group labels can receive a component too',
  112. },
  113. },
  114. };
  115. export const WithDropdownButton = () => (
  116. <DropdownAutoComplete items={groupedItems}>
  117. {({isOpen, selectedItem}) => (
  118. <DropdownButton isOpen={isOpen}>
  119. {selectedItem ? selectedItem.label : 'Click me!'}
  120. </DropdownButton>
  121. )}
  122. </DropdownAutoComplete>
  123. );
  124. WithDropdownButton.storyName = 'With Dropdown Button';
  125. WithDropdownButton.parameters = {
  126. docs: {
  127. description: {
  128. story: 'Use it with dropdownbutton for maximum fun',
  129. },
  130. },
  131. };
  132. export const WithExtraAction = () => (
  133. <DropdownAutoComplete
  134. items={items}
  135. action={<Button priority="primary">Now click me!</Button>}
  136. >
  137. {({isOpen, selectedItem}) => (
  138. <DropdownButton isOpen={isOpen}>
  139. {selectedItem ? selectedItem.label : 'Click me!'}
  140. </DropdownButton>
  141. )}
  142. </DropdownAutoComplete>
  143. );
  144. WithExtraAction.storyName = 'With Extra Action';
  145. WithExtraAction.parameters = {
  146. docs: {
  147. description: {
  148. story: 'Add a call to action button',
  149. },
  150. },
  151. };