emoji-picker-react 4.4.2 → 4.4.4
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 +1 -1
- package/dist/DomUtils/classNames.d.ts +2 -1
- package/dist/emoji-picker-react.cjs.development.js +200 -192
- 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 +200 -192
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/DomUtils/classNames.ts +2 -1
- package/src/DomUtils/scrollTo.ts +6 -1
- package/src/components/body/EmojiVariationPicker.tsx +21 -10
- package/src/hooks/useKeyboardNavigation.ts +2 -1
- package/src/hooks/useSetVariationPicker.ts +1 -10
package/package.json
CHANGED
|
@@ -15,7 +15,8 @@ export enum ClassNames {
|
|
|
15
15
|
emojiPicker = 'EmojiPickerReact',
|
|
16
16
|
open = 'epr-open',
|
|
17
17
|
vertical = 'epr-vertical',
|
|
18
|
-
horizontal = 'epr-horizontal'
|
|
18
|
+
horizontal = 'epr-horizontal',
|
|
19
|
+
variationPicker = 'epr-emoji-variation-picker'
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function asSelectors(...classNames: ClassNames[]): string {
|
package/src/DomUtils/scrollTo.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { useCallback } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useBodyRef } from '../components/context/ElementRefContext';
|
|
4
4
|
|
|
5
|
+
import { asSelectors, ClassNames } from './classNames';
|
|
5
6
|
import {
|
|
6
7
|
categoryLabelHeight,
|
|
7
8
|
closestCategory,
|
|
@@ -52,7 +53,11 @@ export function useScrollTo() {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export function scrollEmojiAboveLabel(emoji: NullableElement) {
|
|
55
|
-
if (!isEmojiBehindLabel(emoji)) {
|
|
56
|
+
if (!emoji || !isEmojiBehindLabel(emoji)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (emoji.closest(asSelectors(ClassNames.variationPicker))) {
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { useEffect } from 'react';
|
|
3
4
|
|
|
4
5
|
import { ClassNames } from '../../DomUtils/classNames';
|
|
5
6
|
import { focusElement } from '../../DomUtils/focusElement';
|
|
7
|
+
import { focusFirstVisibleEmoji } from '../../DomUtils/keyboardNavigation';
|
|
6
8
|
import {
|
|
7
9
|
buttonFromTarget,
|
|
8
10
|
elementHeight,
|
|
9
11
|
emojiTrueOffsetTop,
|
|
10
|
-
emojiTruOffsetLeft
|
|
12
|
+
emojiTruOffsetLeft
|
|
11
13
|
} from '../../DomUtils/selectors';
|
|
12
14
|
import {
|
|
13
15
|
useEmojiStyleConfig,
|
|
14
|
-
useGetEmojiUrlConfig
|
|
16
|
+
useGetEmojiUrlConfig
|
|
15
17
|
} from '../../config/useConfig';
|
|
16
18
|
import { asEmoji } from '../../dataUtils/asEmoji';
|
|
17
19
|
import {
|
|
18
20
|
emojiHasVariations,
|
|
19
21
|
emojiUnified,
|
|
20
|
-
emojiVariations
|
|
22
|
+
emojiVariations
|
|
21
23
|
} from '../../dataUtils/emojiSelectors';
|
|
22
24
|
import {
|
|
23
25
|
useAnchoredEmojiRef,
|
|
24
26
|
useBodyRef,
|
|
25
27
|
useSetAnchoredEmojiRef,
|
|
26
|
-
useVariationPickerRef
|
|
28
|
+
useVariationPickerRef
|
|
27
29
|
} from '../context/ElementRefContext';
|
|
28
30
|
import { useEmojiVariationPickerState } from '../context/PickerContext';
|
|
29
31
|
import { ClickableEmoji } from '../emoji/Emoji';
|
|
@@ -31,7 +33,7 @@ import './EmojiVariationPicker.css';
|
|
|
31
33
|
|
|
32
34
|
enum Direction {
|
|
33
35
|
Up,
|
|
34
|
-
Down
|
|
36
|
+
Down
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export function EmojiVariationPicker() {
|
|
@@ -39,6 +41,7 @@ export function EmojiVariationPicker() {
|
|
|
39
41
|
const VariationPickerRef = useVariationPickerRef();
|
|
40
42
|
const [emoji] = useEmojiVariationPickerState();
|
|
41
43
|
const emojiStyle = useEmojiStyleConfig();
|
|
44
|
+
|
|
42
45
|
const { getTop, getMenuDirection } = useVariationPickerTop(
|
|
43
46
|
VariationPickerRef
|
|
44
47
|
);
|
|
@@ -54,10 +57,18 @@ export function EmojiVariationPicker() {
|
|
|
54
57
|
emojiHasVariations(emoji) &&
|
|
55
58
|
button.classList.contains(ClassNames.emojiHasVariatios);
|
|
56
59
|
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!visible) {
|
|
62
|
+
focusElement(AnchoredEmojiRef.current);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
focusFirstVisibleEmoji(VariationPickerRef.current);
|
|
67
|
+
}, [VariationPickerRef, visible, AnchoredEmojiRef]);
|
|
68
|
+
|
|
57
69
|
let top, pointerStyle;
|
|
58
70
|
|
|
59
71
|
if (!visible && AnchoredEmojiRef.current) {
|
|
60
|
-
focusElement(AnchoredEmojiRef.current);
|
|
61
72
|
setAnchoredEmojiRef(null);
|
|
62
73
|
} else {
|
|
63
74
|
top = getTop();
|
|
@@ -69,9 +80,9 @@ export function EmojiVariationPicker() {
|
|
|
69
80
|
return (
|
|
70
81
|
<div
|
|
71
82
|
ref={VariationPickerRef}
|
|
72
|
-
className={clsx(
|
|
83
|
+
className={clsx(ClassNames.variationPicker, {
|
|
73
84
|
visible,
|
|
74
|
-
'pointing-up': getMenuDirection() === Direction.Down
|
|
85
|
+
'pointing-up': getMenuDirection() === Direction.Down
|
|
75
86
|
})}
|
|
76
87
|
style={{ top }}
|
|
77
88
|
>
|
|
@@ -79,7 +90,7 @@ export function EmojiVariationPicker() {
|
|
|
79
90
|
? [emojiUnified(safeEmoji)]
|
|
80
91
|
.concat(emojiVariations(safeEmoji))
|
|
81
92
|
.slice(0, 6)
|
|
82
|
-
.map(
|
|
93
|
+
.map(unified => (
|
|
83
94
|
<ClickableEmoji
|
|
84
95
|
key={unified}
|
|
85
96
|
emoji={safeEmoji}
|
|
@@ -129,7 +140,7 @@ function useVariationPickerTop(
|
|
|
129
140
|
|
|
130
141
|
return {
|
|
131
142
|
getMenuDirection,
|
|
132
|
-
getTop
|
|
143
|
+
getTop
|
|
133
144
|
};
|
|
134
145
|
|
|
135
146
|
function getMenuDirection() {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { focusFirstVisibleEmoji } from '../DomUtils/keyboardNavigation';
|
|
2
1
|
import { emojiFromElement, NullableElement } from '../DomUtils/selectors';
|
|
3
|
-
import {
|
|
4
|
-
useSetAnchoredEmojiRef,
|
|
5
|
-
useVariationPickerRef
|
|
6
|
-
} from '../components/context/ElementRefContext';
|
|
2
|
+
import { useSetAnchoredEmojiRef } from '../components/context/ElementRefContext';
|
|
7
3
|
import { useEmojiVariationPickerState } from '../components/context/PickerContext';
|
|
8
4
|
|
|
9
5
|
export default function useSetVariationPicker() {
|
|
10
6
|
const setAnchoredEmojiRef = useSetAnchoredEmojiRef();
|
|
11
7
|
const [, setEmojiVariationPicker] = useEmojiVariationPickerState();
|
|
12
|
-
const VariationPickerRef = useVariationPickerRef();
|
|
13
8
|
|
|
14
9
|
return function setVariationPicker(element: NullableElement) {
|
|
15
10
|
const [emoji] = emojiFromElement(element);
|
|
@@ -20,9 +15,5 @@ export default function useSetVariationPicker() {
|
|
|
20
15
|
|
|
21
16
|
setAnchoredEmojiRef(element);
|
|
22
17
|
setEmojiVariationPicker(emoji);
|
|
23
|
-
|
|
24
|
-
requestAnimationFrame(() => {
|
|
25
|
-
focusFirstVisibleEmoji(VariationPickerRef.current);
|
|
26
|
-
});
|
|
27
18
|
};
|
|
28
19
|
}
|