emoji-picker-react 4.7.10 → 4.7.12

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.10",
2
+ "version": "4.7.12",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -98,6 +98,6 @@
98
98
  "rollup-plugin-svg": "^2.0.0"
99
99
  },
100
100
  "dependencies": {
101
- "flairup": "0.0.35"
101
+ "flairup": "0.0.37"
102
102
  }
103
103
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
 
3
+ import { PickerStyleTag } from './Stylesheet/stylesheet';
3
4
  import { Reactions } from './components/Reactions/Reactions';
4
5
  import { Body } from './components/body/Body';
5
6
  import { ElementRefContextProvider } from './components/context/ElementRefContext';
@@ -8,12 +9,14 @@ import { useReactionsModeState } from './components/context/PickerContext';
8
9
  import { Preview } from './components/footer/Preview';
9
10
  import { Header } from './components/header/Header';
10
11
  import PickerMain from './components/main/PickerMain';
12
+ import { useOpenConfig } from './config/useConfig';
11
13
 
12
14
  import { PickerProps } from './index';
13
15
 
14
16
  function EmojiPicker(props: PickerProps) {
15
17
  return (
16
18
  <ElementRefContextProvider>
19
+ <PickerStyleTag />
17
20
  <PickerConfigProvider {...props}>
18
21
  <ContentControl />
19
22
  </PickerConfigProvider>
@@ -24,6 +27,7 @@ function EmojiPicker(props: PickerProps) {
24
27
  function ContentControl() {
25
28
  const [reactionsDefaultOpen] = useReactionsModeState();
26
29
  const [renderAll, setRenderAll] = React.useState(!reactionsDefaultOpen);
30
+ const isOpen = useOpenConfig();
27
31
 
28
32
  React.useEffect(() => {
29
33
  if (!renderAll) {
@@ -31,6 +35,10 @@ function ContentControl() {
31
35
  }
32
36
  }, [renderAll]);
33
37
 
38
+ if (!isOpen) {
39
+ return null;
40
+ }
41
+
34
42
  return (
35
43
  <PickerMain>
36
44
  <Reactions />
@@ -50,6 +58,7 @@ export default React.memo(EmojiPicker, (prev, next) => {
50
58
  const prevCustomEmojis = prev.customEmojis ?? [];
51
59
  const nextCustomEmojis = next.customEmojis ?? [];
52
60
  return (
61
+ prev.open === next.open &&
53
62
  prev.emojiVersion === next.emojiVersion &&
54
63
  prev.reactionsDefaultOpen === next.reactionsDefaultOpen &&
55
64
  prev.searchPlaceHolder === next.searchPlaceHolder &&
@@ -2,9 +2,8 @@ import { Styles, createSheet } from 'flairup';
2
2
  import * as React from 'react';
3
3
 
4
4
  import { ClassNames } from '../DomUtils/classNames';
5
- import { useIsEverMounted } from '../hooks/useIsEverMounted';
6
5
 
7
- export const stylesheet = createSheet('epr');
6
+ export const stylesheet = createSheet('epr', null);
8
7
 
9
8
  const hidden = {
10
9
  display: 'none',
@@ -21,20 +20,14 @@ export const commonStyles = stylesheet.create({
21
20
  }
22
21
  });
23
22
 
24
- export function PickerStyleTag() {
25
- const isMounted = useIsEverMounted();
26
-
27
- if (stylesheet.isApplied() && isMounted) {
28
- return null;
29
- }
30
-
23
+ export const PickerStyleTag = React.memo(function PickerStyleTag() {
31
24
  return (
32
25
  <style
33
26
  suppressHydrationWarning
34
27
  dangerouslySetInnerHTML={{ __html: stylesheet.getStyle() }}
35
28
  />
36
29
  );
37
- }
30
+ });
38
31
 
39
32
  export const commonInteractionStyles = stylesheet.create({
40
33
  '.epr-main': {
@@ -32,12 +32,13 @@ export function useSetConfig(config: PickerConfig) {
32
32
  );
33
33
 
34
34
  React.useEffect(() => {
35
- if (config.customEmojis?.length !== mergedConfig.customEmojis?.length) {
36
- setMergedConfig(mergeConfig(config));
35
+ if (avoidRefresh(config as Props, (mergedConfig as unknown) as Props)) {
36
+ return;
37
37
  }
38
+ setMergedConfig(mergeConfig(config));
38
39
  // not gonna...
39
40
  // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, [config.customEmojis?.length]);
41
+ }, [config.customEmojis?.length, config.open]);
41
42
 
42
43
  return mergedConfig;
43
44
  }
@@ -45,3 +46,10 @@ export function useSetConfig(config: PickerConfig) {
45
46
  export function usePickerConfig() {
46
47
  return React.useContext(ConfigContext);
47
48
  }
49
+
50
+ function avoidRefresh(prev: Props, next: Props) {
51
+ return (
52
+ prev.customEmojis?.length === next.customEmojis?.length &&
53
+ prev.open === next.open
54
+ );
55
+ }
@@ -2,7 +2,7 @@ import { cx } from 'flairup';
2
2
  import * as React from 'react';
3
3
 
4
4
  import { ClassNames } from '../../DomUtils/classNames';
5
- import { PickerStyleTag, stylesheet } from '../../Stylesheet/stylesheet';
5
+ import { stylesheet } from '../../Stylesheet/stylesheet';
6
6
  import {
7
7
  useClassNameConfig,
8
8
  useStyleConfig,
@@ -25,7 +25,6 @@ type Props = Readonly<{
25
25
  export default function PickerMain({ children }: Props) {
26
26
  return (
27
27
  <PickerContextProvider>
28
- <PickerStyleTag />
29
28
  <PickerRootElement>{children}</PickerRootElement>
30
29
  </PickerContextProvider>
31
30
  );
@@ -88,7 +88,8 @@ export function basePickerConfig(): PickerConfigInternal {
88
88
  unicodeToHide: new Set<string>(KNOWN_FAILING_EMOJIS),
89
89
  width: 350,
90
90
  reactionsDefaultOpen: false,
91
- reactions: DEFAULT_REACTIONS
91
+ reactions: DEFAULT_REACTIONS,
92
+ open: true
92
93
  };
93
94
  }
94
95
 
@@ -116,6 +117,7 @@ export type PickerConfigInternal = {
116
117
  customEmojis: CustomEmoji[];
117
118
  reactionsDefaultOpen: boolean;
118
119
  reactions: string[];
120
+ open: boolean;
119
121
  };
120
122
 
121
123
  export type PreviewConfig = {
@@ -26,7 +26,9 @@ export function useDefineMutableConfig(
26
26
 
27
27
  React.useEffect(() => {
28
28
  MutableConfigRef.current.onEmojiClick = config.onEmojiClick || emptyFunc;
29
- }, [config.onEmojiClick]);
29
+ MutableConfigRef.current.onReactionClick =
30
+ config.onReactionClick || config.onEmojiClick;
31
+ }, [config.onEmojiClick, config.onReactionClick]);
30
32
 
31
33
  return MutableConfigRef;
32
34
  }
@@ -66,6 +66,11 @@ export function useCustomEmojisConfig(): CustomEmoji[] {
66
66
  return customEmojis;
67
67
  }
68
68
 
69
+ export function useOpenConfig(): boolean {
70
+ const { open } = usePickerConfig();
71
+ return open;
72
+ }
73
+
69
74
  export function useOnEmojiClickConfig(
70
75
  mouseEventSource: MOUSE_EVENT_SOURCE
71
76
  ): (emoji: EmojiClickData, event: MouseEvent) => void {