Git Product home page Git Product logo

react-quick-reactions's Introduction

react-quick-reactions

Screenshot of react-quick-reactions

Try it out: dylandbl.github.io/react-quick-reactions

A lightweight, customizable popup component for quick reactions and emojis, à la GitHub's reaction popup or Facebook's "likes".

Screenshot of react-quick-reactions

Installation

npm install react-quick-reactions

Or with yarn:

yarn add react-quick-reactions

Example use

import { useState } from "react";
import QuickReactions from "react-quick-reactions";

const App = () => {
  const [isVisible, setIsVisible] = useState(false);
  
  return (
    <div className="App">
      <QuickReactions
        reactionsArray={[
          {
            name: "Laughing",
            content: "😂",
          }
        ]}
        isVisible={isVisible}
        onClose={() => setIsVisible(false)}
        onClickReaction={(reaction) => {
          window.alert(reaction.content);
        }}
        trigger={
          <button
            onClick={() => {
              setIsVisible(!isVisible);
            }}
          >
            Show
          </button>
        }
      />
    </div>
  );
}

API

Prop name Type Default value Description
animation AnimationType "fade" The animation effect used when the popup is displayed.
changeHeaderOnReactionElemHover boolean true When true, the popup's header updates on emoji mouseover to display the emoji's name.
closeButton string | JSX.Element - String or element to replace the default close button.
disableClickAwayToClose boolean - Disables closing by clicking away from the popup.
header string "Quick reactions" Alternative default title for popup's header.
hideCloseButton boolean - Hides the close button.
hideHeader boolean - Hides the header
isVisible boolean false Determines popup visibility.
onClickReaction (value: ReactionObj) => void - Function called when an emoji is clicked. Passes the emoji's ReactionObj.
onClose () => void - Function called on popup close.
placement PlacementType "bottom-start" Positions the popup relative to the trigger.
reactionsArray ReactionObj[] - Array of emojis.
wide boolean - Makes the popup wide instead of tall. Up to eight emojis wide, by default.
closeButtonClassName string - Optional classes for the close button span.
outerDivClassName string - Optional classes for the popup container div.
reactionElementClassName string - Optional classes for the emoji spans.
selectionContainerClassName string - Optional classes for the div containing the array of emojis.

AnimationType

type AnimationType = "drop" | "fade" | "flip" | "zoom" | "none";

PlacementType

type PlacementType =
  | "top-start"
  | "top"
  | "top-end"
  | "left-start"
  | "left"
  | "left-end"
  | "right-start"
  | "right"
  | "right-end"
  | "bottom-start"
  | "bottom"
  | "bottom-end";

ReactionObj

type ReactionObj = {
  id?: string;  // Used as element's #id.
  name: string; // Displayed in popup header.
  content: string | JSX.Element;
};

Example

const emojiArr1 = [
  {
    id: "laughing",
    name: "Laughing",
    content: "😂",
  },
  {
    id: "crying",
    name: "Crying",
    content: "😢",
  },
  {
    id: "thinking",
    name: "Thinking",
    content: "🤔",
  },
  {
    id: "screaming",
    name: "Screaming",
    content: "😱",
  },
];

react-quick-reactions's People

Contributors

dylandbl avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

Kostas Georgiou avatar  avatar

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.