diff --git a/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx b/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx index c7d431d9e7f..711f1ec666e 100644 --- a/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx +++ b/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx @@ -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'; @@ -22,6 +25,35 @@ const ScenarioDescription = ({ }: ScenarioDescriptionProps) => { const { t } = useTranslation('operationalStudies/scenario'); const { openModal } = useModal(); + const [isOpenedDescription, setIsOpenedDescription] = useState(false); + const descriptionRef = useRef(null); + const ref = useRef(null); + const [isTooLongDescription, setIsTooLongDescription] = useState(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 (
@@ -30,10 +62,29 @@ const ScenarioDescription = ({ {scenario.name}
-
{scenario.description && ( -
{scenario.description}
+
+ {scenario.description} + {isTooLongDescription && ( + + (plus) + + )} +
+ )} + {isOpenedDescription && ( +
+ {scenario.description} + + + +
)}