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

Fix preview scrolling #1782

Merged
merged 2 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 0 additions & 9 deletions app/react-native/src/server/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ export default function(publicPath, options) {
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Storybook for React</title>
<style>
/*
When resizing panels, the drag event breaks if the cursor
moves over the iframe. Add the 'dragging' class to the body
at drag start and remove it when the drag ends.
*/
.dragging iframe {
pointer-events: none;
}

/* Styling the fuzzy search box placeholders */
.searchBox::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #ddd;
Expand Down
9 changes: 0 additions & 9 deletions app/react/src/server/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export default function({ assets, publicPath, headHtml }) {
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<title>Storybook</title>
<style>
/*
When resizing panels, the drag event breaks if the cursor
moves over the iframe. Add the 'dragging' class to the body
at drag start and remove it when the drag ends.
*/
.dragging iframe {
pointer-events: none;
}

/* Styling the fuzzy search box placeholders */
.searchBox::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #ddd;
Expand Down
9 changes: 0 additions & 9 deletions app/vue/src/server/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export default function({ assets, publicPath, headHtml }) {
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<title>Storybook</title>
<style>
/*
When resizing panels, the drag event breaks if the cursor
moves over the iframe. Add the 'dragging' class to the body
at drag start and remove it when the drag ends.
*/
.dragging iframe {
pointer-events: none;
}

/* Styling the fuzzy search box placeholders */
.searchBox::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #ddd;
Expand Down
40 changes: 31 additions & 9 deletions lib/ui/src/modules/ui/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { document, localStorage, window } from 'global';
import { localStorage, window } from 'global';
import PropTypes from 'prop-types';
import React from 'react';
import SplitPane from 'react-split-pane';
Expand Down Expand Up @@ -78,6 +78,15 @@ const fullScreenPreviewStyle = {
overflow: 'hidden',
};

const overlayStyle = isDragging => ({
display: isDragging ? 'block' : 'none',
position: 'absolute',
top: '0px',
right: '0px',
bottom: '0px',
left: '0px',
});

const defaultSizes = {
addonPanel: {
down: 200,
Expand All @@ -89,10 +98,6 @@ const defaultSizes = {
},
};

const onDragStart = () => document.body.classList.add('dragging');

const onDragEnd = () => document.body.classList.remove('dragging');

const saveSizes = sizes => {
try {
localStorage.setItem('panelSizes', JSON.stringify(sizes));
Expand Down Expand Up @@ -129,9 +134,12 @@ class Layout extends React.Component {
height: 0,
width: 0,
},
isDragging: false,
};

this.onResize = this.onResize.bind(this);
this.onDragStart = this.onDragStart.bind(this);
this.onDragEnd = this.onDragEnd.bind(this);
}

componentDidMount() {
Expand All @@ -142,6 +150,14 @@ class Layout extends React.Component {
window.removeEventListener('resize', this.onResize);
}

onDragStart() {
this.setState({ isDragging: true });
}

onDragEnd() {
this.setState({ isDragging: false });
}

onResize(pane, mode) {
return size => {
this.layerSizes[pane][mode] = size;
Expand Down Expand Up @@ -200,8 +216,8 @@ class Layout extends React.Component {
size={showStoriesPanel ? storiesPanelDefaultSize : 1}
defaultSize={storiesPanelDefaultSize}
resizerStyle={storiesResizerStyle(showStoriesPanel, storiesPanelOnTop)}
onDragStarted={onDragStart}
onDragFinished={onDragEnd}
onDragStarted={this.onDragStart}
onDragFinished={this.onDragEnd}
onChange={this.onResize('storiesPanel', storiesPanelOnTop ? 'top' : 'left')}
>
{conditionalRender(
Expand All @@ -225,11 +241,17 @@ class Layout extends React.Component {
size={showAddonPanel ? addonPanelDefaultSize : 1}
defaultSize={addonPanelDefaultSize}
resizerStyle={addonResizerStyle(showAddonPanel, addonPanelInRight)}
onDragStarted={onDragStart}
onDragFinished={onDragEnd}
onDragStarted={this.onDragStart}
onDragFinished={this.onDragEnd}
onChange={this.onResize('addonPanel', addonPanelInRight ? 'right' : 'down')}
>
<div style={contentPanelStyle(addonPanelInRight, storiesPanelOnTop)}>
{/*
When resizing panels, the drag event breaks if the cursor
moves over the iframe. Show an overlay div over iframe
at drag start and hide it when the drag ends.
*/}
<div style={overlayStyle(this.state.isDragging)} />
<div
style={previewStyle}
ref={ref => {
Expand Down