From f7b0861ebb853480c4b4f6e3c53038d109524c0e Mon Sep 17 00:00:00 2001 From: theocrsb Date: Mon, 21 Oct 2024 10:14:56 +0200 Subject: [PATCH] fixup! front: Change display when description is too long --- .../Scenario/ScenarioDescription.tsx | 45 ++++++++++++++----- .../operationalStudies/_scenario.scss | 11 ++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx b/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx index 5cc6c46ff44..711f1ec666e 100644 --- a/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx +++ b/front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx @@ -26,38 +26,63 @@ const ScenarioDescription = ({ const { t } = useTranslation('operationalStudies/scenario'); const { openModal } = useModal(); const [isOpenedDescription, setIsOpenedDescription] = useState(false); - const ref = useRef(null); 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 ( -
+
{scenario.name}
-
{scenario.description && ( -
+
+ {scenario.description} + {isTooLongDescription && ( + + (plus) + + )} +
+ )} + {isOpenedDescription && ( +
{scenario.description} - {isOpenedDescription ? : '(plus)'} +
)} diff --git a/front/src/styles/scss/applications/operationalStudies/_scenario.scss b/front/src/styles/scss/applications/operationalStudies/_scenario.scss index 1818483ecf7..2190247523c 100644 --- a/front/src/styles/scss/applications/operationalStudies/_scenario.scss +++ b/front/src/styles/scss/applications/operationalStudies/_scenario.scss @@ -143,6 +143,7 @@ position: relative; .scenario-details-description { + position: relative; color: var(--grey50); font-size: 0.875rem; font-weight: 400; @@ -154,21 +155,21 @@ .not-opened { position: relative; overflow: hidden; - display: -webkit-box; - -webkit-line-clamp: 3; - -webkit-box-orient: vertical; - .display-description { + 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); - padding-inline: 0.2188rem; } } .opened { position: absolute; + top: 0; background-color: var(--white100); color: var(--grey80); padding: 3.375rem 3.5rem 3.125rem 3.5rem;