button.stories.js 7.0 KB

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