Skip to content

Commit f146921

Browse files
committed
feat UGN-362 - adds RTL support
1 parent c263c90 commit f146921

File tree

9 files changed

+49
-12
lines changed

9 files changed

+49
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"ts": "tsc",
1717
"lint": "eslint \"src/**/*.{ts,tsx}\"",
1818
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix",
19-
"prebuild": "rimraf dist && rimraf dist-commonjs && rimraf types",
19+
"prebuild": "npm run clean",
2020
"build": "rollup -c rollup.config.ts",
2121
"build-storybook": "build-storybook -o docs-build",
2222
"release:minor": "git checkout master && git pull && npm run test && npm run ts && npm run build && npm version patch && git add -A && git push && git push --tags && npm publish",
2323
"release:major": "git checkout master && git pull && npm run test && npm run ts && npm run build && npm version major && git add -A && git push && git push --tags && npm publish",
24-
"clean": "rimraf dist"
24+
"clean": "rimraf dist dist-commonjs types"
2525
},
2626
"repository": {
2727
"type": "git",

src/ReactSpreadsheetImport.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import merge from "lodash/merge"
22

33
import { Steps } from "./steps/Steps"
4-
import { themeOverrides } from "./theme"
4+
import { rtlThemeSupport, themeOverrides } from "./theme"
55
import { Providers } from "./components/Providers"
66
import type { RsiProps } from "./types"
77
import { ModalWrapper } from "./components/ModalWrapper"
@@ -24,7 +24,9 @@ export const defaultRSIProps: Partial<RsiProps<any>> = {
2424
export const ReactSpreadsheetImport = <T extends string>(props: RsiProps<T>) => {
2525
const mergedTranslations =
2626
props.translations !== translations ? merge(translations, props.translations) : translations
27-
const mergedThemes = merge(defaultTheme, props.customTheme)
27+
const mergedThemes = props.rtl
28+
? merge(defaultTheme, rtlThemeSupport, props.customTheme)
29+
: merge(defaultTheme, props.customTheme)
2830

2931
return (
3032
<Providers theme={mergedThemes} rsiValues={{ ...props, translations: mergedTranslations }}>

src/components/ModalCloseButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const ModalCloseButton = ({ onClose }: ModalCloseButtonProps) => {
3030
top="20px"
3131
onClick={() => setShowModal(true)}
3232
zIndex="toast"
33+
dir="ltr"
3334
/>
3435
</>
3536
)

src/components/ModalWrapper.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type React from "react"
22
import { Modal, ModalContent, ModalOverlay } from "@chakra-ui/react"
33
import { ModalCloseButton } from "./ModalCloseButton"
4+
import { useRsi } from "../hooks/useRsi"
45

56
type Props = {
67
children: React.ReactNode
@@ -9,6 +10,7 @@ type Props = {
910
}
1011

1112
export const ModalWrapper = ({ children, isOpen, onClose }: Props) => {
13+
const { rtl } = useRsi()
1214
return (
1315
<Modal
1416
isOpen={isOpen}
@@ -19,9 +21,11 @@ export const ModalWrapper = ({ children, isOpen, onClose }: Props) => {
1921
closeOnOverlayClick={false}
2022
scrollBehavior="inside"
2123
>
22-
<ModalOverlay />
23-
<ModalCloseButton onClose={onClose} />
24-
<ModalContent>{children}</ModalContent>
24+
<div dir={rtl ? "rtl" : "ltr"}>
25+
<ModalOverlay />
26+
<ModalCloseButton onClose={onClose} />
27+
<ModalContent>{children}</ModalContent>
28+
</div>
2529
</Modal>
2630
)
2731
}

src/components/Selects/MenuPortal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactDOM from "react-dom"
33
import { Box, useTheme } from "@chakra-ui/react"
44
import { usePopper } from "@chakra-ui/popper"
55
import { rootId } from "../Providers"
6+
import { useRsi } from "../../hooks/useRsi"
67

78
function createWrapperAndAppendToBody(wrapperId: string) {
89
const wrapperElement = document.createElement("div")
@@ -20,6 +21,7 @@ interface PortalProps {
2021

2122
const MenuPortal = (props: PortalProps) => {
2223
const theme = useTheme()
24+
const { rtl } = useRsi()
2325
const { popperRef, referenceRef } = usePopper({
2426
strategy: "fixed",
2527
matchWidth: true,
@@ -51,6 +53,7 @@ const MenuPortal = (props: PortalProps) => {
5153

5254
return ReactDOM.createPortal(
5355
<Box
56+
dir={rtl ? "rtl" : "ltr"}
5457
ref={popperRef}
5558
zIndex={theme.zIndices.tooltip}
5659
sx={{

src/components/Table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import DataGrid, { DataGridProps } from "react-data-grid"
2+
import { useRsi } from "../hooks/useRsi"
23

34
interface Props<Data> extends DataGridProps<Data> {
45
rowHeight?: number
56
hiddenHeader?: boolean
67
}
78

89
export const Table = <Data,>({ className, ...props }: Props<Data>) => {
9-
return <DataGrid className={"rdg-light " + className || ""} {...props} />
10+
const { rtl } = useRsi()
11+
return <DataGrid className={"rdg-light " + className || ""} direction={rtl ? "rtl" : "ltr"} {...props} />
1012
}

src/steps/ValidationStep/components/columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const generateColumns = <T extends string>(fields: Fields<T>): Column<Dat
8080
break
8181
default:
8282
component = (
83-
<Box pl="0.5rem">
83+
<Box paddingInlineStart="0.5rem">
8484
<Input
8585
ref={autoFocusAndSelect}
8686
variant="unstyled"

src/theme.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export const themeOverrides = {
309309
valueContainer: (provided) => ({
310310
...provided,
311311
p: 0,
312-
pl: 2,
312+
paddingInlineStart: 2,
313313
color: "gray.400",
314314
}),
315315
menu: (provided) => ({
@@ -428,9 +428,20 @@ export const themeOverrides = {
428428
".rdg-row:last-child .rdg-cell:last-child": {
429429
borderBottomRightRadius: "lg",
430430
},
431+
".rdg[dir='rtl']": {
432+
".rdg-row:last-child .rdg-cell:first-of-type": {
433+
borderBottomRightRadius: "lg",
434+
borderBottomLeftRadius: "none",
435+
},
436+
".rdg-row:last-child .rdg-cell:last-child": {
437+
borderBottomLeftRadius: "lg",
438+
borderBottomRightRadius: "none",
439+
},
440+
},
431441
".rdg-cell": {
432442
contain: "size layout style paint",
433443
borderRight: "none",
444+
borderInlineEnd: "none",
434445
borderBottom: "1px solid var(--rdg-border-color)",
435446
whiteSpace: "nowrap",
436447
overflow: "hidden",
@@ -439,10 +450,10 @@ export const themeOverrides = {
439450
boxShadow: "inset 0 0 0 1px var(--rdg-selection-color)",
440451
},
441452
"&:first-of-type": {
442-
borderLeft: "1px solid var(--rdg-border-color)",
453+
borderInlineStart: "1px solid var(--rdg-border-color)",
443454
},
444455
"&:last-child": {
445-
borderRight: "1px solid var(--rdg-border-color)",
456+
borderInlineEnd: "1px solid var(--rdg-border-color)",
446457
},
447458
},
448459
".rdg-cell-error": {
@@ -481,4 +492,16 @@ export const themeOverrides = {
481492
},
482493
} as const
483494

495+
export const rtlThemeSupport = {
496+
components: {
497+
Modal: {
498+
baseStyle: {
499+
dialog: {
500+
direction: "rtl",
501+
},
502+
},
503+
},
504+
},
505+
} as const
506+
484507
export type CustomTheme = DeepPartial<typeof themeOverrides>

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export type RsiProps<T extends string> = {
4343
dateFormat?: string
4444
// Sets SheetJS "raw" option. If true, parsing will only be applied to xlsx date fields.
4545
parseRaw?: boolean
46+
// Use for right-to-left (RTL) support
47+
rtl?: boolean
4648
}
4749

4850
export type RawData = Array<string | undefined>

0 commit comments

Comments
 (0)