emoji-picker-react 4.6.15 → 4.7.1

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 (38) hide show
  1. package/README.md +60 -30
  2. package/dist/components/Reactions/BtnPlus.d.ts +2 -0
  3. package/dist/components/Reactions/DEFAULT_REACTIONS.d.ts +1 -0
  4. package/dist/components/Reactions/Reactions.d.ts +2 -0
  5. package/dist/components/context/ElementRefContext.d.ts +1 -0
  6. package/dist/components/context/PickerContext.d.ts +1 -0
  7. package/dist/components/emoji/ClickableEmojiButton.d.ts +2 -1
  8. package/dist/components/emoji/Emoji.d.ts +2 -1
  9. package/dist/config/config.d.ts +5 -1
  10. package/dist/config/mutableConfig.d.ts +3 -2
  11. package/dist/config/useConfig.d.ts +7 -1
  12. package/dist/emoji-picker-react.cjs.development.js +956 -741
  13. package/dist/emoji-picker-react.cjs.development.js.map +1 -1
  14. package/dist/emoji-picker-react.cjs.production.min.js +1 -1
  15. package/dist/emoji-picker-react.cjs.production.min.js.map +1 -1
  16. package/dist/emoji-picker-react.esm.js +957 -742
  17. package/dist/emoji-picker-react.esm.js.map +1 -1
  18. package/dist/hooks/useMouseDownHandlers.d.ts +2 -1
  19. package/package.json +5 -2
  20. package/src/EmojiPickerReact.tsx +28 -3
  21. package/src/Stylesheet/stylesheet.tsx +14 -2
  22. package/src/components/Reactions/BtnPlus.tsx +78 -0
  23. package/src/components/Reactions/DEFAULT_REACTIONS.ts +9 -0
  24. package/src/components/Reactions/Reactions.tsx +63 -0
  25. package/src/components/Reactions/svg/plus.svg +17 -0
  26. package/src/components/body/Body.tsx +10 -3
  27. package/src/components/context/ElementRefContext.tsx +10 -2
  28. package/src/components/context/PickerContext.tsx +16 -3
  29. package/src/components/emoji/ClickableEmojiButton.tsx +8 -2
  30. package/src/components/emoji/Emoji.tsx +4 -1
  31. package/src/components/footer/Preview.tsx +7 -2
  32. package/src/components/header/Header.tsx +5 -1
  33. package/src/components/main/PickerMain.tsx +27 -2
  34. package/src/config/config.ts +11 -3
  35. package/src/config/mutableConfig.ts +5 -3
  36. package/src/config/useConfig.ts +31 -8
  37. package/src/hooks/useMouseDownHandlers.ts +13 -11
  38. package/src/index.tsx +2 -1
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
- import { EmojiClickData } from '../types/exposedTypes';
3
+ import { MouseDownEvent } from './config';
4
4
 
5
5
  export type MutableConfig = {
6
- onEmojiClick?: (emoji: EmojiClickData, event: MouseEvent) => void;
6
+ onEmojiClick?: MouseDownEvent;
7
+ onReactionClick?: MouseDownEvent;
7
8
  };
8
9
 
9
10
  export const MutableConfigContext = React.createContext<
@@ -19,7 +20,8 @@ export function useDefineMutableConfig(
19
20
  config: MutableConfig
20
21
  ): React.MutableRefObject<MutableConfig> {
21
22
  const MutableConfigRef = React.useRef<MutableConfig>({
22
- onEmojiClick: config.onEmojiClick || emptyFunc
23
+ onEmojiClick: config.onEmojiClick || emptyFunc,
24
+ onReactionClick: config.onReactionClick || config.onEmojiClick
23
25
  });
24
26
 
25
27
  React.useEffect(() => {
@@ -22,6 +22,11 @@ import {
22
22
  import { CustomEmoji } from './customEmojiConfig';
23
23
  import { useMutableConfig } from './mutableConfig';
24
24
 
25
+ export enum MOUSE_EVENT_SOURCE {
26
+ REACTIONS = 'reactions',
27
+ PICKER = 'picker'
28
+ }
29
+
25
30
  export function useSearchPlaceHolderConfig(): string {
26
31
  const { searchPlaceHolder, searchPlaceholder } = usePickerConfig();
27
32
  return (
@@ -61,12 +66,17 @@ export function useCustomEmojisConfig(): CustomEmoji[] {
61
66
  return customEmojis;
62
67
  }
63
68
 
64
- export function useOnEmojiClickConfig(): (
65
- emoji: EmojiClickData,
66
- event: MouseEvent
67
- ) => void {
69
+ export function useOnEmojiClickConfig(
70
+ mouseEventSource: MOUSE_EVENT_SOURCE
71
+ ): (emoji: EmojiClickData, event: MouseEvent) => void {
68
72
  const { current } = useMutableConfig();
69
- return current.onEmojiClick || (() => {});
73
+
74
+ const handler =
75
+ (mouseEventSource === MOUSE_EVENT_SOURCE.REACTIONS
76
+ ? current.onReactionClick
77
+ : current.onEmojiClick) ?? current.onEmojiClick;
78
+
79
+ return handler || (() => {});
70
80
  }
71
81
 
72
82
  export function usePreviewConfig(): PreviewConfig {
@@ -100,6 +110,11 @@ export function useStyleConfig(): React.CSSProperties {
100
110
  return { height: getDimension(height), width: getDimension(width), ...style };
101
111
  }
102
112
 
113
+ export function useReactionsOpenConfig(): boolean {
114
+ const { reactionsDefaultOpen } = usePickerConfig();
115
+ return reactionsDefaultOpen;
116
+ }
117
+
103
118
  export function useEmojiVersionConfig(): string | null {
104
119
  const { emojiVersion } = usePickerConfig();
105
120
  return emojiVersion;
@@ -120,6 +135,11 @@ export function useUnicodeToHide() {
120
135
  return unicodeToHide;
121
136
  }
122
137
 
138
+ export function useReactionsConfig(): string[] {
139
+ const { reactions } = usePickerConfig();
140
+ return reactions;
141
+ }
142
+
123
143
  export function useGetEmojiUrlConfig(): (
124
144
  unified: string,
125
145
  style: EmojiStyle
@@ -139,9 +159,12 @@ export function useSearchResultsConfig(searchResultsCount: number): string {
139
159
  const isPlural = searchResultsCount > 1;
140
160
 
141
161
  if (hasResults) {
142
- return isPlural ?
143
- SEARCH_RESULTS_MULTIPLE_RESULTS_FOUND.replace('%n', searchResultsCount.toString())
144
- : SEARCH_RESULTS_ONE_RESULT_FOUND;
162
+ return isPlural
163
+ ? SEARCH_RESULTS_MULTIPLE_RESULTS_FOUND.replace(
164
+ '%n',
165
+ searchResultsCount.toString()
166
+ )
167
+ : SEARCH_RESULTS_ONE_RESULT_FOUND;
145
168
  }
146
169
 
147
170
  return SEARCH_RESULTS_NO_RESULTS_FOUND;
@@ -14,6 +14,7 @@ import {
14
14
  } from '../components/context/PickerContext';
15
15
  import { GetEmojiUrl } from '../components/emoji/BaseEmojiProps';
16
16
  import {
17
+ MOUSE_EVENT_SOURCE,
17
18
  useEmojiStyleConfig,
18
19
  useGetEmojiUrlConfig,
19
20
  useOnEmojiClickConfig
@@ -34,7 +35,8 @@ import { useCloseAllOpenToggles } from './useCloseAllOpenToggles';
34
35
  import useSetVariationPicker from './useSetVariationPicker';
35
36
 
36
37
  export function useMouseDownHandlers(
37
- BodyRef: React.MutableRefObject<NullableElement>
38
+ ContainerRef: React.MutableRefObject<NullableElement>,
39
+ mouseEventSource: MOUSE_EVENT_SOURCE
38
40
  ) {
39
41
  const mouseDownTimerRef = useRef<undefined | number>();
40
42
  const setVariationPicker = useSetVariationPicker();
@@ -42,7 +44,7 @@ export function useMouseDownHandlers(
42
44
  const [, setEmojiVariationPicker] = useEmojiVariationPickerState();
43
45
  const closeAllOpenToggles = useCloseAllOpenToggles();
44
46
  const [activeSkinTone] = useActiveSkinToneState();
45
- const onEmojiClick = useOnEmojiClickConfig();
47
+ const onEmojiClick = useOnEmojiClickConfig(mouseEventSource);
46
48
  const [, updateSuggested] = useUpdateSuggested();
47
49
  const getEmojiUrl = useGetEmojiUrlConfig();
48
50
  const activeEmojiStyle = useEmojiStyleConfig();
@@ -130,27 +132,27 @@ export function useMouseDownHandlers(
130
132
  );
131
133
 
132
134
  useEffect(() => {
133
- if (!BodyRef.current) {
135
+ if (!ContainerRef.current) {
134
136
  return;
135
137
  }
136
- const bodyRef = BodyRef.current;
137
- bodyRef.addEventListener('click', onClick, {
138
+ const confainerRef = ContainerRef.current;
139
+ confainerRef.addEventListener('click', onClick, {
138
140
  passive: true
139
141
  });
140
142
 
141
- bodyRef.addEventListener('mousedown', onMouseDown, {
143
+ confainerRef.addEventListener('mousedown', onMouseDown, {
142
144
  passive: true
143
145
  });
144
- bodyRef.addEventListener('mouseup', onMouseUp, {
146
+ confainerRef.addEventListener('mouseup', onMouseUp, {
145
147
  passive: true
146
148
  });
147
149
 
148
150
  return () => {
149
- bodyRef?.removeEventListener('click', onClick);
150
- bodyRef?.removeEventListener('mousedown', onMouseDown);
151
- bodyRef?.removeEventListener('mouseup', onMouseUp);
151
+ confainerRef?.removeEventListener('click', onClick);
152
+ confainerRef?.removeEventListener('mousedown', onMouseDown);
153
+ confainerRef?.removeEventListener('mouseup', onMouseUp);
152
154
  };
153
- }, [BodyRef, onClick, onMouseDown, onMouseUp]);
155
+ }, [ContainerRef, onClick, onMouseDown, onMouseUp]);
154
156
  }
155
157
 
156
158
  function emojiFromEvent(event: MouseEvent): [DataEmoji, string] | [] {
package/src/index.tsx CHANGED
@@ -24,7 +24,8 @@ export interface PickerProps extends PickerConfig {}
24
24
 
25
25
  export default function EmojiPicker(props: PickerProps) {
26
26
  const MutableConfigRef = useDefineMutableConfig({
27
- onEmojiClick: props.onEmojiClick
27
+ onEmojiClick: props.onEmojiClick,
28
+ onReactionClick: props.onReactionClick
28
29
  });
29
30
 
30
31
  return (