You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.2 KiB

import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { ToggleOption } from '@ghostfolio/common/types';
@Component({
selector: 'gf-toggle',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './toggle.component.html',
styleUrls: ['./toggle.component.scss']
})
export class ToggleComponent implements OnChanges, OnInit {
public static DEFAULT_DATE_RANGE_OPTIONS: ToggleOption[] = [
{ label: $localize`Today`, value: '1d' },
{ label: $localize`YTD`, value: 'ytd' },
{ label: $localize`1Y`, value: '1y' },
{ label: $localize`5Y`, value: '5y' },
{ label: $localize`Max`, value: 'max' }
];
@Input() defaultValue: string;
@Input() isLoading: boolean;
@Input() options: ToggleOption[];
@Output() change = new EventEmitter<Pick<ToggleOption, 'value'>>();
public option = new FormControl<string>(undefined);
public constructor() {}
public ngOnInit() {}
public ngOnChanges() {
this.option.setValue(this.defaultValue);
}
public onValueChange() {
this.change.emit({ value: this.option.value });
}
}