Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const AutoCompleteExample: React.FC = () => {
const [search, setSearch] = useState('');
const changed = (e: React.ChangeEvent) => {
const target = e.target as { value: any };
setSearch(target.value);
};
const match = search.match(/:([a-z_]+)(:)?/);
let suggestions: ReturnType = [];
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></div>
'Activities',
'Travel & Places',
'Objects',
'Symbols',
'Flags',
]
const categories: Array<{
category: string
emojis: Array
}> = categoryOrder.map(category => ({
category,
emojis: sorted[category],
}))
// Map from EmojiMart's `id` to EmojiDatasource's object
const emojiNameMap = Object.values(emojiIndex.emojis).reduce(
(res: {[K in string]: EmojiData}, emoji: any) => {
const shortName = emoji.id
const emojiFromEmojiData = emojidata.find(e => e.short_name === shortName)
if (emojiFromEmojiData) {
res[shortName] = emojiFromEmojiData
}
return res
},
{}
)
export {categories, categoryOrder, emojiIndex, emojiNameMap}