npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reacttoggles

v0.2.8

Published

A collection of commonly used toggle buttons implemented in react with internal css

Downloads

35

Readme

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

| Prop | Type | Description | Valid | Demo | |--- |--- |--- | --- | --- | | checked | bool | If true, the toggle is checked. If false, the toggle is unchecked | All | demo1 demo2 | | fontSize | number | Since 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. | All | demo | | disabled | bool | If true, the toggle is disabled. If false, the toggle is enabled | All | demo | | attributes | object | A key value pair of attributes that needs to be set for the input element. This may include attributes like name, id etc | All | demo | | handleChange | function | A callback function that is executed everytime the toggle value changes. The current toggle value is passed as a parameter to this function | All | demo | | handleClick | function | A callback function that is executed everytime the toggle is clicked. The current synthetic event is passed as a parameter to this function | All | demo | | toggleIcon | object | Configuration for the toggle button. | IosToggle | demo | | onProps | object | Configuration for on state |All | demo1 demo2 | | offProps | object | Configuration for off state |All | demo1 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