diff --git a/README.md b/README.md index e1348be..7a18e2f 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,27 @@ Design goals: import 'emoji-picker-element'; ``` -Or via [unpkg](https://unpkg.com): +Then listen for `emoji-click` events: ```js -import 'https://unpkg.com/emoji-picker-element' +const element = document.querySelector('emoji-picker'); +element.addEventListener('emoji-click', event => console.log(event.detail)) +``` + +This will log: + +```json +{ + "annotation": "grinning face", + "group": 0, + "order": 1, + "shortcodes": [ "gleeful" ], + "tags": [ "face", "grin" ], + "tokens": [ ":d", "face", "gleeful", "grin", "grinning" ], + "unicode": "đŸ˜€", + "version": 1, + "emoticon": ":D" +} ``` ## API @@ -60,13 +77,17 @@ picker.dataSource = '/my-emoji.json'; #### i18n structure -Note that some of these values are only visible to users of screen readers (but you should still support them if you internationalize your app!). +The default English (`"en"`) `i81n` object: ```json { + "emojiUnsupported": "Your browser does not support color emoji.", "loading": "Loading…", + "networkError": "Could not load emoji. Try refreshing.", "regionLabel": "Emoji picker", "search": "Search", + "skinToneLabel": "Choose a skin tone", + "searchResultsLabel": "Search results", "categoriesLabel": "Categories", "categories": { "smileys-emotion": "Smileys and emoticons", @@ -82,6 +103,9 @@ Note that some of these values are only visible to users of screen readers (but } ``` +Note that some of these values are only visible to users of screen readers. +But you should still support them if you internationalize your app! + #### Styling `emoji-picker-element` uses Shadow DOM, so its inner styling is not accessible except via the API described below. diff --git a/package.json b/package.json index f30044e..469f502 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "global": [ "btoa", "crypto", + "CustomEvent", "fetch", "indexedDB", "IDBKeyRange", diff --git a/src/picker/components/Picker/Picker.html b/src/picker/components/Picker/Picker.html index 1f8af4b..73ec050 100644 --- a/src/picker/components/Picker/Picker.html +++ b/src/picker/components/Picker/Picker.html @@ -64,6 +64,7 @@ aria-label={searchMode ? i18n.searchResultsLabel : i18n.categories[currentCategory.name]} id={searchMode ? '' : `tab-${currentCategory.group}`} tabindex="0" + on:click={onEmojiClick} >
_.unicode === unicode) + rootElement.dispatchEvent(new CustomEvent('emoji-click', { + detail: emojiData, + bubbles: true, + composed: true + })) +} + export { locale, dataSource, diff --git a/test.html b/test.html index c069d13..efd9063 100644 --- a/test.html +++ b/test.html @@ -12,6 +12,7 @@