1.5.3 • Published 4 months ago

ng-toggle-button v1.5.3

Weekly downloads
230
License
MIT
Repository
github
Last release
4 months ago

AngularToggleButton

This is a toggle switch button component, you can see the demo here and test it in StackBlitz.

Versions

Angularng-toggle-button
>=15.0.0v1.5.x
>=14.0.0v1.4.x
>=13.0.0v1.3.x
>=12.0.0v1.2.x
>=11.0.0v1.1.x
>=10.0.0v1.0.x
>=9.0.0v0.2.x
v8.x.xv0.1.x

Instalation

npm i ng-toggle-button

or

yarn add ng-toggle-button

Usage

Import the module

import { NgToggleModule } from 'ng-toggle-button';
@NgModule({
  ...
  imports: [
    ...,
    NgToggleModule.forRoot() //or NgToggleModule
  ],
})

Also, you can pass a global configuration for all ng-toggle component in your app

import { NgToggleModule } from 'ng-toggle-button';
@NgModule({
  ...
  imports: [
    ...,
    NgToggleModule.forRoot(config)
  ],
})

The config object is described in the table bellow

Use

<ng-toggle
  [value]="true"
  [color]="{
    unchecked: '#939da2',
    checked: '#f62d51'
  }"
></ng-toggle>

Properties

NameTypeDefaultDescription
valuebooleanfalseInitial state of the toggle button
speednumber300Transition time for the animation
disabledbooleanfalseButton does not react on mouse events
colorstring#0099CCIf String - color of the button when checked If Object - colors for the button when checked/unchecked or disabledExample: {checked: '#00FF00', unchecked: '#FF0000', disabled: '#CCCCCC'}
labelsboolean ObjectfalseIf boolean - shows/hides default labels If Object - sets custom labels for both states. Example: {checked: 'Foo', unchecked: 'Bar'}
switchColorstring Object#fffIf string - color or background property of the switch when checked If Object - colors or background property for the switch when checked/uncheked Example: {checked: '#25EF02', unchecked: 'silver'}
widthnumber50Width of the button
heightnumber22Height of the button
marginnumber3Space between the switch and background border
namestringundefinedName to attach to the generated input field
fontSizenumber10Font size in pixels
fontColorstring ObjectundefinedIf string - color when checked If Object - colors for labels when checked/uncheked Example: {checked: '#25EF02', unchecked: '#35DB15'} by default the text color is white.
textAlignstring \| toggleConfig{checked: 'left', unchecked: 'right'}If string: text-align is applied both checked and unchecked labelsIf toggleConfig: Text align of checked/unchecked labelsExample: {checked: 'center', unchecked: 'center'}
values{checked: any, unchecked: any}{checked: true, unchecked: false}Values for checked and unchecked states, by default checked value is true and unchecked value is false Example: {checked: 1, unchecked: 0}.

toggleConfig type is described below:

toggleConfig = {
  checked: string;
  unchecked: string;
  disabled?: string;
};

Outputs events

NamePayloadDescription
changevalueTriggered when state of the component changes. Contains: value - state of the button

Keyboard Accessibility (WCAG)

The toggle is tabbable, and can be triggered using the spacebar - WCAG 2.4.3(A)

Development server

Clone this repo and download the dependencies. Run ng serve for a dev server. Navigate to http://localhost:4200/.

1.5.3

4 months ago

1.5.3-beta.0

4 months ago

1.5.2

1 year ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

3 years ago

1.3.0-beta.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

1.0.0-beta.0

3 years ago

1.1.0-beta.0

3 years ago

1.2.0-beta.0

3 years ago

0.2.3-beta.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.7

3 years ago

0.2.0-beta.0

3 years ago

0.1.6

3 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago