You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.7 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. # rc-tooltip
  2. ---
  3. React Tooltip
  4. [![NPM version][npm-image]][npm-url]
  5. [![build status][travis-image]][travis-url]
  6. [![Test coverage][coveralls-image]][coveralls-url]
  7. [![gemnasium deps][gemnasium-image]][gemnasium-url]
  8. [![node version][node-image]][node-url]
  9. [![npm download][download-image]][download-url]
  10. [npm-image]: http://img.shields.io/npm/v/rc-tooltip.svg?style=flat-square
  11. [npm-url]: http://npmjs.org/package/rc-tooltip
  12. [travis-image]: https://img.shields.io/travis/react-component/tooltip.svg?style=flat-square
  13. [travis-url]: https://travis-ci.org/react-component/tooltip
  14. [coveralls-image]: https://img.shields.io/coveralls/react-component/tooltip.svg?style=flat-square
  15. [coveralls-url]: https://coveralls.io/r/react-component/tooltip?branch=master
  16. [gemnasium-image]: http://img.shields.io/gemnasium/react-component/tooltip.svg?style=flat-square
  17. [gemnasium-url]: https://gemnasium.com/react-component/tooltip
  18. [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
  19. [node-url]: http://nodejs.org/download/
  20. [download-image]: https://img.shields.io/npm/dm/rc-tooltip.svg?style=flat-square
  21. [download-url]: https://npmjs.org/package/rc-tooltip
  22. ## Screenshot
  23. <img src="http://gtms03.alicdn.com/tps/i3/TB1NQUSHpXXXXaUXFXXlQqyZXXX-1312-572.png" width="600"/>
  24. ## Browsers support
  25. | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Opera |
  26. | --------- | --------- | --------- | --------- | --------- |
  27. | IE 8 + ✔ | Chrome 31.0+ ✔ | Firefox 31.0+ ✔ | Opera 30.0+ ✔ | Safari 7.0+ ✔ |
  28. ## Install
  29. [![rc-tooltip](https://nodei.co/npm/rc-tooltip.png)](https://npmjs.org/package/rc-tooltip)
  30. ## Usage
  31. ```js
  32. var Tooltip = require('rc-tooltip');
  33. var React = require('react');
  34. var ReactDOM = require('react-dom');
  35. // By default, the tooltip has no style.
  36. // Consider importing the stylesheet it comes with:
  37. // 'rc-tooltip/assets/bootstrap_white.css'
  38. ReactDOM.render(
  39. <Tooltip placement="left" trigger={['click']} overlay={<span>tooltip</span>}>
  40. <a href="#">hover</a>
  41. </Tooltip>,
  42. container
  43. );
  44. ```
  45. ## Examples
  46. `npm start` and then go to
  47. [http://localhost:8007/examples](http://localhost:8007/examples)
  48. Online examples: [http://react-component.github.io/tooltip/examples/](http://react-component.github.io/tooltip/examples/)
  49. ## API
  50. ### Props
  51. <table class="table table-bordered table-striped">
  52. <thead>
  53. <tr>
  54. <th style="width: 100px;">name</th>
  55. <th style="width: 50px;">type</th>
  56. <th style="width: 50px;">default</th>
  57. <th>description</th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. <tr>
  62. <td>overlayClassName</td>
  63. <td>string</td>
  64. <td></td>
  65. <td>additional className added to popup overlay</td>
  66. </tr>
  67. <tr>
  68. <td>trigger</td>
  69. <td>string[]</td>
  70. <td>['hover']</td>
  71. <td>which actions cause tooltip shown. enum of 'hover','click','focus'</td>
  72. </tr>
  73. <tr>
  74. <td>mouseEnterDelay</td>
  75. <td>number</td>
  76. <td>0</td>
  77. <td>delay time to show when mouse enter.unit: s.</td>
  78. </tr>
  79. <tr>
  80. <td>mouseLeaveDelay</td>
  81. <td>number</td>
  82. <td>0.1</td>
  83. <td>delay time to hide when mouse leave.unit: s.</td>
  84. </tr>
  85. <tr>
  86. <td>overlayStyle</td>
  87. <td>Object</td>
  88. <td></td>
  89. <td>additional style of overlay node</td>
  90. </tr>
  91. <tr>
  92. <td>prefixCls</td>
  93. <td>String</td>
  94. <td>rc-tooltip</td>
  95. <td>prefix class name</td>
  96. </tr>
  97. <tr>
  98. <td>transitionName</td>
  99. <td>String|Object</td>
  100. <td></td>
  101. <td>same as https://github.com/react-component/animate</td>
  102. </tr>
  103. <tr>
  104. <td>onVisibleChange</td>
  105. <td>Function</td>
  106. <td></td>
  107. <td>call when visible is changed</td>
  108. </tr>
  109. <tr>
  110. <td>afterVisibleChange</td>
  111. <td>Function</td>
  112. <td></td>
  113. <td>call after visible is changed</td>
  114. </tr>
  115. <tr>
  116. <td>visible</td>
  117. <td>boolean</td>
  118. <td></td>
  119. <td>whether tooltip is visible</td>
  120. </tr>
  121. <tr>
  122. <td>defaultVisible</td>
  123. <td>boolean</td>
  124. <td></td>
  125. <td>whether tooltip is visible initially</td>
  126. </tr>
  127. <tr>
  128. <td>placement</td>
  129. <td>String</td>
  130. <td></td>
  131. <td>one of ['left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight']</td>
  132. </tr>
  133. <tr>
  134. <td>align</td>
  135. <td>Object: alignConfig of [dom-align](https://github.com/yiminghe/dom-align)</td>
  136. <td></td>
  137. <td>value will be merged into placement's config</td>
  138. </tr>
  139. <tr>
  140. <td>onPopupAlign</td>
  141. <td>function(popupDomNode, align)</td>
  142. <td></td>
  143. <td>callback when popup node is aligned</td>
  144. </tr>
  145. <tr>
  146. <td>overlay</td>
  147. <td>React.Element | () => React.Element</td>
  148. <td></td>
  149. <td>popup content</td>
  150. </tr>
  151. <tr>
  152. <td>arrowContent</td>
  153. <td>React.Node</td>
  154. <td>null</td>
  155. <td>arrow content</td>
  156. </tr>
  157. <tr>
  158. <td>getTooltipContainer</td>
  159. <td>function</td>
  160. <td></td>
  161. <td>Function returning html node which will act as tooltip container. By default the tooltip attaches to the body. If you want to change the container, simply return a new element.</td>
  162. </tr>
  163. <tr>
  164. <td>destroyTooltipOnHide</td>
  165. <td>boolean</td>
  166. <td>false</td>
  167. <td>whether destroy tooltip when tooltip is hidden</td>
  168. </tr>
  169. <tr>
  170. <td>id</td>
  171. <td>String</td>
  172. <td></td>
  173. <td>Id which gets attached to the tooltip content. Can be used with aria-describedby to achieve Screenreader-Support.</td>
  174. </tr>
  175. </tbody>
  176. </table>
  177. ## Note
  178. `Tooltip` requires child node accepts `onMouseEnter`, `onMouseLeave`, `onFocus`, `onClick` event.
  179. ## Accessibility
  180. For accessibility purpose you can use the `id` prop to link your tooltip with another element. For example attaching it to an input element:
  181. ```jsx
  182. <Tooltip
  183. ...
  184. id={this.props.name}>
  185. <input type="text"
  186. ...
  187. aria-describedby={this.props.name}/>
  188. </Tooltip>
  189. ```
  190. If you do it like this, a screenreader would read the content of your tooltip if you focus the input element.
  191. **NOTE:** `role="tooltip"` is also added to expose the purpose of the tooltip element to a screenreader.
  192. ## Development
  193. ```bash
  194. npm install
  195. npm start
  196. ```
  197. ## Test Case
  198. ```bash
  199. npm test
  200. npm run chrome-test
  201. ```
  202. ## Coverage
  203. ```bash
  204. npm run coverage
  205. ```
  206. ## License
  207. `rc-tooltip` is released under the MIT license.