]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/select/select-options.component.ts
Add ability to set a custom quota
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / select / select-options.component.ts
CommitLineData
30b1e106
C
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
21e493d4 3import { SelectOptionsItem } from '../../../../types/select-options-item.model'
02c01341
RK
4
5@Component({
6 selector: 'my-select-options',
7 styleUrls: [ './select-shared.component.scss' ],
8 templateUrl: './select-options.component.html',
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => SelectOptionsComponent),
13 multi: true
14 }
15 ]
16})
17export class SelectOptionsComponent implements ControlValueAccessor {
18 @Input() items: SelectOptionsItem[] = []
19 @Input() clearable = false
20 @Input() searchable = false
02c01341 21 @Input() groupBy: string
30b1e106 22 @Input() labelForId: string
ead64cdf 23 @Input() searchFn: any
02c01341
RK
24
25 selectedId: number | string
26
02c01341
RK
27 propagateChange = (_: any) => { /* empty */ }
28
29 writeValue (id: number | string) {
30 this.selectedId = id
31 }
32
33 registerOnChange (fn: (_: any) => void) {
34 this.propagateChange = fn
35 }
36
37 registerOnTouched () {
38 // Unused
39 }
40
41 onModelChange () {
42 this.propagateChange(this.selectedId)
43 }
44}