Skip to content

Commit e634746

Browse files
author
EC2 Default User
committed
Basic search box and suggestion listing
1 parent c1aea18 commit e634746

17 files changed

+62737
-0
lines changed

example/bundle.js

Lines changed: 40281 additions & 0 deletions
Large diffs are not rendered by default.

example/bundle.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>React Giphy Selector - Example</title>
6+
</head>
7+
<body>
8+
<div id="example"></div>
9+
10+
<!-- Main -->
11+
<script src="./bundle.js"></script>
12+
</body>
13+
</html>

example/example.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {Selector} from '../lib';
2+
import * as Lib from '../lib';
3+
import * as React from 'react';
4+
import * as ReactDOM from 'react-dom';
5+
6+
// feel free to change these :)
7+
const suggestions = ["stop it", "nice one", "look up", "no", "bad"];
8+
9+
interface IExampleProps {
10+
suggestions: string[];
11+
}
12+
13+
interface IExampleState {
14+
apiKey: string;
15+
}
16+
17+
class ExampleApp extends React.Component<IExampleProps, IExampleState> {
18+
state: IExampleState;
19+
20+
constructor (props: IExampleProps) {
21+
super(props);
22+
23+
this.state = {
24+
apiKey: ""
25+
};
26+
27+
this.onKeyChange = this.onKeyChange.bind(this);
28+
}
29+
30+
public onKeyChange (event: any): void {
31+
this.setState({apiKey: event.target.value});
32+
}
33+
34+
public render (): JSX.Element {
35+
const {apiKey} = this.state;
36+
const {suggestions} = this.props;
37+
38+
// todo: This pattern will not work as the API key needs to be set before selector is constructed
39+
40+
return (
41+
<div>
42+
<div>
43+
<input type="text" placeholder="Enter your Giphy API Key" value={apiKey} onChange={this.onKeyChange}/>
44+
</div>
45+
<div>
46+
<Selector apiKey={apiKey} suggestions={suggestions}/>
47+
</div>
48+
</div>
49+
);
50+
}
51+
}
52+
53+
ReactDOM.render(
54+
<ExampleApp suggestions={suggestions}/>,
55+
document.getElementById('example')
56+
);

example/webpack.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
entry: "./example/example.tsx",
3+
output: {
4+
filename: "bundle.js",
5+
path: __dirname
6+
},
7+
8+
// Enable sourcemaps for debugging webpack's output.
9+
devtool: "source-map",
10+
11+
resolve: {
12+
// Add '.ts' and '.tsx' as resolvable extensions.
13+
extensions: [".ts", ".tsx", ".js", ".json"]
14+
},
15+
16+
module: {
17+
rules: [
18+
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
19+
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
20+
21+
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
22+
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
23+
]
24+
}
25+
};

0 commit comments

Comments
 (0)