Skip to content

Commit

Permalink
docs: update demos for Slider
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Nov 21, 2016
1 parent dd0be2e commit c306494
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 45 deletions.
32 changes: 24 additions & 8 deletions components/slider/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

ReactDOM.render(<div>
<Slider defaultValue={30} />
<Slider range defaultValue={[20, 50]} />
<Slider range defaultValue={[20, 50]} disabled />
</div>
, mountNode);
import { Slider, Switch } from 'antd';

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);
````
22 changes: 13 additions & 9 deletions components/slider/demo/event.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
order: 4
title:
title:
zh-CN: 事件
en-US: Event
---
Expand All @@ -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
);
````
14 changes: 6 additions & 8 deletions components/slider/demo/icon-slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]} />
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
19 changes: 11 additions & 8 deletions components/slider/demo/input-number.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
order: 1
title:
title:
zh-CN: 带输入框的滑块
en-US: Slider with input field
en-US: Slider with InputNumber
---

## zh-CN
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -70,8 +70,11 @@ const DecimalStep = React.createClass({
},
});

ReactDOM.render(<div>
<IntegerStep />
<DecimalStep />
</div>, mountNode);
ReactDOM.render(
<div>
<IntegerStep />
<DecimalStep />
</div>,
mountNode
);
````
17 changes: 9 additions & 8 deletions components/slider/demo/mark.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
order: 3
title:
zh-CN: 分段式滑块
title:
zh-CN: 带标签的滑块
en-US: Graduated slider
---

Expand Down Expand Up @@ -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
);
````
11 changes: 7 additions & 4 deletions components/slider/demo/tip-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
````

0 comments on commit c306494

Please sign in to comment.