Utilities

Direction Provider

Enables RTL behavior for Solid Base components.

Anatomy#

Import the component and wrap it around your app:

Anatomytsx
import { DirectionProvider } from '@egoist/solid-base/direction-provider';

<DirectionProvider>{/* Your app or a group of components */}</DirectionProvider>;

<DirectionProvider> enables child components to adjust behavior based on RTL text direction, but does not affect HTML and CSS. The dir="rtl" HTML attribute or direction: rtl CSS style must be set additionally by your own application code.

API reference#

DirectionProvider#

<DirectionProvider>

Enables RTL behavior for Solid Base components.

PropTypeDefault
directionTextDirection'ltr'

The reading direction of the text

useDirection#

Use this primitive to read the current text direction. This is useful for wrapping portaled components that may be rendered outside your application root and are unaffected by the dir attribute set within.

Reading the directiontsx
import { useDirection } from '@egoist/solid-base/direction-provider';

function Popup(props: { children: JSX.Element }) {
  const direction = useDirection();
  return <div dir={direction()}>{props.children}</div>;
}
Returns Description
Accessor<TextDirection> The direction of the closest <DirectionProvider>, or 'ltr' without one.

Additional types#

type TextDirection = 'ltr' | 'rtl';