File

src/app/lib/multi-select/multi-select.component.ts

Implements

OnInit

Metadata

selector div[uat-multi-select]
styleUrls multi-select.component.css
templateUrl ./multi-select.component.html

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor()

Inputs

filterChangeDelayms

Default value: 200

placeholderText

Default value: Search...

selectionItems

Type: UATMultiSelectItem[]

Outputs

itemSelected $event type: EventEmitter
itemUnselected $event type: EventEmitter

Methods

filterItems
filterItems(text: string)
Parameters :
Name Type Optional Description
text string
Returns : void
ngOnInit
ngOnInit()
Returns : void
onChoiceClicked
onChoiceClicked(item: UATMultiSelectItem)
Parameters :
Name Type Optional Description
item UATMultiSelectItem
Returns : void
onSelectionClicked
onSelectionClicked(item: UATMultiSelectItem)
Parameters :
Name Type Optional Description
item UATMultiSelectItem
Returns : void

Properties

filterInput
filterInput: ElementRef
Type : ElementRef
Decorators : ViewChild

Accessors

choices
getchoices()
Returns : []
selections
getselections()
Returns : []
import { 
    Component, 
    OnInit, 
    Input, 
    Output,
    EventEmitter,
    ViewChild, 
    ElementRef } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { map } from 'rxjs/operators/map';
import { debounceTime } from 'rxjs/operators/debounceTime';
import { distinctUntilChanged } from 'rxjs/operators/distinctUntilChanged';
import { UATMultiSelectItem } from './multi-select-item.interface';

@Component({
    selector: 'div[uat-multi-select]',
    templateUrl: './multi-select.component.html',
    styleUrls: ['./multi-select.component.css'],
})
export class UATMultiSelectComponent implements OnInit {
    @Input() placeholderText = "Search...";
    @Input() filterChangeDelayms = 200;

    @Input() selectionItems: UATMultiSelectItem[];

    get choices(): UATMultiSelectItem[] {
        return this.selectionItems.filter(item=>{ return !item.selected});
    }

    get selections(): UATMultiSelectItem[] {
        return this.selectionItems.filter(item=>{ return item.selected});
    }

    @ViewChild('filter') filterInput: ElementRef;

    @Output() itemSelected = new EventEmitter<UATMultiSelectItem>();
    @Output() itemUnselected = new EventEmitter<UATMultiSelectItem>();

    constructor() {
        console.log('Warning this component is still under heavy development.');
        console.log('It isn\'t completely functional yet and is subject to change.');
    }

    ngOnInit() { 
        fromEvent(this.filterInput.nativeElement, 'keyup')
        .pipe(
            map((event:KeyboardEvent)=>(event.target as HTMLInputElement).value),
            debounceTime(this.filterChangeDelayms),
            distinctUntilChanged())
        .subscribe(
            filterText=> this.filterItems(filterText)
        );

        // temp testing code
        if(!this.selectionItems) {
            this.selectionItems = [
                {
                    text: 'Name',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Position',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Year of Birth',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Rookie Season',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Height',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Weight',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Forty Time',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Bench Weight',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Vertical Jump',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Broad Jump',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Shuttle Time',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Cone Time',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Draft Position',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'College',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'College Division',
                    payload: {},
                    selected: false,
                },
                {
                    text: 'Current Team',
                    payload: {},
                    selected: false,
                }
            ];
        }

        this.selections.push(this.choices[1]);
    }

    onChoiceClicked(item: UATMultiSelectItem) {
        item.selected = true;
        this.itemSelected.emit(item);
    }

    onSelectionClicked(item: UATMultiSelectItem) {
        item.selected = false;
        this.itemUnselected.emit(item);
    }

    filterItems(text: string) {
        console.log(text);
    }
}


<input class="selections-filter" #filter [attr.placeholder]="placeholderText"/>
<div class="container-labels">
    <span>Items</span><span>Selected</span>
</div>
<div class="selections-container">
    <div class="choices">
        <ul>
            <li *ngFor="let choice of choices">
                <a (click)="onChoiceClicked(choice)">{{choice.text}}</a>
            </li>
        </ul>
    </div>
    <div class="selections">
        <ul>
            <li *ngFor="let selection of selections">
                <a (click)="onSelectionClicked(selection)">{{selection.text}}</a>
            </li>
        </ul>
    </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""