copyToClipboardButton.stories.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {ComponentProps, Fragment} from 'react';
  2. import {Button} from 'sentry/components/button';
  3. import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
  4. import JSXProperty from 'sentry/components/stories/jsxProperty';
  5. import Matrix, {PropMatrix} from 'sentry/components/stories/matrix';
  6. import {IconLink} from 'sentry/icons';
  7. import storyBook from 'sentry/stories/storyBook';
  8. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  9. export default storyBook(CopyToClipboardButton, story => {
  10. story('Basic', () => (
  11. <Fragment>
  12. <p>
  13. By default the button will stick the <JSXProperty name="text" value={String} />{' '}
  14. value onto your clipboard; as if you typed <kbd>CTRL+C</kbd> or <kbd>CMD+C</kbd>.
  15. It'll show toast messages, and includes{' '}
  16. <JSXProperty name="onCopy" value={Function} /> &
  17. <JSXProperty name="onError" value={Function} /> callbacks.
  18. </p>
  19. <CopyToClipboardButton text="Hello World" />
  20. </Fragment>
  21. ));
  22. story('useCopyToClipboard()', () => {
  23. const {onClick, label} = useCopyToClipboard({
  24. text: 'Hello World',
  25. // eslint-disable-next-line no-console
  26. onCopy: () => console.log('Copy complete'),
  27. // eslint-disable-next-line no-console
  28. onError: error => console.log('Something went wrong', error),
  29. });
  30. return (
  31. <Fragment>
  32. <p>
  33. There's also a hook you can use to get the same behavior and apply it to any
  34. other component.
  35. </p>
  36. <p>Here's an example where I've chosen a different icon:</p>
  37. <Button icon={<IconLink />} aria-label={label} onClick={onClick} />
  38. </Fragment>
  39. );
  40. });
  41. const propMatrix: PropMatrix<ComponentProps<typeof CopyToClipboardButton>> = {
  42. size: [undefined, 'md', 'sm', 'xs', 'zero'],
  43. iconSize: [undefined, 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
  44. };
  45. story('Size Props', () => (
  46. <Fragment>
  47. <p>
  48. Try to keep the <JSXProperty name="size" value="" /> and{' '}
  49. <JSXProperty name="iconSize" value="" /> props set to the same value. Here's a
  50. grid of all the possible combinations.
  51. </p>
  52. <Matrix
  53. render={CopyToClipboardButton}
  54. propMatrix={propMatrix}
  55. selectedProps={['size', 'iconSize']}
  56. />
  57. </Fragment>
  58. ));
  59. });