0.2.8 • Published 7 years ago

reacttoggles v0.2.8

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

React Toggles Build Status

A simple collection of decently customizable toggle buttons available in 3 basic styles namely ios, skewed and flip. Since this module is more of a plug and play, it uses inline css to style the toggle button so that no external css styles have to be imported.

Installation

npm install reacttoggles

Demo

The demo with live examples can be viewed here.

Use

The reaact toggele comes in 3 variants. The same can be imported and used in the project using

ES6

import { IosToggle, SkewToggle, FlipToggle } from 'reacttoggles'

RequireJS

var Toggle = require('reacttoggles')

var IosToggle = Toggle.IosToggle

var SkewToggle = Toggle.SkewToggle

var FlipToggle = Toggle.FlipToggle

Motivation

Writing a small component like a toggle button is a pain since this doesn't come out of the box with frameworks like bootstrap. Sometimes, all you need is a simple import with a plug and play feature withiut any setup. This is what this modules helps to achieve

Repo

https://github.com/nerdchacha/react-toggles

Props

PropTypeDescriptionValidDemo
checkedboolIf true, the toggle is checked. If false, the toggle is uncheckedAlldemo1 demo2
fontSizenumberSince all dimensions are set using em, this will the fontSize os the em value of the wrapper div. If you want to give the size using css, don't use this property and instead give fontSize using css instead.Alldemo
disabledboolIf true, the toggle is disabled. If false, the toggle is enabledAlldemo
attributesobjectA key value pair of attributes that needs to be set for the input element. This may include attributes like name, id etcAlldemo
handleChangefunctionA callback function that is executed everytime the toggle value changes. The current toggle value is passed as a parameter to this functionAlldemo
handleClickfunctionA callback function that is executed everytime the toggle is clicked. The current synthetic event is passed as a parameter to this functionAlldemo
toggleIconobjectConfiguration for the toggle button.IosToggledemo
onPropsobjectConfiguration for on stateAlldemo1 demo2
offPropsobjectConfiguration for off stateAlldemo1 demo2
toggleIcon : {
    component: String OR ReactElement
    style: {
        backgroundColor: String,
        color: String,
    }
}

NOTE:

The checkbox has a default value of id and name as toggle. Please make sure you provide different values using the attribute props in case you are using more than one toggle button in your project


component : string OR React Element (usually icon) to be displayed when toggle is in on state (only for IosToggle)

backgroundColor: background color of the toggle when the toggle is in on state (only for IosToggle)

color: font color of the toggle when the toggle is in on state (only for IosToggle)

onProps : {
    component: String OR ReactElement
    style: {
        backgroundColor: String,
        color: String,
        toggleBorder: String,
        buttonBorder: String
    }
}

component : string OR React Element (usually icon) to be displayed when toggle is in on state

backgroundColor: background color of the toggle when the toggle is in on state

color: font color of the toggle when the toggle is in on state

toggleBorder: toggle button/bar border color when the toggle is in on state (only for IosToggle)

buttonBorder: toggle button color when the toggle is in on state (only for IosToggle)

offProps : {
    component: String OR ReactElement
    style: {
        backgroundColor: String,
        color: String,
        toggleBorder: String,
        buttonBorder: String
    }
}

component : string OR React Element (usually icon) to be displayed when toggle is in off state

backgroundColor: background color of the toggle when the toggle is in off state

color: font color of the toggle when the toggle is in off state

toggleBorder: toggle button/bar border color when the toggle is in off state (only for IosToggle)

buttonBorder: toggle button color when the toggle is in off state (only for IosToggle)

Using External CSS instead of Inline CSS

We understand that using inline styles is such a pain in the neck specially when you want to override some properties using an external css file.

with the v0.2.0, the module comes with 3 default css stylesheets namely ios.css, skew.css and flip.css available inside the dist folder.

You can now import just the raw toggle (without the inline wrapper element) using

var Toggle = require('reacttoggles').Toggle

OR

let { Toggle } from 'reacttoggles'

Considering you are running through webpack, you can then require any of the 3 css, depending on your requirement, in the same file using

require('reacttoggles/dist/ios.css')

require('reacttoggles/dist/skew.css')

require('reacttoggles/dist/flip.css')

You can finally use the toggle using

<Toggle type='ios' />

<Toggle type='skew' />

<Toggle type='flip' />

NOTE: the type prop is required and must be provided for the css to be applied properly.
NOTE: you can still use all the above mentioned props with this toggle except for style related props. For example

<Toggle type='skew' onProps={{component: <FontAwesome name='times' />}} />

will work fine

but

<Toggle type='skew' onProps={{style: backgroundColor: 'orange'}} />

will make no differene to the css

Dev

you can clone the repo and start the dev mode using npm start command

Tests

The modules currently comes with a test setup but with very minimilistic test cases. Test can be run using from the module directry using the script

npm run test:local

Change Log

changelog can we viewed here

Authors

Yatin Gera initial work and setup

Issue tracker

https://github.com/nerdchacha/react-toggles/issues

License

This project is licensed under the MIT License

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago