From 194e6e9f6cb837c57f8317abe3394714ca8faa32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 13 Jun 2024 11:54:50 -0300 Subject: content, client, css: quick description expand/collapse --- .../dependencies/generateGroupGalleryPage.js | 7 +- .../dependencies/generateQuickDescription.js | 120 +++++++++++++++------ 2 files changed, 87 insertions(+), 40 deletions(-) (limited to 'src/content') diff --git a/src/content/dependencies/generateGroupGalleryPage.js b/src/content/dependencies/generateGroupGalleryPage.js index 6f23710d..34c789b3 100644 --- a/src/content/dependencies/generateGroupGalleryPage.js +++ b/src/content/dependencies/generateGroupGalleryPage.js @@ -13,7 +13,6 @@ export default { 'generateQuickDescription', 'image', 'linkAlbum', - 'linkGroup', 'linkListing', ], @@ -60,9 +59,6 @@ export default { relations.quickDescription = relation('generateQuickDescription', group); - relations.quickDescriptionInfoLink = - relation('linkGroup', group); - relations.coverGrid = relation('generateCoverGrid'); @@ -136,8 +132,7 @@ export default { image.slot('path', path)), }), - relations.quickDescription - .slot('infoPageLink', relations.quickDescriptionInfoLink), + relations.quickDescription, html.tag('p', {class: 'quick-info'}, language.$('groupGalleryPage.infoLine', { diff --git a/src/content/dependencies/generateQuickDescription.js b/src/content/dependencies/generateQuickDescription.js index 3dadfbcf..f555af28 100644 --- a/src/content/dependencies/generateQuickDescription.js +++ b/src/content/dependencies/generateQuickDescription.js @@ -2,40 +2,92 @@ export default { contentDependencies: ['transformContent'], extraDependencies: ['html', 'language'], - relations: (relation, thing) => - ({description: - (thing.descriptionShort || thing.description - ? relation('transformContent', - thing.descriptionShort ?? thing.description) - : null)}), - - data: (thing) => - ({hasLongerDescription: - thing.description && - thing.descriptionShort && - thing.descriptionShort !== thing.description}), - - slots: { - infoPageLink: { - type: 'html', - mutable: true, - }, - }, - - generate: (data, relations, slots, {html, language}) => - html.tag('p', {class: 'quick-info'}, - {[html.joinChildren]: html.tag('br')}, - {[html.onlyIfContent]: true}, - - [ - relations.description?.slot('mode', 'inline'), + query: (thing) => ({ + hasDescription: + !!thing.description, + + hasLongerDescription: + thing.description && + thing.descriptionShort && + thing.descriptionShort !== thing.description, + }), + + relations: (relation, query, thing) => ({ + description: + (query.hasLongerDescription || !thing.description + ? null + : relation('transformContent', thing.description)), + + descriptionShort: + (query.hasLongerDescription + ? relation('transformContent', thing.descriptionShort) + : null), + + descriptionLong: + (query.hasLongerDescription + ? relation('transformContent', thing.description) + : null), + }), + + data: (query) => ({ + hasDescription: query.hasDescription, + hasLongerDescription: query.hasLongerDescription, + }), + + generate(data, relations, {html, language}) { + const prefix = 'misc.quickDescription'; + + const wrapExpandCollapseLink = (expandCollapse, content) => + html.tag('a', {class: `${expandCollapse}-link`}, + {href: '#'}, + content); + + const actionsWhenCollapsed = + (data.hasLongerDescription + ? language.$(prefix, 'expandDescription', { + expand: + wrapExpandCollapseLink('expand', + language.$(prefix, 'expandDescription.expand')), + }) + : null); + + const actionsWhenExpanded = + (data.hasLongerDescription + ? language.$(prefix, 'collapseDescription', { + collapse: + wrapExpandCollapseLink('collapse', + language.$(prefix, 'collapseDescription.collapse')), + }) + : null); + + const wrapActions = (attributes, children) => + html.tag('p', {class: 'quick-description-actions'}, + {[html.onlyIfContent]: true}, + attributes, + + children); + + const wrapContent = (attributes, content) => + html.tag('div', {class: 'description-content'}, + {[html.onlyIfContent]: true}, + attributes, + + content?.slot('mode', 'multiline')); + + return ( + html.tag('div', {class: 'quick-description'}, + {[html.onlyIfContent]: true}, data.hasLongerDescription && - slots.infoPageLink && - language.$('misc.quickDescription.moreInfo', { - link: - slots.infoPageLink - .slot('content', language.$('misc.quickDescription.moreInfo.link')), - }), - ]), + {class: 'collapsed'}, + + [ + wrapContent(null, relations.description), + wrapContent({class: 'short'}, relations.descriptionShort), + wrapContent({class: 'long'}, relations.descriptionLong), + + wrapActions({class: 'when-collapsed'}, actionsWhenCollapsed), + wrapActions({class: 'when-expanded'}, actionsWhenExpanded), + ])); + } }; -- cgit 1.3.0-6-gf8a5