Git Product home page Git Product logo

react-reactions's Introduction

react-reactions

Create your own reaction bar or use one of your favorites!

  • 4 Different Selectors - Slack, Facebook, Pokemon and GitHub
  • 5 Different Counters - GitHub, YouTube, Facebook, Pokemon, and Slack

Downloads

Install via npm (or from the GitHub Package Registry):

npm i @charkour/react-reactions

This originated as a fork of casesandberg/react-reactions which is been modified under the MIT license to include additional features.

New Features

  • Add ability to pass custom icons
  • Fixed security vulnerabilities
  • CJS and ESM support
  • Add ref forwarding support
  • Zero dependencies
  • Built in Typescript and modern React (with TSDX)
  • Works with React 16.8+ and Next 10

Road Map

  • Update current Selectors and Counter to match 2021 styles
  • Add Discord Selector and Counter
  • Add unit testing
  • More??? Suggest a feature on Github Issues

Custom Selectors

Reaction Bar Selector

import React from 'react';
import { ReactionBarSelector } from '@charkour/react-reactions';

const Component = () => {
  return <ReactionBarSelector />;
};

Props:

iconSize?: number β€” String icon pixel size. Defaults to 38px

reactions?: Reaction[]; β€” Array of Reaction objects {label: "haha", node: <div>πŸ˜„</div>, key: "smile"} to display.

onSelect: (key: string) => void; β€” Function callback when emoji is selected

style?: React.CSSProperties - Pass a style object to the selector container

image

Also works with images.

image

Note: When passing an <img> as a Reaction. Specify the iconSize as the height of the image. <img height={iconSize} src="img-source" />

Reaction Counter

import React from 'react';
import { ReactionCounter } from '@charkour/react-reactions';

const Component = () => {
  return <ReactionCounter />;
};

Props:*

iconSize?: number - String icon pixel size. Defaults to 24px

bg?: string - String of hex color for outline of overlapping reactions. Defaults to #fff

reactions: ReactionCounterObject[] - Array of emoji to dispay

user?: string - String name of user so that user displays as You

important?: string[] - Array of strings for important users to display their name

showReactsOnly?: boolean - If true, only show the Reactions and no text. Defaults to false

showTotalOnly?: boolean - If true, only show the number of Reactions and no specific names. Defaults to false

showOthersAlways?: boolean - Will display "and 0 others" if you are the only person who reacted. Defaults to true

className?: string - Pass a string that applies to the counter container

onClick?: () => void - Pass a callback that is added to the onClick property to the counter container

style?: React.CSSProperties - Pass a style object to the counter container

image

Selectors

Slack Selector

import React from 'react';
import { SlackSelector } from '@charkour/react-reactions';

const Component = () => {
  return <SlackSelector />;
};

Props:

active: String of active tab. Defaults to mine

scrollHeight: String pixel height of scroll container. Defaults to 270px

removeEmojis: Array of emojis to remove from emoji list

frequent: Array of emojis to set Frequently Used. Defaults to ['πŸ‘', 'πŸ‰', 'πŸ™Œ', 'πŸ—Ώ', '😊', '🐬', '😹', 'πŸ‘»', 'πŸš€', '🚁', 'πŸ‡', 'πŸ‡¨πŸ‡¦']

onSelect: Function callback when emoji is selected

Fonts: To use the Slack fonts, download the font files here and include them in public/fonts.


Github Selector

import React from 'react';
import { GithubSelector } from '@charkour/react-reactions';

const Component = () => {
  return <GithubSelector />;
};

Props:

reactions: Array of emoji to dispay. Defaults to ['πŸ‘', 'πŸ‘Ž', 'πŸ˜„', 'πŸŽ‰', 'πŸ˜•', '❀️']

onSelect: Function callback when emoji is selected


Facebook Selector

import React from 'react';
import { FacebookSelector } from '@charkour/react-reactions';

const Component = () => {
  return <FacebookSelector />;
};

Props:

reactions: Array of strings for reactions to display. Defaults to ['like', 'love', 'haha', 'wow', 'sad', 'angry']

iconSize: String icon pixel size. Defaults to 38px

onSelect: Function callback when emoji is selected


Pokemon Selector

import React from 'react';
import { PokemonSelector } from '@charkour/react-reactions';

const Component = () => {
  return <PokemonSelector />;
};

Props:

reactions: Array of strings for reactions to display. Defaults to ['like', 'love', 'haha', 'wow', 'sad', 'angry']

iconSize: String icon pixel size. Defaults to 38px

onSelect: Function callback when emoji is selected


Counters

Github Counter

import React from 'react';
import { GithubCounter } from '@charkour/react-reactions';

const Component = () => {
  return <GithubCounter />;
};

Props:

counters: Array of counter objects structured such that:

{
  emoji: 'πŸ‘', // String emoji reaction
  by: 'case', // String of persons name
}

user: String name of user so that user displays as You

onSelect: Function callback when emoji is selected

onAdd: Function callback when add reaction is clicked


Youtube Counter

import React from 'react';
import { YoutubeCounter } from '@charkour/react-reactions';

const Component = () => {
  return <YoutubeCounter />;
};

Props:

like: String number of likes

dislike: String number of dislikes

onLikeClick: Function callback when like is clicked

onDislikeClick: Function callback when dislike is clicked


Facebook Counter

import React from 'react';
import { FacebookCounter } from '@charkour/react-reactions';

const Component = () => {
  return <FacebookCounter />;
};

Props:

counters: Array of counter objects structured such that:

{
  emoji: 'like', // String name of reaction
  by: 'Case Sandberg', // String of persons name
}

user: String name of user so that user displays as You

important: Array of strings for important users to display their name

bg: String of hex color for outline of overlapping reactions. Defaults to #fff

onClick: Function callback when clicked

alwaysShowOthers: boolean. Will display "and 0 others" if you are the only person who reacted.


Pokemon Counter

import React from 'react';
import { PokemonCounter } from '@charkour/react-reactions';

const Component = () => {
  return <PokemonCounter />;
};

Props:

counters: Array of counter objects structured such that:

{
  emoji: 'like', // String name of reaction
  by: 'Charles Kornoelje', // String of persons name
}

user: String name of user so that user displays as You

important: Array of strings for important users to display their name

bg: String of hex color for outline of overlapping reactions. Defaults to #fff

onClick: Function callback when clicked

alwaysShowOthers: boolean. Will display "and 0 others" if you are the only person who reacted.


Slack Counter

import React from 'react';
import { SlackCounter } from '@charkour/react-reactions';

const Component = () => {
  return <SlackCounter />;
};

Props:

counters: Array of counter objects structured such that:

{
  emoji: 'πŸ—Ώ', // String emoji reaction
  by: 'case', // String of persons name
}

user: String name of user so that user displays as You

onSelect: Function callback when emoji is selected

onAdd: Function callback when add reaction is clicked

Fonts: To use the Slack fonts, download the font files here and include them in public/fonts.


Animations

A simple animation can be done on the components using CSS. See this demo. More advaned animations can be done using dynamic styles. See this demo

Development

npm start

This builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.

Then run either Storybook or the example playground:

Storybook

Run inside another terminal:

npm run storybook

This loads the stories from ./stories.

NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.

Example

Then run the example inside another:

cd example
npm i
npm start

The default example imports and live reloads whatever is in /dist, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. No symlinking required, we use Parcel's aliasing.

To do a one-off build, use npm run build.

To run tests, use npm test.

Configuration

Code quality is set up for you with prettier, husky, and lint-staged. Adjust the respective fields in package.json accordingly.

Jest

Jest tests are set up to run with npm test.

GitHub Actions

  • main which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix

Pokemon Illustrations by Chris Owens

react-reactions's People

Contributors

casesandberg avatar charkour avatar dependabot[bot] avatar gh-action-bump-version avatar justemoilouise avatar mastepanoski avatar renovate-bot avatar xtrinch 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-reactions's Issues

Slack Selector - Flag icons shows only letters on Windows

Describe the bug
First of all, thanks for sharing this work. It's amazing!

I installed the library on my project, and it's working fine! But on the Windows Chrome browser, it seems that the flags on SlackSelector are not working properly. Instead of showing the flag itself, it's showing letters.
When I check the network request, the fonts are being loaded correctly.

I'm not sure if it's an expected behavior and it's really complicated to debug. So, any idea of what the issue might be will be very helpful.

To Reproduce
Steps to reproduce the behavior:

  1. Standard installation on a React project
  2. Use SlackSelector on a component
  3. Check the flags on a Windows machine

Expected behavior
I was expecting that the flags would show up instead of letters

Screenshots
88147750-0ddf-403f-a9a4-c65b4c1e21d4

Desktop (please complete the following information):

  • OS: Windows 11 (Home Single Language)
  • Browser: Chrome
  • Version: 115.0.5790.110

Additional context

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • Update dependency @snowpack/plugin-dotenv to v2.2.0
  • Update dependency snowpack to v3.8.8
  • Update dependency @types/mocha to v9

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update dependency dns-packet to 1.3.2 [SECURITY]
  • Update dependency glob-parent to 5.1.2 [SECURITY]
  • Update dependency path-parse to 1.0.7 [SECURITY]
  • Update dependency tar to 6.1.9 [SECURITY]
  • Update dependency ws to 7.4.6 [SECURITY]

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.


  • Check this box to trigger a request for Renovate to run again on this repository

Reaction should have key and label to allow mutable text on tooltip to support i18n

Is your feature request related to a problem? Please describe.
Currently, the reactions in ReactionBarSelector use a label in the tooltip. If I want to use i18n, it is impossible to have a mutable 'label' and a 'key' to determine in a selection event which emoji was selected.

Now:

   const reactions: Reaction[] = React.useMemo(
        () => [
          {
            label: 'woozy',
            node: <div>πŸ₯΄</div>,
          },
          {
            label: 'happy',
            node: <div>πŸ™‚</div>,
          },
          {
            label: 'exploding-head',
            node: <div>🀯</div>,
          },
        ],
        []
      )

So, the content of 'label' is displayed, and I need to display a different text depending on the language, and I need a label to be a key.

Describe the solution you'd like

A reaction should have this structure, e.g.:

  const reactions: Reaction[] = React.useMemo(
      () => [
        {
          key: 'woozy',
          label: i18n.translate('woozy', i18n.language)
          node: <div>πŸ₯΄</div>,
        },
        {
          key: 'happy',
          label: i18n.translate('happy', i18n.language)
          node: <div>πŸ™‚</div>,
        },
        {
          key: 'exploding-head',
          label: i18n.translate('exploding-head', i18n.language)
          node: <div>🀯</div>,
        },
      ],
      [i18n.language]
   )

And onSelect should get key as a param and not label.

SlackSelector header/top bar category icons are missing

Describe the bug
SlackSelector header/top bar category icons are missing. In SlackCounter added an extra icon.

To Reproduce
Please visit this codesandbox

Expected behavior
Header category icons should show properly.

Screenshots
image

Desktop (please complete the following information):

  • OS: Mac
  • Browser: chrome
  • Version: 104.0.5112.79

Additional context
I created a video to explain it more clearly.

Main branch cannot commit

Due to not testing the renovate PRs, main currently cannot commit because it cannot execute the pre-commit hooks.

Add ref forwarding

Is your feature request related to a problem? Please describe.
It is impossible to pass ref to components which is helpful for things like event listening. #121

Describe the solution you'd like
Would like to pass refs to all components in the library.

Describe alternatives you've considered
Can wrap a component in a div (or View) and pass a ref to that. It will just create more elements that way.

Error when I import Reaction Counter

Describe the bug
i dont know what is causing it but everytime I import Reaction Counter and use it in my component I always get an error.

Screenshots
image

Components are broken after updating dependencies

Describe the bug
Some of the components are breaking after updating dependencies.

To Reproduce
Steps to reproduce the behavior:

  1. npm i && npm run storybook
  2. Click through the different components and see they are broken.

Expected behavior
They should not be broken.

You didn't show in custom counter

Describe the bug
When I try to add the custom counter and when I like the post. You didn't show up. And if 3 people like the post, for example, It shows and 2 other people.

My code:

<ReactionCounter reactions={likeArray(post?.Reactions, reactions)} important={["vens"]} user={"vens"} className="text-md text-primary" showOthersAlways={likeArray(post?.Reactions).length > 0 && post?.Reactions?.UserId === user?.id ? true : false} onClick={() => { console.log("will show pop up of person who liked it"); }} /> </p>

Expected behavior
I expected to see You, you and 2 other people

Screenshots

2022-04-13 (2)

Trouble styling some counters

IMG_20210315_235127
Hey, can you make more gap between the emoji and text in the counter?

Also, the emojis get squeezed when div width is limited and the text also doesn't break to the next line and give space to the emojis maybe you should give the emoji div and emojis some min-width and min-height
IMG_20210315_235455

Handle Slack fonts better

Currently, you need to add fonts to the public directory and all subdirectories you want to use it in.

Hover on GithubCounter missing out on Chrome

Describe the bug
While working on Safari and Firefox, the hover counter is missing on Chrome

To Reproduce
Steps to reproduce the behavior:

  1. Have some reactions on a github counter
  2. Hover with mouse

Expected behavior

Chrome : Capture d’écran 2022-05-02 aΜ€ 16 40 22

Firefox : Capture d’écran 2022-05-02 aΜ€ 16 40 49

Pass className to Selector

Ideally, it would be nice to be able to pass a className into the selectors so users could add their own styles into it - background-color, etc.

Screen Shot 2021-09-09 at 6 32 23 PM

Selector and Counter Bundlize as one

Is your feature request related to a problem? Please describe.

Add one type of Component, One for rule the all !
Exemple <Bundlize counter={<GithubCounter_ />} Selectors={<SlackSelector_ />} events={(e)=>{}} />

Describe the solution you'd like
it would be appreciable to have this instantly without managing events/state all the times
image
it would make sens in <Bundlize counter={<GithubCounter_ />} Selectors={ /> events links are bound ...

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Component are seperate UI and visual concept, but would make sens to make as one for user commun use !

Closing the selector when clicked outside of the react-reactions component.

Hi,
Thanks for this awesome library.Much appreciated. πŸ™πŸ½

That said, I have a question please - can I hide the Selector if I clicked anywhere else without selecting any emoji?? I have tried following some articles on SO, but it seems none of them are working.
Some guidance here will be very well appreciated.

Thanks...

Seems like a icon is missing

Describe the bug
It seems that the icons are not getting rendered. I ran the examples and I am seeing this
image
In my app as well, I am seeing this icon instead of the usual "smiley" icon .. Is this expected?
image

To Reproduce
Steps to reproduce the behavior:

  1. Install the package
  2. Import as such import { SlackCounter } from "@charkour/react-reactions";
  3. Use as such <SlackCounter />
  4. You will observe that there are rectangles all over instead of the icons

Expected behavior
An icon should appear where the user needs to click. RIght now a rectangle appears.

Desktop (please complete the following information):

  • OS: MacOs 12.0.1
  • Browser Chrome (97.0)

More flexible Reaction Counter

Similar to the existing FacebookCounter, but accepts any reaction emoji. Also supports other props such as:

  • importantReacts: if there are A LOT of reactions, only show these in the "summary" counter
  • className: to easily style text, spacing, etc
  • iconSize: as in the ReactionBarSelector
  • show only the count of reactions received
  • opt-in to show a text of You and X others

Slack add reaction shows empty box

The default "add reaction" button (SlackSelector) in SlackCounterGroup is an empty box even after downloading fonts/slack-icons-Regular.ttf and fonts/slack-icons-Regular.woff in public/.

empty

However, it shows up after clicking the SlackSelector:
with reaction

Is there something else we need to do to include the emoji?

Expected behavior
I would expect the add reaction button to include required fonts without selecting the SlackSelector.

Screenshots
Included in-line

Desktop (please complete the following information):

  • macOS
  • Chrome
  • Version 98.0.4758.102 (Official Build) (x86_64)

Smartphone (please complete the following information):

  • N/A

Like not working on mobile touch

Describe the bug
The reactions components CustomReaction work perfectly on desktop, but when I try to click on the icon on mobile, it shows click in the console and nothing.

code

<Fragment> <ReactionBarSelector className="bg-secondary" iconSize={"28px"} reactions={reactions} onSelect={(label) => handleReaction(label)} /> </Fragment>

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: Iphone 11 pro max
  • OS: IOS 15.3.1
  • Browser safari
  • Version last version

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.