"use client";
import type { HTMLAttributes, ReactNode } from "react";
import { I18nProvider, useLocale } from "react-aria-components";
import { cx } from "@/utils/cx";
export type Direction = "ltr" | "rtl";
export interface DirectionProviderProps extends Omit, "dir" | "lang" | "children"> {
/** BCP 47 language tag. Arabic and Hebrew resolve to RTL; Chinese to LTR. */
locale: string;
children: ReactNode;
}
/** Keeps CSS direction, React Aria keyboard behavior and portalled menus in sync.
* Use at the app root, or nest providers for regions in another language.
* The default display: contents boundary preserves the surrounding layout.
*/
export function DirectionProvider({ locale, ...props }: DirectionProviderProps) {
return (
);
}
function DirectionBoundary({ children, className, ...props }: Omit) {
const { locale, direction } = useLocale();
return {children}
;
}
/** Also works inside a React Aria I18nProvider. */
export function useDirection(): Direction {
return useLocale().direction;
}