button.stories.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* eslint-disable react/prop-types */
  2. import {Fragment} from 'react';
  3. import styled from '@emotion/styled';
  4. import {action} from '@storybook/addon-actions';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import DropdownButton from 'sentry/components/dropdownButton';
  8. import DropdownLink from 'sentry/components/dropdownLink';
  9. import NavigationButtonGroup from 'sentry/components/navigationButtonGroup';
  10. import {IconDelete} from 'sentry/icons/iconDelete';
  11. const Item = styled('span')`
  12. padding: 12px;
  13. `;
  14. export default {
  15. title: 'Components/Buttons',
  16. component: Button,
  17. };
  18. export const _Button = ({icon, onClick, ...args}) => (
  19. <Button onClick={onClick} icon={icon && <IconDelete />} {...args}>
  20. Button
  21. </Button>
  22. );
  23. _Button.args = {
  24. title: 'title',
  25. priority: undefined,
  26. size: undefined,
  27. borderless: false,
  28. translucentBorder: false,
  29. icon: false,
  30. busy: false,
  31. disabled: false,
  32. };
  33. _Button.argTypes = {
  34. priority: {
  35. control: {
  36. type: 'select',
  37. options: ['default', 'primary', 'danger', 'link', 'form'],
  38. },
  39. },
  40. size: {
  41. control: {
  42. type: 'select',
  43. options: ['zero', 'xs', 'sm', 'md'],
  44. },
  45. },
  46. };
  47. export const Overview = ({busy}) => (
  48. <div>
  49. <div className="section">
  50. <h2>Priorities</h2>
  51. <Item>
  52. <Button to="/test" onClick={action('clicked default')}>
  53. Default Button
  54. </Button>
  55. </Item>
  56. <Item>
  57. <Button title="Tooltip" priority="primary" onClick={action('click primary')}>
  58. Primary Button
  59. </Button>
  60. </Item>
  61. <Item>
  62. <Button priority="danger" onClick={action('click danger')}>
  63. Danger Button
  64. </Button>
  65. </Item>
  66. <Item>
  67. <Button priority="link" onClick={action('click link')}>
  68. Link Button
  69. </Button>
  70. </Item>
  71. <Item>
  72. <Button to="" disabled onClick={action('click disabled')}>
  73. Disabled Button
  74. </Button>
  75. </Item>
  76. </div>
  77. <div className="section">
  78. <h2>Sizes</h2>
  79. <Item>
  80. <Button size="zero" borderless>
  81. Zero
  82. </Button>
  83. </Item>
  84. <Item>
  85. <Button size="xs">X Small</Button>
  86. </Item>
  87. <Item>
  88. <Button size="sm">Small</Button>
  89. </Item>
  90. <Item>
  91. <Button>Default</Button>
  92. </Item>
  93. </div>
  94. <div className="section">
  95. <h2>Icons</h2>
  96. <div style={{display: 'flex', alignItems: 'center'}}>
  97. <Item>
  98. <Button size="zero" borderless icon={<IconDelete size="xs" />} />
  99. </Item>
  100. <Item>
  101. <Button size="xs" icon={<IconDelete size="xs" />}>
  102. X Small
  103. </Button>
  104. </Item>
  105. <Item>
  106. <Button size="sm" icon={<IconDelete size="xs" />}>
  107. Small
  108. </Button>
  109. </Item>
  110. <Item>
  111. <Button icon={<IconDelete />}>Default</Button>
  112. </Item>
  113. </div>
  114. </div>
  115. <div className="section">
  116. <h2>States (busy/disabled)</h2>
  117. <div style={{display: 'flex', alignItems: 'center'}}>
  118. <Item>
  119. <Button busy={busy} priority="primary" size="xs">
  120. Extra Small
  121. </Button>
  122. </Item>
  123. <Item>
  124. <Button busy={busy} priority="primary" size="sm">
  125. Small
  126. </Button>
  127. </Item>
  128. <Item>
  129. <Button busy={busy} priority="primary">
  130. Normal
  131. </Button>
  132. </Item>
  133. <Item>
  134. <Button priority="primary" disabled onClick={action('click disabled')}>
  135. Disabled Button
  136. </Button>
  137. </Item>
  138. </div>
  139. </div>
  140. </div>
  141. );
  142. Overview.storyName = 'Overview';
  143. Overview.args = {
  144. busy: true,
  145. };
  146. Overview.parameters = {
  147. docs: {
  148. description: {
  149. story: 'An overview of all the different buttons and states',
  150. },
  151. },
  152. };
  153. export const _DropdownButton = () => (
  154. <Fragment>
  155. <Item>
  156. <DropdownButton isOpen={false}>Closed</DropdownButton>
  157. </Item>
  158. <Item>
  159. <DropdownButton isOpen>Open</DropdownButton>
  160. </Item>
  161. </Fragment>
  162. );
  163. _DropdownButton.storyName = 'Dropdown Button';
  164. _DropdownButton.parameters = {
  165. docs: {
  166. description: {
  167. story: 'A button meant to be used with some sort of dropdown',
  168. },
  169. },
  170. };
  171. export const _ButtonBar = ({gap}) => (
  172. <div>
  173. <div className="section">
  174. <h3>With a Gap</h3>
  175. <ButtonBar gap={gap}>
  176. <Button>First Button</Button>
  177. <Button>Second Button</Button>
  178. <Button>Third Button</Button>
  179. </ButtonBar>
  180. </div>
  181. <div className="section">
  182. <h3>Merged Buttons with "active" button</h3>
  183. <ButtonBar active="left" merged>
  184. <Button barId="left">Left Button</Button>
  185. <Button barId="right">Right Button</Button>
  186. </ButtonBar>
  187. </div>
  188. <div className="section">
  189. <h3>Multiple Merged Buttons with "active" button</h3>
  190. <ButtonBar active="2" merged>
  191. <Button barId="1">First Button</Button>
  192. <Button barId="2">Second Button</Button>
  193. <Button barId="3">Third Button</Button>
  194. <Button barId="4">Fourth Button</Button>
  195. </ButtonBar>
  196. </div>
  197. <div className="section">
  198. <h3>Works with DropdownLink</h3>
  199. <StartButtonBar merged>
  200. <DropdownLink customTitle={<Button>First DropdownLink</Button>} />
  201. <DropdownLink customTitle={<Button>Second DropdownLink</Button>} />
  202. <DropdownLink customTitle={<Button>Third DropdownLink</Button>} />
  203. </StartButtonBar>
  204. <StartButtonBar merged>
  205. <Button>First Button</Button>
  206. <DropdownLink customTitle={<Button>Second DropdownLink</Button>} />
  207. <Button>Third Button</Button>
  208. </StartButtonBar>
  209. <StartButtonBar merged>
  210. <DropdownLink customTitle={<Button>First DropdownLink</Button>} />
  211. <Button>Second Button</Button>
  212. <DropdownLink customTitle={<Button>Third DropdownLink</Button>} />
  213. </StartButtonBar>
  214. </div>
  215. </div>
  216. );
  217. _ButtonBar.storyName = 'Button Bar';
  218. _ButtonBar.args = {
  219. /** Button gap */
  220. gap: 1,
  221. };
  222. _ButtonBar.argTypes = {
  223. gap: {
  224. control: {
  225. type: 'select',
  226. options: [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4],
  227. },
  228. },
  229. };
  230. _ButtonBar.parameters = {
  231. docs: {
  232. description: {
  233. story: 'Buttons in a Bar container',
  234. },
  235. },
  236. };
  237. export const _NavigationButtonGroup = () => (
  238. <NavigationButtonGroup hasNext={false} hasPrevious links={['#', '#', '#', '#']} />
  239. );
  240. _NavigationButtonGroup.storyName = 'Navigation Button Group';
  241. _NavigationButtonGroup.info = 'Navigation Buttons Group';
  242. const StartButtonBar = styled(ButtonBar)`
  243. justify-content: flex-start;
  244. margin-bottom: 6px;
  245. `;