Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-simple-switch

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-simple-switch

Vanilla JS/CSS Switch UI element

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
363
increased by26.04%
Maintainers
1
Weekly downloads
 
Created
Source

Simple Switch

Simple, accessible, performant implementation of the Switch UI element.

Features:

  • Vanilla JS/CSS: doesn't require any outside library to function
  • Accessible: works properly with screenreaders and the ARIA spec
  • Performant: uses proper layering and transitioning to ensure high performance

  • Installation
  • Creating a Simple Switch

Installation

To install the Switch code, simply import the Javascript and CSS files present into your page as needed. Make sure to place the Javascript code at the bottom of the <body> tag.

Creating a Simple Switch

There are two ways to create a Simple Switch. On page load, the Simple Switch code will automatically detect checkboxes that are flagged as switches, and upgrade them, or you may manually instantiate a switch. See below for more details.

Automatically Creating Switches

To have a switch be automatically upgraded, simply add the data-type attribute to any checkbox-type input that you want upgraded, and set that attribute to the value of simple-switch.

Example:

<input type="checkbox" name="my-checkbox" data-type="simple-switch" />

Manually Creating Switches

You may also manually instantiate a switch, which may be useful for lazily-loaded UI elements or parts of the page. The Switch class which handles upgrading and controlling Switches is available under the SimpleSwitch namespace, and takes one parameter, element, which is a direct reference to the HTMLElement checkbox to be upgraded.

Example:

<input type="checkbox" name="my-checkbox" id="my-checkbox" />
var myCheckbox = document.getElementById("my-checkbox");

new SimpleSwitch.Switch({
    element: myCheckbox
});

Keywords

FAQs

Package last updated on 10 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc