-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import mitt from 'mitt';
import { debounce } from 'lodash';
const emojiPicker = (() => {
const emitter = mitt();
let pickerElement = null;
function init(selector) {
pickerElement = document.querySelector(selector);
if (!pickerElement) throw new Error('Emoji Picker could not find the element with the provided selector.');
// Simple mockup for the picker element
pickerElement.innerHTML = `
<div>Select your emoji: 😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇</div>
`;
attachEventListeners();
}
function attachEventListeners() {
pickerElement.addEventListener('click', debounce(handleClick, 200));
}
function handleClick(event) {
const { target } = event;
if (target.textContent) {
emitter.emit('emoji-selected', { emoji: target.textContent });
}
}
function on(event, handler) {
emitter.on(event, handler);
}
function off(event, handler) {
emitter.off(event, handler);
}
return { init, on, off };
})();
export default emojiPicker;