button
zard/buttonFreeComponent
@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/button.jsonSource
1import {2 afterNextRender,3 ChangeDetectionStrategy,4 Component,5 computed,6 type OnDestroy,7 ElementRef,8 inject,9 input,10 signal,11 ViewEncapsulation,12 booleanAttribute,13} from '@angular/core';1415import { NgIcon, provideIcons } from '@ng-icons/core';16import { lucideLoaderCircle } from '@ng-icons/lucide';17import type { ClassValue } from 'clsx';1819import { mergeClasses } from '@/shared/utils/merge-classes';2021import {22 buttonVariants,23 type ZardButtonShapeVariants,24 type ZardButtonSizeVariants,25 type ZardButtonTypeVariants,26} from './button.variants';2728@Component({29 selector: 'z-button, button[z-button], a[z-button]',30 imports: [NgIcon],31 template: `32 @if (zLoading()) {33 <ng-icon name="lucideLoaderCircle" class="animate-spin duration-2000" />34 }35 <ng-content />36 `,37 changeDetection: ChangeDetectionStrategy.OnPush,38 encapsulation: ViewEncapsulation.None,39 viewProviders: [provideIcons({ lucideLoaderCircle })],40 host: {41 'data-slot': 'button',42 '[class]': 'classes()',43 '[attr.data-disabled]': 'isNotInsideOfButtonOrLink() && zDisabled() || null',44 '[attr.data-icon-only]': 'iconOnly() || null',45 '[attr.data-size]': 'zSize()',46 '[attr.data-variant]': 'zType()',47 '[attr.aria-disabled]': 'isNotInsideOfButtonOrLink() && zDisabled() || null',48 '[attr.disabled]': 'isNotInsideOfButtonOrLink() && zDisabled() ? "" : null',49 '[attr.role]': 'isNotInsideOfButtonOrLink() ? "button" : null',50 '[attr.tabindex]': 'isNotInsideOfButtonOrLink() ? "0" : null',51 },52 exportAs: 'zButton',53})54export class ZardButtonComponent implements OnDestroy {55 private readonly elementRef = inject(ElementRef<HTMLElement>);5657 readonly zType = input<ZardButtonTypeVariants>('default');58 readonly zSize = input<ZardButtonSizeVariants>('default');59 readonly zShape = input<ZardButtonShapeVariants>('default');60 readonly class = input<ClassValue>('');61 readonly zLoading = input(false, { transform: booleanAttribute });62 readonly zDisabled = input(false, { transform: booleanAttribute });6364 private readonly iconOnlyState = signal(false);65 readonly iconOnly = this.iconOnlyState.asReadonly();6667 private _mutationObserver: MutationObserver | null = null;6869 constructor() {70 afterNextRender(() => {71 if (typeof window === 'undefined' || typeof MutationObserver === 'undefined') {72 return;73 }7475 const check = () => {76 const el = this.elementRef.nativeElement;77// … 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 | |
| button-groupbutton-group | @zard | Components | Free | no deps · 3 files | |
| calendarcalendar | @zard | Components | Free | no deps · 7 files |
