Compare commits

...
4 Commits
Author SHA1 Message Date
Benjy Cui e8a86b91e2 Merge pull request #45 from react-component/feat-mark-as-step
Feat mark as step
2015-11-19 11:55:10 +08:00
Benjy Cui 05dafc0f10 bump 3.1.0 2015-11-19 11:43:25 +08:00
Benjy Cui 5dbde43da8 docs: update README.md 2015-11-19 11:43:07 +08:00
Benjy Cui 0a23a67f31 feat: allow user set step to null to make marks as steps 2015-11-19 11:42:04 +08:00
4 changed files with 18 additions and 35 deletions
+11 -23
View File
@@ -88,11 +88,17 @@ ReactDOM.render(<Rcslider />, container);
<td>100</td> <td>100</td>
<td>The maximum value of the slider</td> <td>The maximum value of the slider</td>
</tr> </tr>
<tr>
<td>marks</td>
<td>object {number: string}</td>
<td>{}</td>
<td>Mark on the slider. The key determines the position, and the value determines what will show.</td>
</tr>
<tr> <tr>
<td>step</td> <td>step</td>
<td>number</td> <td>number or `null`</td>
<td>1</td> <td>1</td>
<td>Value to be added or subtracted on each step the slider makes. Must be greater than zero. max - min should be evenly divisible by the step value.</td> <td>Value to be added or subtracted on each step the slider makes. Must be greater than zero. max - min should be evenly divisible by the step value. When `marks` is not an empty object, `step` can be set to `null`, to make marks as steps.</td>
</tr> </tr>
<tr> <tr>
<td>range</td> <td>range</td>
@@ -112,35 +118,17 @@ ReactDOM.render(<Rcslider />, container);
<td></td> <td></td>
<td>Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]`</td> <td>Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]`</td>
</tr> </tr>
<tr>
<td>marks</td>
<td>array</td>
<td>[]</td>
<td>Mark every step for the slider, it will ignore the `step` parameter if it has been defined. Does not work with `range`</td>
</tr>
<tr> <tr>
<td>included</td> <td>included</td>
<td>boolean</td> <td>boolean</td>
<td>true</td> <td>true</td>
<td>If the value is `true`, it means a continuous value interval, otherwise, it is a independent value.</td> <td>If the value is `true`, it means a continuous value interval, otherwise, it is a independent value.</td>
</tr> </tr>
<tr>
<td>defaultIndex</td>
<td>number</td>
<td>0</td>
<td>For step or marks slider, determines the initial position of the handle. Does not work with `range`</td>
</tr>
<tr>
<td>index</td>
<td>number</td>
<td></td>
<td>For step or marks slider, determines current position of the handle. Does not work with `range`</td>
</tr>
<tr> <tr>
<td>disabled</td> <td>disabled</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>If true the handles can't be moved.</td> <td>If `true`, handles can't be moved.</td>
</tr> </tr>
<tr> <tr>
<td>tipTransitionName</td> <td>tipTransitionName</td>
@@ -150,7 +138,7 @@ ReactDOM.render(<Rcslider />, container);
</tr> </tr>
<tr> <tr>
<td>tipFormatter</td> <td>tipFormatter</td>
<td>func</td> <td>function</td>
<td></td> <td></td>
<td>Format the value of the tooltip if it shows.</td> <td>Format the value of the tooltip if it shows.</td>
</tr> </tr>
@@ -158,7 +146,7 @@ ReactDOM.render(<Rcslider />, container);
<td>dots</td> <td>dots</td>
<td>bool</td> <td>bool</td>
<td>false</td> <td>false</td>
<td>For linear slider, when the `step` value is greater than 1, you can set the `dots` to `true` if you want to render the slider bar with dots.</td> <td>When the `step` value is greater than 1, you can set the `dots` to `true` if you want to render the slider with dots.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
+3 -3
View File
@@ -22,11 +22,11 @@ var log = function(value) {
ReactDOM.render( ReactDOM.render(
<div> <div>
<div style={style}> <div style={style}>
<p>Slider with marks, `included=true`</p> <p>Slider with marks, `step=null`</p>
<Slider min={-10} marks={marks} onChange={log} defaultValue={20} /> <Slider min={-10} marks={marks} step={null} onChange={log} defaultValue={20} />
</div> </div>
<div style={style}> <div style={style}>
<p>Slider with marks and steps, `included=true`</p> <p>Slider with marks and steps</p>
<Slider min={-10} marks={marks} step={10} onChange={log} defaultValue={20} /> <Slider min={-10} marks={marks} step={10} onChange={log} defaultValue={20} />
</div> </div>
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "rc-slider", "name": "rc-slider",
"version": "3.0.1", "version": "3.1.0",
"description": "slider ui component for react", "description": "slider ui component for react",
"keywords": [ "keywords": [
"react", "react",
+3 -8
View File
@@ -25,10 +25,6 @@ function pauseEvent(e) {
e.preventDefault(); e.preventDefault();
} }
function isEmpty(collection) {
return Object.keys(collection).length === 0;
}
class Slider extends React.Component { class Slider extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -194,7 +190,7 @@ class Slider extends React.Component {
getPoints() { getPoints() {
const {marks, step, min, max} = this.props; const {marks, step, min, max} = this.props;
const points = Object.keys(marks); const points = Object.keys(marks);
if (isEmpty(marks) || step > 1) { if (step !== null) {
for (let i = min; i <= max; i = i + step) { for (let i = min; i <= max; i = i + step) {
points.push(i); points.push(i);
} }
@@ -291,9 +287,8 @@ class Slider extends React.Component {
render() { render() {
const {handle, upperBound, lowerBound} = this.state; const {handle, upperBound, lowerBound} = this.state;
const {className, prefixCls, disabled, dots, included, range, const {className, prefixCls, disabled, dots, included, range, step,
marks, max, min, tipTransitionName, tipFormatter, children} = this.props; marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
const marksCount = Object.keys(marks).length;
const sliderClassName = classSet({ const sliderClassName = classSet({
[prefixCls]: true, [prefixCls]: true,
@@ -311,7 +306,7 @@ class Slider extends React.Component {
} }
const handleClassName = prefixCls + '-handle'; const handleClassName = prefixCls + '-handle';
const isNoTip = (marksCount > 0) && !tipFormatter; const isNoTip = (step === null) && !tipFormatter;
const upper = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip} tipFormatter={tipFormatter} const upper = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip} tipFormatter={tipFormatter}
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />); offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />);