form
zard/formFreeComponent
@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/form.jsonSource
1import {2 booleanAttribute,3 ChangeDetectionStrategy,4 Component,5 computed,6 input,7 ViewEncapsulation,8} from '@angular/core';910import type { ClassValue } from 'clsx';1112import {13 formControlVariants,14 formFieldVariants,15 formLabelVariants,16 formMessageVariants,17 type ZardFormMessageTypeVariants,18} from '@/shared/components/form/form.variants';19import { mergeClasses } from '@/shared/utils/merge-classes';2021@Component({22 selector: 'z-form-field, [z-form-field]',23 template: '<ng-content />',24 changeDetection: ChangeDetectionStrategy.OnPush,25 encapsulation: ViewEncapsulation.None,26 host: {27 '[class]': 'classes()',28 },29 exportAs: 'zFormField',30})31export class ZardFormFieldComponent {32 readonly class = input<ClassValue>('');3334 protected readonly classes = computed(() => mergeClasses(formFieldVariants(), this.class()));35}3637@Component({38 selector: 'z-form-control, [z-form-control]',39 imports: [],40 template: `41 <div class="relative">42 <ng-content />43 </div>44 @if (errorMessage() || helpText()) {45 <div class="mt-1.5 min-h-5">46 @if (errorMessage()) {47 <p class="text-sm text-red-500">{{ errorMessage() }}</p>48 } @else if (helpText()) {49 <p class="text-muted-foreground text-sm">{{ helpText() }}</p>50 }51 </div>52 }53 `,54 changeDetection: ChangeDetectionStrategy.OnPush,55 encapsulation: ViewEncapsulation.None,56 host: {57 '[class]': 'classes()',58 },59 exportAs: 'zFormControl',60})61export class ZardFormControlComponent {62 readonly class = input<ClassValue>('');63 readonly errorMessage = input<string>('');64 readonly helpText = input<string>('');6566 protected readonly classes = computed(() => mergeClasses(formControlVariants(), this.class()));67}6869@Component({70 selector: 'z-form-label, label[z-form-label]',71 template: '<ng-content />',72 changeDetection: ChangeDetectionStrategy.OnPush,73 encapsulation: ViewEncapsulation.None,74 host: {75 '[class]': 'classes()',76 },77 exportAs: 'zFormLabel',78})79export class ZardFormLabelComponent {80 readonly class = input<ClassValue>('');81 readonly zRequired = input(false, { transform: booleanAttribute });8283 protected readonly classes = computed(() =>84 mergeClasses(formLabelVariants({ zRequired: this.zRequired() }), this.class()),85 );86}8788@Component({89 selector: 'z-form-message, [z-form-message]',90 template: '<ng-content />',91 changeDetection: ChangeDetectionStrategy.OnPush,92 encapsulation: ViewEncapsulation.None,93 host: {94// … 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 |
