@biem/ui

Direction

A provider that tells components whether users read from left to right or from right to left.

A direction provider tells the components inside it whether users read from left to right or from right to left. In a right-to-left interface, a slider counts its value from the right edge, and the left and right arrow keys swap their roles. The provider renders no element and sets no dir attribute, so the element around it sets dir to the same direction, which mirrors the layout.

Reorder level

Usage

direction-default.tsx
import { DirectionProvider } from "@biem/ui/components/ui/direction";
import { Slider } from "@biem/ui/components/ui/slider";

export function DirectionDefault() {
	return (
		<div className="flex w-full max-w-sm flex-col gap-3" dir="rtl">
			<DirectionProvider direction="rtl">
				<span id="reorder-level" className="text-sm font-medium">Reorder level</span>
				<Slider aria-labelledby="reorder-level" defaultValue={[25]}/>
			</DirectionProvider>
		</div>
	);
}

Examples

With useDirection

Shared components that render an element of their own cannot count on the page around them to set the right dir attribute. Through useDirection such a component reads the direction of the nearest provider and sets dir on its element itself, so its layout mirrors together with the controls inside it and users meet one consistent reading direction.

Safety stock

API Reference

DirectionProvider

Propdirection
Type"ltr" | "rtl"
Default"ltr"
DescriptionSets the reading direction that the components inside the provider follow. The provider sets no dir attribute, so the element around it needs dir with the same value.
Propchildren
TypeReactNode
Default–
DescriptionHolds the app or the group of components that follows the direction.

useDirection

useDirection returns the direction that the nearest DirectionProvider sets, "ltr" or "rtl". Without a provider, it returns "ltr". It is a hook, so it takes no arguments, renders no element and has no props of its own.