-
Notifications
You must be signed in to change notification settings - Fork 2
Gallery component (scrollable) #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mjbp
wants to merge
49
commits into
master
Choose a base branch
from
feature/gallery-scroll
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
1231ff2
Initial commit
mjbp 8640a1d
Updates dom and initialisation
mjbp ad57639
Starts tests outline; updates dom
mjbp c2dd368
Starts gallery mark up
mjbp 15dd1f2
Add basic functionality, add tests
mjbp 8c2a68c
Refactor and add tests
mjbp ba7320d
Add tests
mjbp 85189bc
Promisify image loading
mjbp 94459bb
Start img render refactor
mjbp bb20be2
Refactor image loading
mjbp 195ce66
Mock image complete for testing
mjbp 1e03af3
Update manbual initialisation test
mjbp 1c0bf34
Add interaction tests
mjbp 75b4f3c
Add image loading test
mjbp 385d352
Add tests
mjbp e9357a3
Add error hanlding tests
mjbp e9a0b8d
Add picture loading
mjbp 6526ed9
Add preload setting
mjbp 1a5c153
Update preload test
mjbp 104c6b9
Rename live region fn and property
mjbp 2609683
Add URL updating, retrieving index from URL, popstate handler
mjbp 862e844
Refactor and add utils tests
mjbp ae1ff15
Add tests
mjbp 3455e17
Renaming, housekeeping
mjbp 3e887d9
Added video support
Nick-StormID d7f969a
Add inbound linking
mjbp 486365b
Start refactoring loaders
mjbp 7bb5f08
Update implementation to remove loaders
mjbp d085b18
Add playwright axe test
mjbp feb613d
Docs, housekeeping
mjbp d3d3f0d
Add events; housekeeping
mjbp d17d24f
Update window history functionality
mjbp 25ca341
Add keyboard tests
mjbp 8734033
Docs
mjbp a2cc3c7
Revert
mjbp c11b70f
Change playwright test port
mjbp 96839c8
Add viewport meta
mjbp 8ebc9a4
Run keyboard tests across all browsers
mjbp 5f91eab
Remove fullscreen button if not supported (iphone)
mjbp 3cbaa19
Scroll version
mjbp 8ef0dda
Optimise scroll handler; patch ids; update fullscreen; update tests
mjbp 0bcff1d
Update tests, add test hooks
mjbp 707c74d
Update packages/gallery/README.md
mjbp d8bec6a
Update packages/gallery/__tests__/jest/initialisation/manual.js
mjbp 81c8668
Update readme
mjbp 4cdd2fc
Add wait for scroll to test for Safari
mjbp fece9a4
Update packages/gallery/README.md
mjbp ab4cdb6
Update packages/gallery/README.md
mjbp 1b2946c
Update test html
mjbp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .DS_Store | ||
| *.log | ||
| src | ||
| __tests__ | ||
| example | ||
| coverage | ||
| jest.config.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # 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 announcements. | ||
| 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"> | ||
| <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> | ||
| <ul class="gallery__list" tabindex="0"> | ||
| <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__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 | ||
| list: '[data-gallery-list]', | ||
| 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 | ||
mjbp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| ## 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.