tooltip.stories.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React from 'react';
  2. import {withInfo} from '@storybook/addon-info';
  3. import {text, boolean, select} from '@storybook/addon-knobs';
  4. import Tooltip from 'app/components/tooltip';
  5. import Button from 'app/components/button';
  6. class CustomThing extends React.Component {
  7. render() {
  8. return <span>A class component with no ref</span>;
  9. }
  10. }
  11. export default {
  12. title: 'UI/Tooltip',
  13. };
  14. export const _Tooltip = withInfo({
  15. text: 'Adds a tooltip to any component,',
  16. propTablesExclude: [CustomThing, Button, 'Button'],
  17. })(() => {
  18. const title = text('tooltip', 'Basic tooltip content');
  19. const disabled = boolean('Disabled', false);
  20. const displayMode = select('Container display mode', [
  21. 'block',
  22. 'inline-block',
  23. 'inline',
  24. ]);
  25. const position = select(
  26. 'position',
  27. {top: 'top', bottom: 'bottom', left: 'left', right: 'right'},
  28. 'top'
  29. );
  30. const isHoverable = boolean('isHoverable', false);
  31. return (
  32. <React.Fragment>
  33. <h3>With styled component trigger</h3>
  34. <p>
  35. <Tooltip
  36. title={title}
  37. position={position}
  38. disabled={disabled}
  39. containerDisplayMode={displayMode}
  40. isHoverable={isHoverable}
  41. >
  42. <Button>Styled button</Button>
  43. </Tooltip>
  44. </p>
  45. <h3>With class component trigger</h3>
  46. <p>
  47. <Tooltip
  48. title={title}
  49. position={position}
  50. disabled={disabled}
  51. isHoverable={isHoverable}
  52. >
  53. <CustomThing>Custom React Component</CustomThing>
  54. </Tooltip>
  55. </p>
  56. <h3>With an SVG element trigger</h3>
  57. <p>
  58. <svg
  59. viewBox="0 0 100 100"
  60. width="100"
  61. height="100"
  62. xmlns="http://www.w3.org/2000/svg"
  63. >
  64. <Tooltip
  65. title={title}
  66. position={position}
  67. disabled={disabled}
  68. containerDisplayMode={displayMode}
  69. isHoverable={isHoverable}
  70. >
  71. <circle cx="50" cy="50" r="50" />
  72. </Tooltip>
  73. </svg>
  74. </p>
  75. <h3>With element title and native html element</h3>
  76. <p>
  77. <Tooltip
  78. title={
  79. <span>
  80. <em>so strong</em>
  81. </span>
  82. }
  83. containerDisplayMode={displayMode}
  84. position={position}
  85. disabled={disabled}
  86. isHoverable={isHoverable}
  87. >
  88. <button>Native button</button>
  89. </Tooltip>
  90. </p>
  91. </React.Fragment>
  92. );
  93. });