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

ngx-ui-switch

v15.0.0

Published

switch button for angular4

Downloads

122,646

Readme

Angular UI Switch Component

Gitter Build Status license npm version npm GitHub Pages

All Contributors

Open in StackBlitz

Description

This is a simple iOS 7 style switch component for Angular.

alt

Inspired by switchery in Angular.

Installation

npm: npm install ngx-ui-switch --save

yarn: yarn add ngx-ui-switch

Some features are not available in previous versions:

  • CSS styling
  • Switch content (checkedLabel, uncheckedLabel) #309 #343
  • Global options
  • beforeChange event #314 #359

Usage

  • Import into a module (AppModule example below)
// app.module.ts
import { UiSwitchModule } from 'ngx-ui-switch';
import { AppComponent } from './app.component';

@NgModule({
  imports: [BrowserModule, UiSwitchModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}
  • Add default css file to appropriate project(s) angular.json
"styles": [
  "src/styles.css",
  "./node_modules/ngx-ui-switch/ui-switch.component.css"
]

Alternatively, the scss version can be imported into a scss file:

@import '~ngx-ui-switch/ui-switch.component.scss';

Global config

Use when you want to change default values globally.

These settings will override anything passed in via property bindings.

import { UiSwitchModule } from 'ngx-ui-switch';
import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    UiSwitchModule.forRoot({
      size: 'small',
      color: 'rgb(0, 189, 99)',
      switchColor: '#80FFA2',
      defaultBgColor: '#00ACFF',
      defaultBoColor : '#476EFF',
      checkedLabel: 'on',
      uncheckedLabel: 'off'
    })
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}
<ui-switch></ui-switch>

Note that if you are using the switch in a child NgModule, such as a lazy loaded module, then you must also import the module in the module itself or within a shared module. Otherwise you will get the error that it is an unknown component as seen in issue #227.

Two way binding

<ui-switch [(ngModel)]="enable"></ui-switch>

Params

checked

type: boolean

default: false

<ui-switch checked></ui-switch>
<ui-switch [checked]="false"></ui-switch>

disabled

type: boolean

default: false

<ui-switch disabled></ui-switch>
<ui-switch checked [disabled]="true"></ui-switch>

loading

Show a loading state for the toggle button when true. Often utilized with beforeChange.

type: boolean

default: false

<ui-switch [loading]="isLoading">
  <i class="fa fa-spinner fa-pulse" *ngIf="isLoading"></i>
</ui-switch>

change

type: boolean

default: noop

<ui-switch (change)="onChange($event)"></ui-switch>

changeEvent

type: MouseEvent

default: noop

<ui-switch (changeEvent)="onChangeEvent($event)"></ui-switch>
<ui-switch (changeEvent)="$event.stopPropagation()"></ui-switch>

valueChange

type: boolean

default: noop

<ui-switch (valueChange)="onValueChange($event)"></ui-switch>

beforeChange

Utilize an observable to check that the toggle event should complete

type: Observable<boolean>

default: noop

<ui-switch [beforeChange]="OnBeforeChange">
</ui-switch>
OnBeforeChange: Observable<boolean> = new Observable((observer) => {
  const timeout = setTimeout(() => {
    observer.next(true);
  }, 2000);
  return () => clearTimeout(timeout);
});

size

type: string

default: medium

<ui-switch size="small"></ui-switch>
<ui-switch size="large"></ui-switch>

reverse

type: boolean

default: false

<ui-switch reverse></ui-switch>

color

type: string

default: rgb(100, 189, 99)

<ui-switch color="red"></ui-switch>

switchColor

type: string

default: #fff

<ui-switch switchColor="#fcfcfc"></ui-switch>

defaultBgColor

Default background color

type: string

default: #fff

<ui-switch defaultBgColor="red"></ui-switch>

defaultBoColor

Default border color

type: string

default: #dfdfdf

<ui-switch defaultBoColor="black"></ui-switch>

checkedLabel

Checked label (on)

type: string

default: null

<ui-switch checkedLabel="on"></ui-switch>

uncheckedLabel

Unchecked label (off)

type: string

default: null

<ui-switch uncheckedLabel="off"></ui-switch>

checkedTextColor

checked text color of the label (on)

type: string

default: black

<ui-switch checkedTextColor="#7CFC00"></ui-switch>

uncheckedTextColor

Unchecked text color of the label (off)

type: string

default: black

<ui-switch uncheckedTextColor="red"></ui-switch>

Switch Content

<ui-switch uncheckedLabel="off">
  <img src=""/>
</ui-switch>

Aria Label

<ui-switch [ariaLabel]="'labelName'"></ui-switch>

Development

Setup

yarn install

Demo

Edit files in src/app to add to the demo or try changes to the library.

Build library

First, edit version in package.json and src/lib/package.json to publish a new version to npmjs.org

# Build the library into dist/{es5,es2015}
yarn build
# Publish to npm
yarn release

Contributors

Thanks goes to these wonderful people (emoji key):

| webcat_black💻 🎨 💡 🤔 👀 | Chris McKnight💬 💻 📖 🤔 🚇 🔌 👀 🔧 | Jakub💻 📖 | Serhii Kovalenko💻 💡 📦 | Richard McSharry📖 | bitsprint🚇 📦 🔧 | Gianluca Paronitti💻 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | Milos Bejda💻 📖 💡 | kameelyan💻 📖 💡 | Grégory Alary💬 🐛 💻 🎨 | zehtravassos💻 🎨 | H. Rüger🐛 💻 🚧 |

This project follows the all-contributors specification. Contributions of any kind welcome!