Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
71f610e
Initial commit
mjbp Jan 6, 2022
7741ea2
Updates dom and initialisation
mjbp Jan 6, 2022
afe20e1
Starts tests outline; updates dom
mjbp Jan 7, 2022
3f84c87
Starts gallery mark up
mjbp Jan 7, 2022
81d093a
Add basic functionality, add tests
mjbp Jan 7, 2022
05f3d13
Refactor and add tests
mjbp Jan 9, 2022
9e3001c
Add tests
mjbp Jan 9, 2022
2383f00
Promisify image loading
mjbp Jan 10, 2022
16f4748
Start img render refactor
mjbp Jan 10, 2022
8ac3871
Refactor image loading
mjbp Jan 10, 2022
f3a2d10
Mock image complete for testing
mjbp Jan 11, 2022
b151a19
Update manbual initialisation test
mjbp Jan 11, 2022
8ad31a1
Add interaction tests
mjbp Jan 11, 2022
9913110
Add image loading test
mjbp Jan 12, 2022
4b6e74b
Add tests
mjbp Jan 12, 2022
cc5527a
Add error hanlding tests
mjbp Jan 12, 2022
9a410b3
Add picture loading
mjbp Jan 13, 2022
51ce299
Add preload setting
mjbp Jan 14, 2022
afe16f4
Update preload test
mjbp Jan 14, 2022
cc28d26
Rename live region fn and property
mjbp Jan 16, 2022
5ea34bb
Add URL updating, retrieving index from URL, popstate handler
mjbp Jan 17, 2022
675b264
Refactor and add utils tests
mjbp Jan 18, 2022
fd858e3
Add tests
mjbp Jan 18, 2022
bf88d3e
Renaming, housekeeping
mjbp Jan 20, 2022
cb65d1c
Added video support
Nick-StormID Mar 1, 2022
3cf2c16
Add inbound linking
mjbp Mar 18, 2022
8018de7
Start refactoring loaders
mjbp Apr 6, 2022
f4da781
Update implementation to remove loaders
mjbp Mar 13, 2025
f4e3aec
Add playwright axe test
mjbp Mar 14, 2025
41cc611
Docs, housekeeping
mjbp Mar 14, 2025
fb616f8
Add events; housekeeping
mjbp Mar 19, 2025
5da3018
Update window history functionality
mjbp Mar 19, 2025
3899fd2
Add keyboard tests
mjbp Mar 20, 2025
baafa6f
Docs
mjbp Mar 20, 2025
f03690d
Revert
mjbp Mar 20, 2025
2278079
Change playwright test port
mjbp Mar 20, 2025
5920519
Add viewport meta
mjbp Mar 20, 2025
a6707c0
Run keyboard tests across all browsers
mjbp Mar 20, 2025
3cb615e
Remove fullscreen button if not supported (iphone)
mjbp Mar 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .azurite/__azurite_db_blob__.json

This file was deleted.

1 change: 0 additions & 1 deletion .azurite/__azurite_db_blob_extent__.json

This file was deleted.

7 changes: 7 additions & 0 deletions packages/gallery/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
*.log
src
__tests__
example
coverage
jest.config.js
184 changes: 184 additions & 0 deletions packages/gallery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Gallery

Accessible media gallery that can be used inline or in a modal.

---

## Usage

Create the gallery in HTML.

There must be an live region with a `data-gallery-live-region` attribute (an element with `aria-live="polite" aria-atomic="true"` for example) for the accessible announcenments.

Each of the gallery items should have a `data-gallery-item` attribute and an id, which is used to update the document URL and makes slides addressable - you can link to a specific gallery slide using a URL hash matching a slide id. If ids are not added they are programmatically generated.

For navigation, `data-gallery-previous` and `data-gallery-next` attributes on buttons identify them as navigation triggers.

Optionally, a button with `data-gallery-fullscreen` attribute if supporting fullscreen functionality.

Optionally, any buttons with a `data-gallery-navigate` attribute will navigate the gallery to a specific slide, e.g. `data-gallery-navigate="2"`.

```
<div role="region" class="gallery js-gallery" id="gallery">
<div class="gallery__header">
<div class="gallery__total" aria-live="polite" aria-atomic="true" data-gallery-live-region>1 of 5</div>
<button class="gallery__fullscreen" aria-label="Full screen" data-gallery-fullscreen>
<svg class="gallery__fullscreen-icon" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="33.547" height="33.281" viewBox="0 0 33.547 33.281">
<g transform="translate(-1434 -40.572)">
<path d="M7.334,13.243a.919.919,0,0,0,.007-1.294L3.073,7.667l9.847,0a.914.914,0,0,0,0-1.828l-9.847,0L7.348,1.557A.925.925,0,0,0,7.341.263.91.91,0,0,0,6.054.27L.26,6.106h0a1.026,1.026,0,0,0-.19.288A.872.872,0,0,0,0,6.746a.916.916,0,0,0,.26.64l5.794,5.836A.9.9,0,0,0,7.334,13.243Z" transform="translate(1467.547 50.119) rotate(135)" fill="#fff"/>
<path d="M7.334,13.243a.919.919,0,0,0,.007-1.294L3.073,7.667l9.847,0a.914.914,0,0,0,0-1.828l-9.847,0L7.348,1.557A.925.925,0,0,0,7.341.263.91.91,0,0,0,6.054.27L.26,6.106h0a1.026,1.026,0,0,0-.19.288A.872.872,0,0,0,0,6.746a.916.916,0,0,0,.26.64l5.794,5.836A.9.9,0,0,0,7.334,13.243Z" transform="translate(1434 64.307) rotate(-45)" fill="#fff"/>
</g>
</svg>
</button>
</div>
<div class="gallery__main">
<ul class="gallery__list">
<li class="gallery__item" data-gallery-item id="gallery-1">
<div class="gallery__item-img-container">
<picture>
<source srcset="https://placehold.co/1600x1000.jpg" media="(min-width:1000px)">
<source srcset="https://placehold.co/1000x600.png" media="(min-width:700px)">
<source srcset="https://placehold.co/700x400.png" media="(min-width:400px)">
<img loading="lazy" src="https://placehold.co/500x200.png" alt="Test image">
</picture>
</div>
<div class="gallery__item-footer">
<div class="gallery__item-meta">
<div class="gallery__item-description">
<h2 class="gallery__item-artist">Kate Murphy</h2>
<div class="gallery__item-category">Architecture - March</div>
<div class="gallery__item-title">Example project name here</div>
</div>
</div>
</div>
</li>
<li class="gallery__item" data-gallery-item id="gallery-2">
<div class="gallery__item-img-container">
<picture>
<source srcset="https://placehold.co/1600x1400.jpg" media="(min-width:1100px)">
<source srcset="https://placehold.co/1100x1000.png" media="(min-width:710px)">
<source srcset="https://placehold.co/710x900.png" media="(min-width:400px)">
<img loading="lazy" src="https://placehold.co/420x300.png" alt="Test image">
</picture>
</div>
<div class="gallery__item-footer">
<div class="gallery__item-meta">
<div class="gallery__item-description">
<h2 class="gallery__item-artist">Kate Murphy</h2>
<div class="gallery__item-category">Architecture - April</div>
<div class="gallery__item-title">Example project name here</div>
</div>
</div>
</div>
</li>
<li class="gallery__item" data-gallery-item id="gallery-3">
<div class="gallery__item-img-container">
<picture>
<source srcset="https://placehold.co/1630x1500.jpg" media="(min-width:1300px)">
<source srcset="https://placehold.co/1300x1200.png" media="(min-width:730px)">
<source srcset="https://placehold.co/730x300.png" media="(min-width:430px)">
<img loading="lazy" src="https://placehold.co/430x300.png" alt="Test image">
</picture>
</div>
<div class="gallery__item-footer">
<div class="gallery__item-meta">
<div class="gallery__item-description">
<h2 class="gallery__item-artist">Kate Murphy</h2>
<div class="gallery__item-category">Architecture - May</div>
<div class="gallery__item-title">Example project name here</div>
</div>
</div>
</div>
</li>
<li class="gallery__item" data-gallery-item id="gallery-4">
<div class="gallery__item-img-container">
<picture>
<source srcset="https://placehold.co/1640x2400.jpg" media="(min-width:1400px)">
<source srcset="https://placehold.co/1400x2200.png" media="(min-width:740px)">
<source srcset="https://placehold.co/740x1200.png" media="(min-width:440px)">
<img loading="lazy" src="https://placehold.co/430x300.png" alt="Test image">
</picture>
</div>
<div class="gallery__item-footer">
<div class="gallery__item-meta">
<div class="gallery__item-description">
<h2 class="gallery__item-artist">Kate Murphy</h2>
<div class="gallery__item-category">Architecture - June</div>
<div class="gallery__item-title">Example project name here</div>
</div>
</div>
</div>
</li>


</ul>
<button class="gallery__previous" aria-label="Previous image" data-gallery-previous>
<svg class="gallery__previous-icon" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"><rect fill="none" height="24" width="24"/><g><polygon points="17.77,3.77 16,2 6,12 16,22 17.77,20.23 9.54,12"/></g></svg>
</button>
<button class="gallery__next" aria-label="Next image" data-gallery-next>
<svg class="gallery__next-icon" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"><g><path d="M0,0h24v24H0V0z" fill="none"/></g><g><polygon points="6.23,20.23 8,22 18,12 8,2 6.23,3.77 14.46,12"/></g></svg>
</button>
</div>
</div>
```

Install the package
```
npm i -S @stormid/gallery
```

Initialise the gallery
```
import gallery from '@stormid/gallery';

const [instance] = gallery('js-gallery);

## Options

```
{
startIndex: 0,
selector: { //selectors for the gallery elements
item: '[data-gallery-item]',
fullscreen: '[data-gallery-fullscreen]',
liveRegion: '[data-gallery-live-region]',
previous: '[data-gallery-previous]',
next: '[data-gallery-next]',
navigate: '[data-gallery-navigate]'
},
className: { // classNames used to style different gallery states
active: 'is--active',
fullscreen: 'is--fullscreen'
},
manualInitialisation: false, // to prevent automatic initialisation, so it can be initialised via the API
updateURL: true, //change URL when item changes
announcement(current, total){ //template for the accessible announcement
return `${current} of ${total}`;
}
}
```

## API
gallery() returns an array of instances. Each instance exposes the interface
```
{
getState // return the current state Object
initialise // to manually initialise if manualInitialisation setting is true
goTo // navigate to a slide index (zero indexed)
toggleFullScreen // set teh gallery to full screen
}
```

## Events
There are 2 events that an instance of the gallery dispatches:
- `gallery.initialised` when it's initialised
- `gallery.change` when navigating to a different slide


## Tests
```
npm t
```

## License
MIT
Loading