From 6db1bce1e0ffcb575d65a68cde117ab95e9795f8 Mon Sep 17 00:00:00 2001 From: tischsoic Date: Mon, 24 Feb 2025 13:27:52 +0100 Subject: [PATCH] IBX-9628: ellipsized details content --- .../Resources/encore/ibexa.js.config.js | 1 + .../Resources/public/img/ibexa-icons.svg | 3 ++ .../Resources/public/img/icons/arrow-down.svg | 4 ++ .../Resources/public/js/scripts/details.js | 26 ++++++++++ .../Resources/public/scss/_details.scss | 38 +++++++++++++++ .../ui/component/details/details.html.twig | 47 ++++++++++++++++--- 6 files changed, 112 insertions(+), 7 deletions(-) create mode 100755 src/bundle/Resources/public/img/icons/arrow-down.svg create mode 100644 src/bundle/Resources/public/js/scripts/details.js diff --git a/src/bundle/Resources/encore/ibexa.js.config.js b/src/bundle/Resources/encore/ibexa.js.config.js index 25a21db5cf..b0e571de94 100644 --- a/src/bundle/Resources/encore/ibexa.js.config.js +++ b/src/bundle/Resources/encore/ibexa.js.config.js @@ -31,6 +31,7 @@ const layout = [ path.resolve(__dirname, '../public/js/scripts/button.prevent.default.js'), path.resolve(__dirname, '../public/js/scripts/toggle.button.state.toggle.js'), path.resolve(__dirname, '../public/js/scripts/split.btns.js'), + path.resolve(__dirname, '../public/js/scripts/details.js'), path.resolve(__dirname, '../public/js/scripts/udw/browse.js'), path.resolve(__dirname, '../public/js/scripts/admin.multilevel.popup.menu.js'), path.resolve(__dirname, '../public/js/scripts/admin.user.menu.js'), diff --git a/src/bundle/Resources/public/img/ibexa-icons.svg b/src/bundle/Resources/public/img/ibexa-icons.svg index e0293dff56..375b1e8fff 100644 --- a/src/bundle/Resources/public/img/ibexa-icons.svg +++ b/src/bundle/Resources/public/img/ibexa-icons.svg @@ -23,6 +23,9 @@ + + + diff --git a/src/bundle/Resources/public/img/icons/arrow-down.svg b/src/bundle/Resources/public/img/icons/arrow-down.svg new file mode 100755 index 0000000000..9623919c38 --- /dev/null +++ b/src/bundle/Resources/public/img/icons/arrow-down.svg @@ -0,0 +1,4 @@ + +arrow-down + + diff --git a/src/bundle/Resources/public/js/scripts/details.js b/src/bundle/Resources/public/js/scripts/details.js new file mode 100644 index 0000000000..27884ec477 --- /dev/null +++ b/src/bundle/Resources/public/js/scripts/details.js @@ -0,0 +1,26 @@ +(function (global, doc) { + const showMoreBtns = doc.querySelectorAll('.ibexa-details__show-more-btn'); + const toggleShowMore = (ellipsizedContent, showMoreBtn) => { + const showMoreIcon = showMoreBtn.querySelector('.ibexa-details__show-more-btn-icon'); + const showMoreLabel = showMoreBtn.querySelector('.ibexa-details__show-more-label'); + const showLessLabel = showMoreBtn.querySelector('.ibexa-details__show-less-label'); + + ellipsizedContent.classList.toggle('ibexa-details__item-content--ellipsized'); + + showMoreLabel.classList.toggle('ibexa-details__show-more-label--hidden'); + showLessLabel.classList.toggle('ibexa-details__show-less-label--hidden'); + showMoreIcon.classList.toggle('ibexa-details__show-more-btn-icon--opened') + showMoreBtn.classList.toggle('ibexa-details__show-more-btn--opened'); + + }; + + showMoreBtns.forEach((showMoreBtn) => { + const contentWrapper = showMoreBtn.closest('.ibexa-details__item-content-wrapper'); + const ellipsizedContent = contentWrapper.querySelector('.ibexa-details__item-content'); + const isEllipsized = ellipsizedContent.offsetWidth < ellipsizedContent.scrollWidth; + + showMoreBtn.classList.toggle('ibexa-details__show-more-btn--hidden', !isEllipsized); + + showMoreBtn.addEventListener('click', () => toggleShowMore(ellipsizedContent, showMoreBtn), false); + }); +})(window, document); diff --git a/src/bundle/Resources/public/scss/_details.scss b/src/bundle/Resources/public/scss/_details.scss index 99105ff7db..6854daca1c 100644 --- a/src/bundle/Resources/public/scss/_details.scss +++ b/src/bundle/Resources/public/scss/_details.scss @@ -48,6 +48,44 @@ .ibexa-dropdown { margin-left: 0; } + + &--ellipsized { + white-space: nowrap; + overflow: hidden; + display: inline-block; + text-overflow: ellipsis; + } + } + + &__item-content-wrapper { + display: flex; + flex-direction: column; + overflow: hidden; + } + + &__show-more-btn { + display: flex; + align-items: center; + padding-left: 0; + } + + &__show-more-label, + &__show-less-label { + &--hidden { + display: none; + } + } + + &__show-more-btn-icon { + &--opened { + transform: rotate(-180deg); + } + + &.ibexa-icon { + margin-left: calculateRem(12px); + margin-right: 0; + transition: all $ibexa-admin-transition-duration $ibexa-admin-transition; + } } &__header { diff --git a/src/bundle/Resources/views/themes/admin/ui/component/details/details.html.twig b/src/bundle/Resources/views/themes/admin/ui/component/details/details.html.twig index a8c4d434c5..4a59c521c6 100644 --- a/src/bundle/Resources/views/themes/admin/ui/component/details/details.html.twig +++ b/src/bundle/Resources/views/themes/admin/ui/component/details/details.html.twig @@ -40,13 +40,46 @@ (is_field_empty ? ' ibexa-details__item--hidden') }}" >
{{ item.label }}
-
- {% if item.content_raw is defined %} - {{ item.content_raw|raw }} - {% elseif item.content == 'undefined' %} - - - {% else %} - {{ item.content }} +
+
+ {% if item.content_raw is defined %} + {{ item.content_raw|raw }} + {% elseif item.content == 'undefined' %} + - + {% else %} + {{ item.content }} + {% endif %} +
+ {% if item.is_ellipsized|default(false) %} +
+ +
{% endif %}