2.0.2 ā€¢ Published 1 year ago

react-quick-reactions v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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".

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 nameTypeDefault valueDescription
animationAnimationType"fade"The animation effect used when the popup is displayed.
changeHeaderOnReactionElemHoverbooleantrueWhen true, the popup's header updates on emoji mouseover to display the emoji's name.
closeButtonstring \| JSX.Element-String or element to replace the default close button.
disableClickAwayToCloseboolean-Disables closing by clicking away from the popup.
headerstring"Quick reactions"Alternative default title for popup's header.
hideCloseButtonboolean-Hides the close button.
hideHeaderboolean-Hides the header
isVisiblebooleanfalseDetermines 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.
placementPlacementType"bottom-start"Positions the popup relative to the trigger.
reactionsArrayReactionObj[]-Array of emojis.
wideboolean-Makes the popup wide instead of tall. Up to eight emojis wide, by default.
closeButtonClassNamestring-Optional classes for the close button span.
outerDivClassNamestring-Optional classes for the popup container div.
reactionElementClassNamestring-Optional classes for the emoji spans.
selectionContainerClassNamestring-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: "šŸ˜±",
  },
];