-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLNP-3692] Apply postcss-rtlcss plugin for RTL support (#1134)
Applied [postcss-rtlcss plugin](https://github.com/elchininet/postcss-rtlcss) for the better RTL support without tedious manual CSS style modifications. - [x] Added plugin configuration to storybook/main.ts - Allows testing of RTL support during development. - [x] Added plugin configuration to rollup.config.js - Ensures build artifacts support RTL languages. - [x] Created useHTMLTextDirection custom hook - Applies the dir attribute to modal and dropdown portal components for correct RTL rendering. postcss-rtlcss automates the conversion of LTR CSS to RTL, ensuring consistency and reducing manual errors. It automates CSS transformation by converting LTR styles to RTL, ensuring proper alignment and display in RTL mode. You can play around in here https://elchininet.github.io/postcss-rtlcss/ to see what kind of modifications could be made by this plugin.
- Loading branch information
1 parent
7307b8d
commit eb56719
Showing
15 changed files
with
119 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import vitePluginSvgr from 'vite-plugin-svgr'; | ||
import postcssRtl from "postcss-rtlcss"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), vitePluginSvgr({ include: '**/*.svg' })], | ||
css: { | ||
postcss: { | ||
plugins: [postcssRtl({ mode: 'override' })], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const APP_LAYOUT_ROOT = 'sendbird-app__layout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useEffect } from 'react'; | ||
import { MODAL_ROOT } from '../../../hooks/useModal'; | ||
import { EMOJI_MENU_ROOT_ID, MENU_ROOT_ID } from '../../../ui/ContextMenu'; | ||
import { HTMLTextDirection } from '../../../types'; | ||
import { APP_LAYOUT_ROOT } from '../const'; | ||
|
||
const ELEMENT_IDS = [ | ||
MODAL_ROOT, | ||
EMOJI_MENU_ROOT_ID, | ||
MENU_ROOT_ID, | ||
APP_LAYOUT_ROOT, | ||
]; | ||
|
||
/** | ||
* This hook sets the direction (dir) attribute for specified elements. | ||
* | ||
* @param {HTMLTextDirection} direction - The direction to set ('ltr' or 'rtl'). | ||
* | ||
* Note: | ||
* This is necessary because elements such as modal, emoji reaction list, and dropdown | ||
* are at the same level as the Sendbird app root element. They need to have the 'dir' | ||
* attribute set explicitly to ensure proper directionality based on the app's language setting. | ||
*/ | ||
const useApplyTextDirection = (direction: HTMLTextDirection) => { | ||
useEffect(() => { | ||
ELEMENT_IDS.forEach((id) => { | ||
const element = document.getElementById(id); | ||
if (element) { | ||
element.dir = direction; | ||
} | ||
}); | ||
}, [direction]); | ||
}; | ||
|
||
export default useApplyTextDirection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters