Direction
A UI SDK core reading-direction boundary and toggle that mirror content between left-to-right and right-to-left layouts.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/directionThis adds components/keyframery/direction.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
Direction,
DirectionProvider,
DirectionToggle,
} from "@/components/keyframery/direction"Motion
| Move | What you see |
|---|---|
| Direction | After a direction change, content arrives from its new reading side with 28px of travel and a soft blur. |
| Cascade | Content blocks follow the direction change in order. |
| Press | The toggle presses in while its mirror icon flips on a spring. |
Timing and springiness follow the motion style you set. To change how fast this direction moves, pass speed:
<Direction speed="fast">
…
</Direction>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--direction-face | Toggle surface | bg-background |
--direction-ink | Toggle text | text-foreground |
--direction-radius | Toggle corners | rounded-[9px] |
--direction-font | Toggle label size | text-[13px] |
--direction-gap | Toggle gap | gap-1.5 |
--direction-height | Toggle height | h-8 |
--direction-inset-x | Toggle padding | px-3 |
--direction-icon-size | Toggle icon | size-4 |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
Direction
Renders a <div>, and takes its props too.
Prop
Type
DirectionProvider
Renders a <div>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
DirectionToggle: a<button>
Hooks
useDirection
Call it inside the component to read and change its state.
Prop
Type
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves focus to the direction toggle and controls inside the boundary. |
| Enter | Switches the focused direction toggle. |
| Space | Switches the focused direction toggle. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a direction, so this one is defined with its core: one definePrimitive in components/keyframery/core/direction-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/direction.
Questions
How does the animated Direction for UI SDK move?
Direction: After a direction change, content arrives from its new reading side with 28px of travel and a soft blur. Cascade: Content blocks follow the direction change in order. Press: The toggle presses in while its mirror icon flips on a spring.
Do I need Motion or Framer Motion for the animated Direction?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no direction. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/direction-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Direction when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.