checkbox
zard/checkboxFreeComponent
@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/checkbox.jsonSource
1import {2 booleanAttribute,3 ChangeDetectionStrategy,4 Component,5 computed,6 forwardRef,7 input,8 output,9 signal,10 ViewEncapsulation,11} from '@angular/core';12import { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';1314import { NgIcon, provideIcons } from '@ng-icons/core';15import { lucideCheck } from '@ng-icons/lucide';16import type { ClassValue } from 'clsx';1718import { ZardIdDirective } from '@/shared/core';19import { mergeClasses, noopFn } from '@/shared/utils/merge-classes';2021import { checkboxLabelVariants, checkboxVariants } from './checkbox.variants';2223type OnTouchedType = () => void;24type OnChangeType = (value: boolean) => void;2526@Component({27 selector: 'z-checkbox, [z-checkbox]',28 imports: [NgIcon, ZardIdDirective],29 template: `30 <span class="relative flex" zardId="checkbox" #z="zardId">31 <input32 #input33 type="checkbox"34 name="checkbox"35 [id]="zId() || z.id()"36 [class]="classes()"37 [checked]="checked()"38 [disabled]="disabled()"39 [attr.data-state]="checked() ? 'checked' : 'unchecked'"40 [attr.data-checked]="checked() ? '' : null"41 [attr.aria-invalid]="zInvalid() ? 'true' : null"42 (blur)="onCheckboxBlur()"43 (click)="onCheckboxChange()"44 />45 <ng-icon46 name="lucideCheck"47 class="text-primary-foreground pointer-events-none absolute top-1/2 left-1/2 flex -translate-1/2 items-center justify-center transition-opacity"48 [class]="checked() ? 'opacity-100' : 'opacity-0'"49 />50 </span>51 <label [class]="labelClasses()" [for]="zId() || z.id()">52 <ng-content />53 </label>54 `,55 providers: [56 {57 provide: NG_VALUE_ACCESSOR,58 useExisting: forwardRef(() => ZardCheckboxComponent),59 multi: true,60 },61 ],62 changeDetection: ChangeDetectionStrategy.OnPush,63 encapsulation: ViewEncapsulation.None,64 viewProviders: [provideIcons({ lucideCheck })],65 host: {66 'data-slot': 'checkbox',67 '[class]': "(disabled() ? 'cursor-not-allowed' : 'cursor-pointer') + ' flex items-center gap-2'",68 '[attr.aria-disabled]': 'disabled() ? "true" : null',69 '[attr.aria-invalid]': 'zInvalid() ? "true" : null',70 '[attr.data-checked]': "checked() ? '' : null",71 '[attr.data-state]': "checked() ? 'checked' : 'unchecked'",72 },73 exportAs: 'zCheckbox',74})75export class ZardCheckboxComponent implements ControlValueAccessor {76 readonly checkChange = output<boolean>();7778// … 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 |
