Skip to content

Commit

Permalink
Merge pull request #3025 from storybooks/addon-stories-scroll-to-sele…
Browse files Browse the repository at this point in the history
…ction

[Addon Storysource] Add auto scrolling to the selected story
  • Loading branch information
igor-dv authored Feb 19, 2018
2 parents 7e026e3 + ac33fbd commit 7844961
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions addons/storysource/src/StoryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import { EVENT_ID } from './';

registerLanguage('jsx', jsx);

const styles = {
selections: {
backgroundColor: 'rgba(255, 242, 60, 0.2)',
},
panel: {
width: '100%',
},
};

export default class StoryPanel extends Component {
constructor(props) {
super(props);
Expand All @@ -23,9 +32,20 @@ export default class StoryPanel extends Component {
});
});

this.setSelectedStoryRef = this.setSelectedStoryRef.bind(this);
this.lineRenderer = this.lineRenderer.bind(this);
}

componentDidUpdate() {
if (this.selectedStoryRef) {
this.selectedStoryRef.scrollIntoView();
}
}

setSelectedStoryRef(ref) {
this.selectedStoryRef = ref;
}

createPart(rows, stylesheet, useInlineStyles) {
return rows.map((node, i) =>
createElement({
Expand All @@ -51,7 +71,9 @@ export default class StoryPanel extends Component {
return (
<span>
{start}
<div style={{ backgroundColor: 'rgba(255, 242, 60, 0.2)' }}>{selected}</div>
<div ref={this.setSelectedStoryRef} style={styles.selections}>
{selected}
</div>
{end}
</span>
);
Expand All @@ -67,7 +89,7 @@ export default class StoryPanel extends Component {
showLineNumbers="true"
style={darcula}
renderer={this.lineRenderer}
customStyle={{ width: '100%' }}
customStyle={styles.panel}
>
{this.state.source}
</SyntaxHighlighter>
Expand Down
Binary file modified integration/__image_snapshots__/angular-cli-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified integration/__image_snapshots__/cra-kitchen-sink-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified integration/__image_snapshots__/vue-kitchen-sink-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7844961

Please sign in to comment.