Skip to content

Commit 9c73f0c

Browse files
committed
Added README documentation
1 parent 19f3388 commit 9c73f0c

File tree

5 files changed

+124
-17
lines changed

5 files changed

+124
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60+
example/bundle.js
61+
example/bundle.js.map

README.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,110 @@
11
# react-giphy-selector
2-
A search modal for picking the perfect giphy.
2+
A search and select React.JS component for picking the perfect giphy.
3+
4+
{Insert Gif of Example Usage}
5+
6+
> This component is highly-customizable and only provides basic styling out-of-box. The example above includes simple customization to a few elements. You can view this example in `/example/src`.
7+
8+
## Table of Contents
9+
10+
- [Installation](#Installation)
11+
- [Usage](#Usage)
12+
13+
## Installation
14+
15+
You just install `react-giphy-selector` the good ole' fashion way through NPM:
16+
17+
```
18+
npm install --save react-giphy-selector
19+
```
20+
21+
## Usage
22+
23+
This package exports the `Selector` React component and then two helper `enums`:
24+
25+
```js
26+
import {Selector, ResultSort, Rating} from "react-giphy-selector";
27+
28+
```
29+
30+
- [Selector](#Selector)
31+
- [Rating](#Rating)
32+
- [ResultSort](#ResultSort)
33+
34+
### Selector
35+
36+
The selector component contains all of the search, display, and selection logic. The only required properties are `apiKey` and `onGifSelected`.
37+
38+
```jsx
39+
<Selector
40+
apiKey={'myKey'}
41+
onGifSelected={this.saveGif} />
42+
```
43+
44+
That said, there are a bunch of props that allow you to make this component your own. Note: the `?` included at the end of a property name denotes it as optional.
45+
46+
- `apiKey: string`: [Your Giphy Project API Key]([Giphy API Key](https://developers.giphy.com/).
47+
- `onGifSelected?: (gifObject: IGifObject) => void`: The function to fire when a gif search result has been selected. The `IGifObject` represents the full [GIF Object](https://developers.giphy.com/docs/#gif-object) returned via the Giphy API.
48+
- `rating?: Rating`: The maximum rating you want to allow in your search results. Use the exported [Rating](#Rating) enum for help. Default: `Rating.G`.
49+
- `sort?: ResultSort`: The sort order of the search results. Use the helper enum [ResultSort](#ResultSort). Default: `ResultSort.Relevant`.
50+
- `limit?: number`: The number of results to return. Default: `20`.
51+
- `suggestions?: string[]`: An array containing one-click searches to make it easy for your user. Will not show suggestions section if none are passed. Default: `[]`.
52+
- `queryInputPlaceholder?: string`: The placeholder text for the search bar text input. Default `'Enter search text'`.
53+
- `resultColumns?: number`: The number of columns to divide the search results into. Default: `3`.
54+
- `showGiphyMark?: boolean`: Indicates whether to show the "powered by Giphy" mark in the selector. This is required when [using a Giphy Production API Key](https://developers.giphy.com/docs/#production-key). Default: `true`.
55+
56+
#### Styling your Selector
57+
58+
There are a bunch of `props` to help you customize the style of the the selector. Both the `className` and the `style` methods are available. `react-giphy-selector` is very intentionally unopinionated about how exactly each section of the selector should look. Instead, the package offers a lot of customization and flexibility through the props below.
59+
60+
The images below will help you understand the nomenclature of the components:
61+
62+
{Insert images of component sections}
63+
64+
Here are all the props available for styling the component:
65+
66+
- `queryFormClassName?: string`: Additional `className` for the query form section of the component. You can find the default style applied in `src/components/QueryForm.css`.
67+
- `queryFormInputClassName?: string`: Additional `className` for the text input in the query form. You can find the default style applied in `src/components/QueryForm.css`.
68+
- `queryFormSubmitClassName?: string`: Additional `className` for the submit button in the query form. You can find the default style applied in `src/components/QueryForm.css`.
69+
- `queryFormStyle?: object`: A style object to add to the query form style. You can find the default style applied in `src/components/QueryForm.css`.
70+
- `queryFormInputStyle?: object`: A style object to add to the text input in the query form. You can find the default style applied in `src/components/QueryForm.css`.
71+
- `queryFormSubmitStyle?: object`: A style object to add to the submit button in the query form. You can find the default style applied in `src/components/QueryForm.css`.
72+
- `queryFormSubmitContent?: string or Component`: You can pass in a `string` or your own component to render inside the submit button in the query form. This allows you to pass in things like custom icons. Default: `'Search'`.
73+
- `searchResultsClassName?: string`: Additional `className` for the search results component. You can find the default style in `src/components/SearchResults.css`.
74+
- `searchResultsStyle?: object`: A style object to the add to the search results container. You can find the default style in `src/components/SearchResults.css`.
75+
- `searchResultClassName?: string`: Additional `className` to add to a search result. Search results are `a` elements. You can find the default style in `src/components/SearchResult.css`.
76+
- `searchResultStyle?: object`: A style object to add to a search result. Search results are `a` elements. You can find the default style in `src/components/SearchResult.css`.
77+
- `suggestionsClassName?: string`: Additional `className` to add to the suggestions container. You can find the default style in `src/components/Suggestions.css`.
78+
- `suggestionsStyle?: object`: A style object to add to the suggestions container. You can find the default style in `src/components/Suggestions.css`.
79+
- `suggestionClassName?: string`: Additional `className` to add to a suggestion. This is an `a` element. You can find the default style in `src/components/Suggestion.css`.
80+
- `suggestionStyle?: object`: A style object to add to a suggestion. This is an `a` element. You can find the default style in `src/components/Suggestion.css`.
81+
- `loaderClassName?: string`: Additional `className` to add to the loader container. You can find the default style in `src/components/Selector.css`.
82+
- `loaderStyle?: object`: A style object to add to the loader container. You can find the default style in `src/components/Selector.css`.
83+
- `loaderContent?: string or Component`: You can pass in a `string` or customer component to display when results are loading. Default `'Loading'...`.
84+
- `searchErrorClassName?: string`: Additional `className` to add to the error message shown on broken searches. You can find the default style in `src/components/Selector.css`.
85+
- `searchErrorStyle?: object`: A style object to add to the error message shown on broken searches. You can find the default style in `src/components/Selector.css`.
86+
- `footerClassName?: string`: Additional `className` to add to footer of selector. You can find the default style in `src/components/Selector.css`.
87+
- `footerStyle?: object`: A style object to add to footer of selector. You can find the default style in `src/components/Selector.css`.
88+
89+
If you have a cool style you'd like to share, please [make an issue](https://github.com/tshaddix/react-giphy-selector/issues).
90+
91+
### Rating
92+
93+
The `Rating` enum contains all the possible ratings you can limit searches to:
94+
95+
```js
96+
Rating.Y
97+
Rating.G
98+
Rating.PG
99+
Rating.PG13
100+
Rating.R
101+
```
102+
103+
### ResultSort
104+
105+
The `ResultSort` enum contains the different sort methods supported by the Giphy API.
106+
107+
```js
108+
ResultSort.Recent // ordered by most recent
109+
ResultSort.Relevant // ordered by relevance
110+
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "react-giphy-selector",
33
"version": "0.0.1",
4-
"description": "A search modal for picking the perfect giphy.",
4+
"description": "A search & select React.JS component for picking the perfect giphy.",
55
"main": "lib/index.js",
66
"typings": "./index.d.ts",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"build": "./node_modules/.bin/webpack",
1010
"build-example": "./node_modules/.bin/webpack --config example/webpack.config.js",
11-
"format": "./node_modules/.bin/prettier es5 --write \"{{src,example/src}/**/*.{js,ts,tsx},webpack.config.js}\""
11+
"format": "./node_modules/.bin/prettier es5 --write \"{{src,example/src}/**/*.{js,ts,tsx},webpack.config.js}\"",
12+
"prepublish": "npm run build"
1213
},
1314
"repository": {
1415
"type": "git",

src/components/Selector.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ export interface ISelectorProps {
3232

3333
// search results style
3434
searchResultsClassName?: string;
35-
searchResultsStyle: object;
35+
searchResultsStyle?: object;
3636
searchResultClassName?: string;
37-
searchResultStyle: object;
37+
searchResultStyle?: object;
3838

3939
suggestionsClassName?: string;
40-
suggestionsStyle: object;
40+
suggestionsStyle?: object;
4141
suggestionClassName?: string;
42-
suggestionStyle: object;
42+
suggestionStyle?: object;
4343

4444
// loader style/content props
4545
loaderClassName?: string;
46-
loaderStyle: object;
46+
loaderStyle?: object;
4747
loaderContent: any;
4848

4949
// error style/content props
5050
searchErrorClassName?: string;
51-
searchErrorStyle: object;
51+
searchErrorStyle?: object;
5252

5353
// footer style props
5454
footerClassName?: string;
55-
footerStyle: object;
55+
footerStyle?: object;
5656
}
5757

5858
export interface ISelectorState {
@@ -69,7 +69,7 @@ export class Selector extends React.Component<ISelectorProps, ISelectorState> {
6969
limit: 20,
7070
resultColumns: 3,
7171
showGiphyMark: true,
72-
queryInputPlaceholder: 'Search for gifs (e.g. "dogs")',
72+
queryInputPlaceholder: 'Enter search text',
7373
suggestions: [],
7474
loaderContent: "Loading...",
7575
loaderStyle: {},

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
import { Selector as SelectorComponent } from "./components/Selector";
2-
import { Rating as RatingType, ResultSort as ResultSortType } from "./types";
3-
4-
export const Selector = SelectorComponent;
5-
export const Rating = RatingType;
6-
export const ResultSort = ResultSortType;
1+
export { Selector } from "./components/Selector";
2+
export { Rating, ResultSort } from "./types";

0 commit comments

Comments
 (0)