All Projects → enkidevs → react-segmented-control

enkidevs / react-segmented-control

Licence: other
Simple react.js component for a segmented control

Programming Languages

HTML
75241 projects
CSS
56736 projects

react-segmented-control

Simple React component for a segmented control.

Demo

Demo

Install

npm install react-segmented-control --save

or

bower install react-segmented-control --save

Example

Controlled usage:

var SegmentedControl = require('react-segmented-control');

var App = React.createClass({

  getInitialState() {
    return {
      color: 'red'
    };
  },
  render() {
    return (
      <div>
        <SegmentedControl 
          onChange={this.colorUpdated} 
          value={this.state.color}
          name="color">
          <span value="red">Red</span>
          <span value="blue">Blue</span>
        </SegmentedControl>
        <div className='background' style={{background: this.state.color}} />
      </div>
    );
  },
  
  colorUpdated(value) {
    this.setState({color: value});
  }
});

API

Props

All props are optional except name.

className

Class of the Component (in addition of segmented-control).

onChange

Function called when the control is changed (value will be passed as an argument).

defaultValue or value

Use defaultValue to specify an initial value. Use value to use this component as a controlled component.

name

Name of the input.

Styles

Look at react-segmented-control.css for an idea on how to style this component.


MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].