Skip to content

Commit

Permalink
[Slider] Add example showing how to access value
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryboyko committed Apr 13, 2016
1 parent cf4cf87 commit de9abe2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import Slider from 'material-ui/Slider';

export default class SliderExampleControlled extends React.Component {

state = {
firstSlider: 0.5,
secondSlider: 50,
}

handleFirstSlider(event, value) {
this.setState({firstSlider: value});
}

handleSecondSlider(event, value) {
this.setState({secondSlider: value});
}

render() {
return (
<div>
<Slider
defaultValue={0.5}
value={this.state.firstSlider}
onChange={this.handleFirstSlider.bind(this)}
/>
<p>
<span>{'The value of this slider is: '}</span>
<span>{this.state.firstSlider}</span>
<span>{' from a range of 0 to 1 inclusive'}</span>
</p>
<Slider
min={0}
max={100}
step={1}
defaultValue={50}
value={this.state.secondSlider}
onChange={this.handleSecondSlider.bind(this)}
/>
<p>
<span>{'The value of this slider is: '}</span>
<span>{this.state.secondSlider}</span>
<span>{' from a range of 0 to 100 inclusive'}</span>
</p>
</div>
);
}

}
12 changes: 12 additions & 0 deletions docs/src/app/components/pages/components/Slider/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import SliderExampleDisabled from './ExampleDisabled';
import sliderExampleDisabledCode from '!raw!./ExampleDisabled';
import SliderExampleStep from './ExampleStep';
import sliderExampleStepCode from '!raw!./ExampleStep';
import SliderExampleControlled from './ExampleControlled';
import sliderExampleControlledCode from '!raw!./ExampleControlled';
import sliderCode from '!raw!material-ui/lib/Slider/Slider';

const descriptions = {
simple: 'The `defaultValue` property sets the initial position of the slider. The slider appearance changes when ' +
'not at the starting position.',
stepped: 'By default, the slider is continuous. The `step` property causes the slider to move in discrete ' +
'increments.',
value: 'The slider bar can have a set minimum and maximum, and the value can be ' +
'obtained through the value parameter fired on an onChange event.',
};

const SliderPage = () => (
Expand All @@ -45,6 +49,14 @@ const SliderPage = () => (
>
<SliderExampleStep />
</CodeExample>
<CodeExample
title="Controlled Examples"
description={descriptions.value}
code={sliderExampleControlledCode}
>
<SliderExampleControlled />
</CodeExample>

<PropTypeDescription code={sliderCode} />
</div>
);
Expand Down

0 comments on commit de9abe2

Please sign in to comment.