Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #111 from storybooks/device-msg
Browse files Browse the repository at this point in the history
Show a help text on device
  • Loading branch information
Muhammed Thanish authored Nov 8, 2016
2 parents a087ed7 + 3b36dc2 commit 482f838
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/preview/components/StoryView/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { View } from 'react-native';
import { View, Text } from 'react-native';
import style from './style';

export default class StoryView extends Component {
Expand All @@ -13,9 +13,19 @@ export default class StoryView extends Component {
this.setState({storyFn, selection});
}

renderHelp() {
return (
<View style={style.help}>
{this.props.url
? <Text>Please open the Storybook UI ({this.props.url}) with a web browser and select a story for preview.</Text>
: <Text>Please open the Storybook UI with a web browser and select a story for preview.</Text>}
</View>
);
}

render() {
if (!this.state.storyFn) {
return null;
return this.renderHelp();
}
const { kind, story } = this.state.selection;
const context = { kind, story };
Expand Down
6 changes: 6 additions & 0 deletions src/preview/components/StoryView/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ export default {
main: {
flex: 1,
},
help: {
flex: 1,
padding: 15,
alignItems: 'center',
justifyContent: 'center',
},
};
4 changes: 3 additions & 1 deletion src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ export default class Preview {

getStorybookUI(params = {}) {
return () => {
let webUrl = null;
let channel = addons.getChannel();
if (!channel) {
const host = params.host || 'localhost';
const port = params.port || 7007;
const url = `ws://${host}:${port}`;
webUrl = `http://${host}:${port}`;
channel = createChannel({ url });
addons.setChannel(channel);
}
Expand All @@ -67,7 +69,7 @@ export default class Preview {
this._sendSetStories();
this._sendGetCurrentStory();
// finally return the preview component
return <StoryView events={this._events} />;
return <StoryView url={webUrl} events={this._events} />;
}
}

Expand Down

0 comments on commit 482f838

Please sign in to comment.