emoji-picker-react 4.7.18 → 4.9.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/README.md +4 -0
- package/dist/config/config.d.ts +3 -0
- package/dist/config/mutableConfig.d.ts +2 -1
- package/dist/config/useConfig.d.ts +2 -0
- package/dist/emoji-picker-react.cjs.development.js +79 -47
- 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 +79 -47
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/EmojiPickerReact.tsx +23 -9
- package/src/components/Reactions/Reactions.tsx +8 -4
- package/src/components/context/PickerConfigContext.tsx +2 -1
- package/src/components/header/SkinTonePicker/SkinTonePicker.tsx +3 -1
- package/src/config/config.ts +5 -1
- package/src/config/mutableConfig.ts +8 -2
- package/src/config/useConfig.ts +12 -0
- package/src/index.tsx +2 -1
package/package.json
CHANGED
package/src/EmojiPickerReact.tsx
CHANGED
|
@@ -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
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
49
|
+
{allowExpandReactions ? (
|
|
50
|
+
<li>
|
|
51
|
+
<BtnPlus />
|
|
52
|
+
</li>
|
|
53
|
+
) : null}
|
|
50
54
|
</ul>
|
|
51
55
|
);
|
|
52
56
|
}
|
|
@@ -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
|
@@ -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 = {
|
|
@@ -136,6 +138,7 @@ type ConfigExternal = {
|
|
|
136
138
|
previewConfig: Partial<PreviewConfig>;
|
|
137
139
|
onEmojiClick: MouseDownEvent;
|
|
138
140
|
onReactionClick: MouseDownEvent;
|
|
141
|
+
onSkinToneChange: OnSkinToneChange;
|
|
139
142
|
} & Omit<PickerConfigInternal, 'previewConfig' | 'unicodeToHide'>;
|
|
140
143
|
|
|
141
144
|
export type PickerConfig = Partial<ConfigExternal>;
|
|
@@ -143,3 +146,4 @@ export type PickerConfig = Partial<ConfigExternal>;
|
|
|
143
146
|
export type PickerDimensions = string | number;
|
|
144
147
|
|
|
145
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
|
@@ -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;
|
|
@@ -84,6 +89,13 @@ export function useOnEmojiClickConfig(
|
|
|
84
89
|
return handler || (() => {});
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
export function useOnSkinToneChangeConfig(
|
|
93
|
+
): (skinTone: SkinTones) => void {
|
|
94
|
+
const { current } = useMutableConfig();
|
|
95
|
+
|
|
96
|
+
return current.onSkinToneChange || (() => {});
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
export function usePreviewConfig(): PreviewConfig {
|
|
88
100
|
const { previewConfig } = usePickerConfig();
|
|
89
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 (
|