Feature/allow creating custom tags in tag selector component (#4305)
* feat(ui): allow creating custom tags * feat(ui): add new story * Update changelog
This commit is contained in:
parent
56f943824e
commit
35ef06d27a
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Extended the tags selector component by a `readonly` attribute
|
- Extended the tags selector component by a `readonly` attribute
|
||||||
|
- Extended the tags selector component to support creating custom tags
|
||||||
- Added global styles to the _Storybook_ setup
|
- Added global styles to the _Storybook_ setup
|
||||||
|
|
||||||
## 2.138.0 - 2025-02-08
|
## 2.138.0 - 2025-02-08
|
||||||
|
@ -42,6 +42,17 @@
|
|||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (hasPermissionToCreateTags && tagInputControl.value) {
|
||||||
|
<mat-option [value]="tagInputControl.value.trim()">
|
||||||
|
<span class="align-items-center d-flex">
|
||||||
|
<ion-icon class="mr-2" name="add-circle-outline" />
|
||||||
|
<ng-container i18n>Create</ng-container> "{{
|
||||||
|
tagInputControl.value.trim()
|
||||||
|
}}"
|
||||||
|
</span>
|
||||||
|
</mat-option>
|
||||||
|
}
|
||||||
</mat-autocomplete>
|
</mat-autocomplete>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,20 @@ export const Default: Story = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CreateCustomTags: Story = {
|
||||||
|
args: {
|
||||||
|
hasPermissionToCreateTags: true,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
id: 'EMERGENCY_FUND',
|
||||||
|
name: 'Emergency Fund',
|
||||||
|
userId: null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
tagsAvailable: OPTIONS
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const Readonly: Story = {
|
export const Readonly: Story = {
|
||||||
args: {
|
args: {
|
||||||
readonly: true,
|
readonly: true,
|
||||||
|
@ -42,6 +42,7 @@ import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
|
|||||||
templateUrl: 'tags-selector.component.html'
|
templateUrl: 'tags-selector.component.html'
|
||||||
})
|
})
|
||||||
export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
|
export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
|
@Input() hasPermissionToCreateTags = false;
|
||||||
@Input() readonly = false;
|
@Input() readonly = false;
|
||||||
@Input() tags: Tag[];
|
@Input() tags: Tag[];
|
||||||
@Input() tagsAvailable: Tag[];
|
@Input() tagsAvailable: Tag[];
|
||||||
@ -76,10 +77,18 @@ export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onAddTag(event: MatAutocompleteSelectedEvent) {
|
public onAddTag(event: MatAutocompleteSelectedEvent) {
|
||||||
const tag = this.tagsAvailable.find(({ id }) => {
|
let tag = this.tagsAvailable.find(({ id }) => {
|
||||||
return id === event.option.value;
|
return id === event.option.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!tag && this.hasPermissionToCreateTags) {
|
||||||
|
tag = {
|
||||||
|
id: undefined,
|
||||||
|
name: event.option.value as string,
|
||||||
|
userId: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.tagsSelected.update((tags) => {
|
this.tagsSelected.update((tags) => {
|
||||||
return [...(tags ?? []), tag];
|
return [...(tags ?? []), tag];
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user