BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/fluid-functionalism/radio-group

Radio Group

fluid-functionalism/radio-group
FreeComponent

Animated radio group with proximity hover, spring-animated selection dot, and optional Radix UI integration. Supports both controlled index and value-based APIs.

Install it

npx shadcn@latest add https://fluidfunctionalism.com/r/radio-group.json

Source

registry/radix/radio-group.tsxfluidfunctionalism.com/r/radio-group.json · first 6 KB
1"use client";
2
3import {
4 Children,
5 useRef,
6 useState,
7 useEffect,
8 createContext,
9 useContext,
10 forwardRef,
11 isValidElement,
12 type ReactNode,
13 type HTMLAttributes,
14} from "react";
15import { motion, AnimatePresence } from "framer-motion";
16import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
17import { cn } from "@/lib/utils";
18import { spring } from "@/lib/springs";
19import { fontWeights } from "@/lib/font-weight";
20import { useProximityHover } from "@/hooks/use-proximity-hover";
21import { useShape } from "@/lib/shape-context";
22
23interface RadioGroupContextValue {
24 registerItem: (index: number, element: HTMLElement | null) => void;
25 activeIndex: number | null;
26 selectedIndex: number | null;
27 selectedValue?: string;
28 onValueChange?: (value: string) => void;
29 /** Whether any item in the group is currently selected. Drives the roving
30 * tabindex fallback: with no selection, the first item must stay tabbable
31 * or the whole group becomes unreachable by keyboard. */
32 hasSelection: boolean;
33}
34
35const RadioGroupContext = createContext<RadioGroupContextValue | null>(null);
36
37function useRadioGroupContext() {
38 const ctx = useContext(RadioGroupContext);
39 if (!ctx) throw new Error("useRadioGroup must be used within a RadioGroup");
40 return ctx;
41}
42
43interface RadioGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, "onSelect"> {
44 children: ReactNode;
45 selectedIndex?: number;
46 value?: string;
47 onValueChange?: (value: string) => void;
48}
49
50const RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(
51 ({ children, selectedIndex, value, onValueChange, className, ...props }, ref) => {
52 const containerRef = useRef<HTMLDivElement>(null);
53 const childValues = Children.toArray(children)
54 .filter(isValidElement)
55 .map((child) => (child.props as { value?: string }).value);
56 const {
57 activeIndex,
58 setActiveIndex,
59 itemRects,
60 sessionRef,
61 handlers,
62 registerItem,
63 measureItems,
64 } = useProximityHover(containerRef);
65
66 useEffect(() => {
67 measureItems();
68 }, [measureItems, children]);
69
70 const [focusedIndex, setFocusedIndex] = useState<number | null>(null);
71 const resolvedSelectedIndex =
72 value !== undefined
73 ? childValues.findIndex((childValue) => childValue === value)
74 : selectedIndex ?? -1;
75 // Covers all three selection APIs: value, selectedIndex, per-item selected.
76 const hasSelection =
77 resolvedSelectedIndex >= 0 ||
78// … truncated

What it pulls in

npm packages

  • framer-motion
  • @radix-ui/react-radio-group

Other registry items

  • utils
  • https://www.fluidfunctionalism.com/r/springs.json
  • https://www.fluidfunctionalism.com/r/font-weight.json
  • https://www.fluidfunctionalism.com/r/shape-context.json
  • https://www.fluidfunctionalism.com/r/use-proximity-hover.json

Files it writes

  • registry/radix/radio-group.tsx

Facts

Registry
fluid-functionalism
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-02
Last confirmed
today

Go to the source

fluidfunctionalism.com mickadesign/fluid-functionalism on GitHub Raw registry item This item as JSON

More from fluid-functionalism

All 53 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Accordionaccordionfluid-functionalismComponentsFree3 deps
Accordion (Base UI)accordion-basefluid-functionalismComponentsFree3 deps
Ask User Questionsask-user-questionsfluid-functionalismComponentsFree2 deps
Badgebadgefluid-functionalismComponentsFree1 dep
Buttonbuttonfluid-functionalismComponentsFree4 deps
Button (Base UI)button-basefluid-functionalismComponentsFree4 deps
Cardcardfluid-functionalismComponentsFree1 dep
Chat Messagechat-messagefluid-functionalismComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex