toggle-group
zard/toggle-groupFreeComponent
@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/toggle-group.jsonSource
1import { NgTemplateOutlet } from '@angular/common';2import {3 booleanAttribute,4 ChangeDetectionStrategy,5 Component,6 computed,7 forwardRef,8 input,9 linkedSignal,10 output,11 signal,12 type TemplateRef,13 ViewEncapsulation,14} from '@angular/core';15import { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';1617import { NgIcon, type IconName } from '@ng-icons/core';18import type { ClassValue } from 'clsx';1920import {21 toggleVariants,22 type ZardToggleSizeVariants,23 type ZardToggleTypeVariants,24} from '@/shared/components/toggle/toggle.variants';25import { mergeClasses } from '@/shared/utils/merge-classes';2627import { toggleGroupItemVariants, toggleGroupVariants } from './toggle-group.variants';2829export interface ZardToggleGroupItem {30 value: string;31 label?: string;32 icon?: IconName;33 template?: TemplateRef<void>;34 disabled?: boolean;35 ariaLabel?: string;36}3738type OnTouchedType = () => void;39type OnChangeType = (value: string | string[]) => void;4041@Component({42 selector: 'z-toggle-group',43 imports: [NgIcon, NgTemplateOutlet],44 template: `45 <div46 role="group"47 data-slot="toggle-group"48 [class]="classes()"49 [attr.data-variant]="zType()"50 [attr.data-size]="zSize()"51 [attr.data-orientation]="zOrientation()"52 [attr.data-horizontal]="zOrientation() === 'horizontal' || null"53 [attr.data-vertical]="zOrientation() === 'vertical' || null"54 [attr.data-spacing]="zSpacing()"55 [style.--gap]="zSpacing()"56 >57 @for (item of zItems(); track item.value) {58 <button59 type="button"60 data-slot="toggle-group-item"61 [attr.data-variant]="zType()"62 [attr.data-size]="zSize()"63 [attr.data-spacing]="zSpacing()"64 [attr.aria-pressed]="isItemPressed(item.value)"65 [attr.data-state]="isItemPressed(item.value) ? 'on' : 'off'"66 [attr.aria-label]="item.ariaLabel"67 [class]="itemClasses()"68 [disabled]="disabledState() || item.disabled"69 (click)="toggleItem(item)"70 >71 @if (item.template) {72 <ng-container [ngTemplateOutlet]="item.template" />73 } @else {74 @if (item.icon) {75 <ng-icon [name]="item.icon" class="size-4!" />76 }77 @if (item.label) {78 <span>{{ item.label }}</span>79 } @else if (!item.icon) {80 <span>{{ item.value }}</span>81 }82 }83 </button>84 }85// … truncated
What it pulls in
Other registry items
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 |
