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

docs: fix stories #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { storiesOf } from '@storybook/react';

storiesOf('HTML source', module).add('basic', html.basic);

storiesOf('URI source', module).add('basic', uri.basic).add('onMessage', uri.onMessage);
storiesOf('URI source', module).add('basic', uri.basic).add('post message', uri.onMessage);

storiesOf('With method', module).add('basic', method.basic);
14 changes: 8 additions & 6 deletions docs/stories/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { WebView } from 'react-native-webview';
import { text } from '@storybook/addon-knobs';

export const basic = () => (
<WebView
source={{
uri: text('URI', 'https://react-native-web-community.github.io/react-native-web-webview/'),
method: text('Method', 'GET'),
}}
/>
<div style={{ height: '100vh' }}>
<WebView
source={{
uri: text('URI', 'https://react-native-web-community.github.io/react-native-web-webview/'),
method: text('Method', 'GET'),
}}
/>
</div>
);
7 changes: 4 additions & 3 deletions docs/stories/onMessage.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<html>
<body>
<h1>Hello world!</h1>

<input type="text" id="message-input" placeholder="enter your message">
<button id="button">Send message</button>
<script type="text/javascript">
// React Native
Expand All @@ -14,11 +16,10 @@ <h1>Hello world!</h1>
}
}

var payload = JSON.stringify({
name: 'WebView',
});


document.getElementById('button').addEventListener('click', function () {
let payload = document.getElementById("message-input").value || '';
if (window.opener) {
// Web new window
window.opener.postMessage(payload, window.opener.origin);
Expand Down
20 changes: 15 additions & 5 deletions docs/stories/uri.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import React from 'react';
import { WebView } from 'react-native-webview';
import { action } from '@storybook/addon-actions';
import { text } from '@storybook/addon-knobs';

export const basic = () => <WebView source={{ uri: 'https://www.youtube.com/embed/dQw4w9WgXcQ' }} />;
export const basic = () => {
return (
<div style={{ height: '100vh' }}>
<WebView source={{ uri: 'https://www.youtube.com/embed/dQw4w9WgXcQ' }} />
</div>
);
};

export const onMessage = () => (
<WebView source={{ uri: require('./onMessage.html') }} onMessage={action(text('Text', 'onMessage'))} />
);
export const onMessage = () => {
return (
<WebView
source={{ uri: require('./onMessage.html') }}
onMessage={(e) => action('message from webview')(e.nativeEvent.data)}
/>
);
};