slider
zard/sliderFreeComponent
@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/slider.jsonSource
1import { DOCUMENT } from '@angular/common';2import {3 type AfterViewInit,4 booleanAttribute,5 ChangeDetectionStrategy,6 Component,7 computed,8 DestroyRef,9 ElementRef,10 forwardRef,11 inject,12 input,13 linkedSignal,14 numberAttribute,15 output,16 signal,17 viewChild,18 viewChildren,19 ViewEncapsulation,20} from '@angular/core';21import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';22import { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';2324import type { ClassValue } from 'clsx';25import { filter, fromEvent, map, switchMap, takeUntil, tap } from 'rxjs';2627import { mergeClasses, noopFn } from '@/shared/utils/merge-classes';28import { clamp, convertValueToPercentage, roundToStep } from '@/shared/utils/number';2930import {31 sliderOrientationVariants,32 sliderRangeVariants,33 sliderThumbVariants,34 sliderTrackVariants,35 sliderVariants,36} from './slider.variants';3738type OnTouchedType = () => void;39type OnChangeType = (value: number[]) => void;4041@Component({42 selector: 'z-slider-track',43 template: `44 <span #track data-slot="slider-track" [attr.data-orientation]="orientation()" [class]="classes()">45 <ng-content />46 </span>47 `,48 changeDetection: ChangeDetectionStrategy.OnPush,49 encapsulation: ViewEncapsulation.None,50 host: {51 '[style.width]': '"inherit"',52 '[style.height]': '"100%"',53 '[attr.data-orientation]': 'orientation()',54 },55})56export class ZSliderTrackComponent {57 readonly orientation = input<'horizontal' | 'vertical'>('horizontal');58 readonly class = input<ClassValue>('');5960 protected readonly classes = computed(() => mergeClasses(sliderTrackVariants(), 'flex', this.class()));6162 private readonly trackEl = viewChild.required<ElementRef<HTMLElement>>('track');6364 get nativeElement(): HTMLElement {65 return this.trackEl().nativeElement;66 }67}6869@Component({70 selector: 'z-slider-range',71 template: `72 @for (seg of segments(); track $index) {73 <span74 data-slot="slider-range"75 [attr.data-orientation]="orientation()"76 [class]="classes()"77 [style.left]="seg.left"78 [style.right]="seg.right"79 [style.bottom]="seg.bottom"80 [style.top]="seg.top"81 ></span>82 }83 `,84 changeDetection: ChangeDetectionStrategy.OnPush,85 encapsulation: ViewEncapsulation.None,86})87export class ZSliderRangeComponent {88 readonly percent = input<number[]>([0]);8990 readonly orientation = input<'horizontal' | 'vertical'>('horizontal');91// … 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 |
