Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (match && match[2]) {
// smiley is closed
let emoji = emojiIndex.emojis[match[1]];
const isSingleEmoji = (e: EmojiEntry): e is EmojiData => {
return 'name' in e;
};
const isNativeEmoji = (e: EmojiData): e is BaseEmoji => {
return 'native' in e;
};
if (!isSingleEmoji(emoji)) {
emoji = emoji[1];
}
const native = (isNativeEmoji(emoji) && emoji.native) || '';
setSearch(search.replace(match[0], native));
} else if (match && match[1].length > 2) {
suggestions = emojiIndex.search(match[1]) || [];
}
return (
<div>
{suggestions.map(emoji => {
return 'native' in emoji && <span>{emoji.native}</span>;
})}
{match && <div>{match[0]}</div>}
<input value="{search}" placeholder="enter a message..." type="text">
</div>
);
};
const handleInputChange = React.useCallback(() => {
if (!inputRef.current) return
const inputValue = inputRef.current.value
const lastWord = inputValue.split(' ').pop()
const emojiPickerActive = lastWord.startsWith(':') && useEmojis
const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []
if (emojiResults.length === 0) {
// Slice the ':' prefix so we search for emojis instead of emoticons so
// ':smile' => 'smile'
// This is needed because we can also search for ':)' which requires the
// ':' prefix
emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
}
setInputValue(inputValue)
setEmojiResults(emojiResults)
setEmojiPickerActive(emojiPickerActive)
}, [useEmojis])
const handleInputChange = React.useCallback(() => {
if (!inputRef.current) return
const inputValue = inputRef.current.value
const lastWord = inputValue.split(' ').pop()
const emojiPickerActive = lastWord.startsWith(':') && useEmojis
const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []
if (emojiResults.length === 0) {
// Slice the ':' prefix so we search for emojis instead of emoticons so
// ':smile' => 'smile'
// This is needed because we can also search for ':)' which requires the
// ':' prefix
emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
}
setInputValue(inputValue)
setEmojiResults(emojiResults)
setEmojiPickerActive(emojiPickerActive)
}, [useEmojis])
const handleInputChange = React.useCallback(() => {
if (!inputRef.current) return
const inputValue = inputRef.current.value
const lastWord = inputValue.split(' ').pop()
const emojiPickerActive = lastWord.startsWith(':') && useEmojis
const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []
if (emojiResults.length === 0) {
// Slice the ':' prefix so we search for emojis instead of emoticons so
// ':smile' => 'smile'
// This is needed because we can also search for ':)' which requires the
// ':' prefix
emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
}
setInputValue(inputValue)
setEmojiResults(emojiResults)
setEmojiPickerActive(emojiPickerActive)
}, [useEmojis])
const handleInputChange = React.useCallback(() => {
if (!inputRef.current) return
const inputValue = inputRef.current.value
const lastWord = inputValue.split(' ').pop()
const emojiPickerActive = lastWord.startsWith(':') && useEmojis
const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []
if (emojiResults.length === 0) {
// Slice the ':' prefix so we search for emojis instead of emoticons so
// ':smile' => 'smile'
// This is needed because we can also search for ':)' which requires the
// ':' prefix
emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
}
setInputValue(inputValue)
setEmojiResults(emojiResults)
setEmojiPickerActive(emojiPickerActive)
}, [useEmojis])
const emojiDatasource = (filter: string) => ({
data: emojiPrepass.test(filter) ? emojiIndex.search(filter) : [],
useSpaces: false,
})
const emojiRenderer = (item: {colons: string}, selected: boolean) => (
dataProvider: (token) => {
const emojis = emojiIndex.search(token) || [];
return emojis.slice(0, 10);
},
component: AutocompleteItem,