-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(experience-legacy): flip arrow icons on rtl (#6584)
- Loading branch information
1 parent
6a4726b
commit d7663db
Showing
4 changed files
with
54 additions
and
2 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
3 changes: 3 additions & 0 deletions
3
packages/experience-legacy/src/components/FlipOnRtl/index.module.scss
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,3 @@ | ||
.flip { | ||
transform: scaleX(-1); | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/experience-legacy/src/components/FlipOnRtl/index.tsx
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,38 @@ | ||
import classNames from 'classnames'; | ||
import { cloneElement, isValidElement, type ReactElement } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
type Props = { | ||
readonly children: ReactElement<HTMLElement>; | ||
}; | ||
|
||
/** | ||
* This component flips its child element horizontally if the browser's text direction is RTL (right-to-left). | ||
* | ||
* @component | ||
* @example | ||
* ```tsx | ||
* <FlipOnRtl> | ||
* <SVG /> | ||
* </FlipOnRtl> | ||
* ``` | ||
* | ||
* @param {React.ReactNode} children - The SVG or other HTML content to render and flip if RTL. | ||
* @returns {JSX.Element} The flipped content. | ||
*/ | ||
function FlipOnRtl({ children }: Props) { | ||
const { i18n } = useTranslation(); | ||
const isRtl = i18n.dir() === 'rtl'; | ||
|
||
if (!isValidElement(children)) { | ||
return children; | ||
} | ||
|
||
return cloneElement(children, { | ||
className: classNames(children.props.className, isRtl && styles.flip), | ||
}); | ||
} | ||
|
||
export default FlipOnRtl; |
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