import { AfterViewInit, ChangeDetectorRef, ElementRef, EventEmitter, OnDestroy, OnInit, QueryList } from '@angular/core'; import { FormControl, NgControl } from '@angular/forms'; import { TsDocumentService } from '@terminus/ngx-tools/browser'; import { TsChipCollectionComponent, TsChipEvent } from '@terminus/ui/chip'; import { TsFormFieldControl } from '@terminus/ui/form-field'; import { TsOptgroupComponent, TsOptionComponent } from '@terminus/ui/option'; import { TsStyleThemeTypes } from '@terminus/ui/utilities'; import { BehaviorSubject, Subject } from 'rxjs'; import { TsSelectionListPanelComponent, TsSelectionListPanelSelectedEvent } from './selection-list-panel/selection-list-panel.component'; import { TsSelectionListTriggerDirective } from './selection-list-panel/selection-list-trigger.directive'; /** * The event object that is emitted when the select value has changed */ export declare class TsSelectionListChange { source: TsSelectionListComponent; value: T; constructor(source: TsSelectionListComponent, value: T); } export declare type TsSelectionListFormatter = (v: unknown) => string; export declare type TsSelectionListComparator = (a: unknown, b: unknown) => boolean; /** * The selection list UI Component * * @example * * * https://getterminus.github.io/ui-demos-release/components/selection-list */ export declare class TsSelectionListComponent implements OnInit, AfterViewInit, OnDestroy, TsFormFieldControl { private changeDetectorRef; private documentService; elementRef: ElementRef; ngControl: NgControl; /** * Give the component an explicit name * TODO: remove once select & autocomplete have been removed https://github.com/GetTerminus/terminus-ui/issues/1678 */ readonly componentName = "TsSelectionListComponent"; /** * Define the internal FormControl */ selectionListFormControl: FormControl; /** * Store a reference to the document object */ private document; /** * Subject used to alert the parent {@link TsFormFieldComponent} when the label gap should be recalculated * * Implemented as part of TsFormFieldControl. */ readonly labelChanges: Subject; /** * Manages keyboard events for options in the panel. */ private keyManager; /** * The IDs of child options to be passed to the aria-owns attribute. */ optionIds: string; /** * Whether or not the overlay panel is open */ panelOpen: boolean; /** * Since the FormFieldComponent is inside this template, we cannot use a provider to pass this component instance to the form field. * Instead, we pass it manually through the template with this reference. */ selfReference: this; readonly stateChanges: Subject; /** * Define the default component ID */ readonly uid: string; /** * Management of the query string */ querySubject: BehaviorSubject; /** * Store the search query */ searchQuery: string; /** * Access the panel */ panel: TsSelectionListPanelComponent; /** * Access the trigger */ trigger: TsSelectionListTriggerDirective; /** * Access the chip list */ chipList: TsChipCollectionComponent | undefined; /** * Access the actual HTML element */ inputElement: ElementRef; /** * Access a list of all the defined select options */ options: QueryList; /** * Access all of the defined optgroups */ optionGroups: QueryList; /** * Determines whether the select or the input has a value */ get empty(): boolean; /** * Determines whether the input has focus */ get focused(): boolean; /** * Determine if the label should float */ get shouldLabelFloat(): boolean; /** * Determine if the dropdown arrow icon should be visible */ get shouldShowDropdownIcon(): boolean; /** * Determine the trigger display when no user input is allowed */ get staticTriggerDisplay(): string; /** * Define if multiple selections are allowed */ allowMultiple: boolean; /** * Define if should allow duplicate selections */ allowDuplicateSelections: boolean; /** * Define if the user is allowed to type to search/filter */ allowUserInput: boolean; /** * Define a debounce delay for the query stream * * @param value */ set debounceDelay(value: number); get debounceDelay(): number; private _debounceDelay; /** * Define if the required marker should be hidden */ hideRequiredMarker: boolean; /** * Define a hint for the input * * @param value */ set hint(value: string | undefined); get hint(): string | undefined; private _hint; /** * Define an ID for the component * * @param value */ set id(value: string); get id(): string; protected _id: string; /** * Define if the control should be disabled */ isDisabled: boolean; /** * Define if the control is required * * @param value */ set isRequired(value: boolean); get isRequired(): boolean; private _isRequired; /** * Define a minimum character count for queries * * @param value */ set minimumCharacters(value: number); get minimumCharacters(): number; private _minimumCharacters; /** * Define whether a validation or a hint needed. */ noValidationOrHint: boolean; /** * Define if the panel should reopen after a selection is made * * NOTE: Though it is technically 're-opening', it happens fast enough so that it doesn't appear to close at all. */ reopenAfterSelection: boolean; /** * Define if the input should currently be showing a progress spinner */ showProgress: boolean; /** * Define the component theme */ theme: TsStyleThemeTypes; /** * Define if validation messages should be shown immediately or on blur */ validateOnChange: boolean; /** * Value of the select control * * @param newValue */ set value(newValue: string | undefined); get value(): string | undefined; private _value; /** * Define the placeholder/label */ label: string | undefined; /** * Define the name attribute value */ name: string | undefined; /** * Define the formatter for the selected items. * * @param value */ set displayFormatter(value: TsSelectionListFormatter); get displayFormatter(): TsSelectionListFormatter; private _displayFormatter; /** * Define the comparator for the values of the options * * @param a * @param b */ valueComparator: TsSelectionListComparator; /** * Emit when the backdrop is clicked */ readonly backdropClicked: EventEmitter; /** * Emit when the panel is closed */ readonly closed: EventEmitter; /** * Emit the option when a duplicate selection is made */ readonly duplicateSelection: EventEmitter>; /** * Emit when the panel is opened */ readonly opened: EventEmitter; /** * Emit the selected option */ readonly optionSelected: EventEmitter>; /** * Emit the deselected option */ readonly optionDeselected: EventEmitter>; /** * Emit the new query */ readonly queryChange: EventEmitter; /** * Emit the current selections when any selection changes */ readonly selectionChange: EventEmitter>; /** * Event that emits whenever the raw value of the select changes. This is here primarily to facilitate the two-way binding for the `value` * input. * * Needed for {@link TsFormFieldComponent}. */ readonly valueChange: EventEmitter; constructor(changeDetectorRef: ChangeDetectorRef, documentService: TsDocumentService, elementRef: ElementRef, ngControl: NgControl); /** * Seed initial values and set up watchers */ ngOnInit(): void; /** * Subscribe to panel events and query subject changes */ ngAfterViewInit(): void; /** * Needed for untilComponentDestroyed */ ngOnDestroy(): void; /** * Stub in onChange * * Needed for ControlValueAccessor (View -> model callback called when value changes) */ onChange: (value: string) => void; /** * Stub in onTouched * * Needed for ControlValueAccessor (View -> model callback called when select has been touched) */ onTouched: () => void; /** * Close the overlay panel */ close(): void; /** * Focus the native input element */ focusInput(): void; /** * Open the overlay panel */ open(): void; /** * Sets the select's value. Part of the ControlValueAccessor interface required to integrate with Angular's core forms API. * * NOTE: Currently we are not using this, but it still must be present since this component is acting as a CVA. * * @param value - New value to be written to the model */ writeValue(value: string): void; /** * Save a callback function to be invoked when the select's value changes from user input. * Part of the ControlValueAccessor interface required to integrate with Angular's core forms API. * * @param fn - Callback to be triggered when the value changes */ registerOnChange(fn: (value: string) => void): void; /** * Save a callback function to be invoked when the select is blurred by the user. * Part of the ControlValueAccessor interface required to integrate with Angular's core forms API. * * @param fn - Callback to be triggered when the component has been touched */ registerOnTouched(fn: () => {}): void; /** * Disables the select. * Part of the ControlValueAccessor interface required to integrate with Angular's core forms API. * * @param isDisabled - If the component is disabled */ setDisabledState(isDisabled: boolean): void; /** * Ensure the correct element gets focus when the primary container is clicked. * * Implemented as part of TsFormFieldControl. */ onContainerClick(): void; /** * Close the dropdown and reset the query when the user leaves the input * * @param event - The keyboard or mouse event */ handleInputBlur(event: KeyboardEvent | MouseEvent | FocusEvent): void; /** * Select an item * * @param selection - The item to select */ selectItem(selection: TsSelectionListPanelSelectedEvent): void; /** * Deselect an item * * @param option - The option to select */ deselectItem(option: TsChipEvent): void; /** * Function for tracking for-loops changes * * @param index - The item index * @returns The unique ID */ trackByFn(index: any): number; /** * Set up a key manager to listen to keyboard events on the overlay panel */ private initKeyManager; /** * Emit a change event to set the model value */ private propagateChanges; /** * Call FormControl updateValueAndValidity function to ensure value and valid status get updated. */ private updateValueAndValidity; /** * Reset input */ private resetAutocompleteQuery; /** * Scroll the active option into view */ private scrollActiveOptionIntoView; }