Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webcat12345/ngx-ui-switch
Angular UI Switch component
https://github.com/webcat12345/ngx-ui-switch
angular angular-cli angular-ui-switch ng ngx ngx-ui-switch switch ui-switch
Last synced: 28 days ago
JSON representation
Angular UI Switch component
- Host: GitHub
- URL: https://github.com/webcat12345/ngx-ui-switch
- Owner: webcat12345
- License: mit
- Created: 2017-04-12T09:10:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T22:54:19.000Z (7 months ago)
- Last Synced: 2024-04-14T00:45:18.115Z (7 months ago)
- Topics: angular, angular-cli, angular-ui-switch, ng, ngx, ngx-ui-switch, switch, ui-switch
- Language: TypeScript
- Homepage: https://webcat12345.github.io/ngx-ui-switch/demo/
- Size: 4.69 MB
- Stars: 110
- Watchers: 3
- Forks: 67
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- trackawesomelist - ngx-ui-switch (β110) - A simple iOS 7 style switch component for Angular. (Recently Updated / [Sep 16, 2024](/content/2024/09/16/README.md))
- awesome-angular - ngx-ui-switch - A simple iOS 7 style switch component for Angular. (Table of contents / Third Party Components)
- fucking-awesome-angular - ngx-ui-switch - A simple iOS 7 style switch component for Angular. (Table of contents / Third Party Components)
- fucking-awesome-angular - ngx-ui-switch - A simple iOS 7 style switch component for Angular. (Table of contents / Third Party Components)
README
# Angular UI Switch Component
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ngx-discuss/Lobby)
[![Build Status](https://github.com/webcat12345/ngx-ui-switch/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/webcat12345/ngx-ui-switch/actions/workflows/ci.yml)
[![GitHub Pages](https://img.shields.io/badge/Demo-blue?logo=angular&label=Pages&color=7952B3)](https://webcat12345.github.io/ngx-ui-switch/demo/)
[![license](https://img.shields.io/github/license/webcat12345/ngx-ui-switch)](https://github.com/webcat12345/ngx-ui-switch/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/ngx-ui-switch)](https://badge.fury.io/js/ngx-ui-switch)
[![npm](https://img.shields.io/npm/dm/ngx-ui-switch)](https://www.npmjs.com/package/ngx-ui-switch)[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg)](#contributors)
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/ngx-ui-switch)
## Description
This is a simple iOS 7 style switch component for [Angular](https://angular.io).
![alt](logo.png)
Inspired by [switchery](https://github.com/abpetkov/switchery) in [Angular](https://angular.io).
## 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](https://github.com/webcat12345/ngx-ui-switch/issues/309) [#343](https://github.com/webcat12345/ngx-ui-switch/issues/343)
- Global options
- beforeChange event [#314](https://github.com/webcat12345/ngx-ui-switch/issues/314) [#359](https://github.com/webcat12345/ngx-ui-switch/pull/359)## Usage
- Import into a module (`AppModule` example below)
```javascript
// 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`
```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:
```scss
@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.
```javascript
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 {}
``````html
```
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](https://github.com/webcat12345/ngx-ui-switch/issues/227).
# Two way binding
```html
```
# Params
### checked
> type: *boolean*
> default: false
```html
```
### disabled
> type: *boolean*
> default: false
```html
```
### loading
*Show a loading state for the toggle button when true. Often utilized with beforeChange.*
> type: *boolean*
> default: false
```html
```
### change
> type: *boolean*
> default: noop
```html
```
### changeEvent
> type: *MouseEvent*
> default: noop
```html
```
### valueChange
> type: *boolean*
> default: noop
```html
```
### beforeChange
Utilize an observable to check that the toggle event should complete
> type: *Observable\*
> default: noop
```html
```
```typescript
OnBeforeChange: Observable = new Observable((observer) => {
const timeout = setTimeout(() => {
observer.next(true);
}, 2000);
return () => clearTimeout(timeout);
});
```### size
> type: *string*
> default: medium
```html
```
### reverse
> type: *boolean*
> default: false
```html
```
### color
> type: *string*
> default: rgb(100, 189, 99)
```html
```
### switchColor
> type: *string*
> default: #fff
```html
```
### defaultBgColor
Default background color
> type: *string*
> default: #fff
```html
```
### defaultBoColor
*Default border color*
> type: *string*
> default: #dfdfdf
```html
```
### checkedLabel
*Checked label (on)*
> type: *string*
> default: null
```html
```
### uncheckedLabel
*Unchecked label (off)*
> type: *string*
> default: null
```html
```
### checkedTextColor
checked text color of the label (on)
> type: *string*
> default: black
```html
```
### uncheckedTextColor
Unchecked text color of the label (off)
> type: *string*
> default: black
```html
```
## Switch Content
```html
```
## Aria Label
```html
```
## Development
### Setup
```sh
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*
```sh
# Build the library into dist/{es5,es2015}
yarn build
# Publish to npm
yarn release
```## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
| [
webcat_black](https://webcat12345.github.io/)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=webcat12345 "Code") [π¨](#design-webcat12345 "Design") [π‘](#example-webcat12345 "Examples") [π€](#ideas-webcat12345 "Ideas, Planning, & Feedback") [π](#review-webcat12345 "Reviewed Pull Requests") | [
Chris McKnight](https://github.com/cmckni3)
[π¬](#question-cmckni3 "Answering Questions") [π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=cmckni3 "Code") [π](https://github.com/webcat12345/ngx-ui-switch/commits?author=cmckni3 "Documentation") [π€](#ideas-cmckni3 "Ideas, Planning, & Feedback") [π](#infra-cmckni3 "Infrastructure (Hosting, Build-Tools, etc)") [π](#plugin-cmckni3 "Plugin/utility libraries") [π](#review-cmckni3 "Reviewed Pull Requests") [π§](#tool-cmckni3 "Tools") | [
Jakub](https://github.com/kubiq)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=kubiq "Code") [π](https://github.com/webcat12345/ngx-ui-switch/commits?author=kubiq "Documentation") | [
Serhii Kovalenko](https://github.com/cmajsmith)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=cmajsmith "Code") [π‘](#example-cmajsmith "Examples") [π¦](#platform-cmajsmith "Packaging/porting to new platform") | [
Richard McSharry](https://github.com/rmcsharry)
[π](https://github.com/webcat12345/ngx-ui-switch/commits?author=rmcsharry "Documentation") | [
bitsprint](https://github.com/bitsprint)
[π](#infra-bitsprint "Infrastructure (Hosting, Build-Tools, etc)") [π¦](#platform-bitsprint "Packaging/porting to new platform") [π§](#tool-bitsprint "Tools") | [
Gianluca Paronitti](http://www.gamepix.com)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=gparonitti "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Milos Bejda](http://mbejda.com)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=mbejda "Code") [π](https://github.com/webcat12345/ngx-ui-switch/commits?author=mbejda "Documentation") [π‘](#example-mbejda "Examples") | [
kameelyan](https://github.com/kameelyan)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=kameelyan "Code") [π](https://github.com/webcat12345/ngx-ui-switch/commits?author=kameelyan "Documentation") [π‘](#example-kameelyan "Examples") | [
GrΓ©gory Alary](https://gregoryalary.github.io/)
[π¬](#question-gregoryalary "Answering Questions") [π](https://github.com/webcat12345/ngx-ui-switch/issues?q=author%3Agregoryalary "Bug reports") [π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=gregoryalary "Code") [π¨](#design-gregoryalary "Design") | [
zehtravassos](https://github.com/zehtravassos)
[π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=zehtravassos "Code") [π¨](#design-zehtravassos "Design") | [
H. RΓΌger](https://github.com/hrueger)
[π](https://github.com/webcat12345/ngx-ui-switch/issues?q=author%3Ahrueger "Bug reports") [π»](https://github.com/webcat12345/ngx-ui-switch/commits?author=hrueger "Code") [π§](#maintenance-hrueger "Maintenance") |This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!