# Float

> A velocity-snapping floating container that projects throws into corners and tucks past the screen edge into a slim live hairline tab.

Keeping a live huddle, focus timer, screen recording or background deploy visible while you work should never block your canvas. Float wraps any widget in one line: grab anywhere on its surface and flick it toward a corner, and release velocity projects the landing corner straight into coupled springs with subtle banking tilt so the panel carries real momentum. Push or flick it past the left or right wall and it slides cleanly off-screen, pinning a slim hairline edge tab flush against the wall that stays alive via edgePeek (showing a ticking clock, speaking indicator or step counter beside an 8×8 Bayer live seam). Pull the tab inward or tap it to spring the panel right back open. Works fixed to the viewport or bounded inside any relative container, respects resizes, supports optional localStorage persistence and moves between corners with arrow keys.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/float.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/float
- Registry item (source): https://hairlineui.com/r/float.json

## Usage

```tsx
import { Float } from "@/components/float";

<Float
  label="Active huddle"
  storageKey="workspace-huddle-float"
  edgePeek={<span className="font-mono text-xs">04:18</span>}
>
  <YourHuddleCard />
</Float>
```

## Workspace-wide floating call widget with controlled tuck action

Mount Float at your app shell level with scope="viewport" and storageKey so users keep their preferred corner across routes and reloads.

```tsx
"use client";
import { useState } from "react";
import { Float, type FloatCorner } from "@/components/float";

export function ActiveCallOverlay({ elapsed, muted, onToggleMute }: { elapsed: string; muted: boolean; onToggleMute: () => void }) {
  const [corner, setCorner] = useState<FloatCorner>("bottom-right");
  const [tucked, setTucked] = useState(false);

  return (
    <Float
      scope="viewport"
      storageKey="active-call-float"
      label="Active call"
      corner={corner}
      onCornerChange={setCorner}
      tucked={tucked}
      onTuckedChange={setTucked}
      live={!muted}
      edgePeek={
        <span className="inline-flex items-center gap-1.5 font-mono text-xs">
          <span className="size-2 rounded-full bg-emerald-500" />
          {elapsed}
        </span>
      }
    >
      <div className="flex items-center gap-3 rounded-2xl border border-border bg-card px-3.5 py-2.5">
        <span className="text-sm font-medium">Team huddle · {elapsed}</span>
        <button type="button" onClick={onToggleMute} className="rounded-lg border border-border px-2 py-1 text-xs">
          {muted ? "Unmute" : "Mute"}
        </button>
      </div>
    </Float>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children / edgePeek` | `ReactNode / ReactNode` | – | Floating card surface and compact live content shown inside the slim edge tab while tucked. |
| `corner / defaultCorner / onCornerChange` | `FloatCorner / FloatCorner / (c) => void` | `"bottom-right"` | Controlled or uncontrolled corner ("top-left" \| "top-right" \| "bottom-left" \| "bottom-right"). |
| `tucked / defaultTucked / onTuckedChange / tuckable` | `boolean / boolean / (t, edge) => void / boolean` | `false / true` | Edge-tucked state, callback with wall side ("left" \| "right"), and toggle to allow wall tucking. |
| `scope / margin / storageKey` | `"viewport" \| "container" / number / string` | `"viewport" / 16 / –` | Fixed window overlay vs bounded relative parent, safe edge margin in px and optional localStorage key. |
| `live / label / sound` | `boolean / string / boolean` | `true / "Floating panel" / false` | Drives the subtle 8×8 Bayer live seam on the edge tab, accessible region label and opt-in Web Audio landing cues. |

## States

- **docked**: Anchored cleanly inside the chosen corner with safe margin; springs sleep at 0% CPU and interactive buttons inside work normally.
- **dragging & throwing**: Tracks the pointer 1:1 inside safe margins, leans subtly with horizontal velocity, and applies rational rubber-band resistance past the walls while lighting a hairline edge-dock indicator.
- **tucked (live edge tab)**: Slides off-screen and pins a slim hairline tab flush against the left or right wall, showing edgePeek beside a quiet 8×8 Bayer live seam.
- **pulling to restore**: Pulling the edge tab inward past 16px (or tapping it, or pressing the inward arrow key) springs the panel straight back into its corner.
- **reduced motion**: Corner jumps and edge tucking switch cleanly in place with no banking tilt, spring travel or Bayer seam loop.

## What it handles

Floating widgets feel clunky when they jump to the nearest corner regardless of throw speed, steal button clicks, or cover content with no way to park them cleanly out of the way.

- **Velocity-projected corner snapping**: Samples recent pointer velocity and projects the throw 190ms ahead, feeding softened momentum directly into X, Y and banking-tilt springs.
- **Live hairline edge tab**: Pushing or flicking past the left or right wall tucks the card off-screen into a slim edge tab rendering your live edgePeek beside an 8×8 Bayer seam pulse; pull inward or tap to restore.
- **Safe interactive descendants**: Buttons, links, sliders and inputs inside your floating card keep normal click behaviour with a 4px drag threshold on the surrounding surface.
- **Viewport or container scope**: Mount fixed to the entire browser window (scope="viewport") or bounded inside any relative canvas or split pane (scope="container"), clamping cleanly on resize.
- **Optional persistence and keyboard corners**: Pass storageKey to remember corner and tucked state in localStorage; arrow keys move between corners and push into or out of the edge walls.
- **Zero idle cost and reduced motion**: Springs and the edge-tab Bayer canvas sleep completely when settled; under prefers-reduced-motion: reduce, transitions jump cleanly without tilt or travel.

## Replaces

react-draggable PiP, custom fixed floating widget, framer-motion drag constraints

## Where it fits

- **Voice huddles and video calls**: Keep an active call in a corner while navigating documents, then flick it into the wall tab while keeping the speaking indicator live.
- **Focus and billing timers**: Let users move a ticking session timer anywhere on screen or tuck it into the edge while the clock stays readable.
- **Background AI agent and deploy runs**: Track a long-running build or agent task unobtrusively without keeping a modal or drawer open.
- **Mini audio and podcast players**: Wrap a compact player with interactive buttons inside Float; interactive descendants stay clickable while the card body drags.

## Notes

- Interactive controls inside children (buttons, links, inputs, sliders or anything marked data-float-no-drag) never trigger a drag, and a 4px slop threshold protects ordinary taps.
- Because corner coordinates update via ResizeObserver, resizing the browser window never strands the floating panel off-screen.
- When storageKey is provided, saved coordinates hydrate via useSyncExternalStore with zero SSR mismatch.
- Arrow keys move between all four corners; pressing Left from a left corner or Right from a right corner tucks into that wall, and the opposite arrow restores it.
- Under prefers-reduced-motion: reduce, corner moves and edge tucking jump cleanly and the live seam canvas stays asleep.

License: MIT (https://hairlineui.com/license#components)
