emoji-picker-react 4.7.0 → 4.7.2

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.
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { NullableElement } from '../DomUtils/selectors';
3
- export declare function useMouseDownHandlers(BodyRef: React.MutableRefObject<NullableElement>): void;
3
+ import { MOUSE_EVENT_SOURCE } from '../config/useConfig';
4
+ export declare function useMouseDownHandlers(ContainerRef: React.MutableRefObject<NullableElement>, mouseEventSource: MOUSE_EVENT_SOURCE): void;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.0",
2
+ "version": "4.7.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -3,6 +3,7 @@ import * as React from 'react';
3
3
 
4
4
  import { commonStyles, stylesheet } from '../../Stylesheet/stylesheet';
5
5
  import {
6
+ MOUSE_EVENT_SOURCE,
6
7
  useEmojiStyleConfig,
7
8
  useReactionsConfig
8
9
  } from '../../config/useConfig';
@@ -19,7 +20,7 @@ export function Reactions() {
19
20
  const [reactionsOpen] = useReactionsModeState();
20
21
  const ReactionsRef = useReactionsRef();
21
22
  const reactions = useReactionsConfig();
22
- useMouseDownHandlers(ReactionsRef);
23
+ useMouseDownHandlers(ReactionsRef, MOUSE_EVENT_SOURCE.REACTIONS);
23
24
  const emojiStyle = useEmojiStyleConfig();
24
25
 
25
26
  if (!reactionsOpen) {
@@ -38,6 +39,7 @@ export function Reactions() {
38
39
  emojiStyle={emojiStyle}
39
40
  unified={reaction}
40
41
  showVariations={false}
42
+ className={cx(styles.emojiButton)}
41
43
  round
42
44
  />
43
45
  </li>
@@ -58,5 +60,12 @@ const styles = stylesheet.create({
58
60
  justifyContent: 'space-between',
59
61
  alignItems: 'center',
60
62
  height: '100%'
63
+ },
64
+ emojiButton: {
65
+ ':hover': {
66
+ transform: 'scale(1.2)'
67
+ },
68
+
69
+ transition: 'transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.5)'
61
70
  }
62
71
  });
@@ -6,6 +6,7 @@ import {
6
6
  commonInteractionStyles,
7
7
  stylesheet
8
8
  } from '../../Stylesheet/stylesheet';
9
+ import { MOUSE_EVENT_SOURCE } from '../../config/useConfig';
9
10
  import { useOnMouseMove } from '../../hooks/useDisallowMouseMove';
10
11
  import { useMouseDownHandlers } from '../../hooks/useMouseDownHandlers';
11
12
  import { useOnScroll } from '../../hooks/useOnScroll';
@@ -17,7 +18,7 @@ import { EmojiVariationPicker } from './EmojiVariationPicker';
17
18
  export function Body() {
18
19
  const BodyRef = useBodyRef();
19
20
  useOnScroll(BodyRef);
20
- useMouseDownHandlers(BodyRef);
21
+ useMouseDownHandlers(BodyRef, MOUSE_EVENT_SOURCE.PICKER);
21
22
  useOnMouseMove();
22
23
 
23
24
  return (
@@ -18,6 +18,7 @@ type ClickableEmojiButtonProps = Readonly<{
18
18
  hasVariations: boolean;
19
19
  unified?: string;
20
20
  round?: boolean;
21
+ className?: string;
21
22
  }>;
22
23
 
23
24
  export function ClickableEmojiButton({
@@ -28,6 +29,7 @@ export function ClickableEmojiButton({
28
29
  showVariations = true,
29
30
  hasVariations,
30
31
  children,
32
+ className,
31
33
  round = false
32
34
  }: ClickableEmojiButtonProps) {
33
35
  return (
@@ -40,7 +42,8 @@ export function ClickableEmojiButton({
40
42
  [ClassNames.visible]: !hidden && !hiddenOnSearch
41
43
  },
42
44
  !!(hasVariations && showVariations) && styles.hasVariations,
43
- round && styles.round
45
+ round && styles.round,
46
+ className
44
47
  )}
45
48
  data-unified={unified}
46
49
  aria-label={emojiNames[0]}
@@ -28,6 +28,7 @@ export function ClickableEmoji({
28
28
  size,
29
29
  lazyLoad,
30
30
  getEmojiUrl,
31
+ className,
31
32
  round = false
32
33
  }: ClickableEmojiProps) {
33
34
  const hasVariations = emojiHasVariations(emoji);
@@ -49,6 +50,7 @@ export function ClickableEmoji({
49
50
  emojiStyle={emojiStyle}
50
51
  lazyLoad={lazyLoad}
51
52
  getEmojiUrl={getEmojiUrl}
53
+ className={className}
52
54
  />
53
55
  </ClickableEmojiButton>
54
56
  );
@@ -132,9 +132,12 @@ const basePreviewConfig: PreviewConfig = {
132
132
 
133
133
  type ConfigExternal = {
134
134
  previewConfig: Partial<PreviewConfig>;
135
- onEmojiClick: (emoji: EmojiClickData, event: MouseEvent) => void;
135
+ onEmojiClick: MouseDownEvent;
136
+ onReactionClick: MouseDownEvent;
136
137
  } & Omit<PickerConfigInternal, 'previewConfig' | 'unicodeToHide'>;
137
138
 
138
139
  export type PickerConfig = Partial<ConfigExternal>;
139
140
 
140
141
  export type PickerDimensions = string | number;
142
+
143
+ export type MouseDownEvent = (emoji: EmojiClickData, event: MouseEvent) => void;
@@ -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 {
@@ -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 (