Skip to content

Commit

Permalink
feat: make panel target selection less naive
Browse files Browse the repository at this point in the history
Take the option of a single panel in the viewport into account. Warn about PanelSnap not supporting
space between panels yet, and make a best effort snap back to the visible panel.
  • Loading branch information
guidobouman committed May 3, 2018
1 parent e69e20d commit d1a514e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/panelSnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,25 @@ export default class PanelSnap {
}

const panelsInViewport = getElementsInContainerViewport(this.container, this.panelList);

if (panelsInViewport.length === 0) {
throw new Error('PanelSnap could not find a snappable panel, aborting.');
}

const targetIndex = delta > 0 ? panelsInViewport.length - 1 : 0;
this.snapToPanel(panelsInViewport[targetIndex], delta < 0);
if (panelsInViewport.length > 1) {
const targetIndex = delta > 0 ? 1 : panelsInViewport.length - 2;
this.snapToPanel(panelsInViewport[targetIndex], delta < 0);
return;
}

const visiblePanel = panelsInViewport[0];
if (elementFillsContainer(this.container, visiblePanel)) {
return;
}

// TODO: Only one partial panel in viewport, add support for space between panels?
// eslint-disable-next-line no-console
console.error('PanelSnap does not support space between panels, snapping back.');
this.snapToPanel(visiblePanel, delta > 0);
}

snapToPanel(panel, toBottom = false) {
Expand All @@ -118,10 +130,6 @@ export default class PanelSnap {

this.activatePanel(panel);

if (elementFillsContainer(this.container, panel)) {
return;
}

if (this.animation) {
this.animation.stop();
}
Expand Down

0 comments on commit d1a514e

Please sign in to comment.