2.1.5 • Published 5 years ago

react-segmented-control-ios v2.1.5

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

react-segmented-control-ios

Replica of iOS segmented control component done purely in React. Fully Responsive for all device types. Typescript definition file(d.ts) included.

Preview

Segmented-Control

Variants

Variantpreview
BaseBase
DarkDark
SuccessSuccess
ErrorError
LightWhite fg

Installation

npm install react-segmented-control-ios —-save

OR

yarn add react-segmented-control-ios

Usage

  • For commonJS import syntax

    const SegmentedControl = require('react-segmented-control-ios');

  • For Es2016

    import SegmentedControl from 'react-segmented-control-ios';

Props

AttributeTypeDescription
segmentsarrayList of segmentsrequired
selectednumbersegment index to be selecteddefault 0
variantstringvariant namedefault base
onChangeSegmenteventmethod to implement logic on click segmentoptional

Features

  • Disable segment : add disabled: true to segment object as shown in the example below to disable that particular segment

Example

…
import SegmentedControl from 'react-segmented-control-ios';

const segments = [
  { name: 'All' },
  { name: 'Unread', disabled: true },
  { name: 'Drafts' },
  { name: 'Trash' },
  { name: 'Pins' }
];

function handleChange(index) {
    console.log(`selected index : ${index}`);
}

class App extends Component {
  state = {
      segments: segments,
      selected: 0
  };
  
  render() {
    return (
      <div className="App">
        <SegmentedControl
            segments={this.state.segments}
            selected={this.state.selected} 
            variant="base"
            onChangeSegment={handleChange}           
        />        
      </div>
    );
  }
}
…