From 31b7fd62ac071e7918af532ea777f806df7c6dd9 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Wed, 5 Jun 2024 19:19:47 +0100 Subject: [PATCH] Allow lazy images on index grid items --- CHANGELOG.md | 3 ++ .../components/index-grid/fixtures.json | 37 +++++++++++++++++++ .../index-grid/index-grid.stories.js | 3 ++ .../components/index-grid/macro-options.json | 6 +++ .../components/index-grid/template.njk | 2 +- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3731ea..e4cad0d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/nationalarchives/tna-frontend/compare/v0.1.58...HEAD) ### Added + +- Allow `lazyImages` attribute for lazy loading of index grid images + ### Changed ### Deprecated ### Removed diff --git a/src/nationalarchives/components/index-grid/fixtures.json b/src/nationalarchives/components/index-grid/fixtures.json index 0db317e7..90b84561 100644 --- a/src/nationalarchives/components/index-grid/fixtures.json +++ b/src/nationalarchives/components/index-grid/fixtures.json @@ -243,6 +243,43 @@ }, "html": "" }, + { + "name": "lazy images", + "options": { + "title": "My dogs", + "headingLevel": 2, + "items": [ + { + "href": "#/category-0", + "src": "https://picsum.photos/id/237/800/600", + "alt": "Photo of a puppy", + "width": 800, + "height": 600, + "title": "Category #101" + }, + { + "href": "#/category-1", + "src": "https://picsum.photos/id/237/800/600", + "alt": "Photo of a puppy", + "width": 800, + "height": 600, + "title": "Category #102" + }, + { + "href": "#/category-2", + "src": "https://picsum.photos/id/237/800/600", + "alt": "Photo of a puppy", + "width": 800, + "height": 600, + "title": "Category #103" + } + ], + "lazyImages": true, + "columns": 3, + "classes": "index-grid__test-class" + }, + "html": "" + }, { "name": "with classes", "options": { diff --git a/src/nationalarchives/components/index-grid/index-grid.stories.js b/src/nationalarchives/components/index-grid/index-grid.stories.js index d9c714fa..6c367f28 100644 --- a/src/nationalarchives/components/index-grid/index-grid.stories.js +++ b/src/nationalarchives/components/index-grid/index-grid.stories.js @@ -12,6 +12,7 @@ const argTypes = { body: { control: "text" }, text: { control: "text" }, items: { control: "object" }, + lazyImages: { control: "boolean" }, columns: { control: "number" }, columnsMedium: { control: "number" }, columnsSmall: { control: "number" }, @@ -42,6 +43,7 @@ const Template = ({ body, text, items, + lazyImages, columns, columnsMedium, columnsSmall, @@ -61,6 +63,7 @@ const Template = ({ body, text, items, + lazyImages, columns, columnsMedium, columnsSmall, diff --git a/src/nationalarchives/components/index-grid/macro-options.json b/src/nationalarchives/components/index-grid/macro-options.json index 5f19717c..84f4715c 100644 --- a/src/nationalarchives/components/index-grid/macro-options.json +++ b/src/nationalarchives/components/index-grid/macro-options.json @@ -110,6 +110,12 @@ } ] }, + { + "name": "lazyImages", + "type": "boolean", + "required": false, + "description": "If true, make the images a lazily-loaded." + }, { "name": "columns", "type": "string", diff --git a/src/nationalarchives/components/index-grid/template.njk b/src/nationalarchives/components/index-grid/template.njk index 6f9a52b3..3a5d5043 100644 --- a/src/nationalarchives/components/index-grid/template.njk +++ b/src/nationalarchives/components/index-grid/template.njk @@ -63,7 +63,7 @@ {%- for item in params.items %}
  • - {{ item.alt }} + {{ item.alt }} {{ item.title }} {%- if item.label %}