Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: added toggle component
dev_wandrye994587911fd
diff --git a/components/docs/examples/index.tsx b/components/docs/examples/index.tsxindex 45f19cac..62759688 100644--- a/components/docs/examples/index.tsx+++ b/components/docs/examples/index.tsx@@ -56,6 +56,10 @@ import {ContextMenuExampleScene,contextMenuExampleCode,} from "./context-menu-example";+import {+ ToggleGroupExampleScene,+ toggleGroupExampleCode,+} from "./toggle-group-example";export interface ExampleEntry {Component: ComponentType;@@ -271,4 +275,13 @@ export const examples: Record<string, ExampleEntry> = {width: W,height: H,},+ "toggle-group-example": {+ Component: ToggleGroupExampleScene,+ code: toggleGroupExampleCode,+ // Second toggle completes at 92 + dur 14 = 106; a short settle then loop.+ durationInFrames: 115,+ fps: FPS,+ width: W,+ height: H,+ },};diff --git a/components/docs/examples/toggle-group-example.tsx b/components/docs/examples/toggle-group-example.tsxnew file mode 100644index 00000000..c88f54b1--- /dev/null+++ b/components/docs/examples/toggle-group-example.tsx@@ -0,0 +1,74 @@+"use client";++import { Cursor } from "@/registry/remocn-ui/cursor";+import { useCursorPath } from "@/registry/remocn-ui/cursor/use-cursor-path";+import { ToggleGroup } from "@/registry/remocn-ui/toggle-group";+import { useToggleGroupTransition } from "@/registry/remocn-ui/toggle-group/use-toggle-group-transition";++// Default size geometry: pad=4, segMinWidth=88, 2 segments.+// Container width = 4 + 88 + 88 + 4 = 184px. Centered on 1280px canvas:+// left edge = (1280 - 184) / 2 = 548px.+// "Monthly" center X: 548 + 4 + 44 = 596. "Yearly" center X: 548 + 4 + 88 + 44 = 684. Y = 360.+const MONTHLY_X = 596;+const YEARLY_X = 684;+const TOGGLE_Y = 360;++export const ToggleGroupExampleScene = () => {+ // Cursor: park → ease to "Yearly" → click → ease to "Monthly" → click.+ const cursorStyle = useCursorPath([+ { at: 0, x: 80, y: 60 },+ { at: 32, x: YEARLY_X, y: TOGGLE_Y, duration: 28 },+ { at: 44, x: YEARLY_X, y: TOGGLE_Y, click: true, duration: 0 },+ { at: 80, x: MONTHLY_X, y: TOGGLE_Y, duration: 20 },+ { at: 90, x: MONTHLY_X, y: TOGGLE_Y, click: true, duration: 0 },+ ]);++ // Toggle: starts on "Monthly", slides to "Yearly" on first click, back on second.+ const toggleStyle = useToggleGroupTransition([+ { at: 46, state: "Yearly", duration: 14 },+ { at: 92, state: "Monthly", duration: 14 },+ ]);++ return (+ <div style={{ position: "relative", width: "100%", height: "100%" }}>+ {/* ToggleGroup renders position:absolute;inset:0 — it centers itself. */}+ <ToggleGroup style={toggleStyle} />+ <Cursor style={cursorStyle} variant="pointer" />+ </div>+ );+};++export const toggleGroupExampleCode = `import { Cursor } from "@/components/remocn/cursor";+import { useCursorPath } from "@/components/remocn/use-cursor-path";+import { ToggleGroup } from "@/components/remocn/toggle-group";+import { useToggleGroupTransition } from "@/components/remocn/use-toggle-group-transition";++// Default size geometry: pad=4, segMinWidth=88, 2 segments → container 184px wide.+// Centered on a 1280×720 canvas; adjust for your own canvas and segment count.+const MONTHLY_X = 596;+const YEARLY_X = 684;+const TOGGLE_Y = 360;++export const Scene = () => {+ // Cursor eases to "Yearly", clicks, then eases to "Monthly" and clicks again.+ const cursorStyle = useCursorPath([+ { at: 0, x: 80, y: 60 },+ { at: 32, x: YEARLY_X, y: TOGGLE_Y, duration: 28 },+ { at: 44, x: YEARLY_X, y: TOGGLE_Y, click: true, duration: 0 },+ { at: 80, x: MONTHLY_X, y: TOGGLE_Y, duration: 20 },+ { at: 90, x: MONTHLY_X, y: TOGGLE_Y, click: true, duration: 0 },+ ]);++ // Toggle slides "Monthly" → "Yearly" → "Monthly", frame-synced with cursor clicks.+ const toggleStyle = useToggleGroupTransition([+ { at: 46, state: "Yearly", duration: 14 },+ { at: 92, state: "Monthly", duration: 14 },+ ]);++ return (+ <div style={{ position: "relative", width: "100%", height: "100%" }}>+ <ToggleGroup style={toggleStyle} />+ <Cursor style={cursorStyle} variant="pointer" />+ </div>+ );+};`;diff --git a/content/docs/ui/components/meta.json b/content/docs/ui/components/meta.jsonindex 9a722c9c..1cbb3273 100644--- a/content/docs/ui/components/meta.json+++ b/content/docs/ui/components/meta.json@@ -1,5 +1,5 @@{"title": "Components","collapsible": false,- "pages": ["accordion", "alert-dialog", "button", "checkbox", "combobox", "command-menu", "context-menu", "cursor", "dialog", "drawer", "sheet", "dropdown-menu", "input", "popover", "progress", "radio", "select", "skeleton", "slider", "spinner", "switch", "tabs", "toast", "tooltip"]+ "pages": ["accordion", "alert-dialog", "button", "checkbox", "combobox", "command-menu", "context-menu", "cursor", "dialog", "drawer", "sheet", "dropdown-menu", "input", "popover", "progress", "radio", "select", "skeleton", "slider", "spinner", "switch", "tabs", "toast", "toggle-group", "tooltip"]}diff --git a/content/docs/ui/components/toggle-group.mdx b/content/docs/ui/components/toggle-group.mdxnew file mode 100644index 00000000..7b7429d7--- /dev/null+++ b/content/docs/ui/components/toggle-group.mdx@@ -0,0 +1,150 @@+---+title: Toggle Group+description: A segmented control whose active value slides a thumb indicator between segments+---++<ComponentPreview name="toggle-group" />++A state atom representing a segmented button control — a row of labeled segments with a sliding thumb indicator that moves to the active one. Its appearance (which segment is active) is a pure function of the `state` prop. Pass a state directly or drive it from the Remotion timeline via `useCurrentState`. The component reads no frame — only the state value you give it.++## Installation++<InstallBlock name="toggle-group" />++<Note>+Installing `toggle-group` automatically installs the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies`. You do not need to install it separately.+</Note>++## Example++<LiveExample name="toggle-group-example" />++## States++`ToggleGroupState` is:++```ts+type ToggleGroupState = string;+```++The `state` is the active segment's value — one of the strings in the `items` array. When the state changes, the thumb indicator slides to that segment and the active label brightens.++## Snap usage++Pass `state` directly — the component snaps instantly to that visual. Useful for static previews or when you drive state from your own logic:++```tsx+import { ToggleGroup } from "@/components/remocn/toggle-group";++export const Scene = () => (+ <ToggleGroup+ state="Yearly"+ items={[{ value: "Monthly", label: "Monthly" }, { value: "Yearly", label: "Yearly" }]}+ />+);+```++To drive state from the timeline, use `useCurrentState`:++```tsx+import { useCurrentState } from "@/lib/remocn-ui";+import { ToggleGroup } from "@/components/remocn/toggle-group";++export const Scene = () => {+ const state = useCurrentState(+ [+ { at: 46, state: "Yearly" },+ { at: 92, state: "Monthly" },+ ],+ "Monthly",+ );++ return (+ <ToggleGroup+ state={state}+ items={[{ value: "Monthly", label: "Monthly" }, { value: "Yearly", label: "Yearly" }]}+ />+ );+};+```++Each `at` is a **Sequence-local authored frame**. State persists between steps: `Yearly` at frame 46 keeps that segment active until `Monthly` fires at frame 92. See [Concepts](/docs/ui/concepts) for the full `useCurrentState` API.++## Smooth transitions++State changes via `state` snap with no animation. For a smoothly sliding thumb, use `useToggleGroupTransition` from the copied `use-toggle-group-transition.ts` file. It reads the frame, interpolates between state presets, and returns a resolved `ToggleGroupStyle` — pass it to the `style` prop:++```tsx+import { ToggleGroup } from "@/components/remocn/toggle-group";+import { useToggleGroupTransition } from "@/components/remocn/use-toggle-group-transition";++export const Scene = () => {+ const style = useToggleGroupTransition([+ { at: 46, state: "Yearly", duration: 14 },+ { at: 92, state: "Monthly", duration: 14 },+ ]);++ return <ToggleGroup style={style} />;+};+```++The `duration` field on each step overrides the file's `DEFAULT_DURATION` for that specific transition. To globally tune timing and easing, edit `use-toggle-group-transition.ts` directly in your project — that file is yours (shadcn "own your code" philosophy).++`style` takes precedence over `state` when both are provided.++## Sliding thumb and size variants++The only animated field in `ToggleGroupStyle` is `indicatorOffset` — a float index (0, 1, 2…) representing where the thumb sits. The `useToggleGroupTransition` hook interpolates this value so the thumb slides smoothly between segments. The same `indicatorOffset` drives the per-label color blend, so labels crossfade from muted to active as the thumb arrives.++The `size` prop sets the overall scale of the control:++| `size` | Use case |+|---|---|+| `"default"` | Standard — pricing toggles, view switches |+| `"sm"` | Compact toolbar toggles |++## Props++<PropsTable+ rows={[+ {+ name: "state",+ type: "string",+ default: "first item",+ description: "Current visual state (snap path). One of the values in items. State changes snap — no automatic animation.",+ },+ {+ name: "style",+ type: "ToggleGroupStyle",+ description: "Resolved animated visual (smooth path). Pass an interpolated ToggleGroupStyle from useToggleGroupTransition. Takes precedence over state when provided.",+ },+ {+ name: "items",+ type: "ToggleGroupItem[]",+ default: "[{ value: \"Monthly\", label: \"Monthly\" }, { value: \"Yearly\", label: \"Yearly\" }]",+ description: "Segment definitions. Each item has a value (state key), a label (display text), and an optional icon node. The active state is one of the item values.",+ },+ {+ name: "size",+ type: "\"default\" | \"sm\"",+ default: "\"default\"",+ description: "Overall scale of the control — affects height, font size, and padding.",+ },+ {+ name: "theme",+ type: "Partial<RemocnTheme>",+ description: "Per-component theme override. Merges with the active RemocnUIProvider theme and the mode defaults. Must be concrete oklch/hex/rgb values — not CSS custom properties.",+ },+ {+ name: "mode",+ type: "\"light\" | \"dark\"",+ default: "\"light\"",+ description: "Sets the base palette. Overrides the mode on RemocnUIProvider when both are present.",+ },+ {+ name: "className",+ type: "string",+ description: "Optional className passed to the toggle-group element.",+ },+ ]}+/>diff --git a/registry/__index__.tsx b/registry/__index__.tsxindex d2b81304..d86197d3 100644--- a/registry/__index__.tsx+++ b/registry/__index__.tsx@@ -161,6 +161,8 @@ import { PopoverPreview } from "@/registry/remocn-ui/popover/preview";import { popoverConfig } from "@/registry/remocn-ui/popover/config";import { ContextMenuPreview } from "@/registry/remocn-ui/context-menu/preview";import { contextMenuConfig } from "@/registry/remocn-ui/context-menu/config";+import { ToggleGroup } from "@/registry/remocn-ui/toggle-group";+import { toggleGroupConfig } from "@/registry/remocn-ui/toggle-group/config";import { ZoomThroughTransition } from "@/registry/remocn/zoom-through-transition";import { zoomThroughTransitionConfig } from "@/registry/remocn/zoom-through-transition/config";@@ -393,6 +395,9 @@ const registry: Record<string, RegistryEntry> = {// wrapper: a bare panel (transparent, caller-positioned) would sit top-left,// so the wrapper centers it on a stage."context-menu": { Component: ContextMenuPreview, config: contextMenuConfig },+ // toggle-group registers RAW (no preview wrapper): like tabs it paints its own+ // opaque inset:0 centered stage, so the customizer mounts it directly.+ "toggle-group": { Component: ToggleGroup, config: toggleGroupConfig },"spinner": { Component: Spinner, config: spinnerConfig },};diff --git a/registry/remocn-ui/registry.json b/registry/remocn-ui/registry.jsonindex 07d415e7..6a7e6b0d 100644--- a/registry/remocn-ui/registry.json+++ b/registry/remocn-ui/registry.json@@ -591,6 +591,26 @@"target": "components/remocn/use-context-menu-transition.ts"}]+ },+ {+ "name": "toggle-group",+ "type": "registry:component",+ "title": "UI Toggle Group",+ "description": "A segmented control whose active value is a pure function of the timeline; a raised thumb SLIDES between segments (position + width derived from a float indicator offset, no jumps) and the labels crossfade color via mixOklch. The tabs precedent without content panels.",+ "dependencies": ["remotion"],+ "registryDependencies": ["remocn-ui"],+ "files": [+ {+ "path": "toggle-group/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/toggle-group.tsx"+ },+ {+ "path": "toggle-group/use-toggle-group-transition.ts",+ "type": "registry:component",+ "target": "components/remocn/use-toggle-group-transition.ts"+ }+ ]}]}diff --git a/registry/remocn-ui/toggle-group/__tests__/README.md b/registry/remocn-ui/toggle-group/__tests__/README.mdnew file mode 100644index 00000000..40c2abb3--- /dev/null+++ b/registry/remocn-ui/toggle-group/__tests__/README.md@@ -0,0 +1,50 @@+# toggle-group/__tests__++Verification tests for the pure, deterministic surface of the `toggle-group` primitive.++## What is tested++| Section | Source | Coverage |+|---------|--------|----------|+| `DEFAULT_DURATION` | `use-toggle-group-transition.ts` | Constant equals 14 |+| `toggleGroupStyleContext` | `index.tsx` lines 86–99 | trackBg/thumbBg/activeFg/inactiveFg/radius token mapping; items round-trip; light/dark independence |+| `toggleGroupStyle` | `index.tsx` lines 106–112 | Monthly→0, Yearly→1; unknown state→0; empty string→0; 3-item index round-trip |+| `tweenToggleGroupStyle` | `use-toggle-group-transition.ts` lines 33–42 | t=0→a; t=1→b; t=0.5 midpoint; t=0.25 quarter; identity; reverse direction |+| `resolveToggleGroupTransition` | replica of `use-toggle-group-transition.ts` lines 57–82 | before first step; at boundary (progress=0); mid-window eased (non-linear); past window; speed contract |+| `toggleGroupConfig.controls` | `config.ts` | state/size/mode types, defaults, options |+| `toggleGroupConfig.snippet` | `config.ts` | import line; state always emitted; items always emitted inline; default omission; non-default emission; structural round-trip |++## What is NOT tested++**Render path** — `ToggleGroup` calls `useRemocnTheme` (React context) and renders JSX. Not exercised here.++**`SIZE_STYLES`** — This module-private constant maps `ToggleGroupSize` to layout metrics (height, segMinWidth, fontSize, pad, gap). Its values are consumed only inside the JSX render path, which is not exercised here.++## Animation model++`toggleGroupStyle` returns a single numeric field encoding where the thumb sits:++| State | `indicatorOffset` |+|-------|-------------------|+| `"Monthly"` | 0 |+| `"Yearly"` | 1 |+| unknown | 0 (safe fallback) |++Unlike components that have multi-field visuals (opacity, scale, translateY), toggle-group encodes the entire visual in `indicatorOffset` alone. The thumb position, thumb width, and per-label color all derive from this single float inside the pure renderer — so a lerp of `indicatorOffset` slides the thumb smoothly without separate opacity or scale channels.++`useToggleGroupTransition` folds a step list, applies `easings.out` to the linear `progress`, then lerps between the two endpoint presets with `tweenToggleGroupStyle`. Because `out(t) = 1-(1-t)³`, the midpoint `t=0.5` eases to `0.875` — confirmed in the mid-window test: at frame 7 of a 14-frame window, `indicatorOffset=0.875`.++## Snippet items++The snippet **always** emits the `items={[...]}` inline JSX array literal regardless of customizer state. This differs from some other components where items emission is conditional. The inline array ensures the preview shows real labels and remains consistent.++## Determinism grep checklist++Run this on `toggle-group/index.tsx` — it must print nothing:++```bash+grep -nE "useState|useEffect|useCurrentFrame|onClick|onChange|addEventListener|Date\.now|Math\.random|requestAnimationFrame" \+ registry/remocn-ui/toggle-group/index.tsx+```++The `ToggleGroup` component is a pure renderer: no frame reading, no local state, no side effects. Frame reading lives exclusively in `useToggleGroupTransition` (`use-toggle-group-transition.ts`), which is not imported by `index.tsx`.diff --git a/registry/remocn-ui/toggle-group/__tests__/toggle-group.test.ts b/registry/remocn-ui/toggle-group/__tests__/toggle-group.test.tsnew file mode 100644index 00000000..833e3e8f--- /dev/null+++ b/registry/remocn-ui/toggle-group/__tests__/toggle-group.test.ts@@ -0,0 +1,577 @@+/**+ * Verification tests for the PURE / DETERMINISTIC parts of `toggle-group`.+ *+ * Scope:+ * - registry/remocn-ui/toggle-group/index.tsx — ToggleGroupState type,+ * toggleGroupStyle presets, toggleGroupStyleContext+ * - registry/remocn-ui/toggle-group/use-toggle-group-transition.ts+ * — tweenToggleGroupStyle interpolation, DEFAULT_DURATION,+ * pure replica of useToggleGroupTransition+ * - registry/remocn-ui/toggle-group/config.ts — toggleGroupConfig.controls+ * wiring + toggleGroupConfig.snippet output (the state → JSX codegen)+ *+ * The render path (index.tsx) is a PURE-STATE model: `(style) => visual`.+ * `<ToggleGroup>` reads `useRemocnTheme()` internally — that hook is pure at+ * call-time in test context, but the JSX render tree is not exercised here.+ * The pure-testable surface is: the style presets + context builder + tween ++ * customizer wiring + snippet codegen.+ *+ * Runner: Bun's built-in test runner (TypeScript-native, no framework dep).+ * bun test registry/remocn-ui/toggle-group/__tests__+ *+ * --------------------------------------------------------------------------+ * IMPORT STRATEGY+ * --------------------------------------------------------------------------+ * All imports use RELATIVE paths matching the existing test suite pattern.+ * `config.ts` imports `ToggleGroupState` from the toggle-group registry path;+ * none of the pieces under test call a Remotion runtime API at import time —+ * `toggleGroupConfig` is a plain object; `.snippet` is a pure string builder;+ * `toggleGroupStyle` and `tweenToggleGroupStyle` are pure value functions.+ * --------------------------------------------------------------------------+ */++import { describe, expect, it } from "bun:test";+import {+ type ToggleGroupState,+ type ToggleGroupItem,+ toggleGroupStyle,+ toggleGroupStyleContext,+} from "../index";+import {+ tweenToggleGroupStyle,+ DEFAULT_DURATION,+} from "../use-toggle-group-transition";+import { toggleGroupConfig } from "../config";+import { defaultLightTheme } from "@/lib/remocn-ui";++// ===========================================================================+// Shared fixtures+// ===========================================================================++/**+ * The canonical two-item list — mirrors DEFAULT_ITEMS in index.tsx and the+ * config.controls.state.options list. Must stay in sync.+ */+const DEFAULT_ITEMS: ToggleGroupItem[] = [+ { value: "Monthly", label: "Monthly" },+ { value: "Yearly", label: "Yearly" },+];++/** Minimal shape mirroring the customizer's value bag passed to snippet(). */+type SnippetValues = {+ state?: string;+ size?: string;+ mode?: string;+};++const snippet = (values: SnippetValues): string =>+ toggleGroupConfig.snippet(values as Record<string, unknown>);++/**+ * A shared ToggleGroupStyleContext built from the default items + default+ * light theme. Mirrors how the component builds its own context internally.+ * Note: toggleGroupStyleContext takes (items, theme) — no variant argument.+ */+const ctx = toggleGroupStyleContext(DEFAULT_ITEMS, defaultLightTheme);++// ===========================================================================+// 1. DEFAULT_DURATION — sanity check the exported constant+// ===========================================================================++describe("DEFAULT_DURATION", () => {+ it("is a positive number", () => {+ expect(typeof DEFAULT_DURATION).toBe("number");+ expect(DEFAULT_DURATION).toBeGreaterThan(0);+ });++ it("equals 14 (the authored value)", () => {+ expect(DEFAULT_DURATION).toBe(14);+ });+});++// ===========================================================================+// 2. toggleGroupStyleContext — token mapping and round-trips+// The context is pure: (items, theme) => ToggleGroupStyleContext.+// Token map: trackBg=muted, thumbBg=background, activeFg=foreground,+// inactiveFg=mutedForeground, radius=radius.+// ===========================================================================++describe("toggleGroupStyleContext: token mapping (light theme)", () => {+ it("trackBg equals theme.muted", () => {+ expect(ctx.trackBg).toBe(defaultLightTheme.muted);+ });++ it("thumbBg equals theme.background", () => {+ expect(ctx.thumbBg).toBe(defaultLightTheme.background);+ });++ it("activeFg equals theme.foreground", () => {+ expect(ctx.activeFg).toBe(defaultLightTheme.foreground);+ });++ it("inactiveFg equals theme.mutedForeground", () => {+ expect(ctx.inactiveFg).toBe(defaultLightTheme.mutedForeground);+ });++ it("radius equals theme.radius", () => {+ expect(ctx.radius).toBe(defaultLightTheme.radius);+ });+});++describe("toggleGroupStyleContext: items round-trip", () => {+ it("ctx.items is the same array reference passed in", () => {+ expect(ctx.items).toBe(DEFAULT_ITEMS);+ });++ it("ctx.items has the expected length", () => {+ expect(ctx.items).toHaveLength(2);+ });++ it("ctx.items[0].value is 'Monthly'", () => {+ expect(ctx.items[0].value).toBe("Monthly");+ });++ it("ctx.items[1].value is 'Yearly'", () => {+ expect(ctx.items[1].value).toBe("Yearly");+ });+});++describe("toggleGroupStyleContext: light and dark produce independent token sets", () => {+ it("a dark-mode theme produces a different trackBg than the light theme", () => {+ // Build a minimal dark theme by overriding the key tokens+ const darkTheme = {+ ...defaultLightTheme,+ muted: "hsl(217 33% 17%)",+ background: "hsl(222 47% 11%)",+ foreground: "hsl(213 31% 91%)",+ mutedForeground: "hsl(215 20% 65%)",+ };+ const darkCtx = toggleGroupStyleContext(DEFAULT_ITEMS, darkTheme);+ // trackBg maps to muted, which we overrode+ expect(darkCtx.trackBg).not.toBe(ctx.trackBg);+ });+});++// ===========================================================================+// 3. toggleGroupStyle presets — pure (state, ctx) => ToggleGroupStyle+// indicatorOffset is the ONLY field.+// Monthly → 0 (index 0), Yearly → 1 (index 1), unknown → 0 (safe fallback).+// ===========================================================================++describe("toggleGroupStyle: Monthly state", () => {+ it("indicatorOffset is 0 (first item, index 0)", () => {+ expect(toggleGroupStyle("Monthly", ctx).indicatorOffset).toBe(0);+ });+});++describe("toggleGroupStyle: Yearly state", () => {+ it("indicatorOffset is 1 (second item, index 1)", () => {+ expect(toggleGroupStyle("Yearly", ctx).indicatorOffset).toBe(1);+ });+});++describe("toggleGroupStyle: unknown state", () => {+ it("returns indicatorOffset 0 as the safe fallback for an unknown state", () => {+ expect(toggleGroupStyle("Unknown", ctx).indicatorOffset).toBe(0);+ });++ it("returns indicatorOffset 0 for an empty-string state", () => {+ expect(toggleGroupStyle("", ctx).indicatorOffset).toBe(0);+ });+});++describe("toggleGroupStyle: each default item maps to its own index", () => {+ const items: ToggleGroupItem[] = [+ { value: "Monthly", label: "Monthly" },+ { value: "Yearly", label: "Yearly" },+ ];+ const twoCtx = toggleGroupStyleContext(items, defaultLightTheme);++ for (let i = 0; i < items.length; i++) {+ const item = items[i];+ it(`${item.value} → indicatorOffset ${i}`, () => {+ expect(toggleGroupStyle(item.value, twoCtx).indicatorOffset).toBe(i);+ });+ }+});++describe("toggleGroupStyle: 3-item list index round-trip", () => {+ const threeItems: ToggleGroupItem[] = [+ { value: "A", label: "A" },+ { value: "B", label: "B" },+ { value: "C", label: "C" },+ ];+ const threeCtx = toggleGroupStyleContext(threeItems, defaultLightTheme);++ it("A → indicatorOffset 0", () => {+ expect(toggleGroupStyle("A", threeCtx).indicatorOffset).toBe(0);+ });++ it("B → indicatorOffset 1", () => {+ expect(toggleGroupStyle("B", threeCtx).indicatorOffset).toBe(1);+ });++ it("C → indicatorOffset 2", () => {+ expect(toggleGroupStyle("C", threeCtx).indicatorOffset).toBe(2);+ });++ it("unknown state returns 0 in a 3-item context", () => {+ expect(toggleGroupStyle("D", threeCtx).indicatorOffset).toBe(0);+ });+});++// ===========================================================================+// 4. tweenToggleGroupStyle — pure linear interpolation between two styles.+// indicatorOffset is the ONLY field; it lerps linearly.+// a={indicatorOffset:0} (Monthly), b={indicatorOffset:1} (Yearly).+// ===========================================================================++describe("tweenToggleGroupStyle: t=0 returns values equal to a", () => {+ const a = toggleGroupStyle("Monthly", ctx); // indicatorOffset: 0+ const b = toggleGroupStyle("Yearly", ctx); // indicatorOffset: 1+ const r = tweenToggleGroupStyle(a, b, 0);++ it("indicatorOffset equals a.indicatorOffset at t=0", () => {+ expect(r.indicatorOffset).toBeCloseTo(0, 10);+ });+});++describe("tweenToggleGroupStyle: t=1 returns values equal to b", () => {+ const a = toggleGroupStyle("Monthly", ctx); // indicatorOffset: 0+ const b = toggleGroupStyle("Yearly", ctx); // indicatorOffset: 1+ const r = tweenToggleGroupStyle(a, b, 1);++ it("indicatorOffset equals b.indicatorOffset at t=1", () => {+ expect(r.indicatorOffset).toBeCloseTo(1, 10);+ });+});++describe("tweenToggleGroupStyle: t=0.5 midpoint (Monthly → Yearly)", () => {+ // Monthly: indicatorOffset=0, Yearly: indicatorOffset=1+ // Midpoint: 0 + (1-0)*0.5 = 0.5+ const a = toggleGroupStyle("Monthly", ctx);+ const b = toggleGroupStyle("Yearly", ctx);+ const r = tweenToggleGroupStyle(a, b, 0.5);++ it("indicatorOffset midpoint: 0 → 1 gives 0.5", () => {+ expect(r.indicatorOffset).toBeCloseTo(0.5, 10);+ });+});++describe("tweenToggleGroupStyle: t=0.5 midpoint (Yearly → Monthly, reverse)", () => {+ // Yearly: indicatorOffset=1, Monthly: indicatorOffset=0+ // Midpoint: 1 + (0-1)*0.5 = 0.5+ const a = toggleGroupStyle("Yearly", ctx);+ const b = toggleGroupStyle("Monthly", ctx);+ const r = tweenToggleGroupStyle(a, b, 0.5);++ it("indicatorOffset midpoint: 1 → 0 gives 0.5", () => {+ expect(r.indicatorOffset).toBeCloseTo(0.5, 10);+ });+});++describe("tweenToggleGroupStyle: identity (a === b)", () => {+ const a = toggleGroupStyle("Monthly", ctx);+ const r = tweenToggleGroupStyle(a, a, 0.5);++ it("indicatorOffset is unchanged when tweening a style to itself", () => {+ expect(r.indicatorOffset).toBeCloseTo(a.indicatorOffset, 10);+ });+});++describe("tweenToggleGroupStyle: t=0.25 quarter-way", () => {+ // a=0, b=1, t=0.25 → 0.25+ const a = toggleGroupStyle("Monthly", ctx);+ const b = toggleGroupStyle("Yearly", ctx);+ const r = tweenToggleGroupStyle(a, b, 0.25);++ it("indicatorOffset quarter-way: 0 → 1 gives 0.25", () => {+ expect(r.indicatorOffset).toBeCloseTo(0.25, 10);+ });+});++// ===========================================================================+// 5. resolveToggleGroupTransition — pure replica of useToggleGroupTransition+//+// useToggleGroupTransition is impure (calls useRemocnTheme + useStateTransition).+// We mirror its logic as a pure function with `frame` injected as `raw`,+// then assert the easing contract: easings.out(t) = 1-(1-t)^3.+//+// The replica mirrors lines 57–82 of use-toggle-group-transition.ts.+// Default state is items[0].value = "Monthly".+// ===========================================================================++/**+ * Pure replica of useToggleGroupTransition for testing.+ *+ * Mirrors the impure hook with `frame` injected as `raw` so we can test the+ * easing contract without a Remotion render context.+ *+ * Annotated lines match the source in use-toggle-group-transition.ts:+ */+function resolveToggleGroupTransition(+ steps: Array<{ from: number; state: ToggleGroupState; duration?: number }>,+ frame: number, // injected as `raw` — mirrors useCurrentFrame() in the real hook+ items: ToggleGroupItem[] = DEFAULT_ITEMS,+ speed: number = 1,+ defaultDuration: number = DEFAULT_DURATION,+) {+ const localCtx = toggleGroupStyleContext(items, defaultLightTheme); // mirrors line 69+ const defaultState: ToggleGroupState = items[0].value; // mirrors line 73++ // Mirror the step-fold logic from useStateTransition:+ // find the two enclosing steps and compute raw linear progress [0,1].+ let from: ToggleGroupState = defaultState;+ let to: ToggleGroupState = defaultState;+ let progress = 0;++ for (let si = 0; si < steps.length; si++) {+ const step = steps[si];+ const stepStart = step.from;+ const stepDuration = (step.duration ?? defaultDuration) / speed;+ const stepEnd = stepStart + stepDuration;+ const next = steps[si + 1];++ if (frame < stepStart) {+ // Before this step — stay at default (or previous state already set)+ break;+ }++ if (frame >= stepStart) {+ from = step.state;+ to = next?.state ?? step.state;++ if (frame >= stepEnd || !next) {+ // Past this window — snap to end state, progress = 1+ from = next?.state ?? step.state;+ to = from;+ progress = 0;+ } else {+ // Inside the transition window+ progress = (frame - stepStart) / stepDuration;+ }+ }+ }++ // mirrors line 76: const t = easings.out(progress)+ const t = 1 - (1 - progress) ** 3;+ // mirrors lines 77-81: tweenToggleGroupStyle(toggleGroupStyle(from, ctx), toggleGroupStyle(to, ctx), t)+ return tweenToggleGroupStyle(+ toggleGroupStyle(from, localCtx),+ toggleGroupStyle(to, localCtx),+ t,+ );+}++describe("resolveToggleGroupTransition: before first step", () => {+ // At frame 0, before any step at frame=10 fires — default state "Monthly"+ const steps = [{ from: 10, state: "Yearly" as ToggleGroupState }];+ const r = resolveToggleGroupTransition(steps, 0);++ it("holds at Monthly (indicatorOffset=0) before first step fires", () => {+ expect(r.indicatorOffset).toBeCloseTo(0, 10);+ });+});++describe("resolveToggleGroupTransition: at boundary (progress=0, t=0)", () => {+ // At frame=10 exactly, progress=0 → easings.out(0) = 0 → still at Monthly+ const steps = [{ from: 10, state: "Yearly" as ToggleGroupState, duration: 14 }];+ const r = resolveToggleGroupTransition(steps, 10);++ it("indicatorOffset is 0 at the step boundary (progress=0, eased=0)", () => {+ expect(r.indicatorOffset).toBeCloseTo(0, 5);+ });+});++describe("resolveToggleGroupTransition: mid-window eased (frame 7 of 14)", () => {+ // Steps: Monthly at t=0, Yearly at t=0 with duration=14.+ // Frame=7 of a 14-frame window → progress=7/14=0.5+ // easings.out(0.5) = 1-(1-0.5)^3 = 1-0.125 = 0.875+ // tween({indicatorOffset:0}, {indicatorOffset:1}, 0.875) → indicatorOffset=0.875+ const steps = [+ { from: 0, state: "Monthly" as ToggleGroupState, duration: 14 },+ { from: 14, state: "Yearly" as ToggleGroupState },+ ];+ const r = resolveToggleGroupTransition(steps, 7);++ it("indicatorOffset at frame 7 is 0.875 (cubic ease-out applied)", () => {+ expect(r.indicatorOffset).toBeCloseTo(0.875, 5);+ });+});++describe("resolveToggleGroupTransition: past window snaps to target state", () => {+ // Past the 14-frame window from Monthly→Yearly, should be fully at Yearly+ const steps = [+ { from: 0, state: "Monthly" as ToggleGroupState, duration: 14 },+ { from: 14, state: "Yearly" as ToggleGroupState },+ ];+ const r = resolveToggleGroupTransition(steps, 30);++ it("indicatorOffset is 1 (Yearly) after transition completes", () => {+ expect(r.indicatorOffset).toBeCloseTo(1, 5);+ });+});++describe("resolveToggleGroupTransition: speed contract", () => {+ // Speed=2 halves the effective duration: 14/2=7 frames to complete.+ // At frame=3.5 (half of 7-frame window), progress=0.5, eased=0.875.+ const steps = [+ { from: 0, state: "Monthly" as ToggleGroupState, duration: 14 },+ { from: 7, state: "Yearly" as ToggleGroupState },+ ];+ const r = resolveToggleGroupTransition(steps, 3, /* items */ DEFAULT_ITEMS, /* speed */ 2);++ it("speed=2 accelerates transition: indicatorOffset is closer to 1 at frame 3", () => {+ // At frame 3 with speed=2, progress=3/7≈0.4286, eased≈0.73+ // Without speed=2 at frame 3 of 14: progress=3/14≈0.214, eased≈0.57+ // So the eased value should be greater with speed=2+ expect(r.indicatorOffset).toBeGreaterThan(0.6);+ });+});++// ===========================================================================+// 6. toggleGroupConfig.controls — customizer control wiring+// ===========================================================================++describe("toggleGroupConfig.controls.state", () => {+ it("is a select control", () => {+ expect(toggleGroupConfig.controls.state.type).toBe("select");+ });++ it("defaults to 'Monthly' so the preview opens on the first segment", () => {+ expect(toggleGroupConfig.controls.state.default).toBe("Monthly");+ });++ it("has exactly the two documented state options in order", () => {+ const control = toggleGroupConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(control.options).toEqual(["Monthly", "Yearly"]);+ });+});++describe("toggleGroupConfig.controls.size", () => {+ it("is a select control", () => {+ expect(toggleGroupConfig.controls.size.type).toBe("select");+ });++ it("defaults to 'default'", () => {+ expect(toggleGroupConfig.controls.size.default).toBe("default");+ });++ it("has exactly the two size options in order", () => {+ const control = toggleGroupConfig.controls.size;+ if (control.type !== "select") throw new Error("size control must be a select");+ expect(control.options).toEqual(["default", "sm"]);+ });+});++describe("toggleGroupConfig.controls.mode", () => {+ it("is a select control", () => {+ expect(toggleGroupConfig.controls.mode.type).toBe("select");+ });++ it("defaults to 'light'", () => {+ expect(toggleGroupConfig.controls.mode.default).toBe("light");+ });++ it("has exactly the two mode options in order", () => {+ const control = toggleGroupConfig.controls.mode;+ if (control.type !== "select") throw new Error("mode control must be a select");+ expect(control.options).toEqual(["light", "dark"]);+ });+});++// ===========================================================================+// 7. toggleGroupConfig.snippet — pure string builder+//+// Invariant: state is ALWAYS emitted.+// Invariant: items inline literal is ALWAYS emitted (regardless of values).+// Default omission: size omitted when "default"; mode omitted when "light".+// Non-default emission: size emitted when "sm"; mode emitted when "dark".+// ===========================================================================++describe("toggleGroupConfig.snippet: import line", () => {+ it("includes `import { ToggleGroup }` from the correct path", () => {+ const out = snippet({ state: "Monthly" });+ expect(out).toContain("import { ToggleGroup }");+ expect(out).toContain('from "@/components/remocn/toggle-group"');+ });+});++describe("toggleGroupConfig.snippet: state prop always emitted", () => {+ it("emits state=\"Monthly\" for the Monthly option", () => {+ expect(snippet({ state: "Monthly" })).toContain('state="Monthly"');+ });++ it("emits state=\"Yearly\" for the Yearly option", () => {+ expect(snippet({ state: "Yearly" })).toContain('state="Yearly"');+ });++ it("emits the correct state for every control option", () => {+ const control = toggleGroupConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ for (const state of control.options) {+ expect(snippet({ state })).toContain(`state="${state}"`);+ }+ });+});++describe("toggleGroupConfig.snippet: items inline literal always emitted", () => {+ it("always emits the items JSX array regardless of state", () => {+ for (const state of ["Monthly", "Yearly"]) {+ const out = snippet({ state });+ expect(out).toContain("items={[");+ expect(out).toContain('{ value: "Monthly", label: "Monthly" }');+ expect(out).toContain('{ value: "Yearly", label: "Yearly" }');+ }+ });++ it("emits items even when all defaults are set", () => {+ const out = snippet({ state: "Monthly", size: "default", mode: "light" });+ expect(out).toContain("items={[");+ });+});++describe("toggleGroupConfig.snippet: default props are omitted", () => {+ const allDefaults = snippet({ state: "Monthly", size: "default", mode: "light" });++ it("omits size when it equals the default 'default'", () => {+ expect(allDefaults).not.toContain("size=");+ });++ it("omits mode when it equals the default 'light'", () => {+ expect(allDefaults).not.toContain("mode=");+ });+});++describe("toggleGroupConfig.snippet: non-default props are emitted", () => {+ it("emits size=\"sm\" when size is non-default", () => {+ expect(snippet({ state: "Monthly", size: "sm" })).toContain('size="sm"');+ });++ it("emits mode=\"dark\" when mode is non-default", () => {+ expect(snippet({ state: "Monthly", mode: "dark" })).toContain('mode="dark"');+ });++ it("emits both size and mode when both are non-default", () => {+ const out = snippet({ state: "Yearly", size: "sm", mode: "dark" });+ expect(out).toContain('size="sm"');+ expect(out).toContain('mode="dark"');+ });+});++describe("toggleGroupConfig.snippet: structural round-trip", () => {+ const out = snippet({ state: "Monthly" });++ it("starts with the import line", () => {+ expect(out.startsWith("import { ToggleGroup }")).toBe(true);+ });++ it("contains a <ToggleGroup JSX opening", () => {+ expect(out).toContain("<ToggleGroup");+ });++ it("ends with a self-closing />", () => {+ expect(out.trimEnd().endsWith("/>")).toBe(true);+ });+});diff --git a/registry/remocn-ui/toggle-group/config.ts b/registry/remocn-ui/toggle-group/config.tsnew file mode 100644index 00000000..eee1c87e--- /dev/null+++ b/registry/remocn-ui/toggle-group/config.ts@@ -0,0 +1,52 @@+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";+import type { ToggleGroupState } from "@/registry/remocn-ui/toggle-group";++export const toggleGroupConfig: ComponentConfig = {+ componentName: "ToggleGroup",+ importPath: "@/components/remocn/toggle-group",+ controls: {+ state: {+ type: "select",+ default: "Monthly",+ options: ["Monthly", "Yearly"],+ label: "State",+ },+ size: {+ type: "select",+ default: "default",+ options: ["default", "sm"],+ label: "Size",+ },+ mode: {+ type: "select",+ default: "light",+ options: ["light", "dark"],+ label: "Mode",+ },+ },+ durationInFrames: 120,+ fps: FPS,+ compositionWidth: W,+ compositionHeight: H,+ snippet: (values) => {+ const state = (values.state as ToggleGroupState) ?? "Monthly";+ const size = values.size as string | undefined;+ const mode = values.mode as string | undefined;++ const props: string[] = [` state="${state}"`];+ if (size !== undefined && size !== "default")+ props.push(` size="${size}"`);+ if (mode !== undefined && mode !== "light")+ props.push(` mode="${mode}"`);++ return `import { ToggleGroup } from "@/components/remocn/toggle-group";++<ToggleGroup+${props.join("\n")}+ items={[+ { value: "Monthly", label: "Monthly" },+ { value: "Yearly", label: "Yearly" },+ ]}+/>`;+ },+};diff --git a/registry/remocn-ui/toggle-group/index.tsx b/registry/remocn-ui/toggle-group/index.tsxnew file mode 100644index 00000000..bba1b919--- /dev/null+++ b/registry/remocn-ui/toggle-group/index.tsx@@ -0,0 +1,200 @@+"use client";++import type { ReactNode } from "react";+import { mixOklch, type RemocnTheme, useRemocnTheme } from "@/lib/remocn-ui";++/** Active segment — one of the `items` VALUES. */+export type ToggleGroupState = string;++export type ToggleGroupSize = "default" | "sm";++/** One segment of the group. */+export interface ToggleGroupItem {+ value: string;+ label: string;+ /** Optional leading icon node. */+ icon?: ReactNode;+}++export interface ToggleGroupProps {+ /** Current visual state (snap path). State changes snap (no enter-tweens). */+ state?: ToggleGroupState;+ /**+ * Resolved animated visual (smooth path). When provided, takes precedence over+ * `state` — feed it an interpolated `ToggleGroupStyle` from `useToggleGroupTransition`.+ */+ style?: ToggleGroupStyle;+ /** Segments (value + label, optional icon). The active `state` is one value. */+ items?: ToggleGroupItem[];+ size?: ToggleGroupSize;+ theme?: Partial<RemocnTheme>;+ mode?: "light" | "dark";+ className?: string;+}++/** Default segments. */+const DEFAULT_ITEMS: ToggleGroupItem[] = [+ { value: "Monthly", label: "Monthly" },+ { value: "Yearly", label: "Yearly" },+];++const SIZE_STYLES: Record<+ ToggleGroupSize,+ { height: number; segMinWidth: number; fontSize: number; pad: number; gap: number }+> = {+ sm: { height: 32, segMinWidth: 72, fontSize: 13, pad: 3, gap: 6 },+ default: { height: 36, segMinWidth: 88, fontSize: 14, pad: 4, gap: 8 },+};++// ===========================================================================+// Toggle-group visual — the COMPLETE animated look for a moment in time. A+// `state` is a named preset of this visual (`toggleGroupStyle`); the smooth path+// feeds an interpolated `ToggleGroupStyle` straight through. The component is a+// pure renderer of whichever style it receives. The sliding thumb's position ++// width and the per-label color all DERIVE from `indicatorOffset` in render —+// mirrors the Tabs indicator (so position AND width move without jumps).+// ===========================================================================++export interface ToggleGroupStyle {+ /**+ * Float index (0,1,2…) of where the active thumb sits. The only animated+ * field — the thumb position/width and label colors derive from it inside the+ * pure render, so a lerp of this single value slides the thumb smoothly.+ */+ indicatorOffset: number;+}++/** Concrete colors for the active theme, resolved once per render. */+export interface ToggleGroupStyleContext {+ /** Segment values — the thumb is indexed against this. */+ items: ToggleGroupItem[];+ /** Container track background. */+ trackBg: string;+ /** Active (raised) thumb surface. */+ thumbBg: string;+ /** Active label color. */+ activeFg: string;+ /** Inactive label color. */+ inactiveFg: string;+ radius: number;+}++/**+ * Derive the concrete colors for a theme. Pure — call it once and reuse the+ * result for every `toggleGroupStyle(state, ctx)` preset.+ */+export function toggleGroupStyleContext(+ items: ToggleGroupItem[],+ theme: RemocnTheme,+): ToggleGroupStyleContext {+ return {+ items,+ trackBg: theme.muted,+ // A concrete surface lifts the active segment off the muted track.+ thumbBg: theme.background,+ activeFg: theme.foreground,+ inactiveFg: theme.mutedForeground,+ radius: theme.radius,+ };+}++/**+ * The COMPLETE resting visual for a state — a pure `(state, ctx) =>+ * ToggleGroupStyle` map. `indicatorOffset` is the index of `state` in+ * `ctx.items` (safe lookup: unknown state → 0).+ */+export function toggleGroupStyle(+ state: ToggleGroupState,+ ctx: ToggleGroupStyleContext,+): ToggleGroupStyle {+ const i = ctx.items.findIndex((it) => it.value === state);+ return { indicatorOffset: i < 0 ? 0 : i };+}++export function ToggleGroup({+ state = DEFAULT_ITEMS[0].value,+ style,+ items = DEFAULT_ITEMS,+ size = "default",+ theme: themeOverride,+ mode,+ className,+}: ToggleGroupProps) {+ const theme = useRemocnTheme(themeOverride, mode);+ const ctx = toggleGroupStyleContext(items, theme);+ const v = style ?? toggleGroupStyle(state, ctx);++ const sizeStyle = SIZE_STYLES[size];+ const { pad } = sizeStyle;+ // Equal-width segments; the thumb spans exactly one segment and slides by the+ // float `indicatorOffset`, so both position AND width track without jumps.+ const segmentWidth = sizeStyle.segMinWidth;+ const thumbX = pad + v.indicatorOffset * segmentWidth;++ return (+ <div+ className={className}+ style={{+ position: "absolute",+ inset: 0,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ // OPAQUE wrapper — a self-contained widget, not a modal layer (like Tabs).+ background: theme.background,+ fontFamily:+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",+ }}+ >+ <div+ style={{+ position: "relative",+ display: "flex",+ height: sizeStyle.height,+ padding: pad,+ boxSizing: "border-box",+ background: ctx.trackBg,+ borderRadius: ctx.radius,+ }}+ >+ {/* Sliding thumb — a raised surface spanning one segment. */}+ <div+ style={{+ position: "absolute",+ top: pad,+ left: thumbX,+ width: segmentWidth,+ height: sizeStyle.height - pad * 2,+ background: ctx.thumbBg,+ borderRadius: Math.max(2, ctx.radius - 3),+ boxShadow: "0 1px 2px rgba(0,0,0,0.1)",+ }}+ />+ {/* Labels stay in normal flow defining the segment widths. */}+ {items.map((item, i) => {+ const proximity = Math.max(0, 1 - Math.abs(i - v.indicatorOffset));+ return (+ <span+ key={item.value}+ style={{+ position: "relative",+ width: segmentWidth,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ gap: sizeStyle.gap,+ fontSize: sizeStyle.fontSize,+ fontWeight: 500,+ letterSpacing: "-0.01em",+ color: mixOklch(ctx.inactiveFg, ctx.activeFg, proximity),+ }}+ >+ {item.icon}+ {item.label}+ </span>+ );+ })}+ </div>+ </div>+ );+}diff --git a/registry/remocn-ui/toggle-group/use-toggle-group-transition.ts b/registry/remocn-ui/toggle-group/use-toggle-group-transition.tsnew file mode 100644index 00000000..e79f0184--- /dev/null+++ b/registry/remocn-ui/toggle-group/use-toggle-group-transition.ts@@ -0,0 +1,82 @@+"use client";++import {+ easings,+ type RemocnTheme,+ type Step,+ useRemocnTheme,+ useStateTransition,+} from "@/lib/remocn-ui";+import {+ toggleGroupStyle,+ toggleGroupStyleContext,+ type ToggleGroupItem,+ type ToggleGroupState,+ type ToggleGroupStyle,+} from "@/components/remocn/toggle-group";+// ^ install path; resolves in-repo via the @/components/remocn/* tsconfig alias.++/** Default segments — mirrors the component's default `items`. */+const DEFAULT_ITEMS: ToggleGroupItem[] = [+ { value: "Monthly", label: "Monthly" },+ { value: "Yearly", label: "Yearly" },+];++/** Default transition length (frames) when a step omits `duration`. Tune to taste. */+export const DEFAULT_DURATION = 14;++/**+ * Blend two toggle-group visuals: `indicatorOffset` lerps (it's the only field).+ * The thumb position AND width, plus the label colors, all derive from this+ * single value inside the pure render — so a lerp slides the thumb without jumps.+ */+export function tweenToggleGroupStyle(+ a: ToggleGroupStyle,+ b: ToggleGroupStyle,+ t: number,+): ToggleGroupStyle {+ return {+ indicatorOffset:+ a.indicatorOffset + (b.indicatorOffset - a.indicatorOffset) * t,+ };+}++export interface ToggleGroupTransitionOptions {+ items?: ToggleGroupItem[];+ theme?: Partial<RemocnTheme>;+ mode?: "light" | "dark";+ speed?: number;+ defaultDuration?: number;+}++/**+ * Timeline → resolved (eased, tweened) ToggleGroupStyle. The CALLER invokes+ * this; it reads the frame, the `<ToggleGroup>` component does not. Feed the+ * result to `<ToggleGroup style={...} />` for a smooth sliding thumb.+ */+export function useToggleGroupTransition(+ steps: Step<ToggleGroupState>[],+ opts: ToggleGroupTransitionOptions = {},+): ToggleGroupStyle {+ const {+ items = DEFAULT_ITEMS,+ theme: themeOverride,+ mode,+ speed = 1,+ defaultDuration = DEFAULT_DURATION,+ } = opts;+ const theme = useRemocnTheme(themeOverride, mode);+ const ctx = toggleGroupStyleContext(items, theme);+ const { from, to, progress } = useStateTransition(+ steps,+ items[0].value,+ speed,+ defaultDuration,+ );+ const t = easings.out(progress);+ return tweenToggleGroupStyle(+ toggleGroupStyle(from, ctx),+ toggleGroupStyle(to, ctx),+ t,+ );+}