Code Monkey home page Code Monkey logo

react-flat-switch's Introduction

react-flat-switch

Inspired by Oleg Frolov's codepen, React Flat Switch is a toggle/switch component for React.

Installation

npm install --save react-flat-switch

Demo & Example

Live demo: cameronbourke.github.io/example/react-flat-switch

To build the example locally, clone this repo then run:

npm install
npm start
Then open localhost:8080 in a browser.

Usage

import React from 'react';
import FlatSwitch from 'react-flat-switch';

class App extends React.Component {
	...

	render() {
		const background = this.state.switchEnabled ? '#2196f3' : '#DCDCDC';
		const enabledStyles = {
			color: '#2196f3'
		};
		const disabledStyles = {
			color: '#F32121'
		};

		return (
			<section className='container' style={{ background }}>
				<FlatSwitch
					width={150}
					height={40}
					enabled={this.state.switchEnabled}
					enabledText='enable'
					enabledStyles={enabledStyles}
					disabledStyles={disabledStyles}
					disabledText='disable'
					className='list-item--switch'
					onSwitch={this.handleOnClick.bind(this)}
				/>
			</section>
		);
	}
}

Available Props

Property Type Default Description
enabled bool (required) determines which side of the switch is shown
enableText string enable the text value of the enabled side of the switch
disableText string disable the text value of the disabled side of the switch
onSwitch func undefined called when the user clicks the switch
hideBoxShadow bool false will hide any box shadows used
width number/string 150 the width of the component
height number/string 40 the height of the component
className string undefined the classname of the component
enabledStyles object undefined style object that will be applied to the enabled side
disabledStyles object undefined style object that will be applied to the disabled side

Todo

  • Extend Styling Capabilities

License

MIT Licensed Copyright (c) Cameron Bourke 2016

react-flat-switch's People

Stargazers

Mezt Rahmat avatar  avatar Dev avatar Matt avatar Eirik L. Vullum avatar Kyle Mathews avatar Oleg Frolov avatar

Forkers

yss14

react-flat-switch's Issues

Dist folder isn't shipped

Just a small notice: The dist folder is not shipped when installing your package via npm or yarn, which results in an Module not found: Can't resolve 'react-flat-switch' error.

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.