Add proper example in switch readme

old
Javi Velasco 2015-11-12 19:06:56 +01:00
parent acdb2ca0f7
commit d9153468e8
1 changed files with 36 additions and 7 deletions

View File

@ -6,13 +6,40 @@ On/off switches toggle the state of a single settings option. The option that th
```jsx
import Switch from 'react-toolbox/lib/switch';
const SwitchTest = () => (
<fieldset>
<Switch label="Push notifications" />
<Switch checked label="Mail notifications" />
<Switch disabled label="Nothing, thanks"/>
</fieldset>
);
class SwitchTest extends React.Component {
state = {
switch: [true, false, false]
};
handleChange = (index) => {
const state = this.state.switch;
state[index] = !state[index];
this.setState({switch: state});
};
render () {
return (
<section>
<Switch
checked={this.state.switch[0]}
label="Push notifications"
onChange={this.handleChange.bind(this, 0)}
/>
<Switch
checked={this.state.switch[1]}
label="Mail notifications"
onChange={this.handleChange.bind(this, 1)}
/>
<Switch
checked={this.state.switch[2]}
disabled
label="Nothing, thanks"
onChange={this.handleChange.bind(this, 2)}
/>
</section>
);
}
}
```
## Properties
@ -24,4 +51,6 @@ const SwitchTest = () => (
| `disabled` | `Boolean` | `false` | If true, component will be disabled.|
| `label` | `String` | | The text string to use for the floating label element.|
| `name` | `String` | | The text string used as name of the input.|
| `onBlur` | `Function` | | Callback function that is fired when when the switch is blurred.|
| `onChange` | `Function` | | Callback function that is fired when the components's value changes.|
| `onFocus` | `Function` | | Callback function fire when the switch is focused.|