tooltip.stories.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {Component, Fragment} from 'react';
  2. import Button from 'sentry/components/button';
  3. import Tooltip from 'sentry/components/tooltip';
  4. class CustomThing extends Component {
  5. render() {
  6. return <span>A class component with no ref</span>;
  7. }
  8. }
  9. class PassThroughComponent extends Component {
  10. render() {
  11. return this.props.children;
  12. }
  13. }
  14. export default {
  15. title: 'Components/Tooltips/Tooltip',
  16. component: Tooltip,
  17. };
  18. export const _Tooltip = ({...args}) => {
  19. return (
  20. <Fragment>
  21. <h3>With styled component trigger</h3>
  22. <p>
  23. <Tooltip {...args}>
  24. <Button>Styled button</Button>
  25. </Tooltip>
  26. </p>
  27. <h3>With class component trigger</h3>
  28. <p>
  29. <Tooltip {...args}>
  30. <CustomThing>Custom React Component</CustomThing>
  31. </Tooltip>
  32. </p>
  33. <h3>With an SVG element trigger</h3>
  34. <p>
  35. <svg
  36. viewBox="0 0 100 100"
  37. width="100"
  38. height="100"
  39. xmlns="http://www.w3.org/2000/svg"
  40. >
  41. <Tooltip {...args}>
  42. <circle cx="50" cy="50" r="50" />
  43. </Tooltip>
  44. </svg>
  45. </p>
  46. <h3>With element title and native html element</h3>
  47. <p>
  48. <Tooltip
  49. title={
  50. <span>
  51. <em>so strong</em>
  52. </span>
  53. }
  54. {...args}
  55. >
  56. <button>Native button</button>
  57. </Tooltip>
  58. </p>
  59. <h3>With overflowing text</h3>
  60. <p>
  61. <Tooltip {...args}>
  62. <div
  63. style={{
  64. width: 'fit-content',
  65. overflow: 'hidden',
  66. textOverflow: 'ellipsis',
  67. whiteSpace: 'nowrap',
  68. resize: 'horizontal',
  69. }}
  70. >
  71. Activate showOnlyOnOverflow and drag the right side to make this text
  72. overflow. Tooltip will appear on hover when text overflows.
  73. </div>
  74. </Tooltip>
  75. </p>
  76. <h3>With custom component with text</h3>
  77. <p>
  78. <Tooltip {...args}>
  79. <PassThroughComponent>
  80. <div
  81. style={{
  82. width: 'fit-content',
  83. overflow: 'hidden',
  84. textOverflow: 'ellipsis',
  85. whiteSpace: 'nowrap',
  86. resize: 'horizontal',
  87. }}
  88. >
  89. This text is in a custom react component. Activate showOnlyOnOverflow and
  90. drag the right side to make this text overflow.
  91. </div>
  92. </PassThroughComponent>
  93. </Tooltip>
  94. </p>
  95. </Fragment>
  96. );
  97. };
  98. _Tooltip.args = {
  99. title: 'Basic tooltip content',
  100. disabled: false,
  101. /** Container display mode */
  102. displayMode: undefined,
  103. position: 'top',
  104. isHoverable: false,
  105. showOnlyOnOverflow: false,
  106. };
  107. _Tooltip.argTypes = {
  108. displayMode: {
  109. control: {
  110. type: 'select',
  111. options: ['block', 'inline-block', 'inline'],
  112. },
  113. },
  114. position: {
  115. control: {
  116. type: 'select',
  117. options: [
  118. 'bottom',
  119. 'top',
  120. 'left',
  121. 'right',
  122. 'bottom-start',
  123. 'bottom-end',
  124. 'top-start',
  125. 'top-end',
  126. 'left-start',
  127. 'left-end',
  128. 'right-start',
  129. 'right-end',
  130. 'auto',
  131. ],
  132. },
  133. },
  134. };
  135. _Tooltip.parameters = {
  136. docs: {
  137. description: {
  138. story: 'Adds a tooltip to any component',
  139. },
  140. },
  141. };