Skip to content
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

fix: forces delete confirm prompt window to right side when lang = RTL #9792

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import arrowRightIcon from './icon--arrow-right.svg';

import styles from './delete-confirmation-prompt.css';

// TODO: Parametrize from outside if we want more custom messaging
const messages = defineMessages({
shouldDeleteSpriteMessage: {
defaultMessage: 'Are you sure you want to delete this sprite?',
Expand Down Expand Up @@ -47,9 +46,16 @@ const messages = defineMessages({
});

const modalWidth = 300;
const calculateModalPosition = (relativeElemRef, modalPosition) => {
const calculateModalPosition = (relativeElemRef, modalPosition, isRTL) => {
const refPosition = relativeElemRef.getBoundingClientRect();

if (isRTL) {
return {
top: refPosition.top - refPosition.height,
left: refPosition.right + 25
};
}

if (modalPosition === 'left') {
return {
top: refPosition.top - refPosition.height,
Expand All @@ -71,11 +77,9 @@ const getMessage = entityType => {
if (entityType === 'COSTUME') {
return messages.shouldDeleteCostumeMessage;
}

if (entityType === 'SOUND') {
return messages.shouldDeleteSoundMessage;
}

return messages.shouldDeleteSpriteMessage;
};

Expand All @@ -87,12 +91,11 @@ const DeleteConfirmationPrompt = ({
entityType,
relativeElemRef
}) => {
const modalPositionValues = calculateModalPosition(relativeElemRef, modalPosition);
const isRTL = document.querySelector('[dir="rtl"]') !== null;
const modalPositionValues = calculateModalPosition(relativeElemRef, modalPosition, isRTL);

return (<ReactModal
isOpen
// We have to inline the styles, since a part
// of them are dynamically generated
style={{
content: {
...modalPositionValues,
Expand All @@ -103,8 +106,9 @@ const DeleteConfirmationPrompt = ({
padding: 0,
margin: 0,
position: 'absolute',
overflowX: 'hidden',
zIndex: 1000
overflow: 'visible',
zIndex: 1000,
direction: isRTL ? 'rtl' : 'ltr'
},
overlay: {
position: 'fixed',
Expand All @@ -120,13 +124,23 @@ const DeleteConfirmationPrompt = ({
onRequestClose={onCancel}
>
<Box className={styles.modalContainer}>
{ modalPosition === 'right' ?
<Box className={classNames(styles.arrowContainer, styles.arrowContainerLeft)}>
<img
className={styles.deleteIcon}
src={arrowLeftIcon}
/>
</Box> : null }
<Box
className={classNames(
styles.arrowContainer,
isRTL ? styles.arrowContainerRight : styles.arrowContainerLeft
)}
style={{
position: 'absolute',
top: '50%',
transform: 'translateY(-50%)',
[isRTL ? 'left' : 'right']: '-10px'
}}
>
<img
className={styles.deleteIcon}
src={isRTL ? arrowLeftIcon : arrowRightIcon}
/>
</Box>
<Box className={styles.body}>
<Box className={styles.label}>
<FormattedMessage {...getMessage(entityType)} />
Expand Down Expand Up @@ -160,13 +174,6 @@ const DeleteConfirmationPrompt = ({
</button>
</Box>
</Box>
{modalPosition === 'left' ?
<Box className={classNames(styles.arrowContainer, styles.arrowContainerRight)}>
<img
className={styles.deleteIcon}
src={arrowRightIcon}
/>
</Box> : null }
</Box>
</ReactModal>);
};
Expand Down
Loading