|
1 | 1 | # 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 | + |
| 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](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 | + |
| 63 | + |
| 64 | + |
| 65 | +Here are all the props available for styling the component: |
| 66 | + |
| 67 | +- `queryFormClassName?: string`: Additional `className` for the query form section of the component. You can find the default style applied in `src/components/QueryForm.css`. |
| 68 | +- `queryFormInputClassName?: string`: Additional `className` for the text input in the query form. You can find the default style applied in `src/components/QueryForm.css`. |
| 69 | +- `queryFormSubmitClassName?: string`: Additional `className` for the submit button in the query form. You can find the default style applied in `src/components/QueryForm.css`. |
| 70 | +- `queryFormStyle?: object`: A style object to add to the query form style. You can find the default style applied in `src/components/QueryForm.css`. |
| 71 | +- `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`. |
| 72 | +- `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`. |
| 73 | +- `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'`. |
| 74 | +- `searchResultsClassName?: string`: Additional `className` for the search results component. You can find the default style in `src/components/SearchResults.css`. |
| 75 | +- `searchResultsStyle?: object`: A style object to the add to the search results container. You can find the default style in `src/components/SearchResults.css`. |
| 76 | +- `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`. |
| 77 | +- `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`. |
| 78 | +- `suggestionsClassName?: string`: Additional `className` to add to the suggestions container. You can find the default style in `src/components/Suggestions.css`. |
| 79 | +- `suggestionsStyle?: object`: A style object to add to the suggestions container. You can find the default style in `src/components/Suggestions.css`. |
| 80 | +- `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`. |
| 81 | +- `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`. |
| 82 | +- `loaderClassName?: string`: Additional `className` to add to the loader container. You can find the default style in `src/components/Selector.css`. |
| 83 | +- `loaderStyle?: object`: A style object to add to the loader container. You can find the default style in `src/components/Selector.css`. |
| 84 | +- `loaderContent?: string or Component`: You can pass in a `string` or customer component to display when results are loading. Default `'Loading'...`. |
| 85 | +- `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`. |
| 86 | +- `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`. |
| 87 | +- `footerClassName?: string`: Additional `className` to add to footer of selector. You can find the default style in `src/components/Selector.css`. |
| 88 | +- `footerStyle?: object`: A style object to add to footer of selector. You can find the default style in `src/components/Selector.css`. |
| 89 | + |
| 90 | +If you have a cool style you'd like to share, please [make an issue](https://github.com/tshaddix/react-giphy-selector/issues). |
| 91 | + |
| 92 | +### Rating |
| 93 | + |
| 94 | +The `Rating` enum contains all the possible ratings you can limit searches to: |
| 95 | + |
| 96 | +```js |
| 97 | +Rating.Y |
| 98 | +Rating.G |
| 99 | +Rating.PG |
| 100 | +Rating.PG13 |
| 101 | +Rating.R |
| 102 | +``` |
| 103 | + |
| 104 | +### ResultSort |
| 105 | + |
| 106 | +The `ResultSort` enum contains the different sort methods supported by the Giphy API. |
| 107 | + |
| 108 | +```js |
| 109 | +ResultSort.Recent // ordered by most recent |
| 110 | +ResultSort.Relevant // ordered by relevance |
| 111 | +``` |
0 commit comments