angle-slider
diceui-base/angle-sliderFreeComponent
diceui/base publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/angle-slider.jsonSource
1"use client";23import { mergeProps } from "@base-ui/react/merge-props";4import { useRender } from "@base-ui/react/use-render";5import * as React from "react";6import { cn } from "@/lib/utils";7import { VisuallyHiddenInput } from "@/registry/bases/base/components/visually-hidden-input";8import { useAsRef } from "@/registry/bases/base/hooks/use-as-ref";9import { useIsomorphicLayoutEffect } from "@/registry/bases/base/hooks/use-isomorphic-layout-effect";10import { useLazyRef } from "@/registry/bases/base/hooks/use-lazy-ref";11import { useComposedRefs } from "@/registry/bases/base/lib/compose-refs";12import { useDirection } from "@/registry/bases/base/ui/direction";1314const ROOT_NAME = "AngleSlider";15const THUMB_NAME = "AngleSliderThumb";1617const PAGE_KEYS = ["PageUp", "PageDown"];18const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];1920type Direction = "ltr" | "rtl";2122type RootElement = React.ComponentRef<typeof AngleSlider>;23type ThumbElement = React.ComponentRef<typeof AngleSliderThumb>;2425function clamp(value: number, [min, max]: [number, number]) {26 return Math.min(max, Math.max(min, value));27}2829function getNextSortedValues(30 prevValues: number[] = [],31 nextValue: number,32 atIndex: number,33) {34 const nextValues = [...prevValues];35 nextValues[atIndex] = nextValue;36 return nextValues.sort((a, b) => a - b);37}3839function getStepsBetweenValues(values: number[]) {40 return values.slice(0, -1).map((value, index) => {41 const nextValue = values[index + 1];42 return nextValue !== undefined ? nextValue - value : 0;43 });44}4546function hasMinStepsBetweenValues(47 values: number[],48 minStepsBetweenValues: number,49) {50 if (minStepsBetweenValues > 0) {51 const stepsBetweenValues = getStepsBetweenValues(values);52 const actualMinStepsBetweenValues =53 stepsBetweenValues.length > 0 ? Math.min(...stepsBetweenValues) : 0;54 return actualMinStepsBetweenValues >= minStepsBetweenValues;55 }56 return true;57}5859function getDecimalCount(value: number) {60 return (String(value).split(".")[1] ?? "").length;61}6263function roundValue(value: number, decimalCount: number) {64 const rounder = 10 ** decimalCount;65 return Math.round(value * rounder) / rounder;66}6768function getClosestValueIndex(values: number[], nextValue: number) {69 if (values.length === 1) return 0;70 const distances = values.map((value) => Math.abs(value - nextValue));71 const closestDistance = Math.min(...distances);72 return distances.indexOf(closestDistance);73}7475interface ThumbData {76// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/base
All 192 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/base | Components | Free | 1 dep | |
| avatar-groupavatar-group | diceui/base | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/base | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/base | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/base | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/base | Components | Free | no deps | |
| color-pickercolor-picker | diceui/base | Components | Free | 1 dep · 2 files | |
| color-swatchcolor-swatch | diceui/base | Components | Free | 1 dep |
