- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/directionThe CLI writes components/ui/direction.tsx. It needs no package.
Usage#
import { DirectionProvider, useDirection } from '@/components/ui/direction';<DirectionProvider direction="rtl">
{/* the app's screens */}
<PortalHost />
</DirectionProvider>Put the app's PortalHost inside the provider: overlays, such as a menu or a toast, draw there, and read the
direction from the provider around the host.
const direction = useDirection(); // 'ltr' or 'rtl'API reference#
DirectionProvider#
| Prop | Type | Default |
|---|---|---|
direction | 'ltr' | 'rtl' | the system's, from I18nManager.isRTL |
children | ReactNode | - |
It tells the parts inside it which way text reads. On the web it also sets dir on a box around its children
that takes no room of its own (display: contents), so the page lays them out in that direction: rows start
from the right, and ms-* and me-* margins swap sides.
useDirection#
Returns 'ltr' or 'rtl': the nearest DirectionProvider's direction, or the system's outside one.
useDirectionSides#
For a part that places or moves something itself. Returns:
rtl: whether it runs right to left, the provider's direction.layout: the direction the platform lays out rows andstartandendstyles in around it. On the web that is the provider's, which setsdir; on a device it is the system's, whatever a provider says.startandend: the style keys that put a child at the side it runs from and the side it runs to,'start'and'end'wherelayoutruns the same way asrtl, swapped where it does not.sidesSwapped: whetherleftandrightstyles are drawn swapped, true on a device the system lays out right to left unless the app calledI18nManager.swapLeftAndRightInRTL(false), and false on the web.
useMirrored#
Returns a style that mirrors an arrow drawn for text read left to right when the direction is 'rtl', and
undefined when it is 'ltr'.
The items that read it#
Breadcrumb, Pagination,
Calendar, Carousel and the
sub-menu triggers of Dropdown menu,
Context menu and Menubar
mirror their chevrons in text read right to left. Carousel, Slider and
a horizontal Resizable group run from the right, Calendar and Slider
swap their left and right arrow keys, as upstream's do, and Sheet and
Drawer move toward the side a device draws them on. Carousel, Slider and
Resizable place their own parts through useDirectionSides, so they run the provider's way on a device even where
the system lays the app out the other way. The rows the platform lays out, such as a breadcrumb's or a calendar's,
follow the system's direction there. Each item's page says how.
Right to left on a device#
A device lays out the whole app in one direction, which I18nManager holds for the app's life: rows start from
the right and start and end swap sides when the system language reads right to left, or after
I18nManager.forceRTL(true) and a restart. A provider cannot change that for part of a screen, so on a device
it draws nothing around its children and only tells them the direction it was given. A provider that disagrees
with the system turns the items' arrows, keys and their own tracks its way while the rows around them run the
system's way. Set it from the same place as the app's layout direction, such as expo-localization's
getLocales()[0].textDirection, so that both agree.
Differences from upstream#
directiondefaults to the system's direction, where upstream's defaults to'ltr': on a device the system sets the layout direction, and a provider that disagreed with it would make the parts reading it disagree with the layout.- Upstream's provider re-exports
@base-ui/react's, which sets nodiritself and leaves it to the page's<html dir>. A React Native app on the web has no<html>of its own to set, so the provider here setsdiron a box around its children. - On a device the provider changes no layout, as above.
useDirectionSidesanduseMirroredare added. A device lays out in the system's direction whatever a provider says, and draws a sheet or a drawer namedlefton the right when that direction is right to left. Neither happens on the web, so upstream needs neither.