textarea
zard/textareaFreeComponent
@zard publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by @zard on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.zardui.com/r/textarea.jsonSource
1import {2 ChangeDetectionStrategy,3 Component,4 computed,5 effect,6 ElementRef,7 forwardRef,8 inject,9 input,10 model,11 ViewEncapsulation,12} from '@angular/core';13import { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';1415import type { ClassValue } from 'clsx';1617import { ZardInputGroupComponent } from '@/shared/components/input-group';18import { mergeClasses, noopFn } from '@/shared/utils/merge-classes';1920import { inputGroupTextAreaVariants, textareaVariants } from './textarea.variants';2122type OnTouchedType = () => void;23type OnChangeType = (value: string) => void;2425@Component({26 selector: 'textarea[z-textarea]',27 template: '',28 providers: [29 {30 provide: NG_VALUE_ACCESSOR,31 useExisting: forwardRef(() => ZardTextareaComponent),32 multi: true,33 },34 ],35 changeDetection: ChangeDetectionStrategy.OnPush,36 encapsulation: ViewEncapsulation.None,37 host: {38 '[attr.data-slot]': 'parentGroup ? "input-group-control" : "textarea"',39 '[class]': 'classes()',40 '(input)': 'updateValue($event.target)',41 '(blur)': 'onBlur()',42 },43 exportAs: 'zTextarea',44})45export class ZardTextareaComponent implements ControlValueAccessor {46 readonly parentGroup = inject(ZardInputGroupComponent, { optional: true });47 private readonly elementRef = inject(ElementRef<HTMLTextAreaElement>);4849 private onTouchedFn: OnTouchedType = noopFn;50 private onChangeFn: OnChangeType = noopFn;5152 readonly class = input<ClassValue>('');53 readonly value = model<string>('');5455 protected readonly classes = computed(() =>56 mergeClasses(textareaVariants(), this.parentGroup ? inputGroupTextAreaVariants() : '', this.class()),57 );5859 constructor() {60 effect(() => {61 const value = this.value();62 if (value !== undefined && value !== null) {63 this.elementRef.nativeElement.value = value;64 }65 });66 }6768 disable(b: boolean): void {69 this.elementRef.nativeElement.disabled = b;70 }7172 protected updateValue(target: EventTarget | null): void {73 const el = target as HTMLTextAreaElement | null;74 this.value.set(el?.value ?? '');75 this.onChangeFn(this.value());76 }7778 protected onBlur(): void {79 this.onTouchedFn();80 }8182 registerOnChange(fn: OnChangeType): void {83 this.onChangeFn = fn;84 }8586 registerOnTouched(fn: OnTouchedType): void {87 this.onTouchedFn = fn;88 }8990 setDisabledState(isDisabled: boolean): void {91 this.elementRef.nativeElement.disabled = isDisabled;92 }9394// … truncated
Files it writes
More from @zard
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | @zard | Components | Free | no deps · 5 files | |
| alertalert | @zard | Components | Free | no deps · 3 files | |
| alert-dialogalert-dialog | @zard | Components | Free | no deps · 5 files | |
| avataravatar | @zard | Components | Free | no deps · 4 files | |
| badgebadge | @zard | Components | Free | no deps · 3 files | |
| breadcrumbbreadcrumb | @zard | Components | Free | no deps · 4 files | |
| buttonbutton | @zard | Components | Free | no deps · 3 files | |
| button-groupbutton-group | @zard | Components | Free | no deps · 3 files |
