button.stories.js 6.8 KB

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