Skip to content

Commit a75cf7f

Browse files
MECloudswillbouch
andauthored
feat(dashboard): support RTL in dashboard (medusajs#11252)
* fix: add direction attribute to components and adjust styles for RTL support * fix(data-grid): comment it out * Added useDocumentDirection hook * refactor: Integrate useDocumentDirection hook * refactor: Standardize direction prop usage across components * resolve * fix: resolve build errors * fix : remove unused useDocument * Apply RTL styles for some components * Create smooth-gorillas-hide.md * refactor: update some styles for RTL support --------- Co-authored-by: William Bouchard <[email protected]>
1 parent a501364 commit a75cf7f

File tree

70 files changed

+407
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+407
-142
lines changed

.changeset/smooth-gorillas-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
---
4+
5+
feat(dashboard): support RTL in dashboard

packages/admin/dashboard/src/components/common/action-menu/action-menu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EllipsisHorizontal } from "@medusajs/icons"
44
import { PropsWithChildren, ReactNode } from "react"
55
import { Link } from "react-router-dom"
66
import { ConditionalTooltip } from "../conditional-tooltip"
7+
import { useDocumentDirection } from "../../../hooks/use-document-direction"
78

89
export type Action = {
910
icon: ReactNode
@@ -38,14 +39,15 @@ export const ActionMenu = ({
3839
variant = "transparent",
3940
children,
4041
}: ActionMenuProps) => {
42+
const direction = useDocumentDirection()
4143
const inner = children ?? (
4244
<IconButton size="small" variant={variant}>
4345
<EllipsisHorizontal />
4446
</IconButton>
4547
)
4648

4749
return (
48-
<DropdownMenu>
50+
<DropdownMenu dir={direction}>
4951
<DropdownMenu.Trigger asChild>{inner}</DropdownMenu.Trigger>
5052
<DropdownMenu.Content>
5153
{groups.map((group, index) => {

packages/admin/dashboard/src/components/common/json-view-section/json-view-section.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export const JsonViewSection = ({ data }: JsonViewSectionProps) => {
4646
<ArrowUpRightOnBox />
4747
</IconButton>
4848
</Drawer.Trigger>
49-
<Drawer.Content className="bg-ui-contrast-bg-base text-ui-code-fg-subtle !shadow-elevation-commandbar overflow-hidden border border-none max-md:inset-x-2 max-md:max-w-[calc(100%-16px)]">
49+
<Drawer.Content
50+
dir="ltr"
51+
className="bg-ui-contrast-bg-base text-ui-code-fg-subtle !shadow-elevation-commandbar overflow-hidden border border-none max-md:inset-x-2 max-md:max-w-[calc(100%-16px)]"
52+
>
5053
<div className="bg-ui-code-bg-base flex items-center justify-between px-6 py-4">
5154
<div className="flex items-center gap-x-4">
5255
<Drawer.Title asChild>

packages/admin/dashboard/src/components/common/sidebar-link/sidebar-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const SidebarLink = ({
3737
</Text>
3838
</div>
3939
<div className="flex size-7 items-center justify-center">
40-
<TriangleRightMini className="text-ui-fg-muted" />
40+
<TriangleRightMini className="text-ui-fg-muted rtl:rotate-180" />
4141
</div>
4242
</div>
4343
</div>

packages/admin/dashboard/src/components/common/switch-box/switch-box.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export const SwitchBox = <
5050
<div className="bg-ui-bg-component shadow-elevation-card-rest flex items-start gap-x-3 rounded-lg p-3">
5151
<Form.Control>
5252
<Switch
53+
className="rtl:rotate-180"
54+
dir="ltr"
5355
{...field}
5456
checked={value}
5557
onCheckedChange={(e) => {

packages/admin/dashboard/src/components/data-grid/components/data-grid-root.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { FieldValues, UseFormReturn } from "react-hook-form"
2929
import { useTranslation } from "react-i18next"
3030

3131
import { useCommandHistory } from "../../../hooks/use-command-history"
32+
import { useDocumentDirection } from "../../../hooks/use-document-direction"
3233
import { ConditionalTooltip } from "../../common/conditional-tooltip"
3334
import { DataGridContext } from "../context"
3435
import {
@@ -50,7 +51,7 @@ import { isCellMatch, isSpecialFocusKey } from "../utils"
5051
import { DataGridKeyboardShortcutModal } from "./data-grid-keyboard-shortcut-modal"
5152
export interface DataGridRootProps<
5253
TData,
53-
TFieldValues extends FieldValues = FieldValues
54+
TFieldValues extends FieldValues = FieldValues,
5455
> {
5556
data?: TData[]
5657
columns: ColumnDef<TData>[]
@@ -96,7 +97,7 @@ const getCommonPinningStyles = <TData,>(
9697

9798
export const DataGridRoot = <
9899
TData,
99-
TFieldValues extends FieldValues = FieldValues
100+
TFieldValues extends FieldValues = FieldValues,
100101
>({
101102
data = [],
102103
columns,
@@ -700,6 +701,7 @@ const DataGridHeader = ({
700701
const [shortcutsOpen, setShortcutsOpen] = useState(false)
701702
const [columnsOpen, setColumnsOpen] = useState(false)
702703
const { t } = useTranslation()
704+
const direction = useDocumentDirection()
703705

704706
// Since all columns are checked by default, we can check if any column is unchecked
705707
const hasChanged = columnOptions.some((column) => !column.checked)
@@ -716,7 +718,11 @@ const DataGridHeader = ({
716718
return (
717719
<div className="bg-ui-bg-base flex items-center justify-between border-b p-4">
718720
<div className="flex items-center gap-x-2">
719-
<DropdownMenu open={columnsOpen} onOpenChange={handleColumnsOpenChange}>
721+
<DropdownMenu
722+
dir={direction}
723+
open={columnsOpen}
724+
onOpenChange={handleColumnsOpenChange}
725+
>
720726
<ConditionalTooltip
721727
showTooltip={isDisabled}
722728
content={t("dataGrid.columns.disabled")}

packages/admin/dashboard/src/components/data-grid/components/data-grid-toggleable-number-cell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ const OuterComponent = ({
106106
>
107107
<div className="absolute inset-y-0 left-4 z-[3] flex w-fit items-center justify-center">
108108
<Switch
109+
dir="ltr"
109110
ref={buttonRef}
110111
size="small"
111-
className="shrink-0"
112+
className="shrink-0 rtl:rotate-180"
112113
checked={localValue.checked}
113114
disabled={localValue.disabledToggle}
114115
onCheckedChange={handleCheckedChange}

packages/admin/dashboard/src/components/filtering/filter-group/filter-group.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button, DropdownMenu } from "@medusajs/ui"
22
import { ReactNode } from "react"
33
import { useSearchParams } from "react-router-dom"
4+
import { useDocumentDirection } from "../../../hooks/use-document-direction"
45

56
type FilterGroupProps = {
67
filters: {
@@ -37,8 +38,11 @@ type AddFilterMenuProps = {
3738
}
3839

3940
const AddFilterMenu = ({ availableKeys }: AddFilterMenuProps) => {
41+
const direction = useDocumentDirection()
4042
return (
41-
<DropdownMenu>
43+
<DropdownMenu
44+
dir={direction}
45+
>
4246
<DropdownMenu.Trigger asChild>
4347
<Button variant="secondary" size="small">
4448
Add filter

packages/admin/dashboard/src/components/filtering/order-by/order-by.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useState } from "react"
44
import { useTranslation } from "react-i18next"
55
import { useSearchParams } from "react-router-dom"
66

7+
import { useDocumentDirection } from "../../../hooks/use-document-direction"
8+
79
type OrderByProps = {
810
keys: string[]
911
}
@@ -56,6 +58,7 @@ export const OrderBy = ({ keys }: OrderByProps) => {
5658
}>(initState(searchParams))
5759

5860
const { t } = useTranslation()
61+
const direction = useDocumentDirection()
5962

6063
const handleDirChange = (dir: string) => {
6164
setState((prev) => ({
@@ -99,7 +102,7 @@ export const OrderBy = ({ keys }: OrderByProps) => {
99102
}
100103

101104
return (
102-
<DropdownMenu>
105+
<DropdownMenu dir={direction}>
103106
<DropdownMenu.Trigger asChild>
104107
<IconButton size="small">
105108
<ArrowUpDown />

packages/admin/dashboard/src/components/forms/address-form/address-form.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Control } from "react-hook-form"
77
import { AddressSchema } from "../../../lib/schemas"
88
import { Form } from "../../common/form"
99
import { CountrySelect } from "../../inputs/country-select"
10+
import { useDocumentDirection } from "../../../hooks/use-document-direction"
1011

1112
type AddressFieldValues = z.infer<typeof AddressSchema>
1213

@@ -22,7 +23,7 @@ export const AddressForm = ({
2223
layout,
2324
}: AddressFormProps) => {
2425
const { t } = useTranslation()
25-
26+
const direction = useDocumentDirection()
2627
const style = clx("gap-4", {
2728
"flex flex-col": layout === "stack",
2829
"grid grid-cols-2": layout === "grid",
@@ -182,7 +183,11 @@ export const AddressForm = ({
182183
<Form.Label>{t("fields.country")}</Form.Label>
183184
<Form.Control>
184185
{countries ? (
185-
<Select {...field} onValueChange={onChange}>
186+
<Select
187+
dir={direction}
188+
{...field}
189+
onValueChange={onChange}
190+
>
186191
<Select.Trigger ref={ref}>
187192
<Select.Value />
188193
</Select.Trigger>

0 commit comments

Comments
 (0)