Merge pull request #40 from pivotaltracker/native-emoji-picker-option

Allow picker to display emoji natively
nolan/hinaloe-test
Etienne Lemay 2017-02-17 07:53:05 -08:00 committed by GitHub
commit da5cdcf5d3
9 changed files with 39 additions and 12 deletions

View File

@ -26,9 +26,11 @@ import { Picker } from 'emoji-mart'
| **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`) |
| **i18n** | | [`{…}`](#i18n) | [An object](#i18n) containing localized strings | | **i18n** | | [`{…}`](#i18n) | [An object](#i18n) containing localized strings |
| **native** | | `false` | Renders the native unicode emoji |
| **set** | | `apple` | The emoji set: `'apple', 'google', 'twitter', 'emojione'` | | **set** | | `apple` | The emoji set: `'apple', 'google', 'twitter', 'emojione'` |
| **sheetSize** | | `64` | The emoji [sheet size](#sheet-sizes): `16, 20, 32, 64` | | **sheetSize** | | `64` | The emoji [sheet size](#sheet-sizes): `16, 20, 32, 64` |
| **backgroundImageFn** | | ```((set, sheetSize) => `https://unpkg.com/emoji-datasource@2.4.4/sheet_${set}_${sheetSize}.png`)``` | A Fn that returns that image sheet to use for emojis. Useful for avoiding a request if you have the sheet locally. | | **backgroundImageFn** | | ```((set, sheetSize) => `https://unpkg.com/emoji-datasource@2.4.4/sheet_${set}_${sheetSize}.png`)``` | A Fn that returns that image sheet to use for emojis. Useful for avoiding a request if you have the sheet locally. |
| **emojisToShowFilter** | | ```((unicode) => true)``` | A Fn to choose whether an emoji should be displayed or not based on its unicode |
| **skin** | | `1` | Default skin color: `1, 2, 3, 4, 5, 6` | | **skin** | | `1` | Default skin color: `1, 2, 3, 4, 5, 6` |
| **style** | | | Inline styles applied to the root element. Useful for positioning | | **style** | | | Inline styles applied to the root element. Useful for positioning |
| **title** | | `Emoji Mart™` | The title shown when no emojis are hovered | | **title** | | `Emoji Mart™` | The title shown when no emojis are hovered |

View File

@ -91,6 +91,8 @@
.emoji-mart-category .emoji-mart-emoji span { .emoji-mart-category .emoji-mart-emoji span {
z-index: 1; z-index: 1;
position: relative; position: relative;
text-align: center;
cursor: default;
} }
.emoji-mart-category .emoji-mart-emoji:hover:before { .emoji-mart-category .emoji-mart-emoji:hover:before {

View File

@ -10,6 +10,7 @@ class Example extends React.Component {
emojiSize: 24, emojiSize: 24,
perLine: 9, perLine: 9,
skin: 1, skin: 1,
native: false,
set: 'apple', set: 'apple',
hidden: false, hidden: false,
} }
@ -17,11 +18,16 @@ class Example extends React.Component {
handleInput(e) { handleInput(e) {
var { currentTarget } = e, var { currentTarget } = e,
{ value } = currentTarget, { value, type, checked } = currentTarget,
key = currentTarget.getAttribute('data-key'), key = currentTarget.getAttribute('data-key'),
state = {} state = {}
state[key] = parseInt(value) if (type == 'checkbox') {
state[key] = checked
} else {
state[key] = parseInt(value)
}
this.setState(state) this.setState(state)
} }
@ -76,6 +82,7 @@ class Example extends React.Component {
<br /> emojiSize<Operator>=</Operator>&#123;<Variable>{this.state.emojiSize}</Variable>&#125; <input type='range' data-key='emojiSize' onChange={this.handleInput.bind(this)} min='16' max='64' value={this.state.emojiSize} /> <br /> emojiSize<Operator>=</Operator>&#123;<Variable>{this.state.emojiSize}</Variable>&#125; <input type='range' data-key='emojiSize' onChange={this.handleInput.bind(this)} min='16' max='64' value={this.state.emojiSize} />
<br /> perLine<Operator>=</Operator>&#123;<Variable>{this.state.perLine}</Variable>&#125; {this.state.perLine < 10 ? ' ' : ' '} <input type='range' data-key='perLine' onChange={this.handleInput.bind(this)} min='7' max='16' value={this.state.perLine} /> <br /> perLine<Operator>=</Operator>&#123;<Variable>{this.state.perLine}</Variable>&#125; {this.state.perLine < 10 ? ' ' : ' '} <input type='range' data-key='perLine' onChange={this.handleInput.bind(this)} min='7' max='16' value={this.state.perLine} />
<br /> skin<Operator>=</Operator>&#123;<Variable>{this.state.skin}</Variable>&#125; <input type='range' data-key='skin' onChange={this.handleInput.bind(this)} min='1' max='6' value={this.state.skin} /> <br /> skin<Operator>=</Operator>&#123;<Variable>{this.state.skin}</Variable>&#125; <input type='range' data-key='skin' onChange={this.handleInput.bind(this)} min='1' max='6' value={this.state.skin} />
<br /> native<Operator>=</Operator>&#123;<Variable>{this.state.native ? 'true' : 'false'}</Variable>&#125;{this.state.native ? ' ' : ''} <input type='checkbox' data-key='native' onChange={this.handleInput.bind(this)} value={this.state.native} />
<br /> set<Operator>=</Operator><String>'{this.state.set}'</String> <br /> set<Operator>=</Operator><String>'{this.state.set}'</String>
<br /> onClick<Operator>=</Operator>&#123;(<Variable>emoji</Variable>) => console.log(<Variable>emoji</Variable>)&#125; <br /> onClick<Operator>=</Operator>&#123;(<Variable>emoji</Variable>) => console.log(<Variable>emoji</Variable>)&#125;
<br /><Operator>/&gt;</Operator> <br /><Operator>/&gt;</Operator>
@ -86,6 +93,7 @@ class Example extends React.Component {
emojiSize={this.state.emojiSize} emojiSize={this.state.emojiSize}
perLine={this.state.perLine} perLine={this.state.perLine}
skin={this.state.skin} skin={this.state.skin}
native={this.state.native}
set={this.state.set} set={this.state.set}
onClick={(emoji) => console.log(emoji)} onClick={(emoji) => console.log(emoji)}
/> />

View File

@ -53,8 +53,7 @@
"build:example": "node scripts/build-example", "build:example": "node scripts/build-example",
"build:dist": "node scripts/build-dist", "build:dist": "node scripts/build-dist",
"build": "npm run build:data && npm run build:example && npm run build:dist", "build": "npm run build:data && npm run build:example && npm run build:dist",
"watch:example": "node scripts/watch-example", "watch": "node scripts/watch",
"watch": "npm run watch:example",
"react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}", "react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}",
"react:14": "npm run react:clean && npm i react@^0.14 react-dom@^0.14 react-addons-test-utils@^0.14 --save-dev", "react:14": "npm run react:clean && npm i react@^0.14 react-dom@^0.14 react-addons-test-utils@^0.14 --save-dev",
"react:15": "npm run react:clean && npm i react@^15 react-dom@^15 react-addons-test-utils@^15 --save-dev", "react:15": "npm run react:clean && npm i react@^15 react-dom@^15 react-addons-test-utils@^15 --save-dev",

View File

@ -1,7 +1,7 @@
var path = require('path') var path = require('path')
var webpack = require('webpack') var webpack = require('webpack')
var config = require('../example/webpack.config.js'), var config = require('../src/webpack.config.js'),
compiler = webpack(config) compiler = webpack(config)
compiler.watch({}, (err, stats) => { compiler.watch({}, (err, stats) => {

View File

@ -16,9 +16,9 @@ export default class Category extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
var { name, perLine, hasStickyPosition, emojis, emojiProps } = this.props, var { name, perLine, native, hasStickyPosition, emojis, emojiProps } = this.props,
{ skin, size, set } = emojiProps, { skin, size, set } = emojiProps,
{ perLine: nextPerLine, hasStickyPosition: nextHasStickyPosition, emojis: nextEmojis, emojiProps: nextEmojiProps } = nextProps, { perLine: nextPerLine, native: nextNative, hasStickyPosition: nextHasStickyPosition, emojis: nextEmojis, emojiProps: nextEmojiProps } = nextProps,
{ skin: nextSkin, size: nextSize, set: nextSet } = nextEmojiProps, { skin: nextSkin, size: nextSize, set: nextSet } = nextEmojiProps,
shouldUpdate = false shouldUpdate = false
@ -30,7 +30,7 @@ export default class Category extends React.Component {
shouldUpdate = !(emojis == nextEmojis) shouldUpdate = !(emojis == nextEmojis)
} }
if (skin != nextSkin || size != nextSize || set != nextSet || hasStickyPosition != nextHasStickyPosition) { if (skin != nextSkin || size != nextSize || native != nextNative || set != nextSet || hasStickyPosition != nextHasStickyPosition) {
shouldUpdate = true shouldUpdate = true
} }
@ -152,6 +152,7 @@ Category.propTypes = {
emojis: React.PropTypes.array, emojis: React.PropTypes.array,
hasStickyPosition: React.PropTypes.bool, hasStickyPosition: React.PropTypes.bool,
name: React.PropTypes.string.isRequired, name: React.PropTypes.string.isRequired,
native: React.PropTypes.bool.isRequired,
perLine: React.PropTypes.number.isRequired, perLine: React.PropTypes.number.isRequired,
emojiProps: React.PropTypes.object.isRequired, emojiProps: React.PropTypes.object.isRequired,
} }

View File

@ -16,6 +16,7 @@ export default class Emoji extends React.Component {
return ( return (
this.hasSkinVariations && nextProps.skin != this.props.skin || this.hasSkinVariations && nextProps.skin != this.props.skin ||
nextProps.size != this.props.size || nextProps.size != this.props.size ||
nextProps.native != this.props.native ||
nextProps.set != this.props.set || nextProps.set != this.props.set ||
nextProps.emoji != this.props.emoji nextProps.emoji != this.props.emoji
) )
@ -60,7 +61,7 @@ export default class Emoji extends React.Component {
} }
render() { render() {
var { set, size, sheetSize, native, onOver, onLeave, backgroundImageFn } = this.props, var { set, size, sheetSize, native, forceSize, onOver, onLeave, backgroundImageFn } = this.props,
{ unified } = this.getData(), { unified } = this.getData(),
style = {}, style = {},
children = this.props.children children = this.props.children
@ -72,6 +73,12 @@ export default class Emoji extends React.Component {
if (native && unified) { if (native && unified) {
style = { fontSize: size } style = { fontSize: size }
children = unifiedToNative(unified) children = unifiedToNative(unified)
if (forceSize) {
style.display = 'inline-block'
style.width = size
style.height = size
}
} else { } else {
style = { style = {
width: size, width: size,
@ -99,6 +106,7 @@ Emoji.propTypes = {
onClick: React.PropTypes.func, onClick: React.PropTypes.func,
backgroundImageFn: React.PropTypes.func, backgroundImageFn: React.PropTypes.func,
native: React.PropTypes.bool, native: React.PropTypes.bool,
forceSize: React.PropTypes.bool,
skin: React.PropTypes.oneOf([1, 2, 3, 4, 5, 6]), skin: React.PropTypes.oneOf([1, 2, 3, 4, 5, 6]),
sheetSize: React.PropTypes.oneOf([16, 20, 32, 64]), sheetSize: React.PropTypes.oneOf([16, 20, 32, 64]),
set: React.PropTypes.oneOf(['apple', 'google', 'twitter', 'emojione']), set: React.PropTypes.oneOf(['apple', 'google', 'twitter', 'emojione']),
@ -114,6 +122,7 @@ Emoji.defaultProps = {
set: 'apple', set: 'apple',
sheetSize: 64, sheetSize: 64,
native: false, native: false,
forceSize: false,
backgroundImageFn: ((set, sheetSize) => `https://unpkg.com/emoji-datasource@${EMOJI_DATASOURCE_VERSION}/sheet_${set}_${sheetSize}.png`), backgroundImageFn: ((set, sheetSize) => `https://unpkg.com/emoji-datasource@${EMOJI_DATASOURCE_VERSION}/sheet_${set}_${sheetSize}.png`),
onOver: (() => {}), onOver: (() => {}),
onLeave: (() => {}), onLeave: (() => {}),

View File

@ -261,7 +261,7 @@ export default class Picker extends React.Component {
} }
render() { render() {
var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, backgroundImageFn, emojisToShowFilter } = this.props, var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, native, backgroundImageFn, emojisToShowFilter } = this.props,
{ skin } = this.state, { skin } = this.state,
width = (perLine * (emojiSize + 12)) + 12 + 2 width = (perLine * (emojiSize + 12)) + 12 + 2
@ -291,13 +291,16 @@ export default class Picker extends React.Component {
name={category.name} name={category.name}
emojis={category.emojis} emojis={category.emojis}
perLine={perLine} perLine={perLine}
native={native}
hasStickyPosition={this.hasStickyPosition} hasStickyPosition={this.hasStickyPosition}
i18n={this.i18n} i18n={this.i18n}
emojiProps={{ emojiProps={{
native: native,
skin: skin, skin: skin,
size: emojiSize, size: emojiSize,
set: set, set: set,
sheetSize: sheetSize, sheetSize: sheetSize,
forceSize: native,
backgroundImageFn: backgroundImageFn, backgroundImageFn: backgroundImageFn,
onOver: this.handleEmojiOver.bind(this), onOver: this.handleEmojiOver.bind(this),
onLeave: this.handleEmojiLeave.bind(this), onLeave: this.handleEmojiLeave.bind(this),
@ -313,6 +316,7 @@ export default class Picker extends React.Component {
title={title} title={title}
emoji={emoji} emoji={emoji}
emojiProps={{ emojiProps={{
native: native,
size: 38, size: 38,
skin: skin, skin: skin,
set: set, set: set,
@ -339,8 +343,9 @@ Picker.propTypes = {
emoji: React.PropTypes.string, emoji: React.PropTypes.string,
color: React.PropTypes.string, color: React.PropTypes.string,
set: Emoji.propTypes.set, set: Emoji.propTypes.set,
backgroundImageFn: Emoji.propTypes.backgroundImageFn,
skin: Emoji.propTypes.skin, skin: Emoji.propTypes.skin,
native: React.PropTypes.bool,
backgroundImageFn: Emoji.propTypes.backgroundImageFn,
sheetSize: Emoji.propTypes.sheetSize, sheetSize: Emoji.propTypes.sheetSize,
emojisToShowFilter: React.PropTypes.func, emojisToShowFilter: React.PropTypes.func,
} }
@ -356,6 +361,7 @@ Picker.defaultProps = {
color: '#ae65c5', color: '#ae65c5',
set: Emoji.defaultProps.set, set: Emoji.defaultProps.set,
skin: Emoji.defaultProps.skin, skin: Emoji.defaultProps.skin,
native: Emoji.defaultProps.native,
sheetSize: Emoji.defaultProps.sheetSize, sheetSize: Emoji.defaultProps.sheetSize,
backgroundImageFn: Emoji.defaultProps.backgroundImageFn, backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
emojisToShowFilter: (codePoint) => true, emojisToShowFilter: (codePoint) => true,

View File

@ -2155,7 +2155,7 @@ regenerator-transform@0.9.8:
regex-cache@^0.4.2: regex-cache@^0.4.2:
version "0.4.3" version "0.4.3"
resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145" resolved "http://registry.npmjs.org/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145"
dependencies: dependencies:
is-equal-shallow "^0.1.3" is-equal-shallow "^0.1.3"
is-primitive "^2.0.0" is-primitive "^2.0.0"