Skip to content

Commit bb7e31d

Browse files
committed
TT-7335 Center workflow steps relative to full row width
1 parent 29c4d3c commit bb7e31d

1 file changed

Lines changed: 58 additions & 41 deletions

File tree

src/renderer/src/components/PassageDetail/mobile/MobileWorkflowSteps.tsx

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useSnackBar } from '../../../hoc/SnackBar';
1919
import { sharedSelector, workflowStepsSelector } from '../../../selector';
2020
import { shallowEqual, useSelector } from 'react-redux';
2121
import { useWfLabel } from '../../../utils/useWfLabel';
22-
import { useEffect, useMemo, useRef, useState } from 'react';
22+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2323
import { IWorkflowStepsStrings } from '../../../model';
2424
import { toCamel } from '../../../utils/toCamel';
2525

@@ -80,6 +80,22 @@ export default function MobileWorkflowSteps() {
8080
: '';
8181
}, [currentLabel, t]);
8282

83+
const dropdownRef = useRef<HTMLDivElement>(null);
84+
const [dropdownWidth, setDropdownWidth] = useState(0);
85+
86+
useLayoutEffect(() => {
87+
const el = dropdownRef.current;
88+
if (!el) return;
89+
const update = () => {
90+
const style = window.getComputedStyle(el);
91+
setDropdownWidth(el.offsetWidth + parseFloat(style.marginRight));
92+
};
93+
update();
94+
const ro = new ResizeObserver(update);
95+
ro.observe(el);
96+
return () => ro.disconnect();
97+
}, []);
98+
8399
const didMountRef = useRef(false);
84100
const stepRefs = useRef(new Map<string, HTMLElement>());
85101

@@ -105,7 +121,7 @@ export default function MobileWorkflowSteps() {
105121
width: '100%',
106122
}}
107123
>
108-
<Box sx={{ flexShrink: 0, mr: 1 }}>
124+
<Box ref={dropdownRef} sx={{ flexShrink: 0, mr: 1 }}>
109125
<Button
110126
size="small"
111127
endIcon={<ArrowDropDownIcon />}
@@ -138,50 +154,51 @@ export default function MobileWorkflowSteps() {
138154
sx={{
139155
flex: 1,
140156
display: 'flex',
141-
justifyContent: 'flex-start',
142157
overflowX: 'auto',
143158
overflowY: 'hidden',
144159
WebkitOverflowScrolling: 'touch',
145-
pb: 0.25,
146160
}}
147161
>
148-
{workflow.map((step) => {
149-
const isCurrent = step.id === currentstep;
150-
return (
151-
<ButtonBase
152-
key={step.id}
153-
data-cy="workflow-step"
154-
role="button"
155-
onClick={handleSelect(step.id)}
156-
tabIndex={0}
157-
ref={(el) => {
158-
if (el) {
159-
stepRefs.current.set(step.id, el);
160-
} else {
161-
stepRefs.current.delete(step.id);
162-
}
163-
}}
164-
onKeyDown={(e) => {
165-
if (e.key === 'Enter' || e.key === ' ') {
166-
e.preventDefault();
167-
}
168-
}}
169-
sx={{
170-
flex: '0 0 80px',
171-
height: 30,
172-
mr: -0.25,
173-
backgroundColor: isCurrent
174-
? theme.palette.grey[700]
175-
: stepComplete(step.id)
176-
? theme.palette.grey[400]
177-
: theme.palette.grey[200],
178-
clipPath: 'polygon(10% 0%, 100% 0%, 90% 100%, 0% 100%)',
179-
cursor:
180-
recording || commentRecording ? 'not-allowed' : 'pointer',
181-
}}
182-
/>
183-
);
184-
})}
162+
<Box sx={{ display: 'flex', mx: 'auto', pb: 0.25 }}>
163+
{workflow.map((step) => {
164+
const isCurrent = step.id === currentstep;
165+
return (
166+
<ButtonBase
167+
key={step.id}
168+
data-cy="workflow-step"
169+
role="button"
170+
onClick={handleSelect(step.id)}
171+
tabIndex={0}
172+
ref={(el) => {
173+
if (el) {
174+
stepRefs.current.set(step.id, el);
175+
} else {
176+
stepRefs.current.delete(step.id);
177+
}
178+
}}
179+
onKeyDown={(e) => {
180+
if (e.key === 'Enter' || e.key === ' ') {
181+
e.preventDefault();
182+
}
183+
}}
184+
sx={{
185+
flex: '0 0 80px',
186+
height: 30,
187+
mr: -0.25,
188+
backgroundColor: isCurrent
189+
? theme.palette.grey[700]
190+
: stepComplete(step.id)
191+
? theme.palette.grey[400]
192+
: theme.palette.grey[200],
193+
clipPath: 'polygon(10% 0%, 100% 0%, 90% 100%, 0% 100%)',
194+
cursor:
195+
recording || commentRecording ? 'not-allowed' : 'pointer',
196+
}}
197+
/>
198+
);
199+
})}
200+
<Box sx={{ flexShrink: 0, width: dropdownWidth }} />
201+
</Box>
185202
</Box>
186203
</Box>
187204
{currentLabel && (

0 commit comments

Comments
 (0)