button.stories.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {Fragment, useState} from 'react';
  2. import {Button, ButtonProps} from 'sentry/components/button';
  3. import Matrix, {PropMatrix} from 'sentry/components/stories/matrix';
  4. import {IconDelete} from 'sentry/icons';
  5. import storyBook from 'sentry/stories/storyBook';
  6. export default storyBook('Button', story => {
  7. story('Default', () => <Button>Default Button</Button>);
  8. story('onClick', () => {
  9. const [clickCount, setClickCount] = useState(0);
  10. return (
  11. <Fragment>
  12. <p>clicked = {clickCount}</p>
  13. <Button onClick={() => setClickCount(prev => ++prev)}>Click Here</Button>
  14. </Fragment>
  15. );
  16. });
  17. const propMatrix: PropMatrix<ButtonProps> = {
  18. borderless: [false, true],
  19. busy: [false, true],
  20. children: ['Save', undefined],
  21. icon: [undefined, <IconDelete key="" />],
  22. priority: ['default', 'primary', 'danger', 'link', undefined],
  23. size: ['md', 'sm', 'xs', 'zero'],
  24. disabled: [false, true],
  25. external: [false, true],
  26. title: [undefined, 'Save Now'],
  27. translucentBorder: [false, true],
  28. };
  29. story('Props', () => (
  30. <div>
  31. <Matrix<ButtonProps>
  32. render={Button}
  33. propMatrix={propMatrix}
  34. selectedProps={['priority', 'size']}
  35. />
  36. <Matrix<ButtonProps>
  37. render={Button}
  38. propMatrix={propMatrix}
  39. selectedProps={['children', 'icon']}
  40. />
  41. <Matrix<ButtonProps>
  42. render={Button}
  43. propMatrix={propMatrix}
  44. selectedProps={['borderless', 'translucentBorder']}
  45. />
  46. <Matrix<ButtonProps>
  47. render={Button}
  48. propMatrix={propMatrix}
  49. selectedProps={['disabled', 'busy']}
  50. />
  51. </div>
  52. ));
  53. });