compare-slider
diceui-radix/compare-sliderFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/compare-slider.jsonSource
1"use client";23import {4 ChevronDownIcon,5 ChevronLeftIcon,6 ChevronRightIcon,7 ChevronUpIcon,8} from "lucide-react";9import { Slot as SlotPrimitive } from "radix-ui";10import * as React from "react";11import { useComposedRefs } from "@/lib/compose-refs";12import { cn } from "@/lib/utils";13import { useAsRef } from "@/registry/bases/radix/hooks/use-as-ref";14import { useIsomorphicLayoutEffect } from "@/registry/bases/radix/hooks/use-isomorphic-layout-effect";15import { useLazyRef } from "@/registry/bases/radix/hooks/use-lazy-ref";1617const ROOT_NAME = "CompareSlider";18const BEFORE_NAME = "CompareSliderBefore";19const AFTER_NAME = "CompareSliderAfter";20const LABEL_NAME = "CompareSliderLabel";21const HANDLE_NAME = "CompareSliderHandle";2223const PAGE_KEYS = ["PageUp", "PageDown"];24const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];2526type Interaction = "hover" | "drag";27type Orientation = "horizontal" | "vertical";2829interface DivProps extends React.ComponentProps<"div"> {30 asChild?: boolean;31}3233type RootElement = React.ComponentRef<typeof CompareSlider>;3435function clamp(value: number, min: number, max: number): number {36 return Math.min(Math.max(value, min), max);37}3839interface StoreState {40 value: number;41 isDragging: boolean;42}4344interface Store {45 subscribe: (callback: () => void) => () => void;46 getState: () => StoreState;47 setState: <K extends keyof StoreState>(key: K, value: StoreState[K]) => void;48 notify: () => void;49}5051const StoreContext = React.createContext<Store | null>(null);5253function useStore<T>(54 selector: (state: StoreState) => T,55 ogStore?: Store | null,56): T {57 const contextStore = React.useContext(StoreContext);5859 const store = ogStore ?? contextStore;6061 if (!store) {62 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);63 }6465 const getSnapshot = React.useCallback(66 () => selector(store.getState()),67 [store, selector],68 );6970 return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);71}7273interface CompareSliderContextValue {74 interaction: Interaction;75 orientation: Orientation;76}7778const CompareSliderContext =79 React.createContext<CompareSliderContextValue | null>(null);8081function useCompareSliderContext(consumerName: string) {82 const context = React.useContext(CompareSliderContext);83 if (!context) {84 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);85 }86 return context;87}8889interface CompareSliderProps extends DivProps {90// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
