Skip to content

Commit f1c82f1

Browse files
authored
Fix CSS for Dashboard Management in Arabic (#538)
* Field containers are properly positioned when in Arabic * Buttons on the Bottom Bar are properly positioned when in Arabic
1 parent 30c833b commit f1c82f1

File tree

6 files changed

+110
-23
lines changed

6 files changed

+110
-23
lines changed

frontend/src/components/BottomBar/BottomBar.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ const BottomBar = ({
8787
const saveBtnClassName =
8888
selectedLang === LANGUAGES.AR ? 'save-button-ar' : 'save-button';
8989

90+
const discardBtnClassName =
91+
selectedLang === LANGUAGES.AR
92+
? 'discard-button-ar'
93+
: 'discard-button';
94+
9095
return [
9196
<Button
9297
key="bottom-bar-save"
@@ -97,7 +102,7 @@ const BottomBar = ({
97102
</Button>,
98103
<Button
99104
key="bottom-bar-discard"
100-
className="discard-button"
105+
className={discardBtnClassName}
101106
onClick={onDiscard}
102107
>
103108
<b>{translations.components.button.discard.title}</b>
@@ -111,7 +116,13 @@ const BottomBar = ({
111116
const renderToolbarControls = () => {
112117
if (isEditing) {
113118
return (
114-
<div>
119+
<div
120+
className={
121+
selectedLang === LANGUAGES.AR && onAddField
122+
? 'toolbar-editing-div-ar'
123+
: 'toolbar-editing-div'
124+
}
125+
>
115126
{renderStatusSelector()}
116127
{renderDiscardAndSaveButtons()}
117128
</div>
@@ -136,14 +147,20 @@ const BottomBar = ({
136147
const renderAddFieldButton = () => {
137148
let button = null;
138149

150+
let buttonClassName = 'add-field-button';
151+
152+
if (selectedLang !== LANGUAGES.AR) {
153+
buttonClassName += ` ${
154+
isEditing
155+
? 'add-field-expanded-width'
156+
: 'add-field-retracted-width'
157+
}`;
158+
}
159+
139160
if (isEditing && onAddField) {
140161
button = (
141162
<Button
142-
className={`add-field-button ${
143-
isEditing
144-
? 'add-field-expanded-width'
145-
: 'add-field-retracted-width'
146-
}`}
163+
className={buttonClassName}
147164
onClick={() => onAddField(selectedStep)}
148165
>
149166
{translations.components.bottombar.addField}
@@ -154,6 +171,24 @@ const BottomBar = ({
154171
return <div className="add-field-div">{button}</div>;
155172
};
156173

174+
// The edit steps and discard button needs to remain in the same location on the screen,
175+
// regardless of the language. This allows the user to keep the mouse in the same position when
176+
// switching between the Editing-Not Editing state. In order to allow this, the order of the
177+
// add field button and toolbar controls needs to flip below. This counters the flip in left-right
178+
// orientation made to the entire website when the language switches to Arabic.
179+
const controlToolbar =
180+
selectedLang === LANGUAGES.AR && onAddField ? (
181+
<>
182+
{renderToolbarControls()}
183+
{renderAddFieldButton()}
184+
</>
185+
) : (
186+
<>
187+
{renderAddFieldButton()}
188+
{renderToolbarControls()}
189+
</>
190+
);
191+
157192
return (
158193
<AppBar
159194
className="bottom-bar-wrapper"
@@ -164,10 +199,7 @@ const BottomBar = ({
164199
boxShadow: '0 0px 4px 2px rgba(0, 0, 0, 0.15)',
165200
}}
166201
>
167-
<Toolbar className="bottom-toolbar">
168-
{renderAddFieldButton()}
169-
{renderToolbarControls()}
170-
</Toolbar>
202+
<Toolbar className="bottom-toolbar">{controlToolbar}</Toolbar>
171203
</AppBar>
172204
);
173205
};

frontend/src/components/BottomBar/BottomBar.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
@import '../../styles/variables.scss';
33

44
.bottom-bar-wrapper {
5+
// This calculates the width of the step management container, minus a couple of pixels.
6+
// It is used for positioning the add field button when the user is editing and has the language
7+
// set to Arabic.
8+
.toolbar-editing-div-ar {
9+
width: calc(100vw - $drawerWidth - 3 * $verticalMovementWidth - 190px);
10+
}
11+
512
.add-field-retracted-width {
613
margin-inline-start: $drawerWidth;
714
margin-left: $drawerWidth;
@@ -85,6 +92,18 @@
8592
}
8693
}
8794

95+
.discard-button-ar {
96+
background-color: white;
97+
color: #5f5f5f;
98+
font-size: 12px;
99+
padding: 6px 24px 6px 24px;
100+
transition: all 0.2s;
101+
&:hover {
102+
color: black;
103+
background-color: white;
104+
}
105+
}
106+
88107
.discard-button {
89108
background-color: white;
90109
color: #5f5f5f;

frontend/src/components/Sidebar/Sidebar.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Button, Drawer, AppBar, Toolbar } from '@material-ui/core';
44
import PropTypes from 'prop-types';
55
import { makeStyles } from '@material-ui/core/styles';
66

7+
import { LANGUAGES } from '../../utils/constants';
78
import { useTranslations } from '../../hooks/useTranslations';
89

910
const useStyles = makeStyles({
@@ -65,8 +66,14 @@ const Sidebar = ({
6566
};
6667

6768
const getButtonClassname = (stepKey, isHidden) => {
68-
if (selectedStep === stepKey) return 'selected';
69-
return isHidden ? 'hidden' : 'unselected';
69+
let buttonClassNameByLanguage =
70+
selectedLang === LANGUAGES.AR ? 'main-button-ar' : 'main-button';
71+
if (selectedStep === stepKey) {
72+
buttonClassNameByLanguage += ' selected';
73+
} else {
74+
buttonClassNameByLanguage += isHidden ? ' hidden' : ' unselected';
75+
}
76+
return buttonClassNameByLanguage;
7077
};
7178

7279
const generateButtons = () => {
@@ -84,7 +91,7 @@ const Sidebar = ({
8491
return (
8592
<div className="sidebar-button-container">
8693
<div
87-
className={`button main-button ${buttonClassName}`}
94+
className={`button ${buttonClassName}`}
8895
onClick={() => onButtonClick(element.key)}
8996
>
9097
{element.displayName[selectedLang]}

frontend/src/components/Sidebar/Sidebar.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@
4242
}
4343
}
4444

45-
.main-button {
45+
.main-button,
46+
.main-button-ar {
4647
padding-left: 10px;
4748
min-width: $drawerWidth;
4849
}
4950

51+
.main-button {
52+
padding-left: 10px;
53+
}
54+
55+
.main-button-ar {
56+
padding-right: 10px;
57+
}
58+
5059
.order-button {
5160
min-width: $verticalMovementWidth;
5261
text-align: center;

frontend/src/components/StepManagementContent/StepManagementContent.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'semantic-ui-css/semantic.min.css';
44
import PropTypes from 'prop-types';
55

66
import RadioButtonField from '../Fields/RadioButtonField';
7-
import { FIELD_TYPES } from '../../utils/constants';
7+
import { FIELD_TYPES, LANGUAGES } from '../../utils/constants';
88
import { useTranslations } from '../../hooks/useTranslations';
99

1010
const StepManagementContent = ({
@@ -99,20 +99,32 @@ const StepManagementContent = ({
9999
);
100100
}
101101

102+
function getFieldClassName(field) {
103+
let fieldClassName = field.isHidden
104+
? 'hidden-step-field-container'
105+
: 'step-field-container';
106+
107+
// Handles case when the user has the language set to Arabic
108+
if (selectedLang === LANGUAGES.AR) {
109+
fieldClassName += ' ';
110+
if (isEditing) {
111+
fieldClassName += 'expanded-arabic-field-container';
112+
} else {
113+
fieldClassName += 'retracted-arabic-field-container';
114+
}
115+
}
116+
117+
return fieldClassName;
118+
}
119+
102120
function generateButtonInfo(fields, fieldRoot) {
103121
if (!fields) return null;
104122

105123
return fields.map((field) => {
106124
if (field.isDeleted) return null; // don't render fields when they are marked as deleted
107125

108126
return (
109-
<div
110-
className={
111-
field.isHidden
112-
? 'hidden-step-field-container'
113-
: 'step-field-container'
114-
}
115-
>
127+
<div className={getFieldClassName(field)}>
116128
<div className="content">
117129
<div className="info">
118130
<div className="header">

frontend/src/components/StepManagementContent/StepManagementContent.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
font-weight: 700;
1010
}
1111

12+
.retracted-arabic-field-container {
13+
margin-right: -$drawerWidth !important;
14+
}
15+
16+
.expanded-arabic-field-container {
17+
margin-right: -($drawerWidth + 3 * $verticalMovementWidth) !important;
18+
}
19+
1220
.step-field-container {
1321
background-color: #f6f6f6;
1422
border: #f6f6f6 solid 1px;

0 commit comments

Comments
 (0)