libs/ui/toggle/src/lib/toggle/toggle.component.ts
The is a toggle component
<ts-toggle
arialLabel="Disable my thing"
[formControl]="yourHelperToGetFormControl('thingIsDisabled')"
[isDisabled]="true"
[isRequired]="true"
labelPosition="before"
name="My toggle"
theme="accent"
(selectionChange)="myMethod($event)"
>My Toggle!</ts-toggle>
<example-url>https://getterminus.github.io/ui-demos-release/components/toggle</example-url>
changeDetection | ChangeDetectionStrategy.OnPush |
encapsulation | ViewEncapsulation.None |
exportAs | tsToggle |
host | { |
providers |
ControlValueAccessorProviderFactory<TsToggleComponent>(TsToggleComponent)
|
selector | ts-toggle |
styleUrls | ./toggle.component.scss |
templateUrl | ./toggle.component.html |
Properties |
|
Methods |
|
Inputs |
Outputs |
Accessors |
ariaLabel | |
Type : string | undefined
|
|
Define the aria label |
isChecked | |
Type : boolean
|
|
Allow the checked state to be set |
isDisabled | |
Default value : false
|
|
Define if the toggle should be disabled |
isRequired | |
Default value : false
|
|
Define if the toggle is required |
labelPosition | |
Type : "before" | "after"
|
|
Default value : 'after'
|
|
Define the position of the label |
name | |
Default value : 'toggle'
|
|
Define the input name for the toggle |
theme | |
Type : TsStyleThemeTypes
|
|
Default value : 'primary'
|
|
Define the theme |
formControl | |
Type : FormControl
|
|
Default value : new FormControl()
|
|
Inherited from
TsReactiveFormBaseComponent
|
|
Defined in
TsReactiveFormBaseComponent:41
|
|
Define the form control to get access to validators |
selectionChange | |
Type : EventEmitter<TsSlideToggleChange>
|
|
Emit an event each time the toggle value changes |
Public onBlur |
onBlur()
|
Inherited from
TsReactiveFormBaseComponent
|
Defined in
TsReactiveFormBaseComponent:63
|
Set touched on blur
Returns :
void
|
Protected registerOnChange | ||||||
registerOnChange(fn: (_: any) => void)
|
||||||
Inherited from
TsReactiveFormBaseComponent
|
||||||
Defined in
TsReactiveFormBaseComponent:73
|
||||||
Register onChange callback (from ControlValueAccessor interface)
Parameters :
Returns :
void
|
Protected registerOnTouched | ||||||
registerOnTouched(fn: () => void)
|
||||||
Inherited from
TsReactiveFormBaseComponent
|
||||||
Defined in
TsReactiveFormBaseComponent:82
|
||||||
Register onTouched callback (from ControlValueAccessor interface)
Parameters :
Returns :
void
|
Protected writeValue | ||||||
writeValue(value: any)
|
||||||
Inherited from
TsReactiveFormBaseComponent
|
||||||
Defined in
TsReactiveFormBaseComponent:92
|
||||||
Write value to inner value (from ControlValueAccessor interface)
Parameters :
Returns :
void
|
Protected innerValue |
Type : any
|
Default value : ''
|
Inherited from
TsReactiveFormBaseComponent
|
Defined in
TsReactiveFormBaseComponent:24
|
Define the internal data model |
Protected onChangeCallback |
Type : function
|
Default value : noop
|
Inherited from
TsReactiveFormBaseComponent
|
Defined in
TsReactiveFormBaseComponent:30
|
Define placeholder for callback (provided later by the control value accessor) |
Protected onTouchedCallback |
Type : function
|
Default value : noop
|
Inherited from
TsReactiveFormBaseComponent
|
Defined in
TsReactiveFormBaseComponent:35
|
Define placeholder for callback (provided later by the control value accessor) |
isChecked | ||||||
getisChecked()
|
||||||
setisChecked(value: boolean)
|
||||||
Allow the checked state to be set
Parameters :
Returns :
void
|
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
ViewEncapsulation,
} from '@angular/core';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import {
ControlValueAccessorProviderFactory,
TsReactiveFormBaseComponent,
TsStyleThemeTypes,
} from '@terminus/ui-utilities';
/**
* Expose the MatSlideToggleChange event as TsSlideToggleChange. Used by {@link TsToggleComponent}
*/
export class TsSlideToggleChange extends MatSlideToggleChange {}
/**
* The is a toggle component
*
* @example
* <ts-toggle
* arialLabel="Disable my thing"
* [formControl]="yourHelperToGetFormControl('thingIsDisabled')"
* [isDisabled]="true"
* [isRequired]="true"
* labelPosition="before"
* name="My toggle"
* theme="accent"
* (selectionChange)="myMethod($event)"
* >My Toggle!</ts-toggle>
*
* <example-url>https://getterminus.github.io/ui-demos-release/components/toggle</example-url>
*/
@Component({
selector: 'ts-toggle',
templateUrl: './toggle.component.html',
styleUrls: ['./toggle.component.scss'],
host: { class: 'ts-toggle' },
providers: [ControlValueAccessorProviderFactory<TsToggleComponent>(TsToggleComponent)],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
exportAs: 'tsToggle',
})
export class TsToggleComponent extends TsReactiveFormBaseComponent {
/**
* Define the aria label
*/
@Input()
public ariaLabel: string | undefined;
/**
* Allow the checked state to be set
*
* @param value
*/
@Input()
public set isChecked(value: boolean) {
this._isChecked = value;
this.value = this._isChecked;
}
public get isChecked(): boolean {
return this._isChecked;
}
private _isChecked = false;
/**
* Define if the toggle should be disabled
*/
@Input()
public isDisabled = false;
/**
* Define if the toggle is required
*/
@Input()
public isRequired = false;
/**
* Define the position of the label
*/
@Input()
public labelPosition: 'before' | 'after' = 'after';
/**
* Define the input name for the toggle
*/
@Input()
public name = 'toggle';
/**
* Define the theme
*/
@Input()
public theme: TsStyleThemeTypes = 'primary';
/**
* Emit an event each time the toggle value changes
*/
@Output()
public readonly selectionChange: EventEmitter<TsSlideToggleChange> = new EventEmitter();
}