Skip to content

Commit 5d965bb

Browse files
committed
Fully working giphy selector
1 parent 15bf1d0 commit 5d965bb

21 files changed

+1651
-385
lines changed

example/bundle.js

Lines changed: 912 additions & 132 deletions
Large diffs are not rendered by default.

example/bundle.js.map

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

example/example.tsx

Lines changed: 0 additions & 74 deletions
This file was deleted.

example/src/example.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.customQueryFormSubmit {
2+
background: #0097cf;
3+
color: #fff;
4+
border: 0;
5+
padding: 10px 20px;
6+
font-size: 16px;
7+
font-weight: bold;
8+
}
9+
10+
.customQueryFormInput {
11+
padding-left: 10px;
12+
padding-right: 10px;
13+
border: 1px solid #e0e0e0;
14+
border-right: 0;
15+
box-shadow: none;
16+
}
17+
18+
.customSearchResults {
19+
max-height: 400px;
20+
margin-top: 10px;
21+
margin-bottom: 10px;
22+
}
23+
24+
/********************************
25+
CSS classes for example fake modal
26+
********************************/
27+
28+
body {
29+
background: #333;
30+
font-family: sans-serif;
31+
}
32+
33+
.modal {
34+
max-width: 600px;
35+
margin: 60px auto;
36+
background: #fff;
37+
padding: 20px;
38+
border-bottom: 5px solid #111;
39+
}

example/src/example.tsx

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Selector, Rating } from "../../lib";
2+
import * as React from "react";
3+
import * as ReactDOM from "react-dom";
4+
5+
const customStyle = require("./example.css");
6+
7+
// feel free to change these :)
8+
const suggestions = [
9+
"watching",
10+
"quiz",
11+
"stop it",
12+
"nice one",
13+
"learning",
14+
"reading",
15+
"working"
16+
];
17+
18+
interface IExampleProps {
19+
suggestions: string[];
20+
}
21+
22+
interface IExampleState {
23+
apiKey: string;
24+
isKeySubmitted: boolean;
25+
}
26+
27+
class ExampleApp extends React.Component<IExampleProps, IExampleState> {
28+
state: IExampleState;
29+
30+
constructor(props: IExampleProps) {
31+
super(props);
32+
33+
this.state = {
34+
apiKey: "",
35+
isKeySubmitted: false
36+
};
37+
38+
this.onKeyChange = this.onKeyChange.bind(this);
39+
this.onKeySubmit = this.onKeySubmit.bind(this);
40+
this.onGifSelected = this.onGifSelected.bind(this);
41+
}
42+
43+
public onKeyChange(event: any): void {
44+
this.setState({ apiKey: event.target.value });
45+
}
46+
47+
public onKeySubmit(event: any): void {
48+
event.preventDefault();
49+
50+
this.setState({
51+
isKeySubmitted: true
52+
});
53+
}
54+
55+
public onGifSelected(gifObject: any): void {
56+
alert(`You selected a gif! id: ${gifObject.id}`);
57+
}
58+
59+
public render(): JSX.Element {
60+
const { apiKey, isKeySubmitted } = this.state;
61+
const { suggestions } = this.props;
62+
63+
if (!isKeySubmitted) {
64+
return (
65+
<form onSubmit={this.onKeySubmit}>
66+
<input
67+
type="text"
68+
placeholder="Enter your Giphy API Key"
69+
value={apiKey}
70+
onChange={this.onKeyChange}
71+
/>
72+
<button type="submit">Set API Key</button>
73+
</form>
74+
);
75+
}
76+
77+
return (
78+
<div className={customStyle.modal}>
79+
<Selector
80+
apiKey={apiKey}
81+
suggestions={suggestions}
82+
onGifSelected={this.onGifSelected}
83+
rating={Rating.G}
84+
queryFormInputClassName={customStyle.customQueryFormInput}
85+
queryFormSubmitClassName={customStyle.customQueryFormSubmit}
86+
searchResultsClassName={customStyle.customSearchResults}
87+
searchResultClassName={customStyle.customSearchResult}
88+
/>
89+
</div>
90+
);
91+
}
92+
}
93+
94+
ReactDOM.render(
95+
<ExampleApp suggestions={suggestions} />,
96+
document.getElementById("example")
97+
);

example/webpack.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
entry: "./example/example.tsx",
2+
entry: "./example/src/example.tsx",
33
output: {
44
filename: "bundle.js",
55
path: __dirname
@@ -19,7 +19,12 @@ module.exports = {
1919
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
2020

2121
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
22-
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
22+
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
23+
24+
{
25+
test: /\.css$/,
26+
loader: ["style-loader", "css-loader?sourceMap&modules"]
27+
}
2328
]
2429
}
2530
};

0 commit comments

Comments
 (0)