Coder Social home page Coder Social logo

bobbyg603 / ngx-toggle Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 3.0 730 KB

๐Ÿ˜ป๐Ÿ“ฑ๐Ÿ“ Beautiful iOS-style toggle switch for Angular

Home Page: https://bobbyg603.github.io/ngx-toggle

License: MIT License

JavaScript 9.71% Shell 0.22% HTML 29.42% SCSS 11.27% TypeScript 49.38%
angular typescript toggle toggle-switch bobbyg603

ngx-toggle's Introduction

NgxToggle

cd

A simple iOS style toggle switch for Angular projects.

๐Ÿ—๏ธ Installation

Install @bobbyg603/ngx-toggle:

npm i @bobbyg603/ngx-toggle

Import the NgxToggleModule module in each module that uses <ngx-toggle>:

app.module.ts

import { NgxToggleModule } from '@bobbyg603/ngx-toggle';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxToggleModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

๐Ÿง‘โ€๐Ÿ’ป Usage

Add <ngx-toggle> to your component's template:

pricing.component.html

<ngx-toggle 
  id="toggle-example"
  [(checked)]="checked"
  [disabled]="false"
  (checkedChange)="onCheckedChange($event)">
</ngx-toggle>

Be sure to give each toggle a unique id. Failing to give each toggle a unique id will result in clicking one input toggling any inputs with a matching id.

You can also use <ngx-toggle> as a FormControl:

checkout.component.html

<form [formGroup]="formGroup">
  <ngx-toggle class="ms-auto" formControlName="saveForNextTime"></ngx-toggle>
</form>

checkout.component.ts

formGroup = new FormGroup({
  saveForNextTime: new FormControl(false)
});

๐Ÿงฉ API

Inputs

Property Type Description
id string unique identifier for input
checked boolean toggle is on (checked) or off
disabled boolean control is not interactable

Outputs

Property Type Description
checkedChange EventEmitter<boolean> Emits new checked value when control has been toggled

๐Ÿค Attribution

The ngx-toggle-example layout was inspired by Benjamin King's Pricing Cards codepen.

ngx-toggle's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

ngx-toggle's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.