Skip to content

Commit 398c4c0

Browse files
committed
front: Change display when description is too long
Signed-off-by: theocrsb <[email protected]>
1 parent 3de9229 commit 398c4c0

File tree

2 files changed

+88
-8
lines changed

2 files changed

+88
-8
lines changed

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

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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';
@@ -22,6 +24,29 @@ const ScenarioDescription = ({
2224
}: ScenarioDescriptionProps) => {
2325
const { t } = useTranslation('operationalStudies/scenario');
2426
const { openModal } = useModal();
27+
const [isOpenedDescription, setIsOpenedDescription] = useState<boolean>(false);
28+
const [width, setWidth] = useState<number>(0);
29+
const ref = useRef<HTMLInputElement | null>(null);
30+
31+
const showDescription = () => {
32+
setIsOpenedDescription(!isOpenedDescription);
33+
};
34+
35+
useEffect(() => {
36+
const handleResize = () => {
37+
if (ref.current) {
38+
setWidth(ref.current.offsetWidth);
39+
}
40+
};
41+
42+
handleResize();
43+
44+
window.addEventListener('resize', handleResize);
45+
46+
return () => {
47+
window.removeEventListener('resize', handleResize);
48+
};
49+
}, []);
2550

2651
return (
2752
<div>
@@ -31,9 +56,27 @@ const ScenarioDescription = ({
3156
</span>
3257
</div>
3358

34-
<div className="scenario-description">
59+
<div ref={ref} className="scenario-description">
3560
{scenario.description && (
36-
<div className="scenario-details-description">{scenario.description}</div>
61+
<div
62+
title={!isOpenedDescription ? scenario.description : ''}
63+
className={
64+
!isOpenedDescription
65+
? 'scenario-details-description not-opened'
66+
: 'scenario-details-description opened'
67+
}
68+
style={!isOpenedDescription ? { width } : { width: width + 120 }}
69+
>
70+
{scenario.description}
71+
<span
72+
onClick={() => showDescription()}
73+
role="button"
74+
tabIndex={0}
75+
className={!isOpenedDescription ? 'display-description' : 'displayed-description'}
76+
>
77+
{!isOpenedDescription ? '(plus)' : <X />}
78+
</span>
79+
</div>
3780
)}
3881
<div className="flex justify-end">
3982
<button

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

+42-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,7 +141,6 @@
141141

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

146145
.scenario-details-description {
147146
color: var(--grey50);
@@ -152,6 +151,44 @@
152151
word-break: break-all;
153152
}
154153

154+
.not-opened {
155+
position: relative;
156+
overflow: hidden;
157+
display: -webkit-box;
158+
-webkit-line-clamp: 3;
159+
-webkit-box-orient: vertical;
160+
.display-description {
161+
position: absolute;
162+
bottom: 0;
163+
right: 0;
164+
background: rgba(222, 221, 214, 1);
165+
color: var(--grey80);
166+
padding-inline: 0.2188rem;
167+
}
168+
}
169+
170+
.opened {
171+
position: relative;
172+
background-color: var(--white100);
173+
color: var(--grey80);
174+
padding: 3.375rem 3.5rem 3.125rem 3.5rem;
175+
font-size: 1rem;
176+
font-weight: 400;
177+
line-height: 1.5rem;
178+
z-index: 3;
179+
border-radius: 0.375rem;
180+
box-shadow:
181+
0rem 0.375rem 1.3125rem -0.3125rem rgba(255, 171, 88, 0.31),
182+
0rem 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.19),
183+
0rem 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.16);
184+
transform: translateX(-0.5rem);
185+
.displayed-description {
186+
position: absolute;
187+
top: 1rem - 0.3125rem;
188+
right: 1rem;
189+
}
190+
}
191+
155192
.scenario-collapse-button {
156193
position: absolute;
157194
padding-bottom: 0.188rem;
@@ -163,8 +200,8 @@
163200
border-radius: 0.313rem 0 0 0.313rem;
164201
top: 0;
165202
transform: translateX(1.5rem);
166-
box-shadow: 0 0px 0 1px var(--black10);
167-
clip-path: inset(-1px 0 -1px -1px);
203+
box-shadow: 0 0 0 0.0625rem var(--black10);
204+
clip-path: inset(-0.0625rem 0 -0.0625rem -0.0625rem);
168205
}
169206

170207
.update-scenario {
@@ -391,7 +428,7 @@
391428
.invalid-trains {
392429
display: flex;
393430
background: var(--warning5);
394-
box-shadow: inset 0px 1px var(--white100);
431+
box-shadow: inset 0 0.0625rem var(--white100);
395432
height: 3rem;
396433
font-size: 1rem;
397434
font-weight: 600;

0 commit comments

Comments
 (0)