Segment Spotlight
navdeep-singh/segment-spotlightFreeComponent
Composable spotlight primitives with controlled state, animated segments, arbitrary controls, and hover or click activation.
Install it
npx shadcn@latest add https://ui.navdeepsingh.dev/r/segment-spotlight.jsonSource
1'use client'23import * as React from 'react'4import { Slot } from 'radix-ui'5import { motion, useReducedMotion } from 'motion/react'6import { useControllableState } from '@radix-ui/react-use-controllable-state'78import { cn } from '@/lib/utils'910const segmentVariants = {11 default: 'bg-foreground text-background shadow-foreground/20',12 blue: 'bg-blue-600 text-white shadow-blue-600/25',13 purple: 'bg-violet-600 text-white shadow-violet-600/25',14 green: 'bg-emerald-600 text-white shadow-emerald-600/25',15 pink: 'bg-pink-600 text-white shadow-pink-600/25',16 teal: 'bg-teal-600 text-white shadow-teal-600/25',17 orange: 'bg-orange-500 text-white shadow-orange-500/25',18 red: 'bg-red-600 text-white shadow-red-600/25',19 yellow: 'bg-yellow-400 text-zinc-950 shadow-yellow-400/25',20} as const2122type SegmentSpotlightVariant = keyof typeof segmentVariants23type SegmentSpotlightActivationMode = 'hover' | 'click'2425type SegmentSpotlightContextValue = {26 activeValue: string | null27 activeTargets: ReadonlySet<string>28 activationMode: SegmentSpotlightActivationMode29 prefersReducedMotion: boolean30 setActiveValue: (value: string | null) => void31 registerTrigger: (value: string, targets: string[]) => () => void32}3334const SegmentSpotlightContext = React.createContext<SegmentSpotlightContextValue | null>(null)3536function useSegmentSpotlight() {37 const context = React.useContext(SegmentSpotlightContext)3839 if (!context) {40 throw new Error('SegmentSpotlight components must be used within <SegmentSpotlight>.')41 }4243 return context44}4546type SegmentSpotlightProps = Omit<React.ComponentProps<'div'>, 'defaultValue'> & {47 value?: string | null48 defaultValue?: string | null49 onValueChange?: (value: string | null) => void50 activationMode?: SegmentSpotlightActivationMode51}5253function SegmentSpotlight({54 value: valueProp,55 defaultValue = null,56 onValueChange,57 activationMode = 'hover',58 className,59 children,60 ...props61}: SegmentSpotlightProps) {62 const prefersReducedMotion = useReducedMotion()63 const [targetsByValue, setTargetsByValue] = React.useState<Map<string, string[]>>(new Map())64 const [activeValue = null, setActiveValue] = useControllableState({65 prop: valueProp,66 defaultProp: defaultValue,67 onChange: onValueChange,68 })6970 const registerTrigger = React.useCallback((value: string, targets: string[]) => {71 setTargetsByValue((current) => {72 const next = new Map(current)73 next.set(value, targets)74 return next75 })7677 return () => {78// … truncated
What it pulls in
npm packages
Files it writes
More from navdeep-singh
All 64 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Groupanimated-group | navdeep-singh | Components | Free | 1 dep | |
| Animated Numbersanimated-numbers | navdeep-singh | Components | Free | 1 dep | |
| Animated Tabsanimated-tabs | navdeep-singh | Components | Free | 2 deps | |
| Approval Panel Illustrationapproval-panel | navdeep-singh | Components | Free | 2 deps · 2 files | |
| Brand Logobrand-logo | navdeep-singh | Components | Free | 1 dep | |
| Contribution Graphcontribution-graph | navdeep-singh | Components | Free | no deps | |
| Designed for Focus Illustrationdesigned-for-focus-illustration | navdeep-singh | Components | Free | 1 dep | |
| Expandable Cardexpandable-card | navdeep-singh | Components | Free | 4 deps |
