通用可编辑tag组件-边框,编辑按钮
This commit is contained in:
@@ -3,7 +3,9 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} f
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'editable-tag',
|
selector: 'editable-tag',
|
||||||
template: `
|
template: `
|
||||||
<nz-tag *ngIf="!inputVisible" class="editable-tag" title="双击进入编辑" [nzColor]="color" nzNoAnimation (click)="showInput(true)">
|
<nz-tag *ngIf="!inputVisible" class="editable-tag" title="双击进入编辑" [nzColor]="color" nzNoAnimation
|
||||||
|
(click)="showInput(true)"
|
||||||
|
[style.border-style]="showBorder ? 'solid': 'none'">
|
||||||
<ng-content></ng-content>
|
<ng-content></ng-content>
|
||||||
</nz-tag>
|
</nz-tag>
|
||||||
<input #inputElement
|
<input #inputElement
|
||||||
@@ -16,11 +18,15 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} f
|
|||||||
(blur)="handleInputConfirm()"
|
(blur)="handleInputConfirm()"
|
||||||
(keydown.enter)="handleInputConfirm()"
|
(keydown.enter)="handleInputConfirm()"
|
||||||
/>
|
/>
|
||||||
<i nz-icon nzType="edit" nzTheme="fill" style="cursor: pointer" (click)="showInput(false)"></i>
|
<i nz-icon *ngIf="showEditIcon"
|
||||||
|
nzType="edit"
|
||||||
|
nzTheme="fill"
|
||||||
|
style="cursor: pointer;margin-right: 8px;"
|
||||||
|
(click)="showInput(false)">
|
||||||
|
</i>
|
||||||
`,
|
`,
|
||||||
styles: [`.editable-tag {
|
styles: [`.editable-tag {
|
||||||
background: rgb(255, 255, 255);
|
background: rgb(255, 255, 255);
|
||||||
border-style: none;
|
|
||||||
}`]
|
}`]
|
||||||
})
|
})
|
||||||
export class EditableTagComponent implements OnInit {
|
export class EditableTagComponent implements OnInit {
|
||||||
@@ -34,11 +40,19 @@ export class EditableTagComponent implements OnInit {
|
|||||||
|
|
||||||
@Output() valueChange = new EventEmitter<string>();
|
@Output() valueChange = new EventEmitter<string>();
|
||||||
@Input() color: string;
|
@Input() color: string;
|
||||||
|
@Input() showEditIcon: boolean;
|
||||||
|
@Input() showBorder: boolean;
|
||||||
private doubleClickInfo = {
|
private doubleClickInfo = {
|
||||||
date: null,
|
date: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
if (this.showEditIcon == null) {
|
||||||
|
this.showEditIcon = true;
|
||||||
|
}
|
||||||
|
if (this.showBorder == null) {
|
||||||
|
this.showBorder = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showInput(doubleClick: boolean): void {
|
showInput(doubleClick: boolean): void {
|
||||||
|
|||||||
@@ -23,4 +23,6 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
|
||||||
<editable-tag >hhh</editable-tag>
|
<editable-tag color="green">hhh</editable-tag>
|
||||||
|
<editable-tag color="green" [showEditIcon]="false">hhh</editable-tag>
|
||||||
|
<editable-tag color="green" [showBorder]="false">hhh</editable-tag>
|
||||||
|
|||||||
Reference in New Issue
Block a user