Direction

A provider component that sets the text direction for your application.

The DirectionProvider component sets the text direction (ltr or rtl) for Cubix primitives. This is essential for right-to-left languages like Arabic, Hebrew, and Persian. Pair it with dir="rtl" on html (or a wrapping container) so CSS logical properties also flip.

Preview direction

Make changes to your account here.

Installation

pnpm dlx cubix@latest add direction

Usage

Import
import { DirectionProvider } from "@/components/cubix/direction"
Example
<html dir="rtl">
  <body>
    <DirectionProvider direction="rtl">
      {/* Your app content */}
    </DirectionProvider>
  </body>
</html>

useDirection

The useDirection hook returns the current direction from the nearest provider. Useful for portaled UI that renders outside your app root.

Import
import { useDirection } from "@/components/cubix/direction"
Example
function MyComponent() {
  const direction = useDirection()
  return <div>Current direction: {direction}</div>
}

Current direction: ltr

API Reference

DirectionProvider

PropTypeDefaultDescription
direction"ltr" | "rtl""ltr"The reading direction of the text.
childrenReact.ReactNode-App content that should inherit the text direction.

useDirection

PropTypeDefaultDescription
return"ltr" | "rtl"-The current text direction from the nearest DirectionProvider.