120k

文本方向

用于为应用程序设置文本方向的提供程序组件。

DirectionProvider 组件用于为应用程序设置文本方向(ltrrtl)。这对于支持阿拉伯语、希伯来语和波斯语等从右到左书写的语言至关重要。

下面是该组件在 RTL 模式下的预览。使用语言选择器切换语言。若要查看更多示例,请在组件页面中查找 RTL 部分。

تسجيل الدخول إلى حسابك
أدخل بريدك الإلكتروني أدناه لتسجيل الدخول إلى حسابك

安装

pnpm dlx shadcn@latest add direction

用法

import { DirectionProvider } from "@/components/ui/direction"
<html dir="rtl">
  <body>
    <DirectionProvider direction="rtl">
      {/* 您的应用内容 */}
    </DirectionProvider>
  </body>
</html>

useDirection

useDirection hook 用于获取应用程序的当前方向。

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