emoji-picker-react 4.7.11 → 4.7.13
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/README.md +2 -2
- package/dist/DomUtils/detectEmojyPartiallyBelowFold.d.ts +2 -0
- package/dist/config/compareConfig.d.ts +2 -0
- package/dist/config/config.d.ts +1 -0
- package/dist/config/useConfig.d.ts +1 -0
- package/dist/emoji-picker-react.cjs.development.js +79 -43
- package/dist/emoji-picker-react.cjs.development.js.map +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js.map +1 -1
- package/dist/emoji-picker-react.esm.js +80 -44
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/DomUtils/detectEmojyPartiallyBelowFold.ts +16 -0
- package/src/EmojiPickerReact.tsx +10 -24
- package/src/components/context/PickerConfigContext.tsx +24 -3
- package/src/components/main/PickerMain.tsx +1 -2
- package/src/config/compareConfig.ts +28 -0
- package/src/config/config.ts +3 -1
- package/src/config/mutableConfig.ts +3 -1
- package/src/config/useConfig.ts +5 -0
- package/src/hooks/useEmojiPreviewEvents.ts +11 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NullableElement } from './selectors';
|
|
2
|
+
|
|
3
|
+
export function detectEmojyPartiallyBelowFold(
|
|
4
|
+
button: HTMLButtonElement,
|
|
5
|
+
bodyRef: NullableElement
|
|
6
|
+
): number {
|
|
7
|
+
if (!button || !bodyRef) {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const buttonRect = button.getBoundingClientRect();
|
|
12
|
+
const bodyRect = bodyRef.getBoundingClientRect();
|
|
13
|
+
|
|
14
|
+
// If the element is obscured by at least half of its size
|
|
15
|
+
return bodyRect.height - (buttonRect.y - bodyRect.y);
|
|
16
|
+
}
|
package/src/EmojiPickerReact.tsx
CHANGED
|
@@ -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,15 @@ 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 { compareConfig } from './config/compareConfig';
|
|
13
|
+
import { useOpenConfig } from './config/useConfig';
|
|
11
14
|
|
|
12
15
|
import { PickerProps } from './index';
|
|
13
16
|
|
|
14
17
|
function EmojiPicker(props: PickerProps) {
|
|
15
18
|
return (
|
|
16
19
|
<ElementRefContextProvider>
|
|
20
|
+
<PickerStyleTag />
|
|
17
21
|
<PickerConfigProvider {...props}>
|
|
18
22
|
<ContentControl />
|
|
19
23
|
</PickerConfigProvider>
|
|
@@ -24,6 +28,7 @@ function EmojiPicker(props: PickerProps) {
|
|
|
24
28
|
function ContentControl() {
|
|
25
29
|
const [reactionsDefaultOpen] = useReactionsModeState();
|
|
26
30
|
const [renderAll, setRenderAll] = React.useState(!reactionsDefaultOpen);
|
|
31
|
+
const isOpen = useOpenConfig();
|
|
27
32
|
|
|
28
33
|
React.useEffect(() => {
|
|
29
34
|
if (!renderAll) {
|
|
@@ -31,6 +36,10 @@ function ContentControl() {
|
|
|
31
36
|
}
|
|
32
37
|
}, [renderAll]);
|
|
33
38
|
|
|
39
|
+
if (!isOpen) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
return (
|
|
35
44
|
<PickerMain>
|
|
36
45
|
<Reactions />
|
|
@@ -46,27 +55,4 @@ function ContentControl() {
|
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
// eslint-disable-next-line complexity
|
|
49
|
-
export default React.memo(EmojiPicker,
|
|
50
|
-
const prevCustomEmojis = prev.customEmojis ?? [];
|
|
51
|
-
const nextCustomEmojis = next.customEmojis ?? [];
|
|
52
|
-
return (
|
|
53
|
-
prev.emojiVersion === next.emojiVersion &&
|
|
54
|
-
prev.reactionsDefaultOpen === next.reactionsDefaultOpen &&
|
|
55
|
-
prev.searchPlaceHolder === next.searchPlaceHolder &&
|
|
56
|
-
prev.searchPlaceholder === next.searchPlaceholder &&
|
|
57
|
-
prev.defaultSkinTone === next.defaultSkinTone &&
|
|
58
|
-
prev.skinTonesDisabled === next.skinTonesDisabled &&
|
|
59
|
-
prev.autoFocusSearch === next.autoFocusSearch &&
|
|
60
|
-
prev.emojiStyle === next.emojiStyle &&
|
|
61
|
-
prev.theme === next.theme &&
|
|
62
|
-
prev.suggestedEmojisMode === next.suggestedEmojisMode &&
|
|
63
|
-
prev.lazyLoadEmojis === next.lazyLoadEmojis &&
|
|
64
|
-
prev.className === next.className &&
|
|
65
|
-
prev.height === next.height &&
|
|
66
|
-
prev.width === next.width &&
|
|
67
|
-
prev.style === next.style &&
|
|
68
|
-
prev.searchDisabled === next.searchDisabled &&
|
|
69
|
-
prev.skinTonePickerLocation === next.skinTonePickerLocation &&
|
|
70
|
-
prevCustomEmojis.length === nextCustomEmojis.length
|
|
71
|
-
);
|
|
72
|
-
});
|
|
58
|
+
export default React.memo(EmojiPicker, compareConfig);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import { compareConfig } from '../../config/compareConfig';
|
|
3
4
|
import {
|
|
4
5
|
basePickerConfig,
|
|
5
6
|
mergeConfig,
|
|
@@ -32,12 +33,32 @@ export function useSetConfig(config: PickerConfig) {
|
|
|
32
33
|
);
|
|
33
34
|
|
|
34
35
|
React.useEffect(() => {
|
|
35
|
-
if (config
|
|
36
|
-
|
|
36
|
+
if (compareConfig(mergedConfig, config)) {
|
|
37
|
+
return;
|
|
37
38
|
}
|
|
39
|
+
setMergedConfig(mergeConfig(config));
|
|
38
40
|
// not gonna...
|
|
39
41
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, [
|
|
42
|
+
}, [
|
|
43
|
+
config.customEmojis?.length,
|
|
44
|
+
config.open,
|
|
45
|
+
config.emojiVersion,
|
|
46
|
+
config.reactionsDefaultOpen,
|
|
47
|
+
config.searchPlaceHolder,
|
|
48
|
+
config.searchPlaceholder,
|
|
49
|
+
config.defaultSkinTone,
|
|
50
|
+
config.skinTonesDisabled,
|
|
51
|
+
config.autoFocusSearch,
|
|
52
|
+
config.emojiStyle,
|
|
53
|
+
config.theme,
|
|
54
|
+
config.suggestedEmojisMode,
|
|
55
|
+
config.lazyLoadEmojis,
|
|
56
|
+
config.className,
|
|
57
|
+
config.height,
|
|
58
|
+
config.width,
|
|
59
|
+
config.searchDisabled,
|
|
60
|
+
config.skinTonePickerLocation
|
|
61
|
+
]);
|
|
41
62
|
|
|
42
63
|
return mergedConfig;
|
|
43
64
|
}
|
|
@@ -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 {
|
|
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
|
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PickerConfig } from './config';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line complexity
|
|
4
|
+
export function compareConfig(prev: PickerConfig, next: PickerConfig) {
|
|
5
|
+
const prevCustomEmojis = prev.customEmojis ?? [];
|
|
6
|
+
const nextCustomEmojis = next.customEmojis ?? [];
|
|
7
|
+
return (
|
|
8
|
+
prev.open === next.open &&
|
|
9
|
+
prev.emojiVersion === next.emojiVersion &&
|
|
10
|
+
prev.reactionsDefaultOpen === next.reactionsDefaultOpen &&
|
|
11
|
+
prev.searchPlaceHolder === next.searchPlaceHolder &&
|
|
12
|
+
prev.searchPlaceholder === next.searchPlaceholder &&
|
|
13
|
+
prev.defaultSkinTone === next.defaultSkinTone &&
|
|
14
|
+
prev.skinTonesDisabled === next.skinTonesDisabled &&
|
|
15
|
+
prev.autoFocusSearch === next.autoFocusSearch &&
|
|
16
|
+
prev.emojiStyle === next.emojiStyle &&
|
|
17
|
+
prev.theme === next.theme &&
|
|
18
|
+
prev.suggestedEmojisMode === next.suggestedEmojisMode &&
|
|
19
|
+
prev.lazyLoadEmojis === next.lazyLoadEmojis &&
|
|
20
|
+
prev.className === next.className &&
|
|
21
|
+
prev.height === next.height &&
|
|
22
|
+
prev.width === next.width &&
|
|
23
|
+
prev.style === next.style &&
|
|
24
|
+
prev.searchDisabled === next.searchDisabled &&
|
|
25
|
+
prev.skinTonePickerLocation === next.skinTonePickerLocation &&
|
|
26
|
+
prevCustomEmojis.length === nextCustomEmojis.length
|
|
27
|
+
);
|
|
28
|
+
}
|
package/src/config/config.ts
CHANGED
|
@@ -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
|
-
|
|
29
|
+
MutableConfigRef.current.onReactionClick =
|
|
30
|
+
config.onReactionClick || config.onEmojiClick;
|
|
31
|
+
}, [config.onEmojiClick, config.onReactionClick]);
|
|
30
32
|
|
|
31
33
|
return MutableConfigRef;
|
|
32
34
|
}
|
package/src/config/useConfig.ts
CHANGED
|
@@ -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 {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
|
|
4
|
+
import { detectEmojyPartiallyBelowFold } from '../DomUtils/detectEmojyPartiallyBelowFold';
|
|
4
5
|
import { focusElement } from '../DomUtils/focusElement';
|
|
5
6
|
import {
|
|
6
7
|
buttonFromTarget,
|
|
@@ -86,6 +87,16 @@ export function useEmojiPreviewEvents(
|
|
|
86
87
|
const button = buttonFromTarget(e.target as HTMLElement);
|
|
87
88
|
|
|
88
89
|
if (button) {
|
|
90
|
+
const belowFoldByPx = detectEmojyPartiallyBelowFold(button, bodyRef);
|
|
91
|
+
const buttonHeight = button.getBoundingClientRect().height;
|
|
92
|
+
if (belowFoldByPx < buttonHeight / 2) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (belowFoldByPx < buttonHeight) {
|
|
96
|
+
button.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
focusElement(button);
|
|
90
101
|
}
|
|
91
102
|
}
|