0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(experience-legacy): flip arrow icons on rtl (#6584)

This commit is contained in:
Charles Zhao 2024-09-13 16:02:55 +08:00 committed by GitHub
parent 6a4726b588
commit d7663db6cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 54 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import FactorTotp from '@/assets/icons/factor-totp.svg?react';
import FactorWebAuthn from '@/assets/icons/factor-webauthn.svg?react';
import DynamicT from '../DynamicT';
import FlipOnRtl from '../FlipOnRtl';
import mfaFactorButtonStyles from './MfaFactorButton.module.scss';
import styles from './index.module.scss';
@ -65,7 +66,9 @@ const MfaFactorButton = ({ factor, isBinding, onClick }: Props) => {
<DynamicT forKey={(isBinding ? linkFactorDescription : factorDescription)[factor]} />
</div>
</div>
<FlipOnRtl>
<ArrowNext className={mfaFactorButtonStyles.icon} />
</FlipOnRtl>
</button>
);
};

View file

@ -0,0 +1,3 @@
.flip {
transform: scaleX(-1);
}

View file

@ -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;

View file

@ -7,6 +7,8 @@ import ArrowPrev from '@/assets/icons/arrow-prev.svg?react';
import NavClose from '@/assets/icons/nav-close.svg?react';
import { onKeyDownHandler } from '@/utils/a11y';
import FlipOnRtl from '../FlipOnRtl';
import styles from './index.module.scss';
type Props = {
@ -48,7 +50,13 @@ const NavBar = ({ title, type = 'back', isHidden, onClose, onSkip }: Props) => {
onKeyDown={onKeyDownHandler(clickHandler)}
onClick={clickHandler}
>
{isClosable ? <NavClose /> : <ArrowPrev />}
{isClosable ? (
<NavClose />
) : (
<FlipOnRtl>
<ArrowPrev />
</FlipOnRtl>
)}
{!isClosable && <span>{t('action.nav_back')}</span>}
</div>
{title && <div className={styles.title}>{title}</div>}