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

eflex-ember-cli-toggle

v1.0.6

Published

Checkbox based toggle switch component for Ember.js

Downloads

10

Readme

ember-cli-toggle

Checkbox based Toggle Switch component for Ember. Based on this codepen.
Here's the official demo using this component.

NPM
Build Status Ember Observer Score

See the 0.x branch for 0.x code and fixes.

Usage

First install with npm install --save-dev ember-cli-toggle, and add one of the following in your template:

{{x-toggle toggle='startCar'}}
{{x-toggle theme='light' toggle='enableLayer'}}
{{x-toggle theme='ios' size='small' toggle='muteVolume'}}
{{x-toggle theme='flat' toggle='disableTest'}}
{{x-toggle theme='flip' offLabel='Nope' onLabel='Yep' toggle='haveFun'}}
{{x-toggle theme='skewed' size='large' toggle='enablePartyMode'}}

Labels

You can also show text labels on either side of toggle switch with:

{{x-toggle showLabels=true offLabel='Hey' onLabel='Ho' toggle='letsGo'}}

Which would look like (using "default" theme):

This option is available on all themes but is a less sensible choice for those themes which actually include the label within the control (e.g., skew and flip).

Binding

It's perfectly normal to not need bindings for a toggle switch as the "toggle" property allows the container to catch thrown actions which happen at each state transition. Sometimes, however, it's easier to just bind your toggle switch to a property on the container. This is possible with use of the value binding:

{{x-toggle value=controller.heyOrHo showLabels=true offLabel='Hey' onLabel='Ho'}}

This will ensure that the bound property is always set to the true or false value and as it's a two way binding this will allow the toggle control to automatically update its UI when the value is changed external to the component as well.

Finally, it is sometimes the case that rather than a true or false value the toggle is meant to move between two discrete, but non-boolean states. In order to support this functionality there is an overloaded form of setting the onLabel and offLabel properties which not only sets a "label" for the state but also a "value". In our "hey" versus "ho" example you might do the following:

{{x-toggle value=controller.heyOrHo showLabels=true offLabel='Hey:hey' onLabel='Ho:ho'}}

With this configuration the "value" for the on state will be hey and in the off state it will be ho. If the bound property is set to anything other than the two accepted value states it will reset to its "off state".

Available Options

  • theme - One of 'light', 'ios', 'flat', 'flip', 'skewed', 'default'. Defaults to 'default' if not specified.
  • size - One of 'small', 'medium', 'large'. Defaults to 'medium' if not specified.
  • onLabel - The label for the on state. Defaults to 'On'.
  • offLabel - The label for the off state. Defaults to 'Off'.
  • showLabels - Defaults to 'false', if 'true' will display labels on left and ride side of toggle switch
  • toggled - Defaults to false, meaning not enabled by default. When true, an .x-toggle-container-checked class is set on the component.
  • disabled - Defaults to false, which means you can click the toggle. When true, an .x-toggle-disabled class is set on the toggle and an .x-toggle-container-disabled class is set on the component.
  • name - A name to differentiate multiple toggles, gets passed to the toggle action. Defaults to 'default'.

Actions

  • toggle - The toggle action, which has two arguments i.e. isToggled and toggleName. The toggleName is set by the name attribute on the toggle, e.g. {{x-toggle toggle='switchToggled' name='typeA'}}.
actions: {
  switchToggled(isToggled, toggleName) {
    switch(toggleName) {
      case 'typeA': {
        // do something
        break;
      }

      case 'typeB': {
        // do something
        break;
      }

      default: {
        // any other type..
      }
    }
  }
}

Configuring

Add a configuration for ember-cli-toggle to include only the themes that you will use.

ENV['ember-cli-toggle'] = {
  includedThemes: ['light', 'default', 'flip'],
  excludedThemes: ['flip'],
  defaultShowLabels: true, // defaults to false
  defaultTheme: 'light',   // defaults to 'default'
  defaultSize: 'small',    // defaults to 'medium'
  defaultOffLabel: 'False',     // defaults to 'Off'
  defaultOnLabel: 'True'        // defaults to 'On'
};

note: the IOS theme is referred to as just ios not ios7 as was indicated in the originating CSS source

To exclude or not include a theme, means that it's css styles will not be bundled with your application, thus not polluting your app.

Note: Including a blank array e.g. includeThemes: [] will not include any themes, leaving you to define your own theme styles. See the vendor/ember-cli-toggle/themes directory for reference.

Contributing

See CONTRIBUTING.md for details.