emoji-picker-react 4.7.17 → 4.8.0

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.17",
2
+ "version": "4.8.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -10,7 +10,7 @@ import { Preview } from './components/footer/Preview';
10
10
  import { Header } from './components/header/Header';
11
11
  import PickerMain from './components/main/PickerMain';
12
12
  import { compareConfig } from './config/compareConfig';
13
- import { useOpenConfig } from './config/useConfig';
13
+ import { useAllowExpandReactions, useOpenConfig } from './config/useConfig';
14
14
 
15
15
  import { PickerProps } from './index';
16
16
 
@@ -27,14 +27,20 @@ function EmojiPicker(props: PickerProps) {
27
27
 
28
28
  function ContentControl() {
29
29
  const [reactionsDefaultOpen] = useReactionsModeState();
30
+ const allowExpandReactions = useAllowExpandReactions();
31
+
30
32
  const [renderAll, setRenderAll] = React.useState(!reactionsDefaultOpen);
31
33
  const isOpen = useOpenConfig();
32
34
 
33
35
  React.useEffect(() => {
36
+ if (reactionsDefaultOpen && !allowExpandReactions) {
37
+ return;
38
+ }
39
+
34
40
  if (!renderAll) {
35
41
  setRenderAll(true);
36
42
  }
37
- }, [renderAll]);
43
+ }, [renderAll, allowExpandReactions, reactionsDefaultOpen]);
38
44
 
39
45
  if (!isOpen) {
40
46
  return null;
@@ -43,16 +49,24 @@ function ContentControl() {
43
49
  return (
44
50
  <PickerMain>
45
51
  <Reactions />
46
- {renderAll ? (
47
- <>
48
- <Header />
49
- <Body />
50
- <Preview />
51
- </>
52
- ) : null}
52
+ <ExpandedPickerContent renderAll={renderAll} />
53
53
  </PickerMain>
54
54
  );
55
55
  }
56
56
 
57
+ function ExpandedPickerContent({ renderAll }: { renderAll: boolean }) {
58
+ if (!renderAll) {
59
+ return null;
60
+ }
61
+
62
+ return (
63
+ <>
64
+ <Header />
65
+ <Body />
66
+ <Preview />
67
+ </>
68
+ );
69
+ }
70
+
57
71
  // eslint-disable-next-line complexity
58
72
  export default React.memo(EmojiPicker, compareConfig);
@@ -5,7 +5,8 @@ import { commonStyles, stylesheet } from '../../Stylesheet/stylesheet';
5
5
  import {
6
6
  MOUSE_EVENT_SOURCE,
7
7
  useEmojiStyleConfig,
8
- useReactionsConfig
8
+ useReactionsConfig,
9
+ useAllowExpandReactions
9
10
  } from '../../config/useConfig';
10
11
  import { DataEmoji } from '../../dataUtils/DataTypes';
11
12
  import { emojiByUnified } from '../../dataUtils/emojiSelectors';
@@ -22,6 +23,7 @@ export function Reactions() {
22
23
  const reactions = useReactionsConfig();
23
24
  useMouseDownHandlers(ReactionsRef, MOUSE_EVENT_SOURCE.REACTIONS);
24
25
  const emojiStyle = useEmojiStyleConfig();
26
+ const allowExpandReactions = useAllowExpandReactions();
25
27
 
26
28
  if (!reactionsOpen) {
27
29
  return null;
@@ -44,9 +46,11 @@ export function Reactions() {
44
46
  />
45
47
  </li>
46
48
  ))}
47
- <li>
48
- <BtnPlus />
49
- </li>
49
+ {allowExpandReactions ? (
50
+ <li>
51
+ <BtnPlus />
52
+ </li>
53
+ ) : null}
50
54
  </ul>
51
55
  );
52
56
  }
@@ -57,7 +57,8 @@ export function useSetConfig(config: PickerConfig) {
57
57
  config.height,
58
58
  config.width,
59
59
  config.searchDisabled,
60
- config.skinTonePickerLocation
60
+ config.skinTonePickerLocation,
61
+ config.allowExpandReactions
61
62
  ]);
62
63
 
63
64
  return mergedConfig;
@@ -89,7 +89,8 @@ export function basePickerConfig(): PickerConfigInternal {
89
89
  width: 350,
90
90
  reactionsDefaultOpen: false,
91
91
  reactions: DEFAULT_REACTIONS,
92
- open: true
92
+ open: true,
93
+ allowExpandReactions: true
93
94
  };
94
95
  }
95
96
 
@@ -118,6 +119,7 @@ export type PickerConfigInternal = {
118
119
  reactionsDefaultOpen: boolean;
119
120
  reactions: string[];
120
121
  open: boolean;
122
+ allowExpandReactions: boolean;
121
123
  };
122
124
 
123
125
  export type PreviewConfig = {
@@ -41,6 +41,11 @@ export function useDefaultSkinToneConfig(): SkinTones {
41
41
  return defaultSkinTone;
42
42
  }
43
43
 
44
+ export function useAllowExpandReactions(): boolean {
45
+ const { allowExpandReactions } = usePickerConfig();
46
+ return allowExpandReactions;
47
+ }
48
+
44
49
  export function useSkinTonesDisabledConfig(): boolean {
45
50
  const { skinTonesDisabled } = usePickerConfig();
46
51
  return skinTonesDisabled;
@@ -87,12 +87,8 @@ export function useEmojiPreviewEvents(
87
87
  if (button) {
88
88
  const belowFoldByPx = detectEmojyPartiallyBelowFold(button, bodyRef);
89
89
  const buttonHeight = button.getBoundingClientRect().height;
90
- if (belowFoldByPx < buttonHeight / 2) {
91
- return handlePartiallyVisibleElementFocus(button, setPreviewEmoji);
92
- }
93
90
  if (belowFoldByPx < buttonHeight) {
94
- button.scrollIntoView({ behavior: 'smooth', block: 'end' });
95
- return;
91
+ return handlePartiallyVisibleElementFocus(button, setPreviewEmoji);
96
92
  }
97
93
 
98
94
  focusElement(button);