docs: update demos for Slider

This commit is contained in:
Benjy Cui
2016-11-21 16:37:04 +08:00
parent dd0be2e82f
commit c3064949cc
6 changed files with 69 additions and 44 deletions
+23 -7
View File
@@ -14,12 +14,28 @@ title:
Basic slider. When `range` is `true`, display as dual thumb mode. When `disable` is `true`, the slider will not be interactable.
````jsx
import { Slider } from 'antd';
import { Slider, Switch } from 'antd';
ReactDOM.render(<div>
<Slider defaultValue={30} />
<Slider range defaultValue={[20, 50]} />
<Slider range defaultValue={[20, 50]} disabled />
</div>
, mountNode);
class Demo extends React.Component {
state = {
disabled: false,
};
handleDisabledChange = (disabled) => {
this.setState({ disabled });
}
render() {
const { disabled } = this.state;
return (
<div>
Disabled: <Switch checked={disabled} onChange={this.handleDisabledChange} />
<Slider defaultValue={30} disabled={disabled} />
<Slider range defaultValue={[20, 50]} disabled={disabled} />
</div>
);
}
}
ReactDOM.render(<Demo />, mountNode);
````
+13 -9
View File
@@ -1,6 +1,6 @@
---
order: 4
title:
title:
zh-CN: 事件
en-US: Event
---
@@ -11,21 +11,25 @@ title:
## en-US
The `onChange` callback function will fire when the user changes the slider's value.
The `onChange` callback function will fire when the user changes the slider's value.
The `onAfterChange` callback function will fire when `onmouseup` fired.
````jsx
import { Slider } from 'antd';
function log(value) {
console.log(value);
function onChange(value) {
console.log('onChange: ', value);
}
function onAfterChange(value) {
console.log('onAfterChange: ', value);
}
ReactDOM.render(
<div>
<Slider defaultValue={30} onChange={log} />
<Slider range step={10} defaultValue={[20, 50]} onChange={log} />
<Slider defaultValue={30} onAfterChange={log} />
</div>
, mountNode);
<Slider defaultValue={30} onChange={onChange} onAfterChange={onAfterChange} />
<Slider range step={10} defaultValue={[20, 50]} onChange={onChange} onAfterChange={onAfterChange} />
</div>,
mountNode
);
````
+6 -8
View File
@@ -39,7 +39,7 @@ const IconSlider = React.createClass({
render() {
return (
<div className="iconWrapper">
<div className="icon-wrapper">
<Icon className={this.state.preIconClass} type={this.props.icon[0]} />
<Slider {...this.props} onChange={this.handleChange} value={this.state.sliderValue} />
<Icon className={this.state.nextIconClass} type={this.props.icon[1]} />
@@ -48,18 +48,16 @@ const IconSlider = React.createClass({
},
});
ReactDOM.render(
<IconSlider min={0} max={20} value={0} icon={['frown-o', 'smile-o']} />
, mountNode);
ReactDOM.render(<IconSlider min={0} max={20} value={0} icon={['frown-o', 'smile-o']} />, mountNode);
````
````css
.iconWrapper {
.icon-wrapper {
position: relative;
padding: 0px 30px;
}
.iconWrapper .anticon {
.icon-wrapper .anticon {
position: absolute;
top: -3px;
width: 16px;
@@ -69,11 +67,11 @@ ReactDOM.render(
color: #ccc;
}
.iconWrapper .anticon:first-child {
.icon-wrapper .anticon:first-child {
left: 0;
}
.iconWrapper .anticon:last-child {
.icon-wrapper .anticon:last-child {
right: 0;
}
+11 -8
View File
@@ -1,8 +1,8 @@
---
order: 1
title:
title:
zh-CN: 带输入框的滑块
en-US: Slider with input field
en-US: Slider with InputNumber
---
## zh-CN
@@ -34,7 +34,7 @@ const IntegerStep = React.createClass({
<Slider min={1} max={20} onChange={this.onChange} value={this.state.inputValue} />
</Col>
<Col span={4}>
<InputNumber min={1} max={20} style={{ marginLeft: '16px' }}
<InputNumber min={1} max={20} style={{ marginLeft: 16 }}
value={this.state.inputValue} onChange={this.onChange}
/>
</Col>
@@ -61,7 +61,7 @@ const DecimalStep = React.createClass({
<Slider min={0} max={1} onChange={this.onChange} value={this.state.inputValue} step={0.01} />
</Col>
<Col span={4}>
<InputNumber min={0} max={1} style={{ marginLeft: '16px' }} step={0.01}
<InputNumber min={0} max={1} style={{ marginLeft: 16 }} step={0.01}
value={this.state.inputValue} onChange={this.onChange}
/>
</Col>
@@ -70,8 +70,11 @@ const DecimalStep = React.createClass({
},
});
ReactDOM.render(<div>
<IntegerStep />
<DecimalStep />
</div>, mountNode);
ReactDOM.render(
<div>
<IntegerStep />
<DecimalStep />
</div>,
mountNode
);
````
+9 -8
View File
@@ -1,7 +1,7 @@
---
order: 3
title:
zh-CN: 分段式滑块
title:
zh-CN: 带标签的滑块
en-US: Graduated slider
---
@@ -33,15 +33,16 @@ const marks = {
ReactDOM.render(
<div>
<p>`included=true`</p>
<p><code>included=true</code></p>
<Slider marks={marks} defaultValue={37} />
<Slider range marks={marks} defaultValue={[26, 37]} />
<p>`included=false`</p>
<p><code>included=false</code></p>
<Slider marks={marks} included={false} defaultValue={37} />
<p>`marks && step`</p>
<p><code>marks && step</code></p>
<Slider marks={marks} step={10} defaultValue={37} />
<p>`step=null`</p>
<p><code>step=null</code></p>
<Slider marks={marks} step={null} defaultValue={37} />
</div>
, mountNode);
</div>,
mountNode
);
````
+7 -4
View File
@@ -20,8 +20,11 @@ function formatter(value) {
return `${value}%`;
}
ReactDOM.render(<div>
<Slider tipFormatter={formatter} />
<Slider tipFormatter={null} />
</div>, mountNode);
ReactDOM.render(
<div>
<Slider tipFormatter={formatter} />
<Slider tipFormatter={null} />
</div>,
mountNode
);
````