Skip to content

Commit

Permalink
Add skin to emoji data of clicked emojis
Browse files Browse the repository at this point in the history
No `skin` means the emoji doesn’t have multiple skin tones.
  • Loading branch information
EtienneLem committed Sep 9, 2022
1 parent 5c4afcf commit cd0bdef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ getEmojiDataFromNative('🤞🏿').then(console.log)
name: 'Crossed Fingers',
native: '🤞🏿',
shortcodes: ':crossed_fingers::skin-tone-6:',
skin: 6,
unified: '1f91e-1f3ff',
} */
```
Expand Down
1 change: 1 addition & 0 deletions packages/emoji-mart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ getEmojiDataFromNative('🤞🏿').then(console.log)
name: 'Crossed Fingers',
native: '🤞🏿',
shortcodes: ':crossed_fingers::skin-tone-6:',
skin: 6,
unified: '1f91e-1f3ff',
} */
```
Expand Down
12 changes: 11 additions & 1 deletion packages/emoji-mart/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export async function sleep(frames = 1) {
}

export function getEmojiData(emoji, { skinIndex } = {}) {
const skin = emoji.skins[skinIndex] || emoji.skins[0]
const skin =
emoji.skins[skinIndex] ||
(() => {
skinIndex = 0
return emoji.skins[skinIndex]
})()

const emojiData = {
id: emoji.id,
name: emoji.name,
Expand All @@ -26,6 +32,10 @@ export function getEmojiData(emoji, { skinIndex } = {}) {
shortcodes: skin.shortcodes || emoji.shortcodes,
}

if (emoji.skins.length > 1) {
emojiData.skin = skinIndex + 1
}

if (skin.src) {
emojiData.src = skin.src
}
Expand Down

0 comments on commit cd0bdef

Please sign in to comment.