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/README.md
CHANGED
|
@@ -89,6 +89,7 @@ The following props are accepted by them picker:
|
|
|
89
89
|
| reactions | string[] | - | Controls the reactions to display in the reactions picker. Takes unified emoji ids |
|
|
90
90
|
| onReactionClick | `Function` | - | Callback function that is called when a reaction is clicked. The function receives the emoji object as a parameter. If not passed, onEmojiClicked is used. |
|
|
91
91
|
| allowExpandReactions | `boolean` | `true` | Controls whether the reactions picker can be expanded to the main picker. |
|
|
92
|
+
| onSkinToneChange | `Function` | - | Callback function that is called when a skin tone is changed. The function receives new picked skin tone as a parameter. |
|
|
92
93
|
|
|
93
94
|
## Full details
|
|
94
95
|
|
|
@@ -140,6 +141,8 @@ The skin tones typescript enum can be imported directly from the package:
|
|
|
140
141
|
import { SkinTones } from 'emoji-picker-react';
|
|
141
142
|
```
|
|
142
143
|
|
|
144
|
+
- `onSkinToneChange`: `(skinTone: SkinTones) => void` - Callback function when a skin tone is changed.
|
|
145
|
+
|
|
143
146
|
- `searchDisabled`: `boolean` - Whether to disable the search input. Defaults to `false`. When disabled, the skin tone picker will be shown in the preview component.
|
|
144
147
|
|
|
145
148
|
- `skinTonesDisabled`: `boolean` - Whether to disable the skin tone selection. Defaults to `false`.
|
|
@@ -6,5 +6,5 @@ export declare function hasNextRow(parent: NullableElement, element: NullableEle
|
|
|
6
6
|
export declare function getElementInRow(elements: HTMLElement[], row: number, elementsInRow: number, indexInRow: number): NullableElement;
|
|
7
7
|
export declare function getElementInNextRow(allElements: HTMLElement[], currentRow: number, elementsInRow: number, index: number): NullableElement;
|
|
8
8
|
export declare function getElementInPrevRow(allElements: HTMLElement[], currentRow: number, elementsInRow: number, index: number): NullableElement;
|
|
9
|
-
export declare function firstVisibleElementInContainer(parent: NullableElement, elements: HTMLElement[]): NullableElement;
|
|
9
|
+
export declare function firstVisibleElementInContainer(parent: NullableElement, elements: HTMLElement[], maxVisibilityDiffThreshold?: number): NullableElement;
|
|
10
10
|
export declare function hasNextElementSibling(element: HTMLElement): boolean;
|
package/dist/config/config.d.ts
CHANGED
|
@@ -46,8 +46,10 @@ declare type ConfigExternal = {
|
|
|
46
46
|
previewConfig: Partial<PreviewConfig>;
|
|
47
47
|
onEmojiClick: MouseDownEvent;
|
|
48
48
|
onReactionClick: MouseDownEvent;
|
|
49
|
+
onSkinToneChange: OnSkinToneChange;
|
|
49
50
|
} & Omit<PickerConfigInternal, 'previewConfig' | 'unicodeToHide'>;
|
|
50
51
|
export declare type PickerConfig = Partial<ConfigExternal>;
|
|
51
52
|
export declare type PickerDimensions = string | number;
|
|
52
53
|
export declare type MouseDownEvent = (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
54
|
+
export declare type OnSkinToneChange = (emoji: SkinTones) => void;
|
|
53
55
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { MouseDownEvent } from './config';
|
|
2
|
+
import { MouseDownEvent, OnSkinToneChange } from './config';
|
|
3
3
|
export declare type MutableConfig = {
|
|
4
4
|
onEmojiClick?: MouseDownEvent;
|
|
5
5
|
onReactionClick?: MouseDownEvent;
|
|
6
|
+
onSkinToneChange?: OnSkinToneChange;
|
|
6
7
|
};
|
|
7
8
|
export declare const MutableConfigContext: React.Context<React.MutableRefObject<MutableConfig>>;
|
|
8
9
|
export declare function useMutableConfig(): React.MutableRefObject<MutableConfig>;
|
|
@@ -17,6 +17,7 @@ export declare function useCategoriesConfig(): CategoriesConfig;
|
|
|
17
17
|
export declare function useCustomEmojisConfig(): CustomEmoji[];
|
|
18
18
|
export declare function useOpenConfig(): boolean;
|
|
19
19
|
export declare function useOnEmojiClickConfig(mouseEventSource: MOUSE_EVENT_SOURCE): (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
20
|
+
export declare function useOnSkinToneChangeConfig(): (skinTone: SkinTones) => void;
|
|
20
21
|
export declare function usePreviewConfig(): PreviewConfig;
|
|
21
22
|
export declare function useThemeConfig(): Theme;
|
|
22
23
|
export declare function useSuggestedEmojisModeConfig(): SuggestionMode;
|
|
@@ -16893,12 +16893,16 @@ function useMutableConfig() {
|
|
|
16893
16893
|
function useDefineMutableConfig(config) {
|
|
16894
16894
|
var MutableConfigRef = React__default.useRef({
|
|
16895
16895
|
onEmojiClick: config.onEmojiClick || emptyFunc,
|
|
16896
|
-
onReactionClick: config.onReactionClick || config.onEmojiClick
|
|
16896
|
+
onReactionClick: config.onReactionClick || config.onEmojiClick,
|
|
16897
|
+
onSkinToneChange: config.onSkinToneChange || emptyFunc
|
|
16897
16898
|
});
|
|
16898
16899
|
React__default.useEffect(function () {
|
|
16899
16900
|
MutableConfigRef.current.onEmojiClick = config.onEmojiClick || emptyFunc;
|
|
16900
16901
|
MutableConfigRef.current.onReactionClick = config.onReactionClick || config.onEmojiClick;
|
|
16901
16902
|
}, [config.onEmojiClick, config.onReactionClick]);
|
|
16903
|
+
React__default.useEffect(function () {
|
|
16904
|
+
MutableConfigRef.current.onSkinToneChange = config.onSkinToneChange || emptyFunc;
|
|
16905
|
+
}, [config.onSkinToneChange]);
|
|
16902
16906
|
return MutableConfigRef;
|
|
16903
16907
|
}
|
|
16904
16908
|
function emptyFunc() {}
|
|
@@ -16964,6 +16968,11 @@ function useOnEmojiClickConfig(mouseEventSource) {
|
|
|
16964
16968
|
var handler = (_ref = mouseEventSource === MOUSE_EVENT_SOURCE.REACTIONS ? current.onReactionClick : current.onEmojiClick) != null ? _ref : current.onEmojiClick;
|
|
16965
16969
|
return handler || function () {};
|
|
16966
16970
|
}
|
|
16971
|
+
function useOnSkinToneChangeConfig() {
|
|
16972
|
+
var _useMutableConfig2 = useMutableConfig(),
|
|
16973
|
+
current = _useMutableConfig2.current;
|
|
16974
|
+
return current.onSkinToneChange || function () {};
|
|
16975
|
+
}
|
|
16967
16976
|
function usePreviewConfig() {
|
|
16968
16977
|
var _usePickerConfig10 = usePickerConfig(),
|
|
16969
16978
|
previewConfig = _usePickerConfig10.previewConfig;
|
|
@@ -17350,7 +17359,7 @@ function scrollTo(root, top) {
|
|
|
17350
17359
|
return;
|
|
17351
17360
|
}
|
|
17352
17361
|
requestAnimationFrame(function () {
|
|
17353
|
-
$eprBody.scrollTop = top
|
|
17362
|
+
$eprBody.scrollTop = top;
|
|
17354
17363
|
});
|
|
17355
17364
|
}
|
|
17356
17365
|
function scrollBy(root, by) {
|
|
@@ -18363,29 +18372,43 @@ function getElementInPrevRow(allElements, currentRow, elementsInRow, index) {
|
|
|
18363
18372
|
// default to last
|
|
18364
18373
|
return prevRowElements[index] || prevRowElements[prevRowElements.length - 1] || null;
|
|
18365
18374
|
}
|
|
18366
|
-
function firstVisibleElementInContainer(parent, elements) {
|
|
18375
|
+
function firstVisibleElementInContainer(parent, elements, maxVisibilityDiffThreshold) {
|
|
18376
|
+
if (maxVisibilityDiffThreshold === void 0) {
|
|
18377
|
+
maxVisibilityDiffThreshold = 0;
|
|
18378
|
+
}
|
|
18367
18379
|
if (!parent || !elements.length) {
|
|
18368
18380
|
return null;
|
|
18369
18381
|
}
|
|
18370
18382
|
var parentTop = parent.getBoundingClientRect().top;
|
|
18371
18383
|
var parentBottom = parent.getBoundingClientRect().bottom;
|
|
18372
|
-
var parentTopWithLabel = parentTop +
|
|
18384
|
+
var parentTopWithLabel = parentTop + getLabelHeight(parent);
|
|
18373
18385
|
var visibleElements = elements.find(function (element) {
|
|
18374
18386
|
var elementTop = element.getBoundingClientRect().top;
|
|
18375
18387
|
var elementBottom = element.getBoundingClientRect().bottom;
|
|
18376
|
-
|
|
18388
|
+
var maxVisibilityDiffPixels = element.clientHeight * maxVisibilityDiffThreshold;
|
|
18389
|
+
var elementTopWithAllowedDiff = elementTop + maxVisibilityDiffPixels;
|
|
18390
|
+
var elementBottomWithAllowedDiff = elementBottom - maxVisibilityDiffPixels;
|
|
18391
|
+
if (elementTopWithAllowedDiff < parentTopWithLabel) {
|
|
18377
18392
|
return false;
|
|
18378
18393
|
}
|
|
18379
|
-
return
|
|
18394
|
+
return elementTopWithAllowedDiff >= parentTop && elementTopWithAllowedDiff <= parentBottom || elementBottomWithAllowedDiff >= parentTop && elementBottomWithAllowedDiff <= parentBottom;
|
|
18380
18395
|
});
|
|
18381
18396
|
return visibleElements || null;
|
|
18382
18397
|
}
|
|
18383
18398
|
function hasNextElementSibling(element) {
|
|
18384
18399
|
return !!element.nextElementSibling;
|
|
18385
18400
|
}
|
|
18386
|
-
function
|
|
18387
|
-
var
|
|
18388
|
-
|
|
18401
|
+
function getLabelHeight(parentNode) {
|
|
18402
|
+
var labels = Array.from(parentNode.querySelectorAll(asSelectors(ClassNames.label)));
|
|
18403
|
+
for (var _i = 0, _labels = labels; _i < _labels.length; _i++) {
|
|
18404
|
+
var label = _labels[_i];
|
|
18405
|
+
var height = label.getBoundingClientRect().height;
|
|
18406
|
+
// return height if label is not hidden
|
|
18407
|
+
if (height > 0) {
|
|
18408
|
+
return height;
|
|
18409
|
+
}
|
|
18410
|
+
}
|
|
18411
|
+
return DEFAULT_LABEL_HEIGHT;
|
|
18389
18412
|
}
|
|
18390
18413
|
|
|
18391
18414
|
var EmojiButtonSelector = "button" + /*#__PURE__*/asSelectors(ClassNames.emoji);
|
|
@@ -18551,7 +18574,7 @@ function firstVisibleEmoji(parent) {
|
|
|
18551
18574
|
return null;
|
|
18552
18575
|
}
|
|
18553
18576
|
var allEmojis = allVisibleEmojis(parent);
|
|
18554
|
-
return firstVisibleElementInContainer(parent, allEmojis);
|
|
18577
|
+
return firstVisibleElementInContainer(parent, allEmojis, 0.1);
|
|
18555
18578
|
}
|
|
18556
18579
|
function prevCategory(element) {
|
|
18557
18580
|
var category = closestCategory(element);
|
|
@@ -19787,6 +19810,7 @@ function SkinTonePicker(_ref) {
|
|
|
19787
19810
|
var _useActiveSkinToneSta = useActiveSkinToneState(),
|
|
19788
19811
|
activeSkinTone = _useActiveSkinToneSta[0],
|
|
19789
19812
|
setActiveSkinTone = _useActiveSkinToneSta[1];
|
|
19813
|
+
var onSkinToneChange = useOnSkinToneChangeConfig();
|
|
19790
19814
|
var closeAllOpenToggles = useCloseAllOpenToggles();
|
|
19791
19815
|
var focusSearchInput = useFocusSearchInput();
|
|
19792
19816
|
if (isDisabled) {
|
|
@@ -19819,6 +19843,7 @@ function SkinTonePicker(_ref) {
|
|
|
19819
19843
|
onClick: function onClick() {
|
|
19820
19844
|
if (isOpen) {
|
|
19821
19845
|
setActiveSkinTone(skinToneVariation);
|
|
19846
|
+
onSkinToneChange(skinToneVariation);
|
|
19822
19847
|
focusSearchInput();
|
|
19823
19848
|
} else {
|
|
19824
19849
|
setIsOpen(true);
|
|
@@ -20513,7 +20538,8 @@ function ExportedEmoji(_ref) {
|
|
|
20513
20538
|
function EmojiPicker$1(props) {
|
|
20514
20539
|
var MutableConfigRef = useDefineMutableConfig({
|
|
20515
20540
|
onEmojiClick: props.onEmojiClick,
|
|
20516
|
-
onReactionClick: props.onReactionClick
|
|
20541
|
+
onReactionClick: props.onReactionClick,
|
|
20542
|
+
onSkinToneChange: props.onSkinToneChange
|
|
20517
20543
|
});
|
|
20518
20544
|
return React.createElement(ErrorBoundary, null, React.createElement(MutableConfigContext.Provider, {
|
|
20519
20545
|
value: MutableConfigRef
|