Merge pull request #132 from Gargron/feature-pass-down-frequently

Allow passing down a `recent` prop instead of localStorage
release
Etienne Lemay 2017-10-30 17:19:25 -04:00 committed by GitHub
commit 655b047d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import { Picker } from 'emoji-mart'
| **include** | | `[]` | Only load included categories. Accepts [I18n categories keys](#i18n). Order will be respected, except for the `recent` category which will always be the first. | | **include** | | `[]` | Only load included categories. Accepts [I18n categories keys](#i18n). Order will be respected, except for the `recent` category which will always be the first. |
| **exclude** | | `[]` | Don't load excluded categories. Accepts [I18n categories keys](#i18n). | | **exclude** | | `[]` | Don't load excluded categories. Accepts [I18n categories keys](#i18n). |
| **custom** | | `[]` | [Custom emojis](#custom-emojis) | | **custom** | | `[]` | [Custom emojis](#custom-emojis) |
| **recent** | | | Pass your own frequently used emojis as array of string IDs |
| **emojiSize** | | `24` | The emoji width and height | | **emojiSize** | | `24` | The emoji width and height |
| **onClick** | | | Params: `(emoji, event) => {}` | | **onClick** | | | Params: `(emoji, event) => {}` |
| **perLine** | | `9` | Number of emojis per line. While theres no minimum or maximum, this will affect the pickers width. This will set *Frequently Used* length as well (`perLine * 4`) | | **perLine** | | `9` | Number of emojis per line. While theres no minimum or maximum, this will affect the pickers width. This will set *Frequently Used* length as well (`perLine * 4`) |

View File

@ -93,11 +93,11 @@ export default class Category extends React.Component {
} }
getEmojis() { getEmojis() {
var { name, emojis, perLine } = this.props var { name, emojis, recent, perLine } = this.props
if (name == 'Recent') { if (name == 'Recent') {
let { custom } = this.props let { custom } = this.props
let frequentlyUsed = frequently.get(perLine) let frequentlyUsed = recent || frequently.get(perLine)
if (frequentlyUsed.length) { if (frequentlyUsed.length) {
emojis = frequentlyUsed.map(id => { emojis = frequentlyUsed.map(id => {
@ -208,6 +208,7 @@ Category.propTypes = {
native: PropTypes.bool.isRequired, native: PropTypes.bool.isRequired,
perLine: PropTypes.number.isRequired, perLine: PropTypes.number.isRequired,
emojiProps: PropTypes.object.isRequired, emojiProps: PropTypes.object.isRequired,
recent: PropTypes.arrayOf(PropTypes.string),
} }
Category.defaultProps = { Category.defaultProps = {

View File

@ -220,7 +220,7 @@ export default class Picker extends React.PureComponent {
handleEmojiClick(emoji, e) { handleEmojiClick(emoji, e) {
this.props.onClick(emoji, e) this.props.onClick(emoji, e)
if (!this.hideRecent) frequently.add(emoji) if (!this.hideRecent && !this.props.recent) frequently.add(emoji)
var component = this.categoryRefs['category-1'] var component = this.categoryRefs['category-1']
if (component) { if (component) {
@ -420,6 +420,7 @@ export default class Picker extends React.PureComponent {
emojiTooltip, emojiTooltip,
include, include,
exclude, exclude,
recent,
autoFocus, autoFocus,
} = this.props, } = this.props,
{ skin } = this.state, { skin } = this.state,
@ -464,6 +465,9 @@ export default class Picker extends React.PureComponent {
native={native} native={native}
hasStickyPosition={this.hasStickyPosition} hasStickyPosition={this.hasStickyPosition}
i18n={this.i18n} i18n={this.i18n}
recent={
category.name == 'Recent' ? recent : undefined
}
custom={ custom={
category.name == 'Recent' ? CUSTOM_CATEGORY.emojis : undefined category.name == 'Recent' ? CUSTOM_CATEGORY.emojis : undefined
} }
@ -530,6 +534,7 @@ Picker.propTypes = {
emojiTooltip: Emoji.propTypes.tooltip, emojiTooltip: Emoji.propTypes.tooltip,
include: PropTypes.arrayOf(PropTypes.string), include: PropTypes.arrayOf(PropTypes.string),
exclude: PropTypes.arrayOf(PropTypes.string), exclude: PropTypes.arrayOf(PropTypes.string),
recent: PropTypes.arrayOf(PropTypes.string),
autoFocus: PropTypes.bool, autoFocus: PropTypes.bool,
custom: PropTypes.arrayOf( custom: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({