react-toolbox/components/switch
Fred Guest 413ddb7ca8 update Switch.jsx 2016-02-08 10:45:47 -08:00
..
Switch.jsx update Switch.jsx 2016-02-08 10:45:47 -08:00
Thumb.jsx export raw components 2016-01-22 14:12:53 +01:00
_config.scss Remove all `unquote` calls 2015-11-19 12:21:51 +01:00
index.js Remove jsx extension from imports in components 2015-11-28 20:24:46 +01:00
readme.md Update switch examples 2015-12-11 19:11:55 +01:00
style.scss Use ripple decorator in switch 2015-12-07 02:14:10 +01:00

readme.md

Switch

On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state its in, should be made clear from the corresponding inline label. Switches take on the same visual properties of the radio button.

import Switch from 'react-toolbox/lib/switch';

class SwitchTest extends React.Component {
  state = {
    switch_1: true,
    switch_2: false,
    switch_3: true
  };

  handleChange = (field, value) => {
    this.setState({...this.state, [field]: value});
  };

  render () {
    return (
      <section>
        <Switch
          checked={this.state.switch_1}
          label="Push notifications"
          onChange={this.handleChange.bind(this, 'switch_1')}
        />
        <Switch
          checked={this.state.switch_2}
          label="Mail notifications"
          onChange={this.handleChange.bind(this, 'switch_2')}
        />
        <Switch
          checked={this.state.switch_3}
          disabled
          label="Nothing, thanks"
          onChange={this.handleChange.bind(this, 'switch_3')}
        />
      </section>
    );
  }
}

Properties

Name Type Default Description
checked Boolean false If true, the switch will be enabled.
className String '' Sets a class to give custom styles to the switch.
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.