import { AfterViewInit, ChangeDetectorRef, DoCheck, ElementRef, EventEmitter, OnInit, TemplateRef, ViewContainerRef } from '@angular/core'; import { ControlValueAccessor, FormGroupDirective, NgControl, NgForm } from '@angular/forms'; import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { TemplatePortal } from '@angular/cdk/portal'; import { HcFormControlComponent } from '../form-field/hc-form-control.component'; import { PickerItemDirective } from './picker-item.directive'; /** * Describes a wrapper that is crucial for making the multi select picker component function. * This wrapper essentially allows for unique identification of an item via the uuid and * allows for an item's checked state to be tracked. * * The developer using this component probably doesn't care about this object but it is available if needed. */ export interface MultiSelectItem { uuid?: string; payload: T; checked: boolean; } /** * The event class that holds the selected items when the state is saved. */ export declare class MultiSelectPickerChangeEvent { source: MultiSelectPickerComponent; selectedValues: T[]; constructor(source: MultiSelectPickerComponent, selectedValues: T[]); } export declare class MultiSelectPickerComponent extends HcFormControlComponent implements OnInit, AfterViewInit, DoCheck, ControlValueAccessor { private hostElement; private overlay; private _viewContainerRef; private cd; _ngControl: NgControl; /** * Specify a list of options that are not selected * @param values: any[] */ nonSelectedValues: any[]; _nonSelectedValues: any[]; /** * Specify a list of options that are selected. Must be a list of string, number, or objects. * If objects then read the usage guide on Custom Component rendering * @param values */ selectedValues: any[]; _selectedValues: any[]; /** * If for some reason you want to configure both the selected and nonSelected items at the same time you can do so with this input. * Note you will need to wrap your each of your items in a MultiSelectItem object and mark the checked property if the item should * have a selected state. * * This is not likely the input you are looking for. * @param values */ items: MultiSelectItem[]; _items: MultiSelectItem[]; _itemsCopy: MultiSelectItem[]; /** * Configures the placeholder. Expects a string. * @param value */ placeholder: string; _placeholder: string; /** * Specify a function to evaluate if items match a search term from the user * @param value */ filterResolver: (searchTerm: string, item: any) => boolean; _filterResolver: (searchTerm: string, item: any) => boolean; /** * Specify a function to evaluate if MultiSelectPicker items match a search term from the user. See items input for more info. * * This is not likely the input you are looking for. * @param value */ pickerItemFilterResolver: (searchTerm: string, item: MultiSelectItem) => boolean; _pickerItemFilterResolver: (searchTerm: string, item: MultiSelectItem) => boolean; /** * Specify if the control is required or not. */ required: boolean; /** * Specify if the control is disabled or not. */ disabled: boolean; /** * Provide a function to determine what text to show in the selection summary for each selected item. * @param resolver */ summaryTextItemResolver: Function; _summaryTextItemResolver: Function; /** * Specify the max number of items that can be displayed in the selection summary before defaulting to a standard message like: * "Selected: 12 items" */ maxSummaryItems: number; /** * Event listener for when a change has been commited by the user. If the user didn't click save it didn't happen! */ change: EventEmitter>; _filteredItems: MultiSelectItem[]; _inputActive: boolean; _pickerOverlayOpen: boolean; _templatePortal: TemplatePortal; _overlayRef: OverlayRef; _selectedItems: MultiSelectItem[]; _selectedItemsCommitted: MultiSelectItem[]; _form: NgForm | FormGroupDirective | null; _pickerMainControl: ElementRef; _overlayContent: TemplateRef; _listItemTemplate: PickerItemDirective; _tabindex: number; readonly _disabledClass: boolean; _onKeyup(event: any): void; constructor(hostElement: ElementRef, overlay: Overlay, _viewContainerRef: ViewContainerRef, cd: ChangeDetectorRef, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, _ngControl: NgControl); ngOnInit(): void; ngAfterViewInit(): void; /** * Control Value Accessor and related Methods i.e. Make this thing work as a form control */ private onChange; private onTouched; /** * ControlValueAccessor method interface implementation * @param fn */ registerOnChange(fn: any): void; /** * ControlValueAccessor method interface implementation * @param fn */ registerOnTouched(fn: any): void; /** * ControlValueAccessor method interface implementation * @param fn */ writeValue(value: any[]): void; /** * Need to check every cycle because we can't subscribe to form submissions */ ngDoCheck(): void; /** * Handles updating the error state when ngDoCheck fires. */ private _updateErrorState; _markAsTouched(): void; /** * End Control Value Accessor and related Methods */ /** * Handles merging of unselected and selected options and returns a single list of MultiSelectItem objects. * * This then is used by items setter method. * @param unSelectedOptions * @param selectedOptions */ private mergeValues; /** * Click handler * */ _placeholderClicked(): void; /** * Click handler * */ _triggerClicked(): void; /** * Click handler * */ _popoverPlaceholderClicked(): void; /** * Click handler * */ _popoverTriggerClicked(): void; /** * Handles opening the multi select picker popover. * * If show input is true then that will also be called. * This is needed in this order since we can't toggle showInput before the overlay is opened. * @param showInput */ private open; /** * Handles the actual details of showing the picker overlay. Leverages Angular CDK _overlayRef service. */ private showPickerOverlay; /** * Handles closing the multi select picker overlay and cleans up. */ private close; /** * Handles showing the textual search input in the popover * */ private _showInput; /** * Handles hiding the textual search input in the popover * */ _hideInput(): void; /** * Dismisses the popover and resets all picker state to previous state prior to any changes in this latest opened session * */ _cancel(): void; /** * Dismisses the poover and commits and emits selected picker state. * */ _submit(): void; /** * This allows the developer to not have to implement this function for basic searching of string or number lists. * @param filter * @param item */ private defaultFilterResolver; /** * Handles input events from the search input * @param filter * */ _input(filter: string): void; /** * Handles checkbox selection changes * @param item * */ _itemCheckboxChange(item: MultiSelectItem): void; /** * Utility for cloning doing a deep clone of items. * @param items */ private clone; /** * Adds an item to the selected state. * @param item */ private addSelectedItem; /** * Removes and item from the selected state. * @param item */ private removeSelectedItem; /** * Utility to select the raw value / payload from a MultiSelectPicker Item. * The raw value or payload is the value the user actually cares about. * * @param source * */ private _getRawValues; }