Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

há 3 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # rc-slider
  2. ---
  3. Slider UI component for React
  4. [![NPM version][npm-image]][npm-url]
  5. [![build status][travis-image]][travis-url]
  6. [![Test coverage][codecov-image]][codecov-url]
  7. [![david-dm deps][david-dm-image]][david-dm-url]
  8. [![david-dm dev deps][david-dm-dev-image]][david-dm-dev-url]
  9. [![node version][node-image]][node-url]
  10. [![npm download][download-image]][download-url]
  11. [npm-image]: http://img.shields.io/npm/v/rc-slider.svg?style=flat-square
  12. [npm-url]: http://npmjs.org/package/rc-slider
  13. [travis-image]: https://img.shields.io/travis/react-component/slider.svg?style=flat-square
  14. [travis-url]: https://travis-ci.org/react-component/slider
  15. [codecov-image]: https://img.shields.io/codecov/c/github/react-component/slider/master.svg?style=flat-square
  16. [codecov-url]: https://codecov.io/gh/react-component/slider/branch/master
  17. [david-dm-image]: https://david-dm.org/react-component/slider/status.svg
  18. [david-dm-url]: https://david-dm.org/react-component/slider
  19. [david-dm-dev-image]: https://david-dm.org/react-component/slider/dev-status.svg
  20. [david-dm-dev-url]: https://david-dm.org/react-component/slider?type=dev
  21. [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
  22. [node-url]: http://nodejs.org/download/
  23. [download-image]: https://img.shields.io/npm/dm/rc-slider.svg?style=flat-square
  24. [download-url]: https://npmjs.org/package/rc-slider
  25. ## Screenshots
  26. <img src="https://t.alipayobjects.com/images/T1ki8fXeprXXXXXXXX.png" width="550"/>
  27. <img src="https://t.alipayobjects.com/images/T1pPhfXhBqXXXXXXXX.png" width="550"/>
  28. <img src="https://t.alipayobjects.com/images/T1wO8fXd4rXXXXXXXX.png" width="550"/>
  29. <img src="http://i.giphy.com/l46Cs36c9HrHMExoc.gif"/>
  30. ## Features
  31. * Supports IE9, IE9+, Chrome, Firefox & Safari
  32. ## Install
  33. ```bash
  34. npm install --save rc-slider
  35. ```
  36. [![rc-slider](https://nodei.co/npm/rc-slider.png)](https://npmjs.org/package/rc-slider)
  37. ## Usage
  38. ````js
  39. import React from 'react';
  40. import ReactDOM from 'react-dom';
  41. import Slider, { Range } from 'rc-slider';
  42. // We can just import Slider or Range to reduce bundle size
  43. // import Slider from 'rc-slider/lib/Slider';
  44. // import Range from 'rc-slider/lib/Range';
  45. import 'rc-slider/assets/index.css';
  46. ReactDOM.render(
  47. <div>
  48. <Slider />
  49. <Range />
  50. </div>,
  51. container
  52. );
  53. `````
  54. ## API
  55. ### createSliderWithTooltip(Slider | Range) => React.Component
  56. An extension to make Slider or Range support Tooltip on handle.
  57. ```jsx
  58. const Slider = require('rc-slider');
  59. const createSliderWithTooltip = Slider.createSliderWithTooltip;
  60. const Range = createSliderWithTooltip(Slider.Range);
  61. ```
  62. [Online demo](http://react-component.github.io/slider/examples/handle.html)
  63. After Range or Slider was wrapped by createSliderWithTooltip, it will have the following props:
  64. | Name | Type | Default | Description |
  65. | ------------ | ------- | ------- | ----------- |
  66. | tipFormatter | (value: number): React.ReactNode | `value => value` | A function to format tooltip's overlay |
  67. | tipProps | Object | `{` <br>`placement: 'top',` <br> ` prefixCls: 'rc-slider-tooltip',` <br> `overlay: tipFormatter(value)` <br> `}` | A function to format tooltip's overlay |
  68. ### Common API
  69. The following APIs are shared by Slider and Range.
  70. | Name | Type | Default | Description |
  71. | ------------ | ------- | ------- | ----------- |
  72. | className | string | `''` | Additional CSS class for the root DOM node |
  73. | min | number | `0` | The minimum value of the slider |
  74. | max | number | `100` | The maximum value of the slider |
  75. | marks | `{number: ReactNode}` or`{number: { style, label }}` | `{}` | Marks on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains `style` and `label` properties. |
  76. | step | number or `null` | `1` | Value to be added or subtracted on each step the slider makes. Must be greater than zero, and `max` - `min` should be evenly divisible by the step value. <br /> When `marks` is not an empty object, `step` can be set to `null`, to make `marks` as steps. |
  77. | vertical | boolean | `false` | If vertical is `true`, the slider will be vertical. |
  78. | handle | (props) => React.ReactNode | | A handle generator which could be used to customized handle. |
  79. | included | boolean | `true` | If the value is `true`, it means a continuous value interval, otherwise, it is a independent value. |
  80. | reverse | boolean | `false` | If the value is `true`, it means the component is rendered reverse. |
  81. | disabled | boolean | `false` | If `true`, handles can't be moved. |
  82. | dots | boolean | `false` | When the `step` value is greater than 1, you can set the `dots` to `true` if you want to render the slider with dots. |
  83. | onBeforeChange | Function | NOOP | `onBeforeChange` will be triggered when `ontouchstart` or `onmousedown` is triggered. |
  84. | onChange | Function | NOOP | `onChange` will be triggered while the value of Slider changing. |
  85. | onAfterChange | Function | NOOP | `onAfterChange` will be triggered when `ontouchend` or `onmouseup` is triggered. |
  86. | minimumTrackStyle | Object | | please use `trackStyle` instead. (`only used for slider, just for compatibility , will be deprecate at rc-slider@9.x `) |
  87. | maximumTrackStyle | Object | | please use `railStyle` instead (`only used for slider, just for compatibility , will be deprecate at rc-slider@9.x`) |
  88. | handleStyle | Array[Object] \| Object | `[{}]` | The style used for handle. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for multi handle following element order`) |
  89. | trackStyle | Array[Object] \| Object | `[{}]` | The style used for track. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for multi track following element order`)|
  90. | railStyle | Object | `{}` | The style used for the track base color. |
  91. | dotStyle | Object | `{}` | The style used for the dots. |
  92. | activeDotStyle | Object | `{}` | The style used for the active dots. |
  93. ### Slider
  94. | Name | Type | Default | Description |
  95. | ------------ | ------- | ------- | ----------- |
  96. | defaultValue | number | `0` | Set initial value of slider. |
  97. | value | number | - | Set current value of slider. |
  98. | tabIndex | number | `0` | Set the tabIndex of the slider handle. |
  99. ### Range
  100. | Name | Type | Default | Description |
  101. | ------------ | ------- | ------- | ----------- |
  102. | defaultValue | `number[]` | `[0, 0]` | Set initial positions of handles. |
  103. | value | `number[]` | | Set current positions of handles. |
  104. | tabIndex | number[] | `[0, 0]` | Set the tabIndex of each handle. |
  105. | count | number | `1` | Determine how many ranges to render, and multiple handles will be rendered (number + 1). |
  106. | allowCross | boolean | `true` | `allowCross` could be set as `true` to allow those handles to cross. |
  107. | pushable | boolean or number | `false` | `pushable` could be set as `true` to allow pushing of surrounding handles when moving a handle. When set to a number, the number will be the minimum ensured distance between handles. Example: ![](http://i.giphy.com/l46Cs36c9HrHMExoc.gif) |
  108. ## Development
  109. ```
  110. npm install
  111. npm start
  112. ```
  113. ## Example
  114. `npm start` and then go to `http://localhost:8005/examples/`
  115. Online examples: [http://react-component.github.io/slider/](http://react-component.github.io/slider/)
  116. ## Test Case
  117. `http://localhost:8005/tests/runner.html?coverage`
  118. ## Coverage
  119. `http://localhost:8005/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8088/tests/runner.html?coverage`
  120. ## License
  121. `rc-slider` is released under the MIT license.