react-toolbox/components/switch
Vitaliy Filippov ba3993c811 Fix table styles, pass `style` to top-level element in inputs 2019-05-07 16:50:56 +03:00
..
Switch.d.ts Restructure typescript definitions (#1114) 2017-01-18 08:37:37 +01:00
Switch.js Fix table styles, pass `style` to top-level element in inputs 2019-05-07 16:50:56 +03:00
Thumb.js Importing PropTypes from prop-types rather than react (#1413) 2017-04-17 16:14:17 +02:00
config.css Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
index.d.ts Restructure typescript definitions (#1114) 2017-01-18 08:37:37 +01:00
index.js Update dependencies and linter (#1180) 2017-01-26 18:05:32 +01:00
readme.md Fixes #1119 2017-01-21 12:47:21 +01:00
theme.css Fixes #1127 2017-01-18 10:56:03 +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>
    );
  }
}

This component can be styled by context providing a theme with the key RTSwitch through the theme provider.

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 component's value changes.
onFocus Function Callback function that is fired when the switch is focused.
ripple Boolean If true, the ripple effect will be disabled.

Theme

Name Description
disabled Used for the root element if the component is disabled.
field Used for the root element if the component is not disabled.
input Used for the input element.
off Used for a wrapper around the thumb if checked is false.
on Used for a wrapper around the thumb if checked is true.
ripple Used for the ripple inside the switch.
text Used for the text label element.
thumb Used for the thumb element.