emoji-picker-react 4.5.2 → 4.5.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/dist/DomUtils/classNames.d.ts +1 -0
- package/dist/EmojiPickerReact.d.ts +5 -5
- package/dist/config/config.d.ts +1 -1
- package/dist/config/mutableConfig.d.ts +8 -0
- package/dist/emoji-picker-react.cjs.development.js +85 -39
- 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 +85 -40
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/package.json +1 -4
- package/src/DomUtils/classNames.ts +24 -0
- package/src/EmojiPickerReact.tsx +23 -4
- package/src/components/Layout/Flex.tsx +2 -1
- package/src/components/Layout/Space.tsx +2 -1
- package/src/components/atoms/Button.tsx +2 -1
- package/src/components/body/EmojiCategory.tsx +1 -2
- package/src/components/body/EmojiVariationPicker.tsx +1 -2
- package/src/components/emoji/ClickableEmojiButton.tsx +1 -2
- package/src/components/emoji/EmojiImg.tsx +1 -2
- package/src/components/emoji/NativeEmoji.tsx +1 -2
- package/src/components/header/Search.tsx +1 -2
- package/src/components/header/SkinTonePicker.tsx +1 -2
- package/src/components/main/PickerMain.tsx +1 -2
- package/src/components/navigation/CategoryNavigation.tsx +1 -2
- package/src/config/config.ts +1 -9
- package/src/config/mutableConfig.ts +32 -0
- package/src/config/useConfig.ts +3 -2
- package/src/index.tsx +13 -23
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { PickerConfig } from './config/config';
|
|
3
3
|
export { ExportedEmoji as Emoji } from './components/emoji/ExportedEmoji';
|
|
4
4
|
export { EmojiStyle, SkinTones, Theme, Categories, EmojiClickData, SuggestionMode, SkinTonePickerLocation } from './types/exposedTypes';
|
|
5
|
-
export interface
|
|
5
|
+
export interface PickerProps extends PickerConfig {
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
declare const _default: React.MemoExoticComponent<typeof EmojiPicker>;
|
|
9
|
-
export default _default;
|
|
7
|
+
export default function EmojiPicker(props: PickerProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.5.
|
|
2
|
+
"version": "4.5.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -96,8 +96,5 @@
|
|
|
96
96
|
"tsdx": "^0.14.1",
|
|
97
97
|
"tslib": "^2.4.0",
|
|
98
98
|
"typescript": "^4.7.4"
|
|
99
|
-
},
|
|
100
|
-
"dependencies": {
|
|
101
|
-
"clsx": "^1.2.1"
|
|
102
99
|
}
|
|
103
100
|
}
|
|
@@ -22,3 +22,27 @@ export enum ClassNames {
|
|
|
22
22
|
export function asSelectors(...classNames: ClassNames[]): string {
|
|
23
23
|
return classNames.map(c => `.${c}`).join('');
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
export function clsx(...args: any[]): string {
|
|
27
|
+
const classes = args.reduce((classes, arg) => {
|
|
28
|
+
if (typeof arg === 'string') {
|
|
29
|
+
classes.push(arg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(arg)) {
|
|
33
|
+
classes.push(clsx(...arg));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof arg === 'object') {
|
|
37
|
+
Object.entries(arg).forEach(([key, value]) => {
|
|
38
|
+
if (value) {
|
|
39
|
+
classes.push(key);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return classes;
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return classes.filter(Boolean).join(' ');
|
|
48
|
+
}
|
package/src/EmojiPickerReact.tsx
CHANGED
|
@@ -6,12 +6,11 @@ import { PickerConfigProvider } from './components/context/PickerConfigContext';
|
|
|
6
6
|
import { Preview } from './components/footer/Preview';
|
|
7
7
|
import { Header } from './components/header/Header';
|
|
8
8
|
import PickerMain from './components/main/PickerMain';
|
|
9
|
-
import { PickerConfig } from './config/config';
|
|
10
|
-
import './EmojiPickerReact.css';
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
import './EmojiPickerReact.css';
|
|
11
|
+
import { PickerProps } from './index';
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
function EmojiPicker(props: PickerProps) {
|
|
15
14
|
return (
|
|
16
15
|
<ElementRefContextProvider>
|
|
17
16
|
<PickerConfigProvider {...props}>
|
|
@@ -24,3 +23,23 @@ export default function EmojiPicker(props: Props) {
|
|
|
24
23
|
</ElementRefContextProvider>
|
|
25
24
|
);
|
|
26
25
|
}
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line complexity
|
|
28
|
+
export default React.memo(EmojiPicker, (prev, next) => {
|
|
29
|
+
return (
|
|
30
|
+
prev.emojiVersion === next.emojiVersion &&
|
|
31
|
+
prev.searchPlaceHolder === next.searchPlaceHolder &&
|
|
32
|
+
prev.searchPlaceholder === next.searchPlaceholder &&
|
|
33
|
+
prev.defaultSkinTone === next.defaultSkinTone &&
|
|
34
|
+
prev.skinTonesDisabled === next.skinTonesDisabled &&
|
|
35
|
+
prev.autoFocusSearch === next.autoFocusSearch &&
|
|
36
|
+
prev.emojiStyle === next.emojiStyle &&
|
|
37
|
+
prev.theme === next.theme &&
|
|
38
|
+
prev.suggestedEmojisMode === next.suggestedEmojisMode &&
|
|
39
|
+
prev.lazyLoadEmojis === next.lazyLoadEmojis &&
|
|
40
|
+
prev.height === next.height &&
|
|
41
|
+
prev.width === next.width &&
|
|
42
|
+
prev.searchDisabled === next.searchDisabled &&
|
|
43
|
+
prev.skinTonePickerLocation === next.skinTonePickerLocation
|
|
44
|
+
);
|
|
45
|
+
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useEffect } from 'react';
|
|
4
3
|
|
|
5
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
4
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
6
5
|
import { focusFirstVisibleEmoji } from '../../DomUtils/keyboardNavigation';
|
|
7
6
|
import {
|
|
8
7
|
buttonFromTarget,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
|
|
4
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
3
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
5
4
|
import { EmojiStyle } from '../../types/exposedTypes';
|
|
6
5
|
|
|
7
6
|
export function EmojiImg({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
|
|
4
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
3
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
5
4
|
import { parseNativeEmoji } from '../../dataUtils/parseNativeEmoji';
|
|
6
5
|
|
|
7
6
|
export function NativeEmoji({
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useState } from 'react';
|
|
4
3
|
|
|
5
|
-
import { asSelectors, ClassNames } from '../../DomUtils/classNames';
|
|
4
|
+
import { asSelectors, ClassNames, clsx } from '../../DomUtils/classNames';
|
|
6
5
|
import {
|
|
7
6
|
useAutoFocusSearchConfig,
|
|
8
7
|
useSearchDisabledConfig,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
|
|
4
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
3
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
5
4
|
import { useSkinTonesDisabledConfig } from '../../config/useConfig';
|
|
6
5
|
import skinToneVariations, {
|
|
7
6
|
skinTonesNamed
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
|
|
4
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
3
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
5
4
|
import { usePickerSizeConfig, useThemeConfig } from '../../config/useConfig';
|
|
6
5
|
import useIsSearchMode from '../../hooks/useIsSearchMode';
|
|
7
6
|
import { useKeyboardNavigation } from '../../hooks/useKeyboardNavigation';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useState } from 'react';
|
|
4
3
|
import './CategoryNavigation.css';
|
|
5
4
|
|
|
6
|
-
import { ClassNames } from '../../DomUtils/classNames';
|
|
5
|
+
import { ClassNames, clsx } from '../../DomUtils/classNames';
|
|
7
6
|
import {
|
|
8
7
|
categoryFromCategoryConfig,
|
|
9
8
|
categoryNameFromCategoryConfig
|
package/src/config/config.ts
CHANGED
|
@@ -63,14 +63,6 @@ export function basePickerConfig(): PickerConfigInternal {
|
|
|
63
63
|
getEmojiUrl: emojiUrlByUnified,
|
|
64
64
|
height: 450,
|
|
65
65
|
lazyLoadEmojis: false,
|
|
66
|
-
onEmojiClick: function defaultOnClickHandler(
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
-
emoji: EmojiClickData,
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
-
event: MouseEvent
|
|
73
|
-
) {},
|
|
74
66
|
previewConfig: {
|
|
75
67
|
...basePreviewConfig
|
|
76
68
|
},
|
|
@@ -95,7 +87,6 @@ export type PickerConfigInternal = {
|
|
|
95
87
|
autoFocusSearch: boolean;
|
|
96
88
|
emojiStyle: EmojiStyle;
|
|
97
89
|
categories: CategoriesConfig;
|
|
98
|
-
onEmojiClick: (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
99
90
|
theme: Theme;
|
|
100
91
|
suggestedEmojisMode: SuggestionMode;
|
|
101
92
|
lazyLoadEmojis: boolean;
|
|
@@ -123,6 +114,7 @@ const basePreviewConfig: PreviewConfig = {
|
|
|
123
114
|
|
|
124
115
|
type ConfigExternal = {
|
|
125
116
|
previewConfig: Partial<PreviewConfig>;
|
|
117
|
+
onEmojiClick: (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
126
118
|
} & Omit<PickerConfigInternal, 'previewConfig' | 'unicodeToHide'>;
|
|
127
119
|
|
|
128
120
|
export type PickerConfig = Partial<ConfigExternal>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { EmojiClickData } from '../types/exposedTypes';
|
|
4
|
+
|
|
5
|
+
export type MutableConfig = {
|
|
6
|
+
onEmojiClick?: (emoji: EmojiClickData, event: MouseEvent) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const MutableConfigContext = React.createContext<
|
|
10
|
+
React.MutableRefObject<MutableConfig>
|
|
11
|
+
>({} as React.MutableRefObject<MutableConfig>);
|
|
12
|
+
|
|
13
|
+
export function useMutableConfig(): React.MutableRefObject<MutableConfig> {
|
|
14
|
+
const mutableConfig = React.useContext(MutableConfigContext);
|
|
15
|
+
return mutableConfig;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useDefineMutableConfig(
|
|
19
|
+
config: MutableConfig
|
|
20
|
+
): React.MutableRefObject<MutableConfig> {
|
|
21
|
+
const MutableConfigRef = React.useRef<MutableConfig>({
|
|
22
|
+
onEmojiClick: config.onEmojiClick || emptyFunc
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
MutableConfigRef.current.onEmojiClick = config.onEmojiClick || emptyFunc;
|
|
27
|
+
}, [config.onEmojiClick]);
|
|
28
|
+
|
|
29
|
+
return MutableConfigRef;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function emptyFunc() {}
|
package/src/config/useConfig.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
PreviewConfig
|
|
17
17
|
} from './config';
|
|
18
18
|
import { CustomEmoji } from './customEmojiConfig';
|
|
19
|
+
import { useMutableConfig } from './mutableConfig';
|
|
19
20
|
|
|
20
21
|
export function useSearchPlaceHolderConfig(): string {
|
|
21
22
|
const { searchPlaceHolder, searchPlaceholder } = usePickerConfig();
|
|
@@ -60,8 +61,8 @@ export function useOnEmojiClickConfig(): (
|
|
|
60
61
|
emoji: EmojiClickData,
|
|
61
62
|
event: MouseEvent
|
|
62
63
|
) => void {
|
|
63
|
-
const {
|
|
64
|
-
return onEmojiClick;
|
|
64
|
+
const { current } = useMutableConfig();
|
|
65
|
+
return current.onEmojiClick || (() => {});
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export function usePreviewConfig(): PreviewConfig {
|
package/src/index.tsx
CHANGED
|
@@ -3,6 +3,10 @@ import * as React from 'react';
|
|
|
3
3
|
import EmojiPickerReact from './EmojiPickerReact';
|
|
4
4
|
import ErrorBoundary from './components/ErrorBoundary';
|
|
5
5
|
import { PickerConfig } from './config/config';
|
|
6
|
+
import {
|
|
7
|
+
MutableConfigContext,
|
|
8
|
+
useDefineMutableConfig
|
|
9
|
+
} from './config/mutableConfig';
|
|
6
10
|
|
|
7
11
|
export { ExportedEmoji as Emoji } from './components/emoji/ExportedEmoji';
|
|
8
12
|
|
|
@@ -16,32 +20,18 @@ export {
|
|
|
16
20
|
SkinTonePickerLocation
|
|
17
21
|
} from './types/exposedTypes';
|
|
18
22
|
|
|
19
|
-
export interface
|
|
23
|
+
export interface PickerProps extends PickerConfig {}
|
|
24
|
+
|
|
25
|
+
export default function EmojiPicker(props: PickerProps) {
|
|
26
|
+
const MutableConfigRef = useDefineMutableConfig({
|
|
27
|
+
onEmojiClick: props.onEmojiClick
|
|
28
|
+
});
|
|
20
29
|
|
|
21
|
-
function EmojiPicker(props: Props) {
|
|
22
30
|
return (
|
|
23
31
|
<ErrorBoundary>
|
|
24
|
-
<
|
|
32
|
+
<MutableConfigContext.Provider value={MutableConfigRef}>
|
|
33
|
+
<EmojiPickerReact {...props} />
|
|
34
|
+
</MutableConfigContext.Provider>
|
|
25
35
|
</ErrorBoundary>
|
|
26
36
|
);
|
|
27
37
|
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line complexity
|
|
30
|
-
export default React.memo(EmojiPicker, (prev, next) => {
|
|
31
|
-
return (
|
|
32
|
-
prev.emojiVersion === next.emojiVersion &&
|
|
33
|
-
prev.searchPlaceHolder === next.searchPlaceHolder &&
|
|
34
|
-
prev.searchPlaceholder === next.searchPlaceholder &&
|
|
35
|
-
prev.defaultSkinTone === next.defaultSkinTone &&
|
|
36
|
-
prev.skinTonesDisabled === next.skinTonesDisabled &&
|
|
37
|
-
prev.autoFocusSearch === next.autoFocusSearch &&
|
|
38
|
-
prev.emojiStyle === next.emojiStyle &&
|
|
39
|
-
prev.theme === next.theme &&
|
|
40
|
-
prev.suggestedEmojisMode === next.suggestedEmojisMode &&
|
|
41
|
-
prev.lazyLoadEmojis === next.lazyLoadEmojis &&
|
|
42
|
-
prev.height === next.height &&
|
|
43
|
-
prev.width === next.width &&
|
|
44
|
-
prev.searchDisabled === next.searchDisabled &&
|
|
45
|
-
prev.skinTonePickerLocation === next.skinTonePickerLocation
|
|
46
|
-
);
|
|
47
|
-
});
|