Skip to content

Commit

Permalink
front: Change display when description is too long
Browse files Browse the repository at this point in the history
Signed-off-by: theocrsb <theo_crosbie@yahoo.fr>
  • Loading branch information
theocrsb committed Oct 21, 2024
1 parent fdecde7 commit 209217e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Blocked, ChevronLeft, Pencil } from '@osrd-project/ui-icons';
import { useEffect, useRef, useState } from 'react';

import { Blocked, ChevronLeft, Pencil, X } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';

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

import InfraLoadingState from './InfraLoadingState';

Expand All @@ -22,6 +25,35 @@ const ScenarioDescription = ({
}: ScenarioDescriptionProps) => {
const { t } = useTranslation('operationalStudies/scenario');
const { openModal } = useModal();
const [isOpenedDescription, setIsOpenedDescription] = useState<boolean>(false);
const descriptionRef = useRef<HTMLDivElement | null>(null);
const ref = useRef<HTMLDivElement | null>(null);
const [isTooLongDescription, setIsTooLongDescription] = useState<boolean>(false);

const toggleDescription = () => {
setIsOpenedDescription(!isOpenedDescription);
};

const checkIfTooLong = () => {
if (ref && ref.current) {
ref.current.scrollHeight > 60
? setIsTooLongDescription(true)
: setIsTooLongDescription(false);
}
};

useOutsideClick(descriptionRef, () => setIsOpenedDescription(false));

useEffect(() => {
checkIfTooLong();
window.addEventListener('resize', checkIfTooLong);

return () => {
window.removeEventListener('resize', checkIfTooLong);
};
}, []);

useEffect(checkIfTooLong, [scenario.description]);

return (
<div>
Expand All @@ -30,10 +62,29 @@ const ScenarioDescription = ({
{scenario.name}
</span>
</div>

<div className="scenario-description">
{scenario.description && (
<div className="scenario-details-description">{scenario.description}</div>
<div ref={ref} className="scenario-details-description not-opened">
{scenario.description}
{isTooLongDescription && (
<span role="button" onClick={toggleDescription} tabIndex={0}>
(plus)
</span>
)}
</div>
)}
{isOpenedDescription && (
<div ref={descriptionRef} className="scenario-details-description opened">
{scenario.description}
<span
onClick={toggleDescription}
role="button"
tabIndex={0}
className="displayed-description"
>
<X />
</span>
</div>
)}
<div className="flex justify-end">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
min-width: 24.5rem;
max-width: 29.5rem;
padding: 0.875rem 1.5rem 0 1.5rem;
box-shadow: inset -1px 0 var(--black5);
box-shadow: inset -0.0625rem 0 var(--black5);

.scenario-sidemenu :first-child:hover {
.update-scenario {
Expand All @@ -141,9 +141,9 @@

.scenario-description {
position: relative;
text-wrap: wrap;

.scenario-details-description {
position: relative;
color: var(--grey50);
font-size: 0.875rem;
font-weight: 400;
Expand All @@ -152,6 +152,45 @@
word-break: break-all;
}

.not-opened {
position: relative;
overflow: hidden;
max-height: 3.75rem;
max-width: 100%;
span {
padding-inline: 0.2188rem;
position: absolute;
bottom: 0;
right: 0;
background: rgba(222, 221, 214, 1);
color: var(--grey80);
}
}

.opened {
position: absolute;
top: 0;
background-color: var(--white100);
color: var(--grey80);
padding: 3.375rem 3.5rem 3.125rem 3.5rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5rem;
z-index: 3;
border-radius: 0.375rem;
box-shadow:
0rem 0.375rem 1.3125rem -0.3125rem rgba(255, 171, 88, 0.31),
0rem 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.19),
0rem 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.16);
transform: translateX(-0.5rem);
width: calc(100% + 7.5rem);
.displayed-description {
position: absolute;
top: 1rem - 0.3125rem;
right: 1rem;
}
}

.scenario-collapse-button {
position: absolute;
padding-bottom: 0.188rem;
Expand All @@ -163,8 +202,8 @@
border-radius: 0.313rem 0 0 0.313rem;
top: 0;
transform: translateX(1.5rem);
box-shadow: 0 0px 0 1px var(--black10);
clip-path: inset(-1px 0 -1px -1px);
box-shadow: 0 0 0 0.0625rem var(--black10);
clip-path: inset(-0.0625rem 0 -0.0625rem -0.0625rem);
}

.update-scenario {
Expand Down Expand Up @@ -391,7 +430,7 @@
.invalid-trains {
display: flex;
background: var(--warning5);
box-shadow: inset 0px 1px var(--white100);
box-shadow: inset 0 0.0625rem var(--white100);
height: 3rem;
font-size: 1rem;
font-weight: 600;
Expand Down

0 comments on commit 209217e

Please sign in to comment.