@charkour/react-reactions

中文文档
0.11.0发布于 2022/08/16MITTypeScriptESM + CJS零依赖近 30 天下载 1万

😲 Create custom reaction pickers and counters or use your favorites!

原始使用文档
文档目录23 节
  1. New Features
  2. Road Map
  3. Custom Selectors
  4. Reaction Bar Selector
  5. Reaction Counter
  6. Selectors
  7. Slack Selector
  8. Github Selector
  9. Facebook Selector
  10. Pokemon Selector
  11. Counters
  12. Github Counter
  13. Youtube Counter
  14. Facebook Counter
  15. Pokemon Counter
  16. Slack Counter
  17. Animations
  18. Development
  19. Storybook
  20. Example
  21. Configuration
  22. Jest
  23. GitHub Actions

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


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


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

版本与发布记录

@charkour/react-reactions 共发布 21 个版本,首次发布于 2021/01/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.11.0latest2022/08/164 年前
0.10.12022/07/054 年前
0.10.02022/07/034 年前
0.9.02022/06/304 年前
0.8.02022/04/174 年前
0.7.02022/04/174 年前

关于 @charkour/react-reactions 的常见问题

@charkour/react-reactions 是什么?

😲 Create custom reaction pickers and counters or use your favorites!

如何安装 @charkour/react-reactions?

在项目目录运行 npm install @charkour/react-reactions,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@charkour/react-reactions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@charkour/react-reactions 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@charkour/react-reactions 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@charkour/react-reactions 可以商用吗?

@charkour/react-reactions 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@charkour/react-reactions 的下载量有多少?

根据 npm 官方下载统计,@charkour/react-reactions 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,038 次,日均约 335 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@charkour/react-reactions 还在维护吗?

最新版本 0.11.0 发布于 2022/08/16(4 年前);至今共发布 21 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/01/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。