From 788f5bf285686c196ac8c263987d871686f11154 Mon Sep 17 00:00:00 2001 From: emeryro Date: Thu, 30 Mar 2023 08:04:09 +0200 Subject: [PATCH 1/6] use picture --- .../twig/components/page-header/README.md | 10 +++-- .../page-header/ec-page-header.story.js | 4 +- .../page-header/eu-page-header.story.js | 4 +- .../page-header/page-header.html.twig | 42 +++++++++++++------ .../page-header/page-header.test.js | 14 +++++++ src/specs/components/page-header/demo/data.js | 8 ++-- 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/implementations/twig/components/page-header/README.md b/src/implementations/twig/components/page-header/README.md index 83b97601fc7..63e46da3b2c 100644 --- a/src/implementations/twig/components/page-header/README.md +++ b/src/implementations/twig/components/page-header/README.md @@ -12,9 +12,7 @@ npm install --save @ecl/twig-component-page-header - **"title"** (string) (default: '') Title of header - **"hide_title"** (boolean) (default: false) Hide the h1 title, for screen reader only - **"description"** (string) (default: '') Description of header -- **"thumbnail"** (associative array) (default: {}) Thumbnail dipslayed alongside the description - - "alt" (string) Alternative text - - "src" (string) Image path +- **"picture"** (associative array) (default: {}): Image for thumbnail, following ECL Picture structure - **"meta"** (array) (default: []) Meta of header - **"breadcrumb"** (associative array) (default: '') Predefined structure for the ECL Breadcrumb - **"background_image_url"** (string) (default: '') Background image url @@ -23,6 +21,12 @@ npm install --save @ecl/twig-component-page-header - "name" (string) Attribute name, eg. 'data-test' - "value" (string) Attribute value, eg: 'data-test-1' +Deprecated + +- **"thumbnail"** (associative array) (default: {}) Thumbnail dipslayed alongside the description + - "alt" (string) Alternative text + - "src" (string) Image path + ### Example : diff --git a/src/implementations/twig/components/page-header/ec-page-header.story.js b/src/implementations/twig/components/page-header/ec-page-header.story.js index 79282ef446f..6674bd6a26c 100644 --- a/src/implementations/twig/components/page-header/ec-page-header.story.js +++ b/src/implementations/twig/components/page-header/ec-page-header.story.js @@ -152,9 +152,9 @@ const prepareData = (data, args) => { }); } if (!args.show_thumbnail) { - delete data.thumbnail; + delete data.picture; } else if (args.show_thumbnail && !data.show_thumbnail) { - data.thumbnail = demoContent.thumbnail; + data.picture = demoContent.picture; } data.title = args.title; diff --git a/src/implementations/twig/components/page-header/eu-page-header.story.js b/src/implementations/twig/components/page-header/eu-page-header.story.js index 4f518ad728a..0ca3dc0d50a 100644 --- a/src/implementations/twig/components/page-header/eu-page-header.story.js +++ b/src/implementations/twig/components/page-header/eu-page-header.story.js @@ -143,9 +143,9 @@ const prepareData = (data, args) => { data.breadcrumb = { ...demoBreadcrumbLongEC }; } if (!args.show_thumbnail) { - delete data.thumbnail; + delete data.picture; } else if (args.show_thumbnail && !data.show_thumbnail) { - data.thumbnail = demoContent.thumbnail; + data.picture = demoContent.picture; } data.title = args.title; diff --git a/src/implementations/twig/components/page-header/page-header.html.twig b/src/implementations/twig/components/page-header/page-header.html.twig index 1bed54a23f6..c1f28ae53a3 100644 --- a/src/implementations/twig/components/page-header/page-header.html.twig +++ b/src/implementations/twig/components/page-header/page-header.html.twig @@ -5,11 +5,7 @@ - "title" (string) (default: '') Title of header - "hide_title" (boolean) (default: false) Hide the h1 title, for screen reader only - "description" (string) (default: '') Description of header - - "thumbnail" (associative array) (default: {}) Thumbnail dipslayed alongside the description: - { - "alt" (string) Alternative text - "src" (string) Image path - } + - "picture" (associative array) (default: {}): Image for thumbnail, following ECL Picture structure - "meta" (array) (default: []) Meta of header - "breadcrumb" (associative array) (default: '') Predefined structure compatible with EC Breadcrumb - "background_image_url (string) (default: '') Background image url @@ -22,15 +18,24 @@ "value" (optional) (string) ... ], + + Deprecated: + - "thumbnail" (associative array) (default: {}) Thumbnail dipslayed alongside the description: + { + "alt" (string) Alternative text + "src" (string) Image path + } #} -{# variables #} +{# Internal properties #} + {% set _variant = variant|default('') %} {% set _title = title|default('') %} {% set _hide_title = hide_title|default(false) %} {% set _meta = meta|default([]) %} {% set _description = description|default('') %} {% set _thumbnail = thumbnail|default({}) %} +{% set _picture = picture|default({}) %} {% set _breadcrumb = breadcrumb|default({}) %} {% set _css_class = 'ecl-page-header' %} {% set _background_image_url = background_image_url|default('') %} @@ -65,6 +70,17 @@ {% endfor %} {% endif %} +{# Backward compatibility #} + +{% if _picture.img is empty and _thumbnail.src is not empty %} + {% set _picture = { + 'img': { + 'src': _thumbnail.src|default(''), + 'alt': _thumbnail.alt|default('') + } + } %} +{% endif %} + {# Print the result #}
@@ -99,14 +115,14 @@ {% endif %} {% endif %} - {% if _description is not empty or _thumbnail is not empty %} + {% if _description is not empty or _picture.img is not empty %}
- {% if _thumbnail is not empty %} - {{ _thumbnail.alt|default('') }} + {% if _picture.img is not empty %} + {% include '@ecl/picture/picture.html.twig' with { + picture: _picture, + extra_classes: "ecl-page-header__picture", + extra_image_classes: "ecl-page-header__description-thumbnail", + } only %} {% endif %} {% if _description is not empty %}

{{ _description }}

diff --git a/src/implementations/twig/components/page-header/page-header.test.js b/src/implementations/twig/components/page-header/page-header.test.js index 8c89480e928..9533abb7dd8 100644 --- a/src/implementations/twig/components/page-header/page-header.test.js +++ b/src/implementations/twig/components/page-header/page-header.test.js @@ -61,4 +61,18 @@ describe('Page Header Standardised', () => { return expect(render(demoDefault)).resolves.toMatchSnapshot(); }); }); + + describe('with deprectated data', () => { + test('renders correctly', () => { + expect.assertions(1); + + demoDefault.thumbnail = { + alt: 'Europe map', + src: 'https://inno-ecl.s3.amazonaws.com/media/examples/example-image2.jpg', + }; + demoDefault.picture = {}; + + return expect(render(demoDefault)).resolves.toMatchSnapshot(); + }); + }); }); diff --git a/src/specs/components/page-header/demo/data.js b/src/specs/components/page-header/demo/data.js index e61c90b9cff..a559166b93a 100644 --- a/src/specs/components/page-header/demo/data.js +++ b/src/specs/components/page-header/demo/data.js @@ -5,9 +5,11 @@ module.exports = { title: 'Page title', description: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nec ullamcorper mi. Morbi interdum fermentum tempus. Nam nec rhoncus risus, eget dictum elit. Vestibulum gravida tincidunt venenatis.`, meta: ['Meta info', 'DD Month YYYY'], - thumbnail: { - alt: 'Europe map', - src: 'https://inno-ecl.s3.amazonaws.com/media/examples/example-image2.jpg', + picture: { + img: { + src: 'https://inno-ecl.s3.amazonaws.com/media/examples/example-image2.jpg', + alt: 'Europe map', + }, }, background_image_url: 'https://inno-ecl.s3.amazonaws.com/media/examples/example-image2.jpg', From 6bb7111945a1cf5bc21a5f47a98c718d5233e210 Mon Sep 17 00:00:00 2001 From: emeryro Date: Thu, 30 Mar 2023 08:17:28 +0200 Subject: [PATCH 2/6] update test --- .../__snapshots__/page-header.test.js.snap | 253 ++++++++++++++++-- 1 file changed, 233 insertions(+), 20 deletions(-) diff --git a/src/implementations/twig/components/page-header/__snapshots__/page-header.test.js.snap b/src/implementations/twig/components/page-header/__snapshots__/page-header.test.js.snap index 977104abdcf..cc83abbbf6c 100644 --- a/src/implementations/twig/components/page-header/__snapshots__/page-header.test.js.snap +++ b/src/implementations/twig/components/page-header/__snapshots__/page-header.test.js.snap @@ -164,11 +164,15 @@ exports[`Page Header Standardised Background image - renders correctly 1`] = `
- Europe map + + Europe map +

@@ -352,11 +356,15 @@ exports[`Page Header Standardised Default - renders correctly 1`] = `

- Europe map + + Europe map +

@@ -542,11 +550,15 @@ exports[`Page Header Standardised Default renders correctly with extra attribute

- Europe map + + Europe map +

@@ -730,11 +742,212 @@ exports[`Page Header Standardised Default renders correctly with extra class nam

- Europe map + + Europe map + +

+ Lorem ipsum dolor sit amet, + + consectetur adipiscing elit + + . Quisque nec ullamcorper mi. Morbi interdum fermentum tempus. Nam nec rhoncus risus, + + eget dictum elit + + . Vestibulum gravida tincidunt venenatis. +

+
+
+
+ +`; + +exports[`Page Header Standardised with deprectated data renders correctly 1`] = ` + +
+