Skip to content

Commit

Permalink
Allow gallery components to be unbounded
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Dec 10, 2024
1 parent 9e87a78 commit e2816be
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Optional `data-tnacookiesdomain` and `data-tnacookiespath` attributes on the `<html>` element can be used to define the domain and path for cookies
- Analytics added for breadcrumbs and gallery components
- Allowed the document scope of an `EventTracker` instance to be changed
- Gallery components are unbounded by default but can have a background with `bounded: true`

### Changed

Expand Down
31 changes: 31 additions & 0 deletions src/nationalarchives/components/gallery/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@
},
"html": "<section class=\"tna-gallery\" data-module=\"tna-gallery\"><div class=\"tna-gallery__header\"><div class=\"tna-gallery__header-inner\"></div><div class=\"tna-gallery__options tna-button-group tna-button-group--small\" hidden><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"enter-fullscreen\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M32 32C14.3 32 0 46.3 0 64v96c0 17.7 14.3 32 32 32s32-14.3 32-32V96h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H64V352zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32h64v64c0 17.7 14.3 32 32 32s32-14.3 32-32V64c0-17.7-14.3-32-32-32H320zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H320c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V352z\"/></svg><span class=\"tna-visually-hidden\">View the gallery in </span>Full screen</button><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"exit-fullscreen\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M160 64c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H32c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V64zM32 320c-17.7 0-32 14.3-32 32s14.3 32 32 32H96v64c0 17.7 14.3 32 32 32s32-14.3 32-32V352c0-17.7-14.3-32-32-32H32zM352 64c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H352V64zM320 320c-17.7 0-32 14.3-32 32v96c0 17.7 14.3 32 32 32s32-14.3 32-32V384h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H320z\"/></svg>Exit full screen</button><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"show-index\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M128 136c0-22.1-17.9-40-40-40L40 96C17.9 96 0 113.9 0 136l0 48c0 22.1 17.9 40 40 40H88c22.1 0 40-17.9 40-40l0-48zm0 192c0-22.1-17.9-40-40-40H40c-22.1 0-40 17.9-40 40l0 48c0 22.1 17.9 40 40 40H88c22.1 0 40-17.9 40-40V328zm32-192v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V136c0-22.1-17.9-40-40-40l-48 0c-22.1 0-40 17.9-40 40zM288 328c0-22.1-17.9-40-40-40H200c-22.1 0-40 17.9-40 40l0 48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V328zm32-192v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V136c0-22.1-17.9-40-40-40l-48 0c-22.1 0-40 17.9-40 40zM448 328c0-22.1-17.9-40-40-40H360c-22.1 0-40 17.9-40 40v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V328z\"/></svg>See all images</button></div></div><div class=\"tna-gallery__items\"><div class=\"tna-gallery__item\" id=\"test-gallery-item-1\" aria-labelledby=\"test-gallery-item-1-tab\"><p class=\"tna-gallery__item-header\">Image 1 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/50/600/400\" class=\"tna-gallery__item-image\" alt=\"Photo 1\" width=\"600\" height=\"400\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 1</figcaption></figure></div><div class=\"tna-gallery__item\" id=\"test-gallery-item-2\" aria-labelledby=\"test-gallery-item-2-tab\"><p class=\"tna-gallery__item-header\">Image 2 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/51/600/600\" class=\"tna-gallery__item-image\" alt=\"Photo 2\" width=\"400\" height=\"400\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 2</figcaption></figure></div><div class=\"tna-gallery__item\" id=\"test-gallery-item-3\" aria-labelledby=\"test-gallery-item-3-tab\"><p class=\"tna-gallery__item-header\">Image 3 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/52/400/600\" class=\"tna-gallery__item-image\" alt=\"Photo 3\" width=\"400\" height=\"600\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 3</figcaption></figure></div></div><div class=\"tna-gallery__navigation-buttons\" hidden><button type=\"button\" class=\"tna-gallery__navigation-button tna-gallery__navigation-prev\" aria-label=\"Previous image\"><span class=\"tna-gallery__navigation-button-label\"><span class=\"tna-gallery__navigation-button-icon\"></span>Previous</span></button><button type=\"button\" class=\"tna-gallery__navigation-button tna-gallery__navigation-next\" aria-label=\"Next image\"><span class=\"tna-gallery__navigation-button-label\">Next<span class=\"tna-gallery__navigation-button-icon\"></span></span></button></div><div class=\"tna-gallery__navigation\" hidden><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-1-tab\" aria-label=\"Image 1 of 3\" aria-controls=\"test-gallery-item-1\"><img src=\"https://picsum.photos/id/50/600/400\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"600\" height=\"400\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">1</span><span class=\"tna-visually-hidden\"> of 3</span></button><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-2-tab\" aria-label=\"Image 2 of 3\" aria-controls=\"test-gallery-item-2\"><img src=\"https://picsum.photos/id/51/600/600\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"400\" height=\"400\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">2</span><span class=\"tna-visually-hidden\"> of 3</span></button><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-3-tab\" aria-label=\"Image 3 of 3\" aria-controls=\"test-gallery-item-3\"><img src=\"https://picsum.photos/id/52/400/600\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"400\" height=\"600\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">3</span><span class=\"tna-visually-hidden\"> of 3</span></button></div></section>"
},
{
"name": "bounded",
"options": {
"items": [
{
"alt": "Photo 1",
"width": 600,
"height": 400,
"src": "https://picsum.photos/id/50/600/400",
"description": "This is photo number 1"
},
{
"alt": "Photo 2",
"width": 400,
"height": 400,
"src": "https://picsum.photos/id/51/600/600",
"description": "This is photo number 2"
},
{
"alt": "Photo 3",
"width": 400,
"height": 600,
"src": "https://picsum.photos/id/52/400/600",
"description": "This is photo number 3"
}
],
"id": "test-gallery",
"bounded": true
},
"html": "<section class=\"tna-gallery tna-gallery--bounded\" data-module=\"tna-gallery\"><div class=\"tna-gallery__header\"><div class=\"tna-gallery__header-inner\"></div><div class=\"tna-gallery__options tna-button-group tna-button-group--small\" hidden><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"enter-fullscreen\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M32 32C14.3 32 0 46.3 0 64v96c0 17.7 14.3 32 32 32s32-14.3 32-32V96h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H64V352zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32h64v64c0 17.7 14.3 32 32 32s32-14.3 32-32V64c0-17.7-14.3-32-32-32H320zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H320c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V352z\"/></svg><span class=\"tna-visually-hidden\">View the gallery in </span>Full screen</button><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"exit-fullscreen\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M160 64c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H32c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V64zM32 320c-17.7 0-32 14.3-32 32s14.3 32 32 32H96v64c0 17.7 14.3 32 32 32s32-14.3 32-32V352c0-17.7-14.3-32-32-32H32zM352 64c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H352V64zM320 320c-17.7 0-32 14.3-32 32v96c0 17.7 14.3 32 32 32s32-14.3 32-32V384h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H320z\"/></svg>Exit full screen</button><button class=\"tna-button tna-button--icon-only-mobile\" type=\"button\" hidden value=\"show-index\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 448 512\" height=\"24\"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d=\"M128 136c0-22.1-17.9-40-40-40L40 96C17.9 96 0 113.9 0 136l0 48c0 22.1 17.9 40 40 40H88c22.1 0 40-17.9 40-40l0-48zm0 192c0-22.1-17.9-40-40-40H40c-22.1 0-40 17.9-40 40l0 48c0 22.1 17.9 40 40 40H88c22.1 0 40-17.9 40-40V328zm32-192v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V136c0-22.1-17.9-40-40-40l-48 0c-22.1 0-40 17.9-40 40zM288 328c0-22.1-17.9-40-40-40H200c-22.1 0-40 17.9-40 40l0 48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V328zm32-192v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V136c0-22.1-17.9-40-40-40l-48 0c-22.1 0-40 17.9-40 40zM448 328c0-22.1-17.9-40-40-40H360c-22.1 0-40 17.9-40 40v48c0 22.1 17.9 40 40 40h48c22.1 0 40-17.9 40-40V328z\"/></svg>See all images</button></div></div><div class=\"tna-gallery__items\"><div class=\"tna-gallery__item\" id=\"test-gallery-item-1\" aria-labelledby=\"test-gallery-item-1-tab\"><p class=\"tna-gallery__item-header\">Image 1 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/50/600/400\" class=\"tna-gallery__item-image\" alt=\"Photo 1\" width=\"600\" height=\"400\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 1</figcaption></figure></div><div class=\"tna-gallery__item\" id=\"test-gallery-item-2\" aria-labelledby=\"test-gallery-item-2-tab\"><p class=\"tna-gallery__item-header\">Image 2 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/51/600/600\" class=\"tna-gallery__item-image\" alt=\"Photo 2\" width=\"400\" height=\"400\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 2</figcaption></figure></div><div class=\"tna-gallery__item\" id=\"test-gallery-item-3\" aria-labelledby=\"test-gallery-item-3-tab\"><p class=\"tna-gallery__item-header\">Image 3 of 3</p><figure class=\"tna-gallery__item-figure\"><div class=\"tna-gallery__item-figure-inner\"><img src=\"https://picsum.photos/id/52/400/600\" class=\"tna-gallery__item-image\" alt=\"Photo 3\" width=\"400\" height=\"600\" loading=\"lazy\"></div><figcaption class=\"tna-gallery__item-description\">This is photo number 3</figcaption></figure></div></div><div class=\"tna-gallery__navigation-buttons\" hidden><button type=\"button\" class=\"tna-gallery__navigation-button tna-gallery__navigation-prev\" aria-label=\"Previous image\"><span class=\"tna-gallery__navigation-button-label\"><span class=\"tna-gallery__navigation-button-icon\"></span>Previous</span></button><button type=\"button\" class=\"tna-gallery__navigation-button tna-gallery__navigation-next\" aria-label=\"Next image\"><span class=\"tna-gallery__navigation-button-label\">Next<span class=\"tna-gallery__navigation-button-icon\"></span></span></button></div><div class=\"tna-gallery__navigation\" hidden><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-1-tab\" aria-label=\"Image 1 of 3\" aria-controls=\"test-gallery-item-1\"><img src=\"https://picsum.photos/id/50/600/400\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"600\" height=\"400\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">1</span><span class=\"tna-visually-hidden\"> of 3</span></button><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-2-tab\" aria-label=\"Image 2 of 3\" aria-controls=\"test-gallery-item-2\"><img src=\"https://picsum.photos/id/51/600/600\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"400\" height=\"400\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">2</span><span class=\"tna-visually-hidden\"> of 3</span></button><button type=\"button\" class=\"tna-gallery__navigation-item\" id=\"test-gallery-item-3-tab\" aria-label=\"Image 3 of 3\" aria-controls=\"test-gallery-item-3\"><img src=\"https://picsum.photos/id/52/400/600\" class=\"tna-gallery__navigation-item-image\" alt=\"\" width=\"400\" height=\"600\" loading=\"lazy\"><span class=\"tna-visually-hidden\">Image</span><span class=\"tna-gallery__navigation-item-label\">3</span><span class=\"tna-visually-hidden\"> of 3</span></button></div></section>"
},
{
"name": "with title and text",
"options": {
Expand Down
31 changes: 22 additions & 9 deletions src/nationalarchives/components/gallery/gallery.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use "../../variables/a11y" as a11yVariables;
@use "../../tools/a11y";
@use "../../tools/colour";
@use "../../tools/media";
Expand All @@ -11,13 +12,9 @@
grid-template: min-content min-content 1fr / 2fr 1fr;
gap: 0 spacing.space(1);

@include colour.tint;

border-radius: 0.1px;

&__header {
padding: spacing.space(1);

grid-column: 1 / 3;
grid-row: 1;

Expand Down Expand Up @@ -93,7 +90,7 @@
}

&__item-description {
margin: 0 spacing.space(1) spacing.space(1);
margin-bottom: spacing.space(1);
padding: spacing.space(0.5) spacing.space(1);

align-self: flex-start;
Expand Down Expand Up @@ -172,8 +169,8 @@
&__navigation-button-icon {
content: "";

width: 1rem;
height: 1rem;
width: 0.75rem;
height: 0.75rem;

display: block;
flex: none;
Expand Down Expand Up @@ -322,6 +319,16 @@
}
}

&--bounded,
&:fullscreen {
@include colour.tint;
}

&--bounded &__header,
&:fullscreen &__header {
padding: spacing.space(1);
}

&:fullscreen &__header-inner {
display: none;
}
Expand All @@ -338,6 +345,12 @@
}
}

&--bounded &__item-description,
&:fullscreen &__item-description {
margin-right: spacing.space(1);
margin-left: spacing.space(1);
}

&:fullscreen &__item-description {
max-height: 6rem;

Expand Down Expand Up @@ -406,8 +419,8 @@
}

&:fullscreen &__navigation {
padding-top: 0;
padding-left: 0;
// padding-top: 0;
// padding-left: 0;

grid-column: 2 / 3;
grid-row: 2 / 4;
Expand Down
9 changes: 9 additions & 0 deletions src/nationalarchives/components/gallery/gallery.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const argTypes = {
items: { control: "object" },
id: { control: "text" },
showGrid: { control: "boolean" },
bounded: { control: "boolean" },
classes: { control: "text" },
attributes: { control: "object" },
};
Expand All @@ -34,6 +35,7 @@ const Template = ({
items,
id,
showGrid,
bounded,
classes,
attributes,
}) =>
Expand All @@ -47,6 +49,7 @@ const Template = ({
items,
id,
showGrid,
bounded,
classes,
attributes,
},
Expand Down Expand Up @@ -86,6 +89,12 @@ Standard.args = {
classes: "tna-gallery--demo",
};

export const Bounded = Template.bind({});
Bounded.args = {
...Standard.args,
bounded: true,
};

export const Grid = Template.bind({});
Grid.args = {
...Standard.args,
Expand Down
6 changes: 6 additions & 0 deletions src/nationalarchives/components/gallery/macro-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
"required": false,
"description": "If true, don't select the first image when the gallery loads and instead show a grid of images."
},
{
"name": "bounded",
"type": "boolean",
"required": false,
"description": "If true, add a background to the gallery to separate it from surrounding contnet."
},
{
"name": "classes",
"type": "string",
Expand Down
3 changes: 3 additions & 0 deletions src/nationalarchives/components/gallery/template.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% from "nationalarchives/components/button/macro.njk" import tnaButton %}

{%- set containerClasses = [params.classes] if params.classes else [] -%}
{%- if params.bounded -%}
{%- set containerClasses = containerClasses.concat('tna-gallery--bounded') -%}
{%- endif -%}
{%- set classes = containerClasses | join(' ') -%}
<section class="tna-gallery{% if classes %} {{ classes }}{% endif %}" data-module="tna-gallery"{% if params.showGrid %} data-showgrid="true"{% endif %}{% for attribute, value in params.attributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>
<div class="tna-gallery__header">
Expand Down

0 comments on commit e2816be

Please sign in to comment.