parent
8cff39f6fd
commit
1a9d5f97b6
|
@ -37,6 +37,8 @@ export default class Anchors extends React.PureComponent {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const iconId = id.startsWith('custom-') ? 'custom' : id
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={id}
|
key={id}
|
||||||
|
@ -51,7 +53,7 @@ export default class Anchors extends React.PureComponent {
|
||||||
style={{ color: isSelected ? color : null }}
|
style={{ color: isSelected ? color : null }}
|
||||||
>
|
>
|
||||||
<div className="emoji-mart-anchor-icon">
|
<div className="emoji-mart-anchor-icon">
|
||||||
{icons.categories[id]()}
|
{icons.categories[iconId]()}
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
className="emoji-mart-anchor-bar"
|
className="emoji-mart-anchor-bar"
|
||||||
|
|
|
@ -180,11 +180,13 @@ export default class Category extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const label = i18n.categories[id] || name
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
ref={this.setContainerRef}
|
ref={this.setContainerRef}
|
||||||
className="emoji-mart-category"
|
className="emoji-mart-category"
|
||||||
aria-label={i18n.categories[id]}
|
aria-label={label}
|
||||||
style={containerStyles}
|
style={containerStyles}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -197,7 +199,7 @@ export default class Category extends React.Component {
|
||||||
ref={this.setLabelRef}
|
ref={this.setLabelRef}
|
||||||
aria-hidden={true /* already labeled by the section aria-label */}
|
aria-hidden={true /* already labeled by the section aria-label */}
|
||||||
>
|
>
|
||||||
{i18n.categories[id]}
|
{label}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,9 @@ export default class NimblePicker extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
|
this.CUSTOM = []
|
||||||
|
|
||||||
this.RECENT_CATEGORY = { id: 'recent', name: 'Recent', emojis: null }
|
this.RECENT_CATEGORY = { id: 'recent', name: 'Recent', emojis: null }
|
||||||
this.CUSTOM_CATEGORY = { id: 'custom', name: 'Custom', emojis: [] }
|
|
||||||
this.SEARCH_CATEGORY = {
|
this.SEARCH_CATEGORY = {
|
||||||
id: 'search',
|
id: 'search',
|
||||||
name: 'Search',
|
name: 'Search',
|
||||||
|
@ -74,16 +75,37 @@ export default class NimblePicker extends React.PureComponent {
|
||||||
let allCategories = [].concat(this.data.categories)
|
let allCategories = [].concat(this.data.categories)
|
||||||
|
|
||||||
if (props.custom.length > 0) {
|
if (props.custom.length > 0) {
|
||||||
this.CUSTOM_CATEGORY.emojis = props.custom.map((emoji) => {
|
const customCategories = {}
|
||||||
return {
|
let customCategoriesCreated = 0
|
||||||
|
|
||||||
|
props.custom.forEach((emoji) => {
|
||||||
|
if (!customCategories[emoji.customCategory]) {
|
||||||
|
customCategories[emoji.customCategory] = {
|
||||||
|
id: emoji.customCategory
|
||||||
|
? `custom-${emoji.customCategory}`
|
||||||
|
: 'custom',
|
||||||
|
name: emoji.customCategory || 'Custom',
|
||||||
|
emojis: [],
|
||||||
|
anchor: customCategoriesCreated === 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
customCategoriesCreated++
|
||||||
|
}
|
||||||
|
|
||||||
|
const category = customCategories[emoji.customCategory]
|
||||||
|
|
||||||
|
const customEmoji = {
|
||||||
...emoji,
|
...emoji,
|
||||||
// `<Category />` expects emoji to have an `id`.
|
// `<Category />` expects emoji to have an `id`.
|
||||||
id: emoji.short_names[0],
|
id: emoji.short_names[0],
|
||||||
custom: true,
|
custom: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
category.emojis.push(customEmoji)
|
||||||
|
this.CUSTOM.push(customEmoji)
|
||||||
})
|
})
|
||||||
|
|
||||||
allCategories.push(this.CUSTOM_CATEGORY)
|
allCategories.push(...Object.values(customCategories))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hideRecent = true
|
this.hideRecent = true
|
||||||
|
@ -231,7 +253,7 @@ export default class NimblePicker extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Array.prototype.find() when it is more widely supported.
|
// Use Array.prototype.find() when it is more widely supported.
|
||||||
const emojiData = this.CUSTOM_CATEGORY.emojis.filter(
|
const emojiData = this.CUSTOM.filter(
|
||||||
(customEmoji) => customEmoji.id === emoji.id,
|
(customEmoji) => customEmoji.id === emoji.id,
|
||||||
)[0]
|
)[0]
|
||||||
for (let key in emojiData) {
|
for (let key in emojiData) {
|
||||||
|
@ -536,7 +558,7 @@ export default class NimblePicker extends React.PureComponent {
|
||||||
emojisToShowFilter={emojisToShowFilter}
|
emojisToShowFilter={emojisToShowFilter}
|
||||||
include={include}
|
include={include}
|
||||||
exclude={exclude}
|
exclude={exclude}
|
||||||
custom={this.CUSTOM_CATEGORY.emojis}
|
custom={this.CUSTOM}
|
||||||
autoFocus={autoFocus}
|
autoFocus={autoFocus}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -563,7 +585,7 @@ export default class NimblePicker extends React.PureComponent {
|
||||||
}
|
}
|
||||||
custom={
|
custom={
|
||||||
category.id == this.RECENT_CATEGORY.id
|
category.id == this.RECENT_CATEGORY.id
|
||||||
? this.CUSTOM_CATEGORY.emojis
|
? this.CUSTOM
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
emojiProps={{
|
emojiProps={{
|
||||||
|
|
|
@ -23,6 +23,7 @@ function sanitize(emoji) {
|
||||||
emoticons,
|
emoticons,
|
||||||
unified,
|
unified,
|
||||||
custom,
|
custom,
|
||||||
|
customCategory,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
} = emoji,
|
} = emoji,
|
||||||
id = emoji.id || short_names[0],
|
id = emoji.id || short_names[0],
|
||||||
|
@ -36,6 +37,7 @@ function sanitize(emoji) {
|
||||||
colons,
|
colons,
|
||||||
emoticons,
|
emoticons,
|
||||||
custom,
|
custom,
|
||||||
|
customCategory,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ const CUSTOM_EMOJIS = [
|
||||||
short_names: ['octocat'],
|
short_names: ['octocat'],
|
||||||
keywords: ['github'],
|
keywords: ['github'],
|
||||||
imageUrl: 'https://github.githubassets.com/images/icons/emoji/octocat.png',
|
imageUrl: 'https://github.githubassets.com/images/icons/emoji/octocat.png',
|
||||||
|
customCategory: 'GitHub',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Squirrel',
|
name: 'Squirrel',
|
||||||
|
|
Loading…
Reference in New Issue