@ifsworld/granite-components 6.1.0 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -31,6 +31,10 @@ export * from './lib/button/button.module';
31
31
  export * from './lib/button/button.component';
32
32
  export * from './lib/input-field/input-field.module';
33
33
  export * from './lib/input-field/input-field.component';
34
+ export * from './lib/chips/chips.module';
35
+ export * from './lib/chips/chip-list.component';
36
+ export * from './lib/chips/chip.component';
37
+ export * from './lib/chips/chip-input';
34
38
  export * from './lib/label/label.module';
35
39
  export * from './lib/label/label.component';
36
40
  export * from './lib/core/client-environment';
@@ -0,0 +1,89 @@
1
+ import { AfterContentInit, ElementRef, EventEmitter, OnChanges, OnDestroy } from '@angular/core';
2
+ import { GraniteChipListComponent } from './chip-list.component';
3
+ import * as i0 from "@angular/core";
4
+ export interface GraniteChipTextControl {
5
+ /** Unique identifier for the text control. */
6
+ id: string;
7
+ /** The text control's placeholder text. */
8
+ placeholder: string;
9
+ /** Whether the text control has browser focus. */
10
+ focused: boolean;
11
+ /** Whether the text control is empty. */
12
+ empty: boolean;
13
+ /** Focuses the text control. */
14
+ setFocus(options?: FocusOptions): void;
15
+ }
16
+ /** Represents an input event on a `graniteChipInput`. */
17
+ export interface GraniteChipInputEvent {
18
+ /** The native `<input>` element that the event is being fired for. */
19
+ input: HTMLInputElement;
20
+ /** The value of the input. */
21
+ value: string;
22
+ /** Reference to the chip input that emitted the event. */
23
+ chipInput: GraniteChipInputDirective;
24
+ }
25
+ export declare class GraniteChipInputDirective implements GraniteChipTextControl, OnChanges, OnDestroy, AfterContentInit {
26
+ protected _elementRef: ElementRef<HTMLInputElement>;
27
+ /** Unique id for the input. */
28
+ id: string;
29
+ /** The input's placeholder text. */
30
+ placeholder: string;
31
+ /** Register input for chip list */
32
+ set graniteChipInputFor(value: GraniteChipListComponent);
33
+ /**
34
+ * The list of key codes that will trigger a chipEnd event.
35
+ *
36
+ * Defaults to `[ENTER]`.
37
+ */
38
+ graniteChipInputSeparatorKeyCodes: readonly number[] | ReadonlySet<number>;
39
+ /**
40
+ * Whether or not the chipEnd event will be emitted when the input is blurred.
41
+ */
42
+ get graniteChipInputAddOnBlur(): boolean;
43
+ set graniteChipInputAddOnBlur(value: boolean);
44
+ _addOnBlur: boolean;
45
+ /**
46
+ * Whether this is a required field, currently we use it only for setting aria-required.
47
+ */
48
+ get required(): boolean;
49
+ set required(value: boolean);
50
+ protected _required: boolean | undefined;
51
+ /** Whether the input is disabled. */
52
+ get disabled(): boolean;
53
+ set disabled(value: boolean);
54
+ private _disabled;
55
+ /** Emitted when a chip is to be added. */
56
+ readonly graniteChipInputTokenEnd: EventEmitter<GraniteChipInputEvent>;
57
+ /** The native input element to which this directive is attached. */
58
+ readonly inputElement: HTMLInputElement;
59
+ _chipList: GraniteChipListComponent;
60
+ focused: boolean;
61
+ /** Used to prevent focus moving to chips while user is holding backspace */
62
+ private _focusLastChipOnBackspace;
63
+ constructor(_elementRef: ElementRef<HTMLInputElement>);
64
+ ngOnChanges(): void;
65
+ ngOnDestroy(): void;
66
+ ngAfterContentInit(): void;
67
+ /** Utility method to make host definition/tests more clear. */
68
+ _keydown(event?: KeyboardEvent): void;
69
+ /**
70
+ * Pass events to the keyboard manager. Available here for tests.
71
+ */
72
+ _keyup(event: KeyboardEvent): void;
73
+ /** Checks to see if the blur should emit the (chipEnd) event. */
74
+ _blur(): void;
75
+ _focus(): void;
76
+ /** Checks to see if the (chipEnd) event needs to be emitted. */
77
+ _emitChipEnd(event?: KeyboardEvent): void;
78
+ _onInput(): void;
79
+ /** Focuses the input (called from parent level). */
80
+ setFocus(options?: FocusOptions): void;
81
+ /** Clears the input */
82
+ clear(): void;
83
+ /** Whether the input is empty. */
84
+ get empty(): boolean;
85
+ /** Checks whether a keycode is one of the configured separators. */
86
+ private _isSeparatorKey;
87
+ static ɵfac: i0.ɵɵFactoryDeclaration<GraniteChipInputDirective, never>;
88
+ static ɵdir: i0.ɵɵDirectiveDeclaration<GraniteChipInputDirective, "input[graniteChipInputFor]", ["graniteChipInput", "graniteChipInputFor"], { "id": "id"; "placeholder": "placeholder"; "graniteChipInputFor": "graniteChipInputFor"; "graniteChipInputSeparatorKeyCodes": "graniteChipInputSeparatorKeyCodes"; "graniteChipInputAddOnBlur": "graniteChipInputAddOnBlur"; "required": "required"; "disabled": "disabled"; }, { "graniteChipInputTokenEnd": "graniteChipInputTokenEnd"; }, never>;
89
+ }
@@ -0,0 +1,185 @@
1
+ import { FocusKeyManager } from '@angular/cdk/a11y';
2
+ import { Directionality } from '@angular/cdk/bidi';
3
+ import { SelectionModel } from '@angular/cdk/collections';
4
+ import { AfterContentInit, ChangeDetectorRef, DoCheck, ElementRef, OnDestroy, OnInit, QueryList, EventEmitter } from '@angular/core';
5
+ import { ControlValueAccessor, FormGroupDirective, NgControl, NgForm } from '@angular/forms';
6
+ import { Observable } from 'rxjs';
7
+ import { GraniteChipComponent, GraniteChipEvent, GraniteChipSelectionChangeEvent } from './chip.component';
8
+ import { GraniteChipTextControl } from './chip-input';
9
+ import * as i0 from "@angular/core";
10
+ declare abstract class GraniteChipListBase {
11
+ _parentForm: NgForm;
12
+ _parentFormGroup: FormGroupDirective;
13
+ ngControl: NgControl;
14
+ readonly stateChanges: EventEmitter<void>;
15
+ constructor(_parentForm: NgForm, _parentFormGroup: FormGroupDirective, ngControl: NgControl);
16
+ }
17
+ export declare class GraniteChipListComponent extends GraniteChipListBase implements ControlValueAccessor, AfterContentInit, DoCheck, OnInit, OnDestroy {
18
+ protected _elementRef: ElementRef<HTMLElement>;
19
+ private _changeDetectorRef;
20
+ private _dir;
21
+ readonly controlType: string;
22
+ /**
23
+ * When a chip is destroyed, we store the index of the destroyed chip until the chips
24
+ * query list notifies about the update. This is necessary because we cannot determine an
25
+ * appropriate chip that should receive focus until the array of chips updated completely.
26
+ */
27
+ private _lastDestroyedChipIndex;
28
+ /** Subject that emits when the component has been destroyed. */
29
+ private readonly _destroyed;
30
+ /** Subscription to focus changes in the chips. */
31
+ private _chipFocusSubscription;
32
+ /** Subscription to blur changes in the chips. */
33
+ private _chipBlurSubscription;
34
+ /** Subscription to selection changes in chips. */
35
+ private _chipSelectionSubscription;
36
+ /** Subscription to remove changes in chips. */
37
+ private _chipRemoveSubscription;
38
+ /** The chip input to add more chips */
39
+ protected _chipInput: GraniteChipTextControl;
40
+ /** Uid of the chip list */
41
+ _uid: string;
42
+ /** Tab index for the chip list. */
43
+ _tabIndex: number;
44
+ /**
45
+ * User defined tab index.
46
+ * When it is not null, use user defined tab index. Otherwise use _tabIndex
47
+ */
48
+ _userTabIndex: number | null;
49
+ /** The FocusKeyManager which handles focus. */
50
+ _keyManager: FocusKeyManager<GraniteChipComponent>;
51
+ _selectionModel: SelectionModel<GraniteChipComponent>;
52
+ /** The ARIA role applied to the chip list. */
53
+ get role(): string | null;
54
+ set role(role: string | null);
55
+ private _explicitRole?;
56
+ /** Whether the user should be allowed to select multiselect chips. */
57
+ get multiselect(): boolean;
58
+ set multiselect(value: boolean);
59
+ private _multiple;
60
+ /**
61
+ * Whether the chip list is disabled.
62
+ */
63
+ get disabled(): boolean;
64
+ set disabled(value: boolean);
65
+ protected _disabled: boolean;
66
+ /**
67
+ * Whether or not this chip list is selectable. When a chip list is not selectable,
68
+ * the selected states for all the chips inside the chip list are always ignored.
69
+ */
70
+ get selectable(): boolean;
71
+ set selectable(value: boolean);
72
+ protected _selectable: boolean;
73
+ set tabindex(value: number);
74
+ ariaLabel: string | null;
75
+ ariaLabelledby: string | null;
76
+ ariaOrientation: 'horizontal' | 'vertical';
77
+ /** The chips contained within this chip list. */
78
+ chips: QueryList<GraniteChipComponent>;
79
+ /** Unique identifier for the chip list. */
80
+ get id(): string;
81
+ /** Whether any chips or the matChipInput inside of this chip-list has focus. */
82
+ get focused(): boolean;
83
+ /** Whether the chip list is empty. */
84
+ get empty(): boolean;
85
+ /** The array of selected chips inside chip list. */
86
+ get selected(): GraniteChipComponent[] | GraniteChipComponent;
87
+ /** Combined stream of all of the child chips' selection change events. */
88
+ get chipSelectionChanges(): Observable<GraniteChipSelectionChangeEvent>;
89
+ /** Combined stream of all of the child chips' focus change events. */
90
+ get chipFocusChanges(): Observable<GraniteChipEvent>;
91
+ /** Combined stream of all of the child chips' blur change events. */
92
+ get chipBlurChanges(): Observable<GraniteChipEvent>;
93
+ /** Combined stream of all of the child chips' remove change events. */
94
+ get chipRemoveChanges(): Observable<GraniteChipEvent>;
95
+ /** Function when changed */
96
+ _onChange: (value: any) => void;
97
+ /** Function when changed */
98
+ _onTouched: () => void;
99
+ constructor(_elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, _dir: Directionality, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, ngControl: NgControl);
100
+ ngAfterContentInit(): void;
101
+ ngOnInit(): void;
102
+ ngDoCheck(): void;
103
+ ngOnDestroy(): void;
104
+ /** Associates an HTML input element with this chip list. */
105
+ registerInput(inputElement: GraniteChipTextControl): void;
106
+ writeValue(value: any): void;
107
+ registerOnChange(fn: (value: any) => void): void;
108
+ registerOnTouched(fn: () => void): void;
109
+ setDisabledState(isDisabled: boolean): void;
110
+ /**
111
+ * Focus chip list when click on the container.
112
+ */
113
+ onContainerClick(event: MouseEvent): void;
114
+ /**
115
+ * Focuses the first non-disabled chip in this chip list, or the associated input when there
116
+ * are no eligible chips.
117
+ */
118
+ focus(options?: FocusOptions): void;
119
+ /** Attempt to focus an input if we have one. */
120
+ _focusInput(options?: FocusOptions): void;
121
+ /**
122
+ * Pass events to the keyboard manager. Available here for tests.
123
+ */
124
+ _keydown(event: KeyboardEvent): void;
125
+ /**
126
+ * Check the tab index as you should not be allowed to focus an empty list.
127
+ */
128
+ protected _updateTabIndex(): void;
129
+ /**
130
+ * If the amount of chips changed, we need to update the
131
+ * key manager state and focus the next closest chip.
132
+ */
133
+ protected _updateFocusForDestroyedChips(): void;
134
+ /**
135
+ * Utility to ensure all indexes are valid.
136
+ *
137
+ * @param index The index to be checked.
138
+ * @returns True if the index is valid for our list of chips.
139
+ */
140
+ private _isValidIndex;
141
+ private _setSelectionByValue;
142
+ /**
143
+ * Finds and selects the chip based on its value.
144
+ * @returns Chip that has the corresponding value.
145
+ */
146
+ private _selectValue;
147
+ private _initializeSelection;
148
+ /**
149
+ * Deselects every chip in the list.
150
+ * @param skip Chip that should not be deselected.
151
+ */
152
+ private _clearSelection;
153
+ /**
154
+ * Sorts the model values, ensuring that they keep the same
155
+ * order that they have in the panel.
156
+ */
157
+ private _sortValues;
158
+ private _compareWith;
159
+ /** When blurred, mark the field as touched when focus moved outside the chip list. */
160
+ _blur(): void;
161
+ /** Mark the field as touched */
162
+ _markAsTouched(): void;
163
+ /**
164
+ * Removes the `tabindex` from the chip list and resets it back afterwards, allowing the
165
+ * user to tab out of it. This prevents the list from capturing focus and redirecting
166
+ * it back to the first chip, creating a focus trap, if it user tries to tab away.
167
+ */
168
+ _allowFocusEscape(): void;
169
+ private _resetChips;
170
+ private _dropSubscriptions;
171
+ /** Listens to user-generated selection events on each chip. */
172
+ private _listenToChipsSelection;
173
+ /** Listens to user-generated selection events on each chip. */
174
+ private _listenToChipsFocus;
175
+ private _listenToChipsRemoved;
176
+ /** Checks whether an event comes from inside a chip element. */
177
+ private _originatesFromChip;
178
+ /** Checks whether any of the chips is focused. */
179
+ private _hasFocusedChip;
180
+ /** Syncs the list's state with the individual chips. */
181
+ private _syncChipsState;
182
+ static ɵfac: i0.ɵɵFactoryDeclaration<GraniteChipListComponent, [null, null, { optional: true; }, { optional: true; }, { optional: true; }, { optional: true; self: true; }]>;
183
+ static ɵcmp: i0.ɵɵComponentDeclaration<GraniteChipListComponent, "granite-chip-list", ["graniteChipList"], { "role": "role"; "multiselect": "multiselect"; "disabled": "disabled"; "selectable": "selectable"; "tabindex": "tabindex"; "ariaLabel": "aria-label"; "ariaLabelledby": "aria-labelledby"; "ariaOrientation": "aria-orientation"; }, {}, ["chips"], ["*"]>;
184
+ }
185
+ export {};
@@ -0,0 +1,104 @@
1
+ import { FocusableOption } from '@angular/cdk/a11y';
2
+ import { ChangeDetectorRef, ElementRef, EventEmitter, NgZone, OnDestroy } from '@angular/core';
3
+ import * as i0 from "@angular/core";
4
+ /** Event fired on an individual `granite-chip` element. */
5
+ export interface GraniteChipEvent {
6
+ /** The chip the event was fired on. */
7
+ chip: GraniteChipComponent;
8
+ }
9
+ /** Event object emitted by GraniteChip when selected or deselected. */
10
+ export declare class GraniteChipSelectionChangeEvent {
11
+ /** Reference to the chip that emitted the event. */
12
+ source: GraniteChipComponent;
13
+ /** Whether the chip that emitted the event is selected. */
14
+ selected: boolean;
15
+ /** Whether the selection change was a result of a user interaction. */
16
+ isUserInput: boolean;
17
+ }
18
+ export declare class GraniteChipComponent implements FocusableOption, OnDestroy {
19
+ _elementRef: ElementRef;
20
+ private _ngZone;
21
+ private _changeDetectorRef;
22
+ /** Whether the chip has focus. */
23
+ _hasFocus: boolean;
24
+ /** Whether the chip list is selectable */
25
+ _chipListSelectable: boolean;
26
+ /** Whether the chip list is in multi-selection mode. */
27
+ _chipListMultiple: boolean;
28
+ /** Whether the chip list as a whole is disabled. */
29
+ _chipListDisabled: boolean;
30
+ /** ARIA role that should be applied to the chip. */
31
+ role: string;
32
+ /** Whether the chip is selected. */
33
+ get selected(): boolean;
34
+ set selected(value: boolean);
35
+ protected _selected: boolean;
36
+ /** The value of the chip. Defaults to the text content inside `<granite-chip>` tags. */
37
+ get value(): any;
38
+ set value(val: any);
39
+ private _value;
40
+ /**
41
+ * Whether or not the chip is selectable. When a chip is not selectable,
42
+ * changes to its selected state are always ignored. By default a chip is
43
+ * selectable, and it becomes non-selectable if its parent chip list is
44
+ * not selectable.
45
+ */
46
+ get selectable(): boolean;
47
+ set selectable(value: boolean);
48
+ protected _selectable: boolean;
49
+ /** Whether the chip is disabled. Also the individual chips are disabled when chip list is disabled */
50
+ get disabled(): boolean;
51
+ set disabled(value: boolean);
52
+ protected _disabled: boolean;
53
+ /**
54
+ * Whether the chip can be removed from the list
55
+ */
56
+ get removable(): boolean;
57
+ set removable(value: boolean);
58
+ protected _removable: boolean;
59
+ /** Whether the chip is in an invalid state. */
60
+ get invalid(): boolean;
61
+ set invalid(value: boolean);
62
+ protected _invalid: boolean;
63
+ ariaLabel: string | null;
64
+ ariaLabelledby: string | null;
65
+ /** Emitted when the chip is selected or deselected. */
66
+ readonly selectionChange: EventEmitter<GraniteChipSelectionChangeEvent>;
67
+ /** Emitted when a chip is to be removed. */
68
+ readonly removed: EventEmitter<GraniteChipEvent>;
69
+ /** Emitted when the chip is destroyed. */
70
+ readonly destroyed: EventEmitter<GraniteChipEvent>;
71
+ tabIndex: number;
72
+ inputChip: boolean;
73
+ /** Emits when the chip is focused. */
74
+ readonly chipFocus: EventEmitter<GraniteChipEvent>;
75
+ /** Emits when the chip is blurred. */
76
+ readonly chipBlur: EventEmitter<GraniteChipEvent>;
77
+ constructor(_elementRef: ElementRef, _ngZone: NgZone, _changeDetectorRef: ChangeDetectorRef, tabIndex?: string);
78
+ ngOnDestroy(): void;
79
+ /** Selects the chip. */
80
+ select(isUserInput?: boolean): void;
81
+ /** Deselects the chip. */
82
+ deselect(): void;
83
+ /** Toggles the current selected state of this chip. */
84
+ toggleSelected(isUserInput?: boolean): boolean;
85
+ /** Allows for programmatic focusing of the chip unless it's disabled. */
86
+ focus(): void;
87
+ /**
88
+ * Allows for programmatic removal of the chip.
89
+ * Called by the GraniteChipList when the DELETE or BACKSPACE keys are pressed.
90
+ * Informs any listeners of the removal request. Does not remove the chip from the DOM.
91
+ */
92
+ remove(): void;
93
+ /** Handles click events on the chip. */
94
+ _handleClick(event: Event): void;
95
+ /** Handle custom key presses. */
96
+ _handleKeydown(event: KeyboardEvent): void;
97
+ _handleRemoveClick(event: Event): void;
98
+ _blur(): void;
99
+ private _dispatchSelectionChange;
100
+ /** The ARIA selected applied to the chip. */
101
+ get ariaSelected(): string | null;
102
+ static ɵfac: i0.ɵɵFactoryDeclaration<GraniteChipComponent, [null, null, { optional: true; }, { attribute: "tabindex"; }]>;
103
+ static ɵcmp: i0.ɵɵComponentDeclaration<GraniteChipComponent, "granite-chip, granite-input-chip", ["graniteChip"], { "tabIndex": "tabIndex"; "role": "role"; "selected": "selected"; "value": "value"; "selectable": "selectable"; "disabled": "disabled"; "removable": "removable"; "invalid": "invalid"; "ariaLabel": "aria-label"; "ariaLabelledby": "aria-labelledby"; }, { "selectionChange": "selectionChange"; "removed": "removed"; "destroyed": "destroyed"; "chipFocus": "chipFocus"; "chipBlur": "chipBlur"; }, never, ["*"]>;
104
+ }
@@ -0,0 +1,12 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./chip-list.component";
3
+ import * as i2 from "./chip.component";
4
+ import * as i3 from "./chip-input";
5
+ import * as i4 from "@angular/common";
6
+ import * as i5 from "@angular/forms";
7
+ import * as i6 from "../icon/icon.module";
8
+ export declare class GraniteChipsModule {
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<GraniteChipsModule, never>;
10
+ static ɵmod: i0.ɵɵNgModuleDeclaration<GraniteChipsModule, [typeof i1.GraniteChipListComponent, typeof i2.GraniteChipComponent, typeof i3.GraniteChipInputDirective], [typeof i4.CommonModule, typeof i5.FormsModule, typeof i5.ReactiveFormsModule, typeof i6.GraniteIconModule], [typeof i1.GraniteChipListComponent, typeof i2.GraniteChipComponent, typeof i3.GraniteChipInputDirective]>;
11
+ static ɵinj: i0.ɵɵInjectorDeclaration<GraniteChipsModule>;
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ifsworld/granite-components",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "peerDependencies": {
5
5
  "@angular/cdk": ">=13.0.0",
6
6
  "@angular/common": ">=13.0.0",
@@ -14,6 +14,7 @@
14
14
  "rxjs": ">=6.0.0",
15
15
  "@microsoft/applicationinsights-web": "^2.8.4",
16
16
  "@microsoft/applicationinsights-clickanalytics-js": "^2.8.4",
17
+ "@angular/forms": "13.3.11",
17
18
  "primeng": "13.4.1"
18
19
  },
19
20
  "dependencies": {