Skip to content

Commit 209217e

Browse files
committed
front: Change display when description is too long
Signed-off-by: theocrsb <[email protected]>
1 parent fdecde7 commit 209217e

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx

+54-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { Blocked, ChevronLeft, Pencil } from '@osrd-project/ui-icons';
1+
import { useEffect, useRef, useState } from 'react';
2+
3+
import { Blocked, ChevronLeft, Pencil, X } from '@osrd-project/ui-icons';
24
import { useTranslation } from 'react-i18next';
35

46
import type { InfraWithState, ScenarioResponse } from 'common/api/osrdEditoastApi';
57
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
68
import AddAndEditScenarioModal from 'modules/scenario/components/AddOrEditScenarioModal';
9+
import useOutsideClick from 'utils/hooks/useOutsideClick';
710

811
import InfraLoadingState from './InfraLoadingState';
912

@@ -22,6 +25,35 @@ const ScenarioDescription = ({
2225
}: ScenarioDescriptionProps) => {
2326
const { t } = useTranslation('operationalStudies/scenario');
2427
const { openModal } = useModal();
28+
const [isOpenedDescription, setIsOpenedDescription] = useState<boolean>(false);
29+
const descriptionRef = useRef<HTMLDivElement | null>(null);
30+
const ref = useRef<HTMLDivElement | null>(null);
31+
const [isTooLongDescription, setIsTooLongDescription] = useState<boolean>(false);
32+
33+
const toggleDescription = () => {
34+
setIsOpenedDescription(!isOpenedDescription);
35+
};
36+
37+
const checkIfTooLong = () => {
38+
if (ref && ref.current) {
39+
ref.current.scrollHeight > 60
40+
? setIsTooLongDescription(true)
41+
: setIsTooLongDescription(false);
42+
}
43+
};
44+
45+
useOutsideClick(descriptionRef, () => setIsOpenedDescription(false));
46+
47+
useEffect(() => {
48+
checkIfTooLong();
49+
window.addEventListener('resize', checkIfTooLong);
50+
51+
return () => {
52+
window.removeEventListener('resize', checkIfTooLong);
53+
};
54+
}, []);
55+
56+
useEffect(checkIfTooLong, [scenario.description]);
2557

2658
return (
2759
<div>
@@ -30,10 +62,29 @@ const ScenarioDescription = ({
3062
{scenario.name}
3163
</span>
3264
</div>
33-
3465
<div className="scenario-description">
3566
{scenario.description && (
36-
<div className="scenario-details-description">{scenario.description}</div>
67+
<div ref={ref} className="scenario-details-description not-opened">
68+
{scenario.description}
69+
{isTooLongDescription && (
70+
<span role="button" onClick={toggleDescription} tabIndex={0}>
71+
(plus)
72+
</span>
73+
)}
74+
</div>
75+
)}
76+
{isOpenedDescription && (
77+
<div ref={descriptionRef} className="scenario-details-description opened">
78+
{scenario.description}
79+
<span
80+
onClick={toggleDescription}
81+
role="button"
82+
tabIndex={0}
83+
className="displayed-description"
84+
>
85+
<X />
86+
</span>
87+
</div>
3788
)}
3889
<div className="flex justify-end">
3990
<button

front/src/styles/scss/applications/operationalStudies/_scenario.scss

+44-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
min-width: 24.5rem;
120120
max-width: 29.5rem;
121121
padding: 0.875rem 1.5rem 0 1.5rem;
122-
box-shadow: inset -1px 0 var(--black5);
122+
box-shadow: inset -0.0625rem 0 var(--black5);
123123

124124
.scenario-sidemenu :first-child:hover {
125125
.update-scenario {
@@ -141,9 +141,9 @@
141141

142142
.scenario-description {
143143
position: relative;
144-
text-wrap: wrap;
145144

146145
.scenario-details-description {
146+
position: relative;
147147
color: var(--grey50);
148148
font-size: 0.875rem;
149149
font-weight: 400;
@@ -152,6 +152,45 @@
152152
word-break: break-all;
153153
}
154154

155+
.not-opened {
156+
position: relative;
157+
overflow: hidden;
158+
max-height: 3.75rem;
159+
max-width: 100%;
160+
span {
161+
padding-inline: 0.2188rem;
162+
position: absolute;
163+
bottom: 0;
164+
right: 0;
165+
background: rgba(222, 221, 214, 1);
166+
color: var(--grey80);
167+
}
168+
}
169+
170+
.opened {
171+
position: absolute;
172+
top: 0;
173+
background-color: var(--white100);
174+
color: var(--grey80);
175+
padding: 3.375rem 3.5rem 3.125rem 3.5rem;
176+
font-size: 1rem;
177+
font-weight: 400;
178+
line-height: 1.5rem;
179+
z-index: 3;
180+
border-radius: 0.375rem;
181+
box-shadow:
182+
0rem 0.375rem 1.3125rem -0.3125rem rgba(255, 171, 88, 0.31),
183+
0rem 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.19),
184+
0rem 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.16);
185+
transform: translateX(-0.5rem);
186+
width: calc(100% + 7.5rem);
187+
.displayed-description {
188+
position: absolute;
189+
top: 1rem - 0.3125rem;
190+
right: 1rem;
191+
}
192+
}
193+
155194
.scenario-collapse-button {
156195
position: absolute;
157196
padding-bottom: 0.188rem;
@@ -163,8 +202,8 @@
163202
border-radius: 0.313rem 0 0 0.313rem;
164203
top: 0;
165204
transform: translateX(1.5rem);
166-
box-shadow: 0 0px 0 1px var(--black10);
167-
clip-path: inset(-1px 0 -1px -1px);
205+
box-shadow: 0 0 0 0.0625rem var(--black10);
206+
clip-path: inset(-0.0625rem 0 -0.0625rem -0.0625rem);
168207
}
169208

170209
.update-scenario {
@@ -391,7 +430,7 @@
391430
.invalid-trains {
392431
display: flex;
393432
background: var(--warning5);
394-
box-shadow: inset 0px 1px var(--white100);
433+
box-shadow: inset 0 0.0625rem var(--white100);
395434
height: 3rem;
396435
font-size: 1rem;
397436
font-weight: 600;

0 commit comments

Comments
 (0)