feat: textarea/div component in nwui
This commit is contained in:
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './textarea.component';
|
||||
@@ -0,0 +1,5 @@
|
||||
<div [attr.contenteditable]="contenteditable" [className]="className" #ref (blur)="leaveFn()">
|
||||
@if(!value) {
|
||||
<ng-content></ng-content>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
.nwui-textarea {
|
||||
border-radius: 8px;
|
||||
height: auto;
|
||||
color: #efdee0;
|
||||
outline: none;
|
||||
padding-inline: 2rem 1rem;
|
||||
background-color: transparent;
|
||||
border: 2px solid #e4bdc3;
|
||||
font-size: 1rem;
|
||||
font-weight: inherit;
|
||||
min-height: 3rem;
|
||||
line-height: 3rem;
|
||||
&:focus {
|
||||
border: 2px solid #efdee0;
|
||||
}
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
word-wrap: break-word;
|
||||
}
|
||||
36
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
36
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'nwui-textarea',
|
||||
imports: [CommonModule],
|
||||
standalone: true,
|
||||
styleUrls: ['./textarea.component.scss'],
|
||||
templateUrl: './textarea.component.html',
|
||||
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class NWUITextAreaComponent implements AfterViewInit {
|
||||
@Input() disabled = false;
|
||||
@Input() value = '';
|
||||
@Input() contenteditable = true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
@Output() leave = new EventEmitter<string>();
|
||||
@ViewChild('ref') ref: ElementRef<HTMLDivElement> | null = null;
|
||||
|
||||
get className(): string {
|
||||
return `nwui-textarea ${this.disabled && !this.contenteditable ? 'disabled' : ''}`;
|
||||
}
|
||||
|
||||
leaveFn() {
|
||||
if (this.ref) {
|
||||
const target = this.ref.nativeElement;
|
||||
const text = target.textContent || '';
|
||||
if (this.leave) this.leave.emit(text);
|
||||
target.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
if (this.ref && this.value) this.ref.nativeElement.textContent = this.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user