BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/@zard/switch

switch

zard/switch
FreeComponent

@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/switch.json

Source

switch.component.tswww.zardui.com/r/switch.json
1import {
2 booleanAttribute,
3 ChangeDetectionStrategy,
4 Component,
5 computed,
6 forwardRef,
7 input,
8 model,
9 signal,
10 ViewEncapsulation,
11} from '@angular/core';
12import { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
13
14import type { ClassValue } from 'clsx';
15
16import { ZardIdDirective } from '@/shared/core';
17import { mergeClasses, noopFn } from '@/shared/utils/merge-classes';
18
19import { switchVariants, type ZardSwitchSizeVariants } from './switch.variants';
20
21type OnTouchedType = () => void;
22type OnChangeType = (value: boolean) => void;
23
24@Component({
25 selector: 'z-switch',
26 imports: [ZardIdDirective],
27 template: `
28 <span class="flex items-center space-x-2" zardId="switch" #z="zardId" [attr.data-checked]="zChecked() ? '' : null">
29 <button
30 [id]="zId() || z.id()"
31 type="button"
32 role="switch"
33 [attr.data-state]="status()"
34 [attr.aria-checked]="zChecked()"
35 [attr.aria-invalid]="zInvalid() ? 'true' : null"
36 [class]="classes()"
37 [disabled]="zDisabled() || formDisabled()"
38 (click)="onSwitchChange()"
39 >
40 <span
41 [attr.data-size]="zSize()"
42 [attr.data-state]="status()"
43 class="bg-background dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground pointer-events-none block rounded-full ring-0 transition-transform data-[size=default]:size-4 data-[size=sm]:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
44 ></span>
45 </button>
46
47 <label
48 class="text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
49 [for]="zId() || z.id()"
50 >
51 <ng-content><span class="sr-only">toggle switch</span></ng-content>
52 </label>
53 </span>
54 `,
55 providers: [
56 {
57 provide: NG_VALUE_ACCESSOR,
58 useExisting: forwardRef(() => ZardSwitchComponent),
59 multi: true,
60 },
61 ],
62 changeDetection: ChangeDetectionStrategy.OnPush,
63 encapsulation: ViewEncapsulation.None,
64 exportAs: 'zSwitch',
65})
66export class ZardSwitchComponent implements ControlValueAccessor {
67 readonly class = input<ClassValue>('');
68 readonly zChecked = model<boolean>(false);
69 readonly zId = input<string>('');
70 readonly zSize = input<ZardSwitchSizeVariants>('default');
71 readonly zDisabled = input(false, { transform: booleanAttribute });
72 readonly zInvalid = input(false, { transform: booleanAttribute });
73
74// … truncated

Files it writes

  • switch.component.ts
  • switch.variants.ts
  • index.ts

Facts

Registry
@zard
Type
registry:component
Access
Free
Files written
3
Licence
MIT
First indexed
2026-08-06
Last confirmed
yesterday

Go to the source

Docs on @zard www.zardui.com zard-ui/zardui on GitHub Raw registry item This item as JSON

More from @zard

All 49 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
accordionaccordion@zardComponentsFreeno deps · 5 files
alertalert@zardComponentsFreeno deps · 3 files
alert-dialogalert-dialog@zardComponentsFreeno deps · 5 files
avataravatar@zardComponentsFreeno deps · 4 files
badgebadge@zardComponentsFreeno deps · 3 files
breadcrumbbreadcrumb@zardComponentsFreeno deps · 4 files
buttonbutton@zardComponentsFreeno deps · 3 files
button-groupbutton-group@zardComponentsFreeno deps · 3 files
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex