Skip to content

Rtl fix #209

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

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion src/components/EditorCanvas/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks";
import TableInfo from "../EditorSidePanel/TablesTab/TableInfo";
import { useTranslation } from "react-i18next";
import { dbToTypes } from "../../data/datatypes";
import { isRtl } from "../../i18n/utils/rtl";
import i18n from "../../i18n/i18n";

export default function Table(props) {
const [hoveredField, setHoveredField] = useState(-1);
Expand Down Expand Up @@ -84,6 +86,7 @@ export default function Table(props) {
? "border-solid border-blue-500"
: "border-zinc-500"
}`}
style={{ direction: "ltr" }}
>
<div
className="h-[10px] w-full rounded-t-md"
Expand Down Expand Up @@ -190,7 +193,10 @@ export default function Table(props) {
key={i}
content={
<div className="popover-theme">
<div className="flex justify-between items-center pb-2">
<div
className="flex justify-between items-center pb-2"
style={{ direction: "ltr" }}
>
<p className="me-4 font-bold">{e.name}</p>
<p className="ms-4">
{e.type +
Expand Down Expand Up @@ -235,6 +241,11 @@ export default function Table(props) {
}
position="right"
showArrow
style={
isRtl(i18n.language)
? { direction: "rtl" }
: { direction: "ltr" }
}
>
{field(e, i)}
</Popover>
Expand Down
32 changes: 25 additions & 7 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import {
IconCaretdown,
IconChevronRight,
IconChevronLeft,
IconChevronUp,
IconChevronDown,
IconSaveStroked,
Expand Down Expand Up @@ -68,6 +69,7 @@ import { useTranslation } from "react-i18next";
import { exportSQL } from "../../utils/exportSQL";
import { databases } from "../../data/databases";
import { jsonToMermaid } from "../../utils/exportAs/mermaid";
import { isRtl } from "../../i18n/utils/rtl";

export default function ControlPanel({
diagramId,
Expand Down Expand Up @@ -109,7 +111,7 @@ export default function ControlPanel({
const { undoStack, redoStack, setUndoStack, setRedoStack } = useUndoRedo();
const { selectedElement, setSelectedElement } = useSelect();
const { transform, setTransform } = useTransform();
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const navigate = useNavigate();

const invertLayout = (component) =>
Expand Down Expand Up @@ -1374,15 +1376,20 @@ export default function ControlPanel({

function toolbar() {
return (
<div className="py-1.5 px-5 flex justify-between items-center rounded-xl my-1 sm:mx-1 xl:mx-6 select-none overflow-hidden toolbar-theme">
<div
className="py-1.5 px-5 flex justify-between items-center rounded-xl my-1 sm:mx-1 xl:mx-6 select-none overflow-hidden toolbar-theme"
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<div className="flex justify-start items-center">
<LayoutDropdown />
<Divider layout="vertical" margin="8px" />
<Dropdown
style={{ width: "240px" }}
position="bottomLeft"
position={isRtl(i18n.language) ? "bottomRight" : "bottomLeft"}
render={
<Dropdown.Menu>
<Dropdown.Menu
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<Dropdown.Item
onClick={fitWindow}
style={{ display: "flex", justifyContent: "space-between" }}
Expand Down Expand Up @@ -1562,7 +1569,10 @@ export default function ControlPanel({

function header() {
return (
<nav className="flex justify-between pt-1 items-center whitespace-nowrap">
<nav
className="flex justify-between pt-1 items-center whitespace-nowrap"
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<div className="flex justify-start items-center">
<Link to="/">
<img
Expand Down Expand Up @@ -1608,7 +1618,10 @@ export default function ControlPanel({
<Dropdown
key={category}
position="bottomLeft"
style={{ width: "240px" }}
style={{
width: "240px",
direction: isRtl(i18n.language) ? "rtl" : "ltr",
}}
render={
<Dropdown.Menu>
{Object.keys(menu[category]).map((item, index) => {
Expand Down Expand Up @@ -1642,7 +1655,12 @@ export default function ControlPanel({
onClick={menu[category][item].function}
>
{t(item)}
<IconChevronRight />

{isRtl(i18n.language) ? (
<IconChevronLeft />
) : (
<IconChevronRight />
)}
</Dropdown.Item>
</Dropdown>
);
Expand Down
11 changes: 7 additions & 4 deletions src/components/EditorHeader/LayoutDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Dropdown } from "@douyinfe/semi-ui";
import { useFullscreen, useLayout } from "../../hooks";
import { enterFullscreen, exitFullscreen } from "../../utils/fullscreen";
import { useTranslation } from "react-i18next";
import { isRtl } from "../../i18n/utils/rtl";
import i18n from "../../i18n/i18n";

export default function LayoutDropdown() {
const fullscreen = useFullscreen();
Expand All @@ -19,7 +21,10 @@ export default function LayoutDropdown() {
return (
<Dropdown
position="bottomLeft"
style={{ width: "180px" }}
style={{
width: "180px",
direction: isRtl(i18n.language) ? "rtl" : "ltr",
}}
render={
<Dropdown.Menu>
<Dropdown.Item
Expand Down Expand Up @@ -48,9 +53,7 @@ export default function LayoutDropdown() {
</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item
icon={
fullscreen ? <IconCheckboxTick /> : <div className="px-2" />
}
icon={fullscreen ? <IconCheckboxTick /> : <div className="px-2" />}
onClick={() => {
if (fullscreen) {
exitFullscreen();
Expand Down
10 changes: 8 additions & 2 deletions src/components/EditorHeader/Modal/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { githubLight } from "@uiw/codemirror-theme-github";
import { useTranslation } from "react-i18next";
import { importSQL } from "../../../utils/importSQL";
import { databases } from "../../../data/databases";
import { isRtl } from "../../../i18n/utils/rtl";

const languageExtension = {
sql: [sql()],
Expand All @@ -53,7 +54,7 @@ export default function Modal({
setExportData,
importDb,
}) {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const { setTables, setRelationships, database, setDatabase } = useDiagram();
const { setNotes } = useNotes();
const { setAreas } = useAreas();
Expand Down Expand Up @@ -324,6 +325,7 @@ export default function Modal({

return (
<SemiUIModal
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
title={getModalTitle(modal)}
visible={modal !== MODAL.NONE}
onOk={getModalOnOk}
Expand Down Expand Up @@ -362,7 +364,11 @@ export default function Modal({
}}
cancelText={t("cancel")}
width={modal === MODAL.NEW || modal === MODAL.OPEN ? 740 : 600}
bodyStyle={{ maxHeight: window.innerHeight - 280, overflow: "auto" }}
bodyStyle={{
maxHeight: window.innerHeight - 280,
overflow: "auto",
direction: "ltr",
}}
>
{getModalBody()}
</SemiUIModal>
Expand Down
5 changes: 4 additions & 1 deletion src/components/EditorSidePanel/SidePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useTranslation } from "react-i18next";
import { useMemo } from "react";
import { databases } from "../../data/databases";
import EnumsTab from "./EnumsTab/EnumsTab";
import { isRtl } from "../../i18n/utils/rtl";
import i18n from "../../i18n/i18n";

export default function SidePanel({ width, resize, setResize }) {
const { layout } = useLayout();
Expand Down Expand Up @@ -46,7 +48,7 @@ export default function SidePanel({ width, resize, setResize }) {
});
}

return tabs;
return isRtl(i18n.language) ? tabs.reverse() : tabs;
}, [t, database]);

return (
Expand All @@ -64,6 +66,7 @@ export default function SidePanel({ width, resize, setResize }) {
setSelectedElement((prev) => ({ ...prev, currentTab: key }))
}
collapsible
tabBarStyle={{ direction: "ltr" }}
>
{tabList.length &&
tabList.map((tab) => (
Expand Down
1 change: 1 addition & 0 deletions src/components/EditorSidePanel/TablesTab/TableInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function TableInfo({ data }) {
<div
key={"field_" + j}
className={`cursor-pointer ${drag.draggingOverIndexList.includes(j) ? "opacity-25" : ""}`}
style={{ direction: "ltr" }}
draggable
onDragStart={() => {
setDrag((prev) => ({ ...prev, draggingElementIndex: j }));
Expand Down
6 changes: 4 additions & 2 deletions src/components/Workspace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import FloatingControls from "./FloatingControls";
import { Modal } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";
import { databases } from "../data/databases";
import { isRtl } from "../i18n/utils/rtl";

export default function WorkSpace() {
const [id, setId] = useState(0);
Expand Down Expand Up @@ -49,11 +50,11 @@ export default function WorkSpace() {
setDatabase,
} = useDiagram();
const { undoStack, redoStack, setUndoStack, setRedoStack } = useUndoRedo();
const { t } = useTranslation();
const { t, i18n } = useTranslation();

const handleResize = (e) => {
if (!resize) return;
const w = e.clientX;
const w = isRtl(i18n.language) ? window.innerWidth - e.clientX : e.clientX;
if (w > 340) setWidth(w);
};

Expand Down Expand Up @@ -358,6 +359,7 @@ export default function WorkSpace() {
// https://stackoverflow.com/a/70976017/1137077
e.target.releasePointerCapture(e.pointerId);
}}
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
{layout.sidebar && (
<SidePanel resize={resize} setResize={setResize} width={width} />
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/utils/rtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const rtlLanguages = ["ar", "he", "fa", "ps", "ur"];
export const isRtl = (language) => rtlLanguages.includes(language);
Loading