Skip to content

Commit 3b353d1

Browse files
pishi.aipishi-ai
authored andcommitted
fix(gui): rtl support for delete-confirmation-prompt
This commit adds RTL (Right-to-Left) support for the delete-confirmation-prompt. In RTL languages, when multiple sprites are opened, the delete section of the confirmation prompt extended beyond the window boundary. This update fixes the layout so it displays correctly in RTL as well as LTR.
1 parent c9af4a3 commit 3b353d1

File tree

7 files changed

+78
-19
lines changed

7 files changed

+78
-19
lines changed

packages/scratch-gui/src/components/delete-confirmation-prompt/delete-confirmation-prompt.css

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,32 @@
1010
.arrow-container {
1111
display: flex;
1212
align-items: center;
13+
}
14+
15+
[dir="ltr"] .arrow-container {
1316
margin-right: -7px;
1417
}
1518

16-
.arrow-container-left {
19+
[dir="rtl"] .arrow-container {
20+
margin-left: -7px;
21+
}
22+
23+
[dir="ltr"] .arrow-container-left {
1724
margin-right: -7px;
1825
}
1926

20-
.arrow-container-right {
27+
[dir="rtl"] .arrow-container-left {
2128
margin-left: -7px;
2229
}
2330

31+
[dir="ltr"] .arrow-container-right {
32+
margin-left: -7px;
33+
}
34+
35+
[dir="rtl"] .arrow-container-right {
36+
margin-right: -7px;
37+
}
38+
2439
.body {
2540
padding: 1rem 1.5rem;
2641
border-radius: 0.5rem;
@@ -55,14 +70,22 @@
5570
margin: auto;
5671
}
5772

58-
.button-row button.ok-button {
73+
[dir="ltr"] .button-row button.ok-button {
5974
margin-left: 0;
6075
}
6176

62-
.button-row button.cancel-button {
77+
[dir="rtl"] .button-row button.ok-button {
78+
margin-right: 0;
79+
}
80+
81+
[dir="ltr"] .button-row button.cancel-button {
6382
margin-right: 0;
6483
}
6584

85+
[dir="rtl"] .button-row button.cancel-button {
86+
margin-left: 0;
87+
}
88+
6689
.message {
6790
margin-top: 0.25rem;
6891
}
@@ -71,4 +94,3 @@
7194
height: 1.5rem;
7295
width: 1.5rem;
7396
}
74-

packages/scratch-gui/src/components/delete-confirmation-prompt/delete-confirmation-prompt.jsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ const DeleteConfirmationPrompt = ({
8585
onOk,
8686
modalPosition,
8787
entityType,
88-
relativeElemRef
88+
relativeElemRef,
89+
isRtl
8990
}) => {
9091
const modalPositionValues = calculateModalPosition(relativeElemRef, modalPosition);
9192

@@ -119,12 +120,15 @@ const DeleteConfirmationPrompt = ({
119120
contentLabel={intl.formatMessage(messages.confirmDeletionHeading)}
120121
onRequestClose={onCancel}
121122
>
122-
<Box className={styles.modalContainer}>
123-
{ modalPosition === 'right' ?
123+
<Box
124+
className={styles.modalContainer}
125+
dir={isRtl ? 'rtl' : 'ltr'}
126+
>
127+
{((modalPosition === 'right' && !isRtl) || (modalPosition === 'left' && isRtl)) ?
124128
<Box className={classNames(styles.arrowContainer, styles.arrowContainerLeft)}>
125129
<img
126130
className={styles.deleteIcon}
127-
src={arrowLeftIcon}
131+
src={isRtl ? arrowRightIcon : arrowLeftIcon}
128132
/>
129133
</Box> : null }
130134
<Box className={styles.body}>
@@ -160,11 +164,11 @@ const DeleteConfirmationPrompt = ({
160164
</button>
161165
</Box>
162166
</Box>
163-
{modalPosition === 'left' ?
167+
{((modalPosition === 'left' && !isRtl) || (modalPosition === 'right' && isRtl)) ?
164168
<Box className={classNames(styles.arrowContainer, styles.arrowContainerRight)}>
165169
<img
166170
className={styles.deleteIcon}
167-
src={arrowRightIcon}
171+
src={isRtl ? arrowLeftIcon : arrowRightIcon}
168172
/>
169173
</Box> : null }
170174
</Box>
@@ -177,7 +181,8 @@ DeleteConfirmationPrompt.propTypes = {
177181
relativeElemRef: PropTypes.object,
178182
entityType: PropTypes.string,
179183
modalPosition: PropTypes.string,
180-
intl: intlShape.isRequired
184+
intl: intlShape.isRequired,
185+
isRtl: PropTypes.bool
181186
};
182187

183188
const DeleteConfirmationPromptIntl = injectIntl(DeleteConfirmationPrompt);

packages/scratch-gui/src/components/sprite-selector/sprite-list.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const SpriteList = function (props) {
3030
ordering,
3131
raised,
3232
selectedId,
33-
items
33+
items,
34+
isRtl
3435
} = props;
3536

3637
const isSpriteDrag = draggingType === DragConstants.SPRITE;
@@ -95,7 +96,7 @@ const SpriteList = function (props) {
9596
onDuplicateButtonClick={onDuplicateSprite}
9697
onExportButtonClick={onExportSprite}
9798
withDeleteConfirmation
98-
deleteConfirmationModalPosition={'left'}
99+
deleteConfirmationModalPosition={isRtl ? 'right' : 'left'}
99100
/>
100101
</SortableAsset>
101102
);
@@ -134,7 +135,8 @@ SpriteList.propTypes = {
134135
onSelectSprite: PropTypes.func,
135136
ordering: PropTypes.arrayOf(PropTypes.number),
136137
raised: PropTypes.bool,
137-
selectedId: PropTypes.string
138+
selectedId: PropTypes.string,
139+
isRtl: PropTypes.bool
138140
};
139141

140142
export default SortableHOC(SpriteList);

packages/scratch-gui/src/components/sprite-selector/sprite-selector.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const SpriteSelectorComponent = function (props) {
111111
onDuplicateSprite={onDuplicateSprite}
112112
onExportSprite={onExportSprite}
113113
onSelectSprite={onSelectSprite}
114+
isRtl={isRtl(intl.locale)}
114115
/>
115116
<ActionMenu
116117
className={styles.addButton}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {connect} from 'react-redux';
4+
5+
import DeleteConfirmationPromptComponent from '../components/delete-confirmation-prompt/delete-confirmation-prompt.jsx';
6+
7+
const DeleteConfirmationPrompt = props => (
8+
<DeleteConfirmationPromptComponent {...props} />
9+
);
10+
11+
DeleteConfirmationPrompt.propTypes = {
12+
isRtl: PropTypes.bool,
13+
onCancel: PropTypes.func.isRequired,
14+
onOk: PropTypes.func.isRequired,
15+
modalPosition: PropTypes.string,
16+
entityType: PropTypes.string.isRequired,
17+
relativeElemRef: PropTypes.object.isRequired
18+
};
19+
20+
const mapStateToProps = state => ({
21+
isRtl: state.locales.isRtl
22+
});
23+
24+
export default connect(
25+
mapStateToProps
26+
)(DeleteConfirmationPrompt);

packages/scratch-gui/src/containers/sprite-selector-item.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import getCostumeUrl from '../lib/get-costume-url';
1010
import DragRecognizer from '../lib/drag-recognizer';
1111
import {getEventXY} from '../lib/touch-utils';
1212
import {GUIStoragePropType} from '../gui-config';
13-
import DeleteConfirmationPrompt from '../components/delete-confirmation-prompt/delete-confirmation-prompt.jsx';
13+
import DeleteConfirmationPrompt from './delete-confirmation-prompt';
1414

1515
import SpriteSelectorItemComponent from '../components/sprite-selector-item/sprite-selector-item.jsx';
1616

@@ -155,6 +155,7 @@ class SpriteSelectorItem extends React.PureComponent {
155155
relativeElemRef={this.ref}
156156
entityType={this.props.dragType}
157157
modalPosition={deleteConfirmationModalPosition}
158+
isRtl={this.props.isRtl}
158159
/> : null}
159160
<SpriteSelectorItemComponent
160161
componentRef={this.setRef}
@@ -194,15 +195,17 @@ SpriteSelectorItem.propTypes = {
194195
selected: PropTypes.bool,
195196
withDeleteConfirmation: PropTypes.bool,
196197
deleteConfirmationModalPosition: PropTypes.string,
197-
vm: PropTypes.instanceOf(VM).isRequired
198+
vm: PropTypes.instanceOf(VM).isRequired,
199+
isRtl: PropTypes.bool
198200
};
199201

200202
const mapStateToProps = (state, {id}) => ({
201203
storage: state.scratchGui.config.storage,
202204
dragging: state.scratchGui.assetDrag.dragging,
203205
receivedBlocks: state.scratchGui.hoveredTarget.receivedBlocks &&
204206
state.scratchGui.hoveredTarget.sprite === id,
205-
vm: state.scratchGui.vm
207+
vm: state.scratchGui.vm,
208+
isRtl: state.locales.isRtl
206209
});
207210
const mapDispatchToProps = dispatch => ({
208211
dispatchSetHoveredSprite: spriteId => {

packages/scratch-gui/test/unit/containers/sprite-selector-item.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import VM from '@scratch/scratch-vm';
77
import SpriteSelectorItemContainer from '../../../src/containers/sprite-selector-item';
88
import DeleteButton from '../../../src/components/delete-button/delete-button';
99
import {legacyConfig} from '../../../src/legacy-config';
10-
import DeleteConfirmationPrompt from '../../../src/components/delete-confirmation-prompt/delete-confirmation-prompt.jsx';
10+
import DeleteConfirmationPrompt from '../../../src/containers/delete-confirmation-prompt';
1111

1212
jest.mock('../../../src/components/delete-confirmation-prompt/delete-confirmation-prompt.jsx', () => jest.fn(() => null));
1313
describe('SpriteSelectorItem Container', () => {

0 commit comments

Comments
 (0)