Skip to content

Fixes issue #54 - addition of examples #56

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit 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
28 changes: 28 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Examples &amp; Test Scenarios</title>

<style type="text/css">
.tt {
font-family: Courier New, Courier, monospace;
}

.example {
color: #777;
padding: 4px;
}
</style>
</head>

<body>
<h1>Examples &amp; Test Scenarios</h1>

<div id="app"></div>

<script src="/bundle.js"></script>
</body>

</html>
48 changes: 48 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';

import ReactPhoneInput from '../src';

class ExampleUsageComponent extends Component {

constructor(props) {
super(props);
this.state = {
phone: ''
};

this.handleChange = this.handleChange.bind(this);
}

handleChange(phone) {
this.setState({
phone: phone
});
}

render () {
return (
<div>
<h3>Example 1</h3>
<p>Demonstrates usages of 'preferredCountries' option, in conjunction with 'excludeCountries'</p>
<pre className="example">&lt;ReactPhoneInput defaultCountry='us' preferredCountries={['us', 'de']} excludeCountries={'in'}/&gt;</pre>
<ReactPhoneInput defaultCountry='us' preferredCountries={['us', 'de']} excludeCountries={'in'}/>
<h3>Example 2</h3>
<p>Demonstrates usages of 'preferredCountries' option only</p>
<pre className="example">&lt;ReactPhoneInput defaultCountry='de' preferredCountries={['it']}/&gt;</pre>
<ReactPhoneInput defaultCountry='de' preferredCountries={['it']}/>
<h3>Example 3</h3>
<p>Demonstrates usages of <span className="tt">onChange</span> event handler</p>
<pre className="example">&lt;ReactPhoneInput onChange={'{this.handleChange}'} /&gt;</pre>
<ReactPhoneInput onChange={this.handleChange} />
<p>You entered: {this.state.phone}</p>
</div>
);
}

}

ReactDOM.render(
<ExampleUsageComponent />,
document.getElementById('app')
);
12 changes: 1 addition & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,4 @@ ReactPhoneInput.propTypes = {
onKeyDown: React.PropTypes.func
};

export default ReactPhoneInput;

if (__DEV__) {
const ReactDOM = require('react-dom');
ReactDOM.render(
<ReactPhoneInput defaultCountry='us' preferredCountries={['us', 'de']} excludeCountries={'in'}/>,
document.getElementById('content'));
ReactDOM.render(
<ReactPhoneInput defaultCountry='de' preferredCountries={['it']}/>,
document.getElementById('content'));
}
export default ReactPhoneInput;
38 changes: 24 additions & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var common = {
filename: 'index.js'
},
module: {
loaders: [
{
loaders: [{
test: /\.(js|jsx)$/,
loader: 'babel',
include: path.resolve(ROOT_PATH, 'src')
Expand All @@ -41,15 +40,27 @@ var common = {
if (TARGET === 'dev') {
module.exports = merge(common, {
devtool: 'eval',
// module: {
// loaders: [
// {
// test: /\.jsx?$/,
// loaders: ['react-hot', 'babel?stage=1'],
// include: path.resolve(ROOT_PATH, 'src')
// }
// ]
// },
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: [/node_modules/],
options: {
presets: [
'babel-preset-es2015',
'babel-preset-react'
].map(require.resolve),
}
}]
},
entry: {
app: ['./example/index.js']
},
output: {
path: 'example',
filename: 'bundle.js'
},
// externals: [/node_modules/],
devServer: {
publicPath: 'http://localhost:8181/',
port: '8181',
Expand All @@ -59,7 +70,7 @@ if (TARGET === 'dev') {
hot: true,
inline: true,
progress: true,
contentBase: 'dist'
contentBase: 'example'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
Expand Down Expand Up @@ -110,5 +121,4 @@ if (TARGET === 'build') {
new webpack.optimize.DedupePlugin()
]
});
}

}