Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL Support #1638

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17c6690
feat(alert-dialog): add rtl support
nahasco Sep 11, 2024
c83be56
feat(alert): add rtl support
nahasco Sep 11, 2024
a25fa15
feat(carousel): add rtl support
nahasco Sep 11, 2024
cbe3c2c
feat(command): add rtl support
nahasco Sep 11, 2024
3233e39
feat(context-menu): add rtl support
nahasco Sep 11, 2024
527da48
feat(dialog): add rtl support
nahasco Sep 11, 2024
401a470
feat(drawer): add rtl support
nahasco Sep 11, 2024
6ae9bee
feat(dropdown-menu): add rtl support
nahasco Sep 11, 2024
de6fe31
feat(menubar): add rtl support
nahasco Sep 12, 2024
e8cfcaf
feat(navigation-menu): add rtl support
nahasco Sep 15, 2024
ef74963
feat(pagination): add rtl support
nahasco Sep 15, 2024
48a1122
refactor: use tailwind rtl and rotate to rotate chevrons instead of u…
nahasco Sep 15, 2024
f8aef7f
feat(carousel): improve rtl support
nahasco Sep 15, 2024
6d2a66e
feat(select): add rtl support
nahasco Sep 15, 2024
8550e65
feat(sheet): add rtl support
nahasco Oct 3, 2024
f18ccc1
feat(switch): add rtl support
nahasco Oct 3, 2024
a441163
feat(table): add rtl support
nahasco Oct 3, 2024
d3ba573
feat(breadcrumb): add rtl support
jjeem Nov 27, 2024
14ba98c
feat(input-otp): add rtl support
jjeem Nov 27, 2024
8525300
feat(calendar): add rtl support
jjeem Nov 27, 2024
3a5b777
feat(toast): add rtl support
nahasco Dec 6, 2024
238d856
Merge pull request #1 from jjeem/main
nahasco Dec 6, 2024
0d46f0d
Sync fork
nahasco Dec 7, 2024
b159f6e
feat(sidebar): add rtl support
jjeem Dec 10, 2024
370b30d
Merge branch 'main' into main
nahasco Dec 11, 2024
844f09a
Merge branch 'nahasco:main' into main
jjeem Dec 11, 2024
a1b28d9
Merge pull request #2 from jjeem/main
nahasco Dec 11, 2024
1f32bc2
Merge branch 'main' into main
nahasco Dec 14, 2024
11485d0
Merge branch 'main' into main
nahasco Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-context-menu": "^2.1.4",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-direction": "^1.1.0",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
"@radix-ui/react-icons": "^1.3.0",
Expand Down Expand Up @@ -60,7 +61,7 @@
"contentlayer2": "^0.4.6",
"date-fns": "^2.30.0",
"embla-carousel-autoplay": "8.0.0-rc15",
"embla-carousel-react": "8.0.0-rc15",
"embla-carousel-react": "8.0.1",
"framer-motion": "^11.0.24",
"geist": "^1.2.2",
"input-otp": "^1.2.2",
Expand Down
4 changes: 2 additions & 2 deletions apps/www/registry/default/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const AlertDialogHeader = ({
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
"flex flex-col space-y-2 text-center sm:text-start",
className
)}
{...props}
Expand All @@ -65,7 +65,7 @@ const AlertDialogFooter = ({
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 rtl:space-x-reverse",
Copy link

@dodeca-6-tope dodeca-6-tope Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not flex flex-col-reverse sm:flex-row sm:justify-end sm:gap-2? I think it'd be cleaner.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt want to change the original styling alot. Just adding rtl:space-x-reverse at the end is the most minimal, i think.

className
)}
{...props}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/registry/default/ui/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"

const alertVariants = cva(
"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
"relative w-full rounded-lg border p-4 [&>svg~*]:ps-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:start-4 [&>svg]:top-4 [&>svg]:text-foreground",
{
variants: {
variant: {
Expand Down
25 changes: 19 additions & 6 deletions apps/www/registry/default/ui/carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client"

import * as React from "react"
import { useDirection } from "@radix-ui/react-direction"
import useEmblaCarousel, {
type UseEmblaCarouselType,
} from "embla-carousel-react"
Expand All @@ -19,6 +20,7 @@ type CarouselProps = {
plugins?: CarouselPlugin
orientation?: "horizontal" | "vertical"
setApi?: (api: CarouselApi) => void
direction: "ltr" | "rtl"
}

type CarouselContextProps = {
Expand Down Expand Up @@ -58,9 +60,11 @@ const Carousel = React.forwardRef<
},
ref
) => {
const dir = useDirection()
const [carouselRef, api] = useEmblaCarousel(
{
...opts,
direction: dir,
axis: orientation === "horizontal" ? "x" : "y",
},
plugins
Expand Down Expand Up @@ -132,6 +136,7 @@ const Carousel = React.forwardRef<
scrollNext,
canScrollPrev,
canScrollNext,
direction: dir,
}}
>
<div
Expand Down Expand Up @@ -162,7 +167,7 @@ const CarouselContent = React.forwardRef<
ref={ref}
className={cn(
"flex",
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
orientation === "horizontal" ? "-ms-4" : "-mt-4 flex-col",
className
)}
{...props}
Expand All @@ -185,7 +190,7 @@ const CarouselItem = React.forwardRef<
aria-roledescription="slide"
className={cn(
"min-w-0 shrink-0 grow-0 basis-full",
orientation === "horizontal" ? "pl-4" : "pt-4",
orientation === "horizontal" ? "ps-4" : "pt-4",
className
)}
{...props}
Expand All @@ -208,15 +213,19 @@ const CarouselPrevious = React.forwardRef<
className={cn(
"absolute h-8 w-8 rounded-full",
orientation === "horizontal"
? "-left-12 top-1/2 -translate-y-1/2"
? "-start-12 top-1/2 -translate-y-1/2"
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
className
)}
disabled={!canScrollPrev}
onClick={scrollPrev}
{...props}
>
<ArrowLeft className="h-4 w-4" />
{orientation === "horizontal" ? (
<ArrowLeft className="h-4 w-4 rtl:rotate-180" />
) : (
<ArrowLeft className="h-4 w-4" />
)}
<span className="sr-only">Previous slide</span>
</Button>
)
Expand All @@ -237,15 +246,19 @@ const CarouselNext = React.forwardRef<
className={cn(
"absolute h-8 w-8 rounded-full",
orientation === "horizontal"
? "-right-12 top-1/2 -translate-y-1/2"
? "-end-12 top-1/2 -translate-y-1/2"
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
className
)}
disabled={!canScrollNext}
onClick={scrollNext}
{...props}
>
<ArrowRight className="h-4 w-4" />
{orientation === "horizontal" ? (
<ArrowRight className="h-4 w-4 rtl:rotate-180" />
) : (
<ArrowRight className="h-4 w-4" />
)}
<span className="sr-only">Next slide</span>
</Button>
)
Expand Down
4 changes: 2 additions & 2 deletions apps/www/registry/default/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CommandInput = React.forwardRef<
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
>(({ className, ...props }, ref) => (
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
<Search className="me-2 h-4 w-4 shrink-0 opacity-50" />
<CommandPrimitive.Input
ref={ref}
className={cn(
Expand Down Expand Up @@ -133,7 +133,7 @@ const CommandShortcut = ({
return (
<span
className={cn(
"ml-auto text-xs tracking-widest text-muted-foreground",
"ms-auto text-xs tracking-widest text-muted-foreground",
className
)}
{...props}
Expand Down
18 changes: 9 additions & 9 deletions apps/www/registry/default/ui/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const ContextMenuSubTrigger = React.forwardRef<
ref={ref}
className={cn(
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
>
{children}
<ChevronRight className="ml-auto h-4 w-4" />
<ChevronRight className="ms-auto h-4 w-4 rtl:rotate-180" />
</ContextMenuPrimitive.SubTrigger>
))
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName
Expand Down Expand Up @@ -81,7 +81,7 @@ const ContextMenuItem = React.forwardRef<
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
Expand All @@ -96,13 +96,13 @@ const ContextMenuCheckboxItem = React.forwardRef<
<ContextMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex cursor-default select-none items-center rounded-sm py-1.5 ps-8 pe-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
checked={checked}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span className="absolute start-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</ContextMenuPrimitive.ItemIndicator>
Expand All @@ -120,12 +120,12 @@ const ContextMenuRadioItem = React.forwardRef<
<ContextMenuPrimitive.RadioItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex cursor-default select-none items-center rounded-sm py-1.5 ps-8 pe-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span className="absolute start-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Circle className="h-2 w-2 fill-current" />
</ContextMenuPrimitive.ItemIndicator>
Expand All @@ -145,7 +145,7 @@ const ContextMenuLabel = React.forwardRef<
ref={ref}
className={cn(
"px-2 py-1.5 text-sm font-semibold text-foreground",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
Expand All @@ -172,7 +172,7 @@ const ContextMenuShortcut = ({
return (
<span
className={cn(
"ml-auto text-xs tracking-widest text-muted-foreground",
"ms-auto text-xs tracking-widest text-muted-foreground",
className
)}
{...props}
Expand Down
6 changes: 3 additions & 3 deletions apps/www/registry/default/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DialogContent = React.forwardRef<
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<DialogPrimitive.Close className="absolute end-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
Expand All @@ -59,7 +59,7 @@ const DialogHeader = ({
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
"flex flex-col space-y-1.5 text-center sm:text-start",
className
)}
{...props}
Expand All @@ -73,7 +73,7 @@ const DialogFooter = ({
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 rtl:space-x-reverse",
className
)}
{...props}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/registry/default/ui/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const DrawerHeader = ({
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
className={cn("grid gap-1.5 p-4 text-center sm:text-start", className)}
{...props}
/>
)
Expand Down
18 changes: 9 additions & 9 deletions apps/www/registry/default/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const DropdownMenuSubTrigger = React.forwardRef<
ref={ref}
className={cn(
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
>
{children}
<ChevronRight className="ml-auto h-4 w-4" />
<ChevronRight className="ms-auto h-4 w-4 rtl:rotate-180" />
</DropdownMenuPrimitive.SubTrigger>
))
DropdownMenuSubTrigger.displayName =
Expand Down Expand Up @@ -84,7 +84,7 @@ const DropdownMenuItem = React.forwardRef<
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
Expand All @@ -99,13 +99,13 @@ const DropdownMenuCheckboxItem = React.forwardRef<
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex cursor-default select-none items-center rounded-sm py-1.5 ps-8 pe-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
checked={checked}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span className="absolute start-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</DropdownMenuPrimitive.ItemIndicator>
Expand All @@ -123,12 +123,12 @@ const DropdownMenuRadioItem = React.forwardRef<
<DropdownMenuPrimitive.RadioItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex cursor-default select-none items-center rounded-sm py-1.5 ps-8 pe-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span className="absolute start-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<Circle className="h-2 w-2 fill-current" />
</DropdownMenuPrimitive.ItemIndicator>
Expand All @@ -148,7 +148,7 @@ const DropdownMenuLabel = React.forwardRef<
ref={ref}
className={cn(
"px-2 py-1.5 text-sm font-semibold",
inset && "pl-8",
inset && "ps-8",
className
)}
{...props}
Expand All @@ -174,7 +174,7 @@ const DropdownMenuShortcut = ({
}: React.HTMLAttributes<HTMLSpanElement>) => {
return (
<span
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
className={cn("ms-auto text-xs tracking-widest opacity-60", className)}
{...props}
/>
)
Expand Down
Loading