-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Common tag input component * Removed commented code * Merge branch 'dev' into feature/common-tag-input-component-1607 * Styling component * Using Tag input component in FF Add feature flag modal (#1650) * Using Tag input component in FF Add feature flag modal * Made tags as empty array in formbuilder. Removed required attribute from component --------- Co-authored-by: danoswaltCL <[email protected]>
- Loading branch information
1 parent
607014e
commit 0978442
Showing
7 changed files
with
152 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
|
||
.confirm-delete { | ||
margin-bottom: 12px; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ared-standalone-component-lib/components/common-tag-input/common-tag-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<mat-form-field appearance="outline" subscriptSizing="dynamic"> | ||
<mat-label class="ft-14-400"> | ||
{{ 'home.new-experiment.overview.tags.placeHolder' | translate }} | ||
</mat-label> | ||
<mat-chip-grid #tagsList class="chip-grid" aria-label="Tags" formControlName="tags"> | ||
<mat-chip-row | ||
*ngFor="let componentTag of tags.value" | ||
[selectable]="isChipSelectable" | ||
[removable]="isChipRemovable" | ||
(removed)="removeChip(componentTag)" | ||
> | ||
<span class="ft-12-600 chip-label"> | ||
{{ componentTag }} | ||
</span> | ||
<mat-icon matChipRemove *ngIf="isChipRemovable">cancel</mat-icon> | ||
</mat-chip-row> | ||
<input | ||
class="ft-14-400" | ||
[matChipInputFor]="tagsList" | ||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" | ||
[matChipInputAddOnBlur]="addChipOnBlur" | ||
(matChipInputTokenEnd)="addChip($event)" | ||
/> | ||
</mat-chip-grid> | ||
</mat-form-field> |
3 changes: 3 additions & 0 deletions
3
...ared-standalone-component-lib/components/common-tag-input/common-tag-input.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mat-form-field { | ||
width: 100%; | ||
} |
84 changes: 84 additions & 0 deletions
84
...shared-standalone-component-lib/components/common-tag-input/common-tag-input.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Component, forwardRef } from '@angular/core'; | ||
import { NG_VALUE_ACCESSOR, ControlValueAccessor, FormControl } from '@angular/forms'; | ||
import { MatChipInputEvent } from '@angular/material/chips'; | ||
import { ENTER, COMMA } from '@angular/cdk/keycodes'; | ||
import { CommonModule } from '@angular/common'; | ||
import { MatChipsModule } from '@angular/material/chips'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
// This Component is made to manage a list of tags using mat-chips. | ||
// It uses ControlValueAccessor which implements methods to synchronize the component's value with the parent form control. | ||
// writeValue(value: string[]): Sets the component's value. | ||
// registerOnChange(fn: any): Registers a callback for when the value changes. | ||
// registerOnTouched(fn: any): Registers a callback for when the component is touched. | ||
|
||
// Example Usage: | ||
// <app-common-tags-input formControlName="tags"></app-common-tags-input> | ||
|
||
@Component({ | ||
selector: 'app-common-tags-input', | ||
templateUrl: './common-tag-input.component.html', | ||
styleUrls: ['./common-tag-input.component.scss'], | ||
standalone: true, | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => CommonTagsInputComponent), | ||
multi: true, | ||
}, | ||
], | ||
imports: [CommonModule, MatChipsModule, MatFormFieldModule, MatIconModule, MatInputModule, TranslateModule], | ||
}) | ||
export class CommonTagsInputComponent implements ControlValueAccessor { | ||
isChipSelectable = true; | ||
isChipRemovable = true; | ||
addChipOnBlur = true; | ||
readonly separatorKeysCodes: number[] = [ENTER, COMMA]; | ||
|
||
tags = new FormControl<string[]>([]); | ||
|
||
addChip(event: MatChipInputEvent) { | ||
const input = event.chipInput; | ||
const value = (event.value || '').trim().toLowerCase(); | ||
|
||
// Add chip | ||
if (value) { | ||
const currentTags = this.tags.value || []; | ||
if (!currentTags.includes(value)) { | ||
this.tags.setValue([...currentTags, value]); | ||
this.tags.updateValueAndValidity(); | ||
} | ||
} | ||
|
||
// Reset the input value | ||
if (input) { | ||
input.clear(); | ||
} | ||
} | ||
|
||
removeChip(tag: string) { | ||
const currentTags = this.tags.value || []; | ||
const index = currentTags.indexOf(tag); | ||
|
||
if (index >= 0) { | ||
currentTags.splice(index, 1); | ||
this.tags.setValue(currentTags); | ||
this.tags.updateValueAndValidity(); | ||
} | ||
} | ||
|
||
// Implement ControlValueAccessor methods | ||
writeValue(value: string[]) { | ||
this.tags.setValue(value || []); | ||
} | ||
|
||
registerOnChange(fn: any) { | ||
this.tags.valueChanges.subscribe(fn); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
registerOnTouched(fn: any) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters