Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to allow Emoji-Mart to use custom fallback images, and properly respect provided image and spritesheet URLs #874

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
coverage
node_modules
dist
nbproject
20 changes: 13 additions & 7 deletions packages/emoji-mart/src/components/Emoji/Emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { Data } from '../../config'
import { SearchIndex } from '../../helpers'

export default function Emoji(props) {
let { id, skin, emoji } = props
let {
id,
skin,
emoji,
imageURL,
spritesheetURL,
fallbackImageURL,
fallbackSpritesheetURL,
} = props

if (props.shortcodes) {
const matches = props.shortcodes.match(SearchIndex.SHORTCODES_REGEX)
Expand All @@ -24,15 +32,13 @@ export default function Emoji(props) {
const imageSrc =
emojiSkin.src ||
(props.set != 'native' && !props.spritesheet
? typeof props.getImageURL === 'function'
? props.getImageURL(props.set, emojiSkin.unified)
: `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@14.0.0/img/${props.set}/64/${emojiSkin.unified}.png`
? imageURL !== null
? imageURL.replace('emojiskin-unified', emojiSkin.unified)
: fallbackImageURL.replace('emojiskin-unified', emojiSkin.unified)
: undefined)

const spritesheetSrc =
typeof props.getSpritesheetURL === 'function'
? props.getSpritesheetURL(props.set)
: `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@14.0.0/img/${props.set}/sheets-256/64.png`
spritesheetURL !== null ? spritesheetURL : fallbackSpritesheetURL

return (
<span class="emoji-mart-emoji" data-emoji-set={props.set}>
Expand Down
5 changes: 5 additions & 0 deletions packages/emoji-mart/src/components/Emoji/EmojiElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export default class EmojiElement extends HTMLElement {

async connectedCallback() {
const props = getProps(this.props, EmojiProps, this)
// These aren't needed at this point; including them only bloats the resulting HTML
this.removeAttribute('imageurl')
this.removeAttribute('spritesheeturl')
this.removeAttribute('fallbackimageurl')
this.removeAttribute('fallbackspritesheeturl')
props.element = this
props.ref = (component) => {
this.component = component
Expand Down
5 changes: 5 additions & 0 deletions packages/emoji-mart/src/components/Emoji/EmojiProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export default {
// Shared
set: PickerProps.set,
skin: PickerProps.skin,
// Added to ensure the Emoji object can access these parameters
imageURL: PickerProps.imageURL,
spritesheetURL: PickerProps.spritesheetURL,
fallbackImageURL: PickerProps.fallbackImageURL,
fallbackSpritesheetURL: PickerProps.fallbackSpritesheetURL,
}
10 changes: 8 additions & 2 deletions packages/emoji-mart/src/components/Picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,10 @@ export default class Picker extends Component {
size={this.props.emojiButtonSize}
skin={this.state.tempSkin || this.state.skin}
spritesheet={true}
getSpritesheetURL={this.props.getSpritesheetURL}
imageURL={this.props.imageURL}
spritesheetURL={this.props.spritesheetURL}
fallbackImageURL={this.props.fallbackImageURL}
fallbackSpritesheetURL={this.props.fallbackSpritesheetURL}
/>
</div>

Expand Down Expand Up @@ -793,7 +796,10 @@ export default class Picker extends Component {
size={this.props.emojiSize}
skin={skin}
spritesheet={true}
getSpritesheetURL={this.props.getSpritesheetURL}
imageURL={this.props.imageURL}
spritesheetURL={this.props.spritesheetURL}
fallbackImageURL={this.props.fallbackImageURL}
fallbackSpritesheetURL={this.props.fallbackSpritesheetURL}
/>
</button>
</PureInlineComponent>
Expand Down
6 changes: 4 additions & 2 deletions packages/emoji-mart/src/components/Picker/PickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ export default {
custom: null,
data: null,
i18n: null,
imageURL: null,
spritesheetURL: null,
fallbackImageURL: null,
fallbackSpritesheetURL: null,

// Callbacks
getImageURL: null,
getSpritesheetURL: null,
onAddCustomEmoji: null,
onClickOutside: null,
onEmojiSelect: null,
Expand Down
Loading