emoji-picker-react 4.8.0 → 4.9.1
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 +3 -0
- package/dist/DomUtils/elementPositionInRow.d.ts +1 -1
- package/dist/config/config.d.ts +2 -0
- package/dist/config/mutableConfig.d.ts +2 -1
- package/dist/config/useConfig.d.ts +1 -0
- package/dist/emoji-picker-react.cjs.development.js +37 -11
- 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 +37 -11
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/DomUtils/elementPositionInRow.ts +27 -11
- package/src/DomUtils/scrollTo.ts +1 -1
- package/src/DomUtils/selectors.ts +1 -1
- package/src/components/header/SkinTonePicker/SkinTonePicker.tsx +3 -1
- package/src/config/config.ts +2 -0
- package/src/config/mutableConfig.ts +8 -2
- package/src/config/useConfig.ts +7 -0
- package/src/index.tsx +2 -1
package/package.json
CHANGED
|
@@ -143,7 +143,8 @@ export function getElementInPrevRow(
|
|
|
143
143
|
|
|
144
144
|
export function firstVisibleElementInContainer(
|
|
145
145
|
parent: NullableElement,
|
|
146
|
-
elements: HTMLElement[]
|
|
146
|
+
elements: HTMLElement[],
|
|
147
|
+
maxVisibilityDiffThreshold = 0
|
|
147
148
|
): NullableElement {
|
|
148
149
|
if (!parent || !elements.length) {
|
|
149
150
|
return null;
|
|
@@ -151,20 +152,27 @@ export function firstVisibleElementInContainer(
|
|
|
151
152
|
|
|
152
153
|
const parentTop = parent.getBoundingClientRect().top;
|
|
153
154
|
const parentBottom = parent.getBoundingClientRect().bottom;
|
|
154
|
-
|
|
155
|
-
const parentTopWithLabel = parentTop + getLabelHight(parent);
|
|
155
|
+
const parentTopWithLabel = parentTop + getLabelHeight(parent);
|
|
156
156
|
|
|
157
157
|
const visibleElements = elements.find(element => {
|
|
158
158
|
const elementTop = element.getBoundingClientRect().top;
|
|
159
159
|
const elementBottom = element.getBoundingClientRect().bottom;
|
|
160
|
+
const maxVisibilityDiffPixels =
|
|
161
|
+
element.clientHeight * maxVisibilityDiffThreshold;
|
|
160
162
|
|
|
161
|
-
|
|
163
|
+
const elementTopWithAllowedDiff = elementTop + maxVisibilityDiffPixels;
|
|
164
|
+
const elementBottomWithAllowedDiff =
|
|
165
|
+
elementBottom - maxVisibilityDiffPixels;
|
|
166
|
+
|
|
167
|
+
if (elementTopWithAllowedDiff < parentTopWithLabel) {
|
|
162
168
|
return false;
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
return (
|
|
166
|
-
(
|
|
167
|
-
|
|
172
|
+
(elementTopWithAllowedDiff >= parentTop &&
|
|
173
|
+
elementTopWithAllowedDiff <= parentBottom) ||
|
|
174
|
+
(elementBottomWithAllowedDiff >= parentTop &&
|
|
175
|
+
elementBottomWithAllowedDiff <= parentBottom)
|
|
168
176
|
);
|
|
169
177
|
});
|
|
170
178
|
|
|
@@ -175,10 +183,18 @@ export function hasNextElementSibling(element: HTMLElement) {
|
|
|
175
183
|
return !!element.nextElementSibling;
|
|
176
184
|
}
|
|
177
185
|
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
parentNode
|
|
181
|
-
.querySelector(asSelectors(ClassNames.label))
|
|
182
|
-
?.getBoundingClientRect().height ?? DEFAULT_LABEL_HEIGHT /* default */
|
|
186
|
+
function getLabelHeight(parentNode: HTMLElement) {
|
|
187
|
+
const labels = Array.from(
|
|
188
|
+
parentNode.querySelectorAll(asSelectors(ClassNames.label))
|
|
183
189
|
);
|
|
190
|
+
|
|
191
|
+
for (const label of labels) {
|
|
192
|
+
const height = label.getBoundingClientRect().height;
|
|
193
|
+
// return height if label is not hidden
|
|
194
|
+
if (height > 0) {
|
|
195
|
+
return height;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return DEFAULT_LABEL_HEIGHT;
|
|
184
200
|
}
|
package/src/DomUtils/scrollTo.ts
CHANGED
|
@@ -264,7 +264,7 @@ export function firstVisibleEmoji(parent: NullableElement) {
|
|
|
264
264
|
|
|
265
265
|
const allEmojis = allVisibleEmojis(parent);
|
|
266
266
|
|
|
267
|
-
return firstVisibleElementInContainer(parent, allEmojis);
|
|
267
|
+
return firstVisibleElementInContainer(parent, allEmojis, 0.1);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
export function prevCategory(element: NullableElement): NullableElement {
|
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { ClassNames } from '../../../DomUtils/classNames';
|
|
6
6
|
import { stylesheet } from '../../../Stylesheet/stylesheet';
|
|
7
|
-
import { useSkinTonesDisabledConfig
|
|
7
|
+
import {useOnSkinToneChangeConfig, useSkinTonesDisabledConfig} from '../../../config/useConfig';
|
|
8
8
|
import skinToneVariations from '../../../data/skinToneVariations';
|
|
9
9
|
import { useCloseAllOpenToggles } from '../../../hooks/useCloseAllOpenToggles';
|
|
10
10
|
import { useFocusSearchInput } from '../../../hooks/useFocus';
|
|
@@ -41,6 +41,7 @@ export function SkinTonePicker({
|
|
|
41
41
|
const isDisabled = useSkinTonesDisabledConfig();
|
|
42
42
|
const [isOpen, setIsOpen] = useSkinToneFanOpenState();
|
|
43
43
|
const [activeSkinTone, setActiveSkinTone] = useActiveSkinToneState();
|
|
44
|
+
const onSkinToneChange = useOnSkinToneChangeConfig();
|
|
44
45
|
const closeAllOpenToggles = useCloseAllOpenToggles();
|
|
45
46
|
const focusSearchInput = useFocusSearchInput();
|
|
46
47
|
|
|
@@ -89,6 +90,7 @@ export function SkinTonePicker({
|
|
|
89
90
|
onClick={() => {
|
|
90
91
|
if (isOpen) {
|
|
91
92
|
setActiveSkinTone(skinToneVariation);
|
|
93
|
+
onSkinToneChange(skinToneVariation);
|
|
92
94
|
focusSearchInput();
|
|
93
95
|
} else {
|
|
94
96
|
setIsOpen(true);
|
package/src/config/config.ts
CHANGED
|
@@ -138,6 +138,7 @@ type ConfigExternal = {
|
|
|
138
138
|
previewConfig: Partial<PreviewConfig>;
|
|
139
139
|
onEmojiClick: MouseDownEvent;
|
|
140
140
|
onReactionClick: MouseDownEvent;
|
|
141
|
+
onSkinToneChange: OnSkinToneChange;
|
|
141
142
|
} & Omit<PickerConfigInternal, 'previewConfig' | 'unicodeToHide'>;
|
|
142
143
|
|
|
143
144
|
export type PickerConfig = Partial<ConfigExternal>;
|
|
@@ -145,3 +146,4 @@ export type PickerConfig = Partial<ConfigExternal>;
|
|
|
145
146
|
export type PickerDimensions = string | number;
|
|
146
147
|
|
|
147
148
|
export type MouseDownEvent = (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
149
|
+
export type OnSkinToneChange = (emoji: SkinTones) => void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {MouseDownEvent, OnSkinToneChange} from './config';
|
|
4
4
|
|
|
5
5
|
export type MutableConfig = {
|
|
6
6
|
onEmojiClick?: MouseDownEvent;
|
|
7
7
|
onReactionClick?: MouseDownEvent;
|
|
8
|
+
onSkinToneChange?: OnSkinToneChange;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export const MutableConfigContext = React.createContext<
|
|
@@ -21,7 +22,8 @@ export function useDefineMutableConfig(
|
|
|
21
22
|
): React.MutableRefObject<MutableConfig> {
|
|
22
23
|
const MutableConfigRef = React.useRef<MutableConfig>({
|
|
23
24
|
onEmojiClick: config.onEmojiClick || emptyFunc,
|
|
24
|
-
onReactionClick: config.onReactionClick || config.onEmojiClick
|
|
25
|
+
onReactionClick: config.onReactionClick || config.onEmojiClick,
|
|
26
|
+
onSkinToneChange: config.onSkinToneChange || emptyFunc
|
|
25
27
|
});
|
|
26
28
|
|
|
27
29
|
React.useEffect(() => {
|
|
@@ -30,6 +32,10 @@ export function useDefineMutableConfig(
|
|
|
30
32
|
config.onReactionClick || config.onEmojiClick;
|
|
31
33
|
}, [config.onEmojiClick, config.onReactionClick]);
|
|
32
34
|
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
MutableConfigRef.current.onSkinToneChange = config.onSkinToneChange || emptyFunc;
|
|
37
|
+
}, [config.onSkinToneChange])
|
|
38
|
+
|
|
33
39
|
return MutableConfigRef;
|
|
34
40
|
}
|
|
35
41
|
|
package/src/config/useConfig.ts
CHANGED
|
@@ -89,6 +89,13 @@ export function useOnEmojiClickConfig(
|
|
|
89
89
|
return handler || (() => {});
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
export function useOnSkinToneChangeConfig(
|
|
93
|
+
): (skinTone: SkinTones) => void {
|
|
94
|
+
const { current } = useMutableConfig();
|
|
95
|
+
|
|
96
|
+
return current.onSkinToneChange || (() => {});
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
export function usePreviewConfig(): PreviewConfig {
|
|
93
100
|
const { previewConfig } = usePickerConfig();
|
|
94
101
|
return previewConfig;
|
package/src/index.tsx
CHANGED
|
@@ -25,7 +25,8 @@ export interface PickerProps extends PickerConfig {}
|
|
|
25
25
|
export default function EmojiPicker(props: PickerProps) {
|
|
26
26
|
const MutableConfigRef = useDefineMutableConfig({
|
|
27
27
|
onEmojiClick: props.onEmojiClick,
|
|
28
|
-
onReactionClick: props.onReactionClick
|
|
28
|
+
onReactionClick: props.onReactionClick,
|
|
29
|
+
onSkinToneChange: props.onSkinToneChange,
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
return (
|