Skip to content
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

Update: Add hover state to thumbnails #965

Merged
merged 2 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
18 changes: 13 additions & 5 deletions src/lib/ThumbnailsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VirtualScroller from './VirtualScroller';
import BoundedCache from './BoundedCache';

const CLASS_BOX_PREVIEW_THUMBNAIL = 'bp-thumbnail';
const CLASS_BOX_PREVIEW_THUMBNAIL_BORDER = 'bp-thumbnail-border';
const CLASS_BOX_PREVIEW_THUMBNAIL_NAV = 'bp-thumbnail-nav';
const CLASS_BOX_PREVIEW_THUMBNAIL_IMAGE = 'bp-thumbnail-image';
const CLASS_BOX_PREVIEW_THUMBNAIL_IMAGE_LOADED = 'bp-thumbnail-image-loaded';
Expand Down Expand Up @@ -75,7 +76,7 @@ class ThumbnailsSidebar {
// The image and page number have pointer-events: none so
// any click should be the thumbnail element itself.
if (target.classList.contains(CLASS_BOX_PREVIEW_THUMBNAIL_NAV)) {
const thumbnailEl = target.parentNode;
const thumbnailEl = target.parentNode.parentNode;
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
// Get the page number
const { bpPageNum: pageNumStr } = thumbnailEl.dataset;
const pageNum = parseInt(pageNumStr, 10);
Expand Down Expand Up @@ -208,8 +209,14 @@ class ThumbnailsSidebar {
thumbnailEl.className = CLASS_BOX_PREVIEW_THUMBNAIL;
thumbnailEl.dataset.bpPageNum = pageNum;
thumbnailEl.appendChild(this.createPageNumber(pageNum));

const thumbnailBorderEl = document.createElement('div');
thumbnailBorderEl.className = CLASS_BOX_PREVIEW_THUMBNAIL_BORDER;

const thumbnailNav = this.createThumbnailNav();
thumbnailEl.appendChild(thumbnailNav);

thumbnailBorderEl.appendChild(thumbnailNav);
thumbnailEl.appendChild(thumbnailBorderEl);

if (pageNum === this.currentPage) {
thumbnailEl.classList.add(CLASS_BOX_PREVIEW_THUMBNAIL_IS_SELECTED);
Expand All @@ -233,23 +240,24 @@ class ThumbnailsSidebar {
createThumbnailNav() {
const thumbnailNav = document.createElement('a');
thumbnailNav.className = CLASS_BOX_PREVIEW_THUMBNAIL_NAV;
thumbnailNav.tabIndex = '0';
return thumbnailNav;
}

/**
* Request the thumbnail image to be made
*
* @param {number} itemIndex - the item index in the overall list (0 indexed)
* @param {HTMLElement} thumbnailEl - the thumbnail button element
* @param {HTMLElement} thumbnailEl - the thumbnail element
* @return {void}
*/
requestThumbnailImage(itemIndex, thumbnailEl) {
requestAnimationFrame(() => {
this.createThumbnailImage(itemIndex).then((imageEl) => {
// Promise will resolve with null if create image request was already in progress
if (imageEl) {
// Appends to the lastChild which should be the thumbnail nav element
thumbnailEl.lastChild.appendChild(imageEl);
// Appends to the thumbnail nav element
thumbnailEl.lastChild.firstChild.appendChild(imageEl);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selection logic is getting pretty hairy. Can we avoid the extra wrapper?

thumbnailEl.classList.add(CLASS_BOX_PREVIEW_THUMBNAIL_IMAGE_LOADED);
}

Expand Down
10 changes: 8 additions & 2 deletions src/lib/__tests__/ThumbnailsSidebar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('ThumbnailsSidebar', () => {
stubs.renderNextThumbnailImage = sandbox.stub(thumbnailsSidebar, 'renderNextThumbnailImage');

const thumbnailEl = {
lastChild: { appendChild: stubs.appendChild },
lastChild: { firstChild: { appendChild: stubs.appendChild } },
classList: { add: stubs.addClass }
};

Expand Down Expand Up @@ -311,6 +311,7 @@ describe('ThumbnailsSidebar', () => {

describe('thumbnailClickHandler()', () => {
let targetEl;
let borderEl;
let parentEl;
let evt;

Expand All @@ -325,7 +326,12 @@ describe('ThumbnailsSidebar', () => {
targetEl = document.createElement('div');
targetEl.classList.add('bp-thumbnail-nav');

parentEl.appendChild(targetEl);
borderEl = document.createElement('div');
borderEl.classList.add('bp-thumbnail-border');

borderEl.appendChild(targetEl);

parentEl.appendChild(borderEl);

evt = {
target: targetEl,
Expand Down
27 changes: 22 additions & 5 deletions src/lib/viewers/doc/_docBase.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import '../../boxuiVariables';

$thumbnail-border-radius: 3px;
// Accounts for the 1px border on the right so the remaining width is actually 225
$thumbnail-sidebar-width: 226px;

Expand Down Expand Up @@ -47,25 +46,43 @@ $thumbnail-sidebar-width: 226px;
width: 34px;
}

.bp-thumbnail-border {
border: 2px solid transparent;
border-radius: 3px;
display: flex;
flex: 1 0 auto;
padding: 0;
}

.bp-thumbnail-nav {
background-color: $d-eight;
border: $thumbnail-border-radius solid $ffive;
border-radius: $thumbnail-border-radius;
border: 1px solid $ffive;
cursor: pointer;
flex: 1 0 154px;
outline: none;
overflow: hidden;
padding: 0;
}

.bp-thumbnail:not(.bp-thumbnail-is-selected) {
.bp-thumbnail-nav:focus,
.bp-thumbnail-nav:hover {
border-color: $seesee;
}
}

.bp-thumbnail-image {
background-position: center;
background-repeat: no-repeat;
background-size: contain;
pointer-events: none;
}

.bp-thumbnail.bp-thumbnail-is-selected .bp-thumbnail-nav {
border-color: $fours;
.bp-thumbnail.bp-thumbnail-is-selected {
.bp-thumbnail-nav,
.bp-thumbnail-border {
border-color: $fours;
}
}

.bp-thumbnails-container--dark {
Expand Down