Giter Site home page Giter Site logo

xnukernel / segmented-control-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chaoticbit/segmented-control-react

0.0 0.0 0.0 556 KB

Simple implementation of iOS segmented-control component made purely in React

Home Page: https://chaoticbit.github.io/segmented-control-react/

License: MIT License

JavaScript 58.05% CSS 41.95%

segmented-control-react's Introduction

Segmented Control React

Replica of iOS segmented control component done purely in React. Fully Responsive for all device types.

Preview

Segmented-Control

Variants

Variant preview
Base Base
Dark Dark
Success Success
Error Error
Light White fg

Installation

npm install segmented-control-react —-save

OR

yarn add segmented-control-react

Usage

  • For commonJS import syntax

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

  • For Es2016

    import { SegmentedControl } from 'segmented-control-react';

Props

Attribute Type Description
segments array List of segments required
selected number segment index to be selected default 0
variant string variant name default base
onChangeSegment event method to implement logic on click segment optional

Features

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

Example

…
import { SegmentedControl } from 'segmented-control-react';

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>
    );
  }
}
…

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.