emoji-picker-react 3.6.1 → 4.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +17 -20
  2. package/README.md +129 -168
  3. package/dist/DomUtils/categoryNameFromDom.d.ts +1 -0
  4. package/dist/DomUtils/scrollCategoryIntoView.d.ts +1 -0
  5. package/dist/DomUtils/scrollTo.d.ts +1 -0
  6. package/dist/DomUtils/selectors.d.ts +12 -0
  7. package/dist/components/Layout/Flex.d.ts +14 -0
  8. package/dist/components/Layout/Relative.d.ts +7 -0
  9. package/dist/components/body/Body.d.ts +3 -0
  10. package/dist/components/body/EmojiCategory.d.ts +10 -0
  11. package/dist/components/body/EmojiList.d.ts +3 -0
  12. package/dist/components/body/EmojiVariationPicker.d.ts +3 -0
  13. package/dist/components/body/RecentlyUsed.d.ts +7 -0
  14. package/dist/components/context/ElementRefContext.d.ts +17 -0
  15. package/dist/components/context/PickerConfigContext.d.ts +8 -0
  16. package/dist/components/context/PickerContext.d.ts +21 -0
  17. package/dist/components/emoji/Emoji.d.ts +14 -0
  18. package/dist/components/footer/Preview.d.ts +7 -0
  19. package/dist/components/header/Header.d.ts +3 -0
  20. package/dist/components/header/Search.d.ts +3 -0
  21. package/dist/components/header/SkinTonePicker.d.ts +3 -0
  22. package/dist/components/main/PickerMain.d.ts +7 -0
  23. package/dist/components/navigation/CategoryNavigation.d.ts +3 -0
  24. package/dist/config/categoryConfig.d.ts +21 -0
  25. package/dist/config/cdnUrls.d.ts +2 -0
  26. package/dist/config/config.d.ts +26 -0
  27. package/dist/config/useConfig.d.ts +11 -0
  28. package/dist/data/emojis.d.ts +40 -0
  29. package/dist/data/groups.d.ts +2 -0
  30. package/dist/data/skinToneVariations.d.ts +3 -0
  31. package/dist/dataUtils/DataTypes.d.ts +8 -0
  32. package/dist/dataUtils/alphaNumericEmojiIndex.d.ts +4 -0
  33. package/dist/dataUtils/asEmoji.d.ts +2 -0
  34. package/dist/dataUtils/emojiSelectors.d.ts +15 -0
  35. package/dist/dataUtils/parseNativeEmoji.d.ts +1 -0
  36. package/dist/dataUtils/recentlyUsed.d.ts +11 -0
  37. package/dist/emoji-picker-react.cjs.development.css +13 -0
  38. package/dist/emoji-picker-react.cjs.development.js +7419 -0
  39. package/dist/emoji-picker-react.cjs.development.js.map +1 -0
  40. package/dist/emoji-picker-react.cjs.production.min.js +2 -0
  41. package/dist/emoji-picker-react.cjs.production.min.js.map +1 -0
  42. package/dist/emoji-picker-react.esm.js +7485 -0
  43. package/dist/emoji-picker-react.esm.js.map +1 -0
  44. package/dist/hooks/preloadEmoji.d.ts +4 -0
  45. package/dist/hooks/useActiveCategoryScrollDetection.d.ts +2 -0
  46. package/dist/hooks/useCloseAllOpenToggles.d.ts +4 -0
  47. package/dist/hooks/useEmojiElements.d.ts +1 -0
  48. package/dist/hooks/useEmojiMouseEnter.d.ts +3 -0
  49. package/dist/hooks/useFilter.d.ts +8 -0
  50. package/dist/hooks/useInitialLoad.d.ts +2 -0
  51. package/dist/hooks/useIsEmojiHidden.d.ts +2 -0
  52. package/dist/hooks/useIsSearchMode.d.ts +1 -0
  53. package/dist/hooks/useMouseDownHandlers.d.ts +2 -0
  54. package/dist/hooks/useOnScroll.d.ts +2 -0
  55. package/dist/index.d.ts +7 -0
  56. package/dist/index.js +8 -3
  57. package/dist/types/exposedTypes.d.ts +28 -0
  58. package/package.json +72 -52
  59. package/src/DomUtils/categoryNameFromDom.ts +3 -0
  60. package/src/DomUtils/scrollCategoryIntoView.ts +18 -0
  61. package/src/DomUtils/scrollTo.ts +11 -0
  62. package/src/DomUtils/selectors.ts +93 -0
  63. package/src/EmojiPickerReact.css +85 -0
  64. package/src/components/Layout/Flex.css +11 -0
  65. package/src/components/Layout/Flex.tsx +28 -0
  66. package/src/components/Layout/Relative.tsx +14 -0
  67. package/src/components/body/Body.css +6 -0
  68. package/src/components/body/Body.tsx +24 -0
  69. package/src/components/body/EmojiCategory.css +38 -0
  70. package/src/components/body/EmojiCategory.tsx +27 -0
  71. package/src/components/body/EmojiList.css +5 -0
  72. package/src/components/body/EmojiList.tsx +101 -0
  73. package/src/components/body/EmojiVariationPicker.css +65 -0
  74. package/src/components/body/EmojiVariationPicker.tsx +154 -0
  75. package/src/components/body/RecentlyUsed.tsx +50 -0
  76. package/src/components/body/svg/triangle.svg +11 -0
  77. package/src/components/context/ElementRefContext.tsx +61 -0
  78. package/src/components/context/PickerConfigContext.tsx +29 -0
  79. package/src/components/context/PickerContext.tsx +139 -0
  80. package/src/components/emoji/Emoji.css +44 -0
  81. package/src/components/emoji/Emoji.tsx +104 -0
  82. package/src/components/footer/Preview.css +14 -0
  83. package/src/components/footer/Preview.tsx +80 -0
  84. package/src/components/header/Header.css +4 -0
  85. package/src/components/header/Header.tsx +21 -0
  86. package/src/components/header/Search.css +72 -0
  87. package/src/components/header/Search.tsx +36 -0
  88. package/src/components/header/SkinTonePicker.css +86 -0
  89. package/src/components/header/SkinTonePicker.tsx +55 -0
  90. package/src/components/header/svg/magnifier.svg +13 -0
  91. package/src/components/header/svg/times.svg +33 -0
  92. package/src/components/main/PickerMain.css +11 -0
  93. package/src/components/main/PickerMain.tsx +42 -0
  94. package/src/components/navigation/CategoryNavigation.css +82 -0
  95. package/src/components/navigation/CategoryNavigation.tsx +32 -0
  96. package/src/components/navigation/svg/CategoryNav.svg +508 -0
  97. package/src/config/categoryConfig.ts +107 -0
  98. package/src/config/cdnUrls.ts +24 -0
  99. package/src/config/config.ts +50 -0
  100. package/src/config/useConfig.ts +52 -0
  101. package/src/data/emojis.ts +5350 -0
  102. package/src/data/groups.ts +12 -0
  103. package/src/data/skinToneVariations.ts +12 -0
  104. package/src/dataUtils/DataTypes.ts +10 -0
  105. package/src/dataUtils/alphaNumericEmojiIndex.ts +23 -0
  106. package/src/dataUtils/asEmoji.ts +5 -0
  107. package/src/dataUtils/emojiSelectors.ts +94 -0
  108. package/src/dataUtils/parseNativeEmoji.ts +6 -0
  109. package/src/dataUtils/recentlyUsed.ts +61 -0
  110. package/src/hooks/preloadEmoji.ts +29 -0
  111. package/src/hooks/useActiveCategoryScrollDetection.ts +46 -0
  112. package/src/hooks/useCloseAllOpenToggles.ts +26 -0
  113. package/src/hooks/useEmojiElements.ts +7 -0
  114. package/src/hooks/useEmojiMouseEnter.ts +59 -0
  115. package/src/hooks/useFilter.ts +142 -0
  116. package/src/hooks/useInitialLoad.ts +9 -0
  117. package/src/hooks/useIsEmojiHidden.ts +16 -0
  118. package/src/hooks/useIsSearchMode.ts +7 -0
  119. package/src/hooks/useMouseDownHandlers.ts +160 -0
  120. package/src/hooks/useOnScroll.ts +28 -0
  121. package/src/index.tsx +27 -0
  122. package/src/types/exposedTypes.ts +31 -0
  123. package/.babelrc +0 -30
  124. package/.eslintrc.js +0 -37
  125. package/.github/workflows/npmpublish.yml +0 -30
  126. package/.prettierignore +0 -2
  127. package/.storybook/addons.js +0 -2
  128. package/.storybook/config.js +0 -9
  129. package/assets/captured.gif +0 -0
  130. package/dist/index.js.LICENSE.txt +0 -5
  131. package/dist/index.js.map +0 -1
  132. package/dist/main.css +0 -206
  133. package/dist/main.css.map +0 -1
  134. package/emoji-picker-react.d.ts +0 -45
  135. package/webpack.config.js +0 -52
@@ -0,0 +1,160 @@
1
+ import { SkinTones } from './../types/exposedTypes';
2
+ import { useEffect, useRef } from 'react';
3
+
4
+ import { emojiFromElement, isEmojiElement } from '../DomUtils/selectors';
5
+ import { useSetAnchoredEmojiRef } from '../components/context/ElementRefContext';
6
+ import {
7
+ useActiveSkinToneState,
8
+ useDisallowClickRef,
9
+ useEmojiVariationPickerState
10
+ } from '../components/context/PickerContext';
11
+ import {
12
+ useEmojiStyleConfig,
13
+ useOnEmojiClickConfig
14
+ } from '../config/useConfig';
15
+ import { DataEmoji } from '../dataUtils/DataTypes';
16
+ import {
17
+ activeVariationFromUnified,
18
+ emojiHasVariations,
19
+ emojiNames,
20
+ emojiUnified,
21
+ emojiUrlByUnified
22
+ } from '../dataUtils/emojiSelectors';
23
+ import { parseNativeEmoji } from '../dataUtils/parseNativeEmoji';
24
+ import { setRecentlyUsed } from '../dataUtils/recentlyUsed';
25
+ import { EmojiClickData, EmojiStyle } from '../types/exposedTypes';
26
+
27
+ import { useCloseAllOpenToggles } from './useCloseAllOpenToggles';
28
+ import { preloadEmoji } from './preloadEmoji';
29
+
30
+ let mouseDownTimer: undefined | number;
31
+
32
+ export function useMouseDownHandlers(
33
+ BodyRef: React.MutableRefObject<HTMLElement | null>
34
+ ) {
35
+ const preloading = useRef(false);
36
+ const setAnchoredEmojiRef = useSetAnchoredEmojiRef();
37
+ const disallowClickRef = useDisallowClickRef();
38
+ const [, setEmojiVariationPicker] = useEmojiVariationPickerState();
39
+ const { closeAllOpenToggles, dependencyArray } = useCloseAllOpenToggles();
40
+ const [activeSkinTone] = useActiveSkinToneState();
41
+ const onEmojiClick = useOnEmojiClickConfig();
42
+ const emojiStyle = useEmojiStyleConfig();
43
+
44
+ useEffect(() => {
45
+ if (!BodyRef.current) {
46
+ return;
47
+ }
48
+ const bodyRef = BodyRef.current;
49
+ bodyRef.addEventListener('click', onClick, {
50
+ passive: true
51
+ });
52
+
53
+ bodyRef.addEventListener('mousedown', onMouseDown, {
54
+ passive: true
55
+ });
56
+ bodyRef.addEventListener('mouseup', onMouseUp, {
57
+ passive: true
58
+ });
59
+
60
+ return () => {
61
+ bodyRef?.removeEventListener('click', onClick);
62
+ bodyRef?.removeEventListener('mousedown', onMouseDown);
63
+ bodyRef?.removeEventListener('mouseup', onMouseUp);
64
+ };
65
+ }, [BodyRef, ...dependencyArray]);
66
+
67
+ function onClick(event: MouseEvent) {
68
+ if (disallowClickRef.current) {
69
+ return;
70
+ }
71
+
72
+ closeAllOpenToggles();
73
+
74
+ const emoji = emojiFromEvent(event);
75
+
76
+ if (!emoji) {
77
+ return;
78
+ }
79
+
80
+ const unified = emojiUnified(emoji);
81
+
82
+ const skinToneToUse = activeVariationFromUnified(unified) || activeSkinTone;
83
+
84
+ setRecentlyUsed(emoji, skinToneToUse);
85
+ onEmojiClick(event, emojiClickOutput(emoji, skinToneToUse));
86
+ }
87
+
88
+ function onMouseDown(event: MouseEvent) {
89
+ if (mouseDownTimer) {
90
+ clearTimeout(mouseDownTimer);
91
+ }
92
+
93
+ const emoji = emojiFromEvent(event);
94
+
95
+ if (!emoji || !emojiHasVariations(emoji)) {
96
+ return;
97
+ }
98
+
99
+ preloading.current = true;
100
+
101
+ window?.setTimeout(() => {
102
+ if (preloading.current) {
103
+ preloadEmoji(emoji, emojiStyle);
104
+ preloading.current = false;
105
+ }
106
+ }, 50);
107
+
108
+ mouseDownTimer = window?.setTimeout(() => {
109
+ disallowClickRef.current = true;
110
+ mouseDownTimer = undefined;
111
+ closeAllOpenToggles();
112
+ setAnchoredEmojiRef(event.target as HTMLElement);
113
+ setEmojiVariationPicker(emoji);
114
+ }, 250);
115
+ }
116
+ function onMouseUp() {
117
+ preloading.current = false;
118
+
119
+ if (mouseDownTimer) {
120
+ clearTimeout(mouseDownTimer);
121
+ mouseDownTimer = undefined;
122
+ } else if (disallowClickRef.current) {
123
+ // The problem we're trying to overcome here
124
+ // is that the emoji has both mouseup and click events
125
+ // and when releasing a mouseup event
126
+ // the click gets triggered too
127
+ // So we're disallowing the click event for a short time
128
+
129
+ requestAnimationFrame(() => {
130
+ disallowClickRef.current = false;
131
+ });
132
+ }
133
+ }
134
+ }
135
+
136
+ function emojiFromEvent(event: MouseEvent): DataEmoji | undefined {
137
+ const target = event?.target as HTMLElement;
138
+ if (!isEmojiElement(target)) {
139
+ return;
140
+ }
141
+
142
+ return emojiFromElement(target);
143
+ }
144
+
145
+ function emojiClickOutput(
146
+ emoji: DataEmoji,
147
+ activeSkinTone: SkinTones
148
+ ): EmojiClickData {
149
+ const unified = emojiUnified(emoji, activeSkinTone);
150
+ return {
151
+ activeSkinTone,
152
+ emoji: parseNativeEmoji(unified),
153
+ getImageUrl(emojiStyle: EmojiStyle) {
154
+ return emojiUrlByUnified(emojiStyle, unified);
155
+ },
156
+ names: emojiNames(emoji),
157
+ unified,
158
+ unifiedWithoutSkinTone: emojiUnified(emoji)
159
+ };
160
+ }
@@ -0,0 +1,28 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { ElementRef } from '../components/context/ElementRefContext';
4
+
5
+ import { useCloseAllOpenToggles } from './useCloseAllOpenToggles';
6
+
7
+ export function useOnScroll(BodyRef: ElementRef) {
8
+ const { closeAllOpenToggles, dependencyArray } = useCloseAllOpenToggles();
9
+
10
+ useEffect(() => {
11
+ const bodyRef = BodyRef.current;
12
+ if (!bodyRef) {
13
+ return;
14
+ }
15
+
16
+ bodyRef.addEventListener('scroll', onScroll, {
17
+ passive: true
18
+ });
19
+
20
+ function onScroll() {
21
+ closeAllOpenToggles();
22
+ }
23
+
24
+ return () => {
25
+ bodyRef?.removeEventListener('scroll', onScroll);
26
+ };
27
+ }, [...dependencyArray, BodyRef, closeAllOpenToggles]);
28
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+
3
+ import { Body } from './components/body/Body';
4
+ import { ElementRefContextProvider } from './components/context/ElementRefContext';
5
+ import { PickerConfigProvider } from './components/context/PickerConfigContext';
6
+ import { Preview } from './components/footer/Preview';
7
+ import { Header } from './components/header/Header';
8
+ import PickerMain from './components/main/PickerMain';
9
+ import { PickerConfig } from './config/config';
10
+ import './EmojiPickerReact.css';
11
+ export { EmojiStyle, SkinTones, Theme } from './types/exposedTypes';
12
+
13
+ export interface Props extends PickerConfig {}
14
+
15
+ export function EmojiPicker(props: Props) {
16
+ return (
17
+ <ElementRefContextProvider>
18
+ <PickerConfigProvider {...props}>
19
+ <PickerMain>
20
+ <Header />
21
+ <Body />
22
+ <Preview />
23
+ </PickerMain>
24
+ </PickerConfigProvider>
25
+ </ElementRefContextProvider>
26
+ );
27
+ }
@@ -0,0 +1,31 @@
1
+ export type EmojiClickData = {
2
+ activeSkinTone: SkinTones;
3
+ unified: string;
4
+ unifiedWithoutSkinTone: string;
5
+ emoji: string;
6
+ names: string[];
7
+ getImageUrl: (emojiStyle: EmojiStyle) => string;
8
+ };
9
+
10
+ export enum EmojiStyle {
11
+ NATIVE = 'native',
12
+ APPLE = 'apple',
13
+ TWITTER = 'twitter',
14
+ GOOGLE = 'google',
15
+ FACEBOOK = 'facebook'
16
+ }
17
+
18
+ export enum Theme {
19
+ DARK = 'dark',
20
+ LIGHT = 'light',
21
+ AUTO = 'auto'
22
+ }
23
+
24
+ export enum SkinTones {
25
+ NEUTRAL = 'neutral',
26
+ LIGHT = '1f3fb',
27
+ MEDIUM_LIGHT = '1f3fc',
28
+ MEDIUM = '1f3fd',
29
+ MEDIUM_DARK = '1f3fe',
30
+ DARK = '1f3ff'
31
+ }
package/.babelrc DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "presets": [
3
- "@babel/preset-react",
4
- [
5
- "@babel/preset-env",
6
- {
7
- "targets": {
8
- "browsers": ["last 4 versions", "not ie <= 10"]
9
- },
10
- "modules": false
11
- }
12
- ]
13
- ],
14
- "env": {
15
- "test": {
16
- "presets": [
17
- "@babel/preset-react",
18
- [
19
- "@babel/preset-env",
20
- {
21
- "targets": {
22
- "node": "current"
23
- }
24
- }
25
- ]
26
- ]
27
- }
28
- },
29
- "plugins": ["@babel/plugin-transform-runtime"]
30
- }
package/.eslintrc.js DELETED
@@ -1,37 +0,0 @@
1
- module.exports = {
2
- env: {
3
- es6: true,
4
- jest: true,
5
- node: true,
6
- browser: true,
7
- },
8
- extends: [
9
- 'eslint:recommended',
10
- 'plugin:react/recommended',
11
- 'plugin:import/errors',
12
- 'plugin:import/warnings',
13
- ],
14
- parserOptions: {
15
- ecmaVersion: 2020,
16
- sourceType: 'module',
17
- },
18
- globals: {
19
- DEFAULT_EMOJI_URL: true,
20
- },
21
- rules: {
22
- 'no-console': 2,
23
- indent: 0,
24
- quotes: 0,
25
- semi: ['error', 'always'],
26
- eqeqeq: ['error', 'always'],
27
- 'no-trailing-spaces': ['error', { ignoreComments: true }],
28
- 'consistent-this': 2,
29
- 'import/no-self-import': 2,
30
- 'import/no-internal-modules': 0,
31
- 'import/no-dynamic-require': 0,
32
- 'import/no-useless-path-segments': 2,
33
- 'import/order': 1,
34
- 'import/newline-after-import': 2,
35
- },
36
- ignorePatterns: ['node_modules', 'dist'],
37
- };
@@ -1,30 +0,0 @@
1
- name: Node.js Package
2
-
3
- on:
4
- release:
5
- types: [created]
6
-
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v1
12
- - uses: actions/setup-node@v1
13
- with:
14
- node-version: 12
15
- - run: npm ci
16
- - run: npm run build
17
-
18
- publish-npm:
19
- needs: build
20
- runs-on: ubuntu-latest
21
- steps:
22
- - uses: actions/checkout@v1
23
- - uses: actions/setup-node@v1
24
- with:
25
- node-version: 12
26
- registry-url: https://registry.npmjs.org/
27
- - run: npm ci
28
- - run: npm publish
29
- env:
30
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- dist/
2
- node_modules/
@@ -1,2 +0,0 @@
1
- import '@storybook/addon-actions/register';
2
- import '@storybook/addon-links/register';
@@ -1,9 +0,0 @@
1
- import { configure } from '@storybook/react';
2
-
3
- // automatically import all files ending in *.stories.js
4
- const req = require.context('../stories', true, /\.stories\.js$/);
5
- function loadStories() {
6
- req.keys().forEach(filename => req(filename));
7
- }
8
-
9
- configure(loadStories, module);
Binary file
@@ -1,5 +0,0 @@
1
- /*!
2
- Copyright (c) 2017 Jed Watson.
3
- Licensed under the MIT License (MIT), see
4
- http://jedwatson.github.io/classnames
5
- */