GithubHelp home page GithubHelp logo

mrbartusek / gif-picker-react Goto Github PK

View Code? Open in Web Editor NEW
29.0 2.0 4.0 19.37 MB

Tenor GIF Picker component for React ⚛️

Home Page: http://dokurno.dev/gif-picker-react/

License: MIT License

JavaScript 6.82% TypeScript 70.20% CSS 20.81% HTML 0.81% MDX 1.36%
gif gif-picker react react-component react-library tenor tsup typescript reactjs

gif-picker-react's Introduction

Gif Picker React | Live Demo

npm GitHub Workflow Status npm bundle size downloads

demo

An Tenor GIF picker component for React applications that runs on Tenor API V2. This picker fits styling of emoji-picker-react and can be used next to it.

What to know before using

  • In order to access Tenor API you are required to provide API key. This is a free and simple process that takes less than 60 seconds.
  • Tenor requires attribution from products that use their API. This library comply with that rule by adding Search Tenor placeholder to the search bar.

Installation

npm install gif-picker-react

Obtaining Tenor API v2 key

In order to use GifPicker element you are required to provide Tenor API key via tenorApiKey prop. To obtain this key please follow this simple guide:

  1. Login in to Google Cloud Console
  2. Create a new project
  3. In Google Cloud Marketplace navigate to Tenor API
  4. Click on Enable
  5. In navigation menu go to APIs and services tab and select Credentials
  6. Click + create credentials and create API key, copy generated API key
  7. Pass this key as prop to tenorApiKey

Usage

import GifPicker from 'gif-picker-react';

function App() {
  return (
    <div>
      <GifPicker tenorApiKey={"YOUR_API_KEY"} />
    </div>
  );
}

Props

The following props are accepted by the picker:

Prop Type Default Description
tenorApiKey string Required Tenor v2 API key, obtained from Google Cloud Console
onGifClick function Callback function that is called when an gif is clicked. The function receives the TenorImage object as a parameter.
theme Theme Theme.LIGHT Controls the theme of the picker. If you are using Typescript you can use Theme enum. Possible values are light, dark and auto.
autoFocusSearch boolean true Controls the auto focus of the search input.
contentFilter ContentFilter ContentFilter.OFF Controls the Tenor Content filtering options. If you are using Typescript you can use ContentFilter enum. Possible values are high, medium, low, off
clientKey string gif-picker-react Name of your application. Used to differentiate multiple applications using same API key.
country string US Specify the country of origin for the request. To do so, provide its two-letter ISO 3166-1 country code.
locale string (xx_YY) en_US Specify the default language to interpret the search string. xx is the language's ISO 639-1 language code, while the optional _YY value is the two-letter ISO 3166-1 country code.
width number / string 350 Controls the width of the picker. You can provide a number that will be treated as pixel size, or your any accepted css width as string.
height number / string 450 Controls the height of the picker. You can provide a number that will be treated as pixel size, or your any accepted css width as string.
categoryHeight number / string 100 Controls the height of the home page reaction category. You can provide a number that will be treated as pixel size, or your any accepted css width as string.

TenorImage

This object is provided as an argument to callback specified in onGifClick:

Property Type Description
id string Tenor result identifier
tenorUrl string The full URL to view the post on tenor.com
shortTenorUrl string Short URL to view the post on tenor.com
description string Textual description of the content. You can use this do populate image object alt attribute
createdAt Date Date object that represents when this post was created.
tags string[] Array of tags for the post
url string Direct URL to the image source
height number Height of the image in pixels
width number Width of the image in pixels
preview TenorImagePreview Gif preview object with dimensions scaled down

TenorImagePreview

This object is used for displaying the preview image gifs in the picker. You can use it to render smaller and lower-resolution versions of the gifs.

Property Type Description
url string Direct URL to the preview image source
height number Height of the preview image in pixels
width number Width of the preview image in pixels

This is an example TenorImage object:

{
  id: "16596569648018104856",
  tenorUrl: "https://tenor.com/view/american-psycho-patrick-bateman-american-psycho-gif-7212093",
  shortTenorUrl: "https://tenor.com/Eqmf.gif",
  description: "American Psycho Patrick Bateman GIF",
  createdAt: Date,
  tags: [ "American Psycho", "Patrick Bateman", "American", "psycho"],
  url: "https://media.tenor.com/5lLcKZgmIhgAAAAC/american-psycho-patrick-bateman.gif",
  height: 240,
  width: 244,
  preview: {
    url: "https://media.tenor.com/5lLcKZgmIhgAAAAM/american-psycho-patrick-bateman.gif",
    height: 120,
    width: 122
  }
}

Customization

Custom Picker Width and Height

To customize the dimensions of the picker, use the height and width props. You can pass in a number that will be treated as pixel size, or your any accepted css width/height as string.

<GifPicker height={500} width={400} />
<GifPicker height="100%" width="15em" />

CSS Variables

The picker can be customized via CSS variables. The root selector for the picker is .GifPickerReact, when overriding, make sure to provide a more specific selector.

The list of possible variables is quite extensive, but the main ones you may want to override are:

  • --gpr-bg-color - Background color of the picker.
  • --gpr-text-color - Font color on the picker.
  • --gpr-highlight-color - Color on the hover on focus on some search bar, categories and gif.

You can find full list of all variables in GifPickerReact.css.

Contributing

Want to contribute to the project?

First of all, thanks! Check CONTRIBUTING.md for more details.

gif-picker-react's People

Contributors

0xm4m4n avatar mrbartusek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gif-picker-react's Issues

Add disabled property

Hello,

is there a chance to add a disabled property to be able to be able to control the disabled state?

Thank you and keep up the good work.

Support Vanilla JS

this is exactly what i was looking for but it just had to be for react... could you please make it pure js.

Dynamically set columns count

The code for generating columns is hard-coded for two as of now:

https://github.com/MrBartusek/gif-picker-react/blob/master/src/components/body/GifList.tsx#L43-L63

That means the picker looks good with the default or similar to the default width but will look horribly on other ones:

image

This count of columns should be dynamically set depending on the picker's width. This also means the height of the categories which is controlled by categoryHeight should be removed or replaced with something like categoryAspectRatio since it too, will be dynamic.

Error Handling

Imagine what happens if I provide a wrong api key?
There should be a onError handler so that I can explicitly see if my api key is wrong? like I refreshed my tenor api key.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.