emoji-picker-react 4.1.0 → 4.1.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/dist/DomUtils/classNames.d.ts +3 -1
- package/dist/emoji-picker-react.cjs.development.js +12 -3
- 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 +12 -3
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/DomUtils/classNames.ts +4 -2
- package/src/components/body/EmojiList.tsx +2 -1
- package/src/components/header/Search.tsx +29 -10
- package/src/components/main/PickerMain.tsx +3 -3
- package/src/hooks/useFilter.ts +8 -8
package/package.json
CHANGED
|
@@ -10,9 +10,11 @@ export enum ClassNames {
|
|
|
10
10
|
categoryContent = 'epr-emoji-category-content',
|
|
11
11
|
emojiHasVariatios = 'epr-emoji-has-variations',
|
|
12
12
|
scrollBody = 'epr-body',
|
|
13
|
-
|
|
13
|
+
emojiList = 'epr-emoji-list',
|
|
14
|
+
external = '__EmojiPicker__',
|
|
15
|
+
emojiPicker = 'EmojiPickerReact',
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function asSelectors(...classNames: ClassNames[]): string {
|
|
17
|
-
return classNames.map(c => `.${c}`).join('');
|
|
19
|
+
return classNames.map((c) => `.${c}`).join('');
|
|
18
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import { ClassNames } from '../../DomUtils/classNames';
|
|
3
4
|
import {
|
|
4
5
|
Categories,
|
|
5
6
|
CategoryConfig,
|
|
@@ -28,7 +29,7 @@ export function EmojiList() {
|
|
|
28
29
|
const categories = useCategoriesConfig();
|
|
29
30
|
|
|
30
31
|
return (
|
|
31
|
-
<ul className=
|
|
32
|
+
<ul className={ClassNames.emojiList}>
|
|
32
33
|
{categories.map((categoryConfig, index) => {
|
|
33
34
|
const category = categoryFromCategoryConfig(categoryConfig);
|
|
34
35
|
|
|
@@ -2,15 +2,16 @@ import clsx from 'clsx';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
|
+
import { asSelectors, ClassNames } from '../../DomUtils/classNames';
|
|
5
6
|
import {
|
|
6
7
|
useAutoFocusSearchConfig,
|
|
7
|
-
useSearchPlaceHolderConfig
|
|
8
|
+
useSearchPlaceHolderConfig,
|
|
8
9
|
} from '../../config/useConfig';
|
|
9
10
|
import { useCloseAllOpenToggles } from '../../hooks/useCloseAllOpenToggles';
|
|
10
11
|
import {
|
|
11
12
|
getNormalizedSearchTerm,
|
|
12
13
|
useClearSearch,
|
|
13
|
-
useFilter
|
|
14
|
+
useFilter,
|
|
14
15
|
} from '../../hooks/useFilter';
|
|
15
16
|
import Relative from '../Layout/Relative';
|
|
16
17
|
import { Button } from '../atoms/Button';
|
|
@@ -41,7 +42,7 @@ export function Search() {
|
|
|
41
42
|
className="epr-search"
|
|
42
43
|
type="text"
|
|
43
44
|
placeholder={placeholder}
|
|
44
|
-
onChange={event => {
|
|
45
|
+
onChange={(event) => {
|
|
45
46
|
setInc(inc + 1);
|
|
46
47
|
setTimeout(() => {
|
|
47
48
|
onChange(event?.target?.value ?? value);
|
|
@@ -60,14 +61,32 @@ export function Search() {
|
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
const CSS_SEARCH_SELECTOR = `${asSelectors(
|
|
65
|
+
ClassNames.emojiPicker
|
|
66
|
+
)} ${asSelectors(ClassNames.emojiList)}`;
|
|
67
|
+
|
|
63
68
|
function CssSearch({ value }: { value: undefined | string }) {
|
|
64
|
-
|
|
69
|
+
if (!value) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const searchQuery = `button[data-full-name*="${getNormalizedSearchTerm(
|
|
74
|
+
value
|
|
75
|
+
)}"]`;
|
|
76
|
+
|
|
77
|
+
return (
|
|
65
78
|
<style>{`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
${CSS_SEARCH_SELECTOR} ${asSelectors(
|
|
80
|
+
ClassNames.category
|
|
81
|
+
)}:not(:has(${searchQuery})) {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
${CSS_SEARCH_SELECTOR} button${asSelectors(
|
|
86
|
+
ClassNames.emoji
|
|
87
|
+
)}:not(${searchQuery}) {
|
|
88
|
+
display: none;
|
|
89
|
+
}
|
|
71
90
|
`}</style>
|
|
72
|
-
)
|
|
91
|
+
);
|
|
73
92
|
}
|
|
@@ -38,14 +38,14 @@ function PickerRootElement({ children }: RootProps) {
|
|
|
38
38
|
|
|
39
39
|
const style = {
|
|
40
40
|
height: `${height}px`,
|
|
41
|
-
width: `${width}px
|
|
41
|
+
width: `${width}px`,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
45
|
<aside
|
|
46
|
-
className={clsx(
|
|
46
|
+
className={clsx(ClassNames.emojiPicker, 'epr-main', {
|
|
47
47
|
[ClassNames.searchActive]: searchModeActive,
|
|
48
|
-
'epr-dark-theme': theme === Theme.DARK
|
|
48
|
+
'epr-dark-theme': theme === Theme.DARK,
|
|
49
49
|
})}
|
|
50
50
|
ref={PickerMainRef}
|
|
51
51
|
style={style}
|
package/src/hooks/useFilter.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { scrollTo } from '../DomUtils/scrollTo';
|
|
2
2
|
import {
|
|
3
3
|
usePickerMainRef,
|
|
4
|
-
useSearchInputRef
|
|
4
|
+
useSearchInputRef,
|
|
5
5
|
} from '../components/context/ElementRefContext';
|
|
6
6
|
import {
|
|
7
7
|
FilterState,
|
|
8
8
|
useFilterRef,
|
|
9
|
-
useSearchTermState
|
|
9
|
+
useSearchTermState,
|
|
10
10
|
} from '../components/context/PickerContext';
|
|
11
11
|
import { DataEmoji } from '../dataUtils/DataTypes';
|
|
12
12
|
import { emojiNames } from '../dataUtils/emojiSelectors';
|
|
@@ -67,7 +67,7 @@ export function useFilter() {
|
|
|
67
67
|
return {
|
|
68
68
|
onChange,
|
|
69
69
|
searchTerm,
|
|
70
|
-
SearchInputRef
|
|
70
|
+
SearchInputRef,
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
function onChange(inputValue: string) {
|
|
@@ -87,9 +87,9 @@ export function useFilter() {
|
|
|
87
87
|
return applySearch(nextValue);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
setFilterRef(current =>
|
|
90
|
+
setFilterRef((current) =>
|
|
91
91
|
Object.assign(current, {
|
|
92
|
-
[nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue)
|
|
92
|
+
[nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue),
|
|
93
93
|
})
|
|
94
94
|
);
|
|
95
95
|
applySearch(nextValue);
|
|
@@ -129,14 +129,14 @@ function filterEmojiObjectByKeyword(
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
function hasMatch(emoji: DataEmoji, keyword: string): boolean {
|
|
132
|
-
return emojiNames(emoji).some(name => name.includes(keyword));
|
|
132
|
+
return emojiNames(emoji).some((name) => name.includes(keyword));
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
export function useIsEmojiFiltered(): (unified: string) => boolean {
|
|
136
136
|
const { current: filter } = useFilterRef();
|
|
137
137
|
const [searchTerm] = useSearchTermState();
|
|
138
138
|
|
|
139
|
-
return unified => isEmojiFilteredBySearchTerm(unified, filter, searchTerm);
|
|
139
|
+
return (unified) => isEmojiFilteredBySearchTerm(unified, filter, searchTerm);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
function isEmojiFilteredBySearchTerm(
|
|
@@ -167,7 +167,7 @@ function findLongestMatch(
|
|
|
167
167
|
|
|
168
168
|
const longestMatchingKey = Object.keys(dict)
|
|
169
169
|
.sort((a, b) => b.length - a.length)
|
|
170
|
-
.find(key => keyword.includes(key));
|
|
170
|
+
.find((key) => keyword.includes(key));
|
|
171
171
|
|
|
172
172
|
if (longestMatchingKey) {
|
|
173
173
|
return dict[longestMatchingKey];
|