2016-05-31 14:36:52 +00:00
|
|
|
|
import React from 'react'
|
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
|
|
2016-10-27 03:27:55 +00:00
|
|
|
|
import { Picker, Emoji } from '../src'
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
2017-05-26 08:01:45 +00:00
|
|
|
|
const CUSTOM_EMOJIS = [
|
|
|
|
|
{
|
|
|
|
|
name: 'Octocat',
|
|
|
|
|
short_names: ['octocat'],
|
|
|
|
|
keywords: ['github'],
|
|
|
|
|
imageUrl: 'https://assets-cdn.github.com/images/icons/emoji/octocat.png?v7'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Squirrel',
|
|
|
|
|
short_names: ['shipit', 'squirrel'],
|
|
|
|
|
keywords: ['github'],
|
|
|
|
|
imageUrl: 'https://assets-cdn.github.com/images/icons/emoji/shipit.png?v7'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2017-04-24 01:37:45 +00:00
|
|
|
|
const CATEGORIES = [
|
|
|
|
|
'recent',
|
|
|
|
|
'people',
|
|
|
|
|
'nature',
|
|
|
|
|
'foods',
|
|
|
|
|
'activity',
|
|
|
|
|
'places',
|
|
|
|
|
'objects',
|
|
|
|
|
'symbols',
|
|
|
|
|
'flags',
|
2017-05-27 16:27:47 +00:00
|
|
|
|
'custom',
|
2017-04-24 01:37:45 +00:00
|
|
|
|
]
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
class Example extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
this.state = {
|
|
|
|
|
emojiSize: 24,
|
|
|
|
|
perLine: 9,
|
2016-05-31 23:36:50 +00:00
|
|
|
|
skin: 1,
|
2017-04-23 13:32:03 +00:00
|
|
|
|
native: true,
|
2016-05-31 14:36:52 +00:00
|
|
|
|
set: 'apple',
|
2016-07-15 16:24:50 +00:00
|
|
|
|
hidden: false,
|
2017-06-27 21:24:00 +00:00
|
|
|
|
currentEmoji: { id: '+1' },
|
2017-04-24 01:37:45 +00:00
|
|
|
|
autoFocus: false,
|
|
|
|
|
include: [],
|
|
|
|
|
exclude: [],
|
2016-05-31 14:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleInput(e) {
|
|
|
|
|
var { currentTarget } = e,
|
2017-04-24 01:37:45 +00:00
|
|
|
|
{ type } = currentTarget,
|
2016-05-31 14:36:52 +00:00
|
|
|
|
key = currentTarget.getAttribute('data-key'),
|
2017-04-24 01:37:45 +00:00
|
|
|
|
mount = currentTarget.getAttribute('data-mount'),
|
2016-05-31 14:36:52 +00:00
|
|
|
|
state = {}
|
|
|
|
|
|
2017-02-17 15:49:12 +00:00
|
|
|
|
if (type == 'checkbox') {
|
2017-04-24 01:37:45 +00:00
|
|
|
|
var { checked } = currentTarget,
|
|
|
|
|
value = currentTarget.getAttribute('data-value')
|
|
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
if (checked) {
|
|
|
|
|
state[key] = this.state[key].concat(value)
|
|
|
|
|
} else {
|
|
|
|
|
state[key] = this.state[key].filter((item) => { return item != value })
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
state[key] = checked
|
|
|
|
|
}
|
2017-02-17 15:49:12 +00:00
|
|
|
|
} else {
|
2017-04-24 01:37:45 +00:00
|
|
|
|
var { value } = currentTarget
|
2017-02-17 15:49:12 +00:00
|
|
|
|
state[key] = parseInt(value)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 01:37:45 +00:00
|
|
|
|
if (mount) {
|
|
|
|
|
this.setState({ hidden: true }, () => {
|
|
|
|
|
state.hidden = false
|
|
|
|
|
this.setState(state)
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.setState(state)
|
|
|
|
|
}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return <div>
|
2016-07-29 16:41:22 +00:00
|
|
|
|
<div>
|
|
|
|
|
<h1 className='demo-title'>Emoji Mart</h1>
|
|
|
|
|
|
|
|
|
|
<iframe
|
|
|
|
|
src='https://ghbtns.com/github-btn.html?user=missive&repo=emoji-mart&type=star&count=true'
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
scrolling='0'
|
|
|
|
|
width='170px'
|
|
|
|
|
height='20px'
|
|
|
|
|
></iframe>
|
|
|
|
|
</div>
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
2016-07-29 16:08:30 +00:00
|
|
|
|
<div className="row">
|
2017-05-27 17:52:49 +00:00
|
|
|
|
{['native', 'apple', 'google', 'twitter', 'emojione', 'messenger', 'facebook'].map((set) => {
|
2017-04-23 13:32:03 +00:00
|
|
|
|
var props = { disabled: !this.state.native && set == this.state.set }
|
|
|
|
|
|
|
|
|
|
if (set == 'native' && this.state.native) {
|
|
|
|
|
props.disabled = true
|
|
|
|
|
}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
|
|
|
|
return <button
|
2016-07-29 16:08:30 +00:00
|
|
|
|
key={set}
|
|
|
|
|
value={set}
|
2017-04-23 13:32:03 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
if (set == 'native') {
|
|
|
|
|
this.setState({ native: true })
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({ set: set, native: false })
|
|
|
|
|
}
|
|
|
|
|
}}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
{...props}>
|
2017-04-23 13:32:03 +00:00
|
|
|
|
{set}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
</button>
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-07-29 16:08:30 +00:00
|
|
|
|
<div className="row">
|
2016-07-15 16:24:50 +00:00
|
|
|
|
<button
|
|
|
|
|
onClick={() => this.setState({ hidden: !this.state.hidden })}
|
|
|
|
|
>{this.state.hidden ? 'Mount' : 'Unmount'}</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
<pre style={{
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
margin: '1em',
|
|
|
|
|
width: '460px',
|
|
|
|
|
}}>
|
2016-07-27 15:35:12 +00:00
|
|
|
|
<Operator>import</Operator> {Picker} <Operator>from</Operator> <String>'emoji-mart'</String>
|
2016-05-31 14:36:52 +00:00
|
|
|
|
<br />
|
|
|
|
|
<br /><Operator><</Operator><Variable>Picker</Variable>
|
2017-04-24 01:37:45 +00:00
|
|
|
|
<br /> emojiSize<Operator>=</Operator>{<Variable>{this.state.emojiSize}</Variable>} <input type='range' data-key='emojiSize' data-mount={true} onChange={this.handleInput.bind(this)} min='16' max='64' value={this.state.emojiSize} />
|
2016-06-09 00:22:06 +00:00
|
|
|
|
<br /> perLine<Operator>=</Operator>{<Variable>{this.state.perLine}</Variable>} {this.state.perLine < 10 ? ' ' : ' '} <input type='range' data-key='perLine' onChange={this.handleInput.bind(this)} min='7' max='16' value={this.state.perLine} />
|
2016-05-31 23:36:50 +00:00
|
|
|
|
<br /> skin<Operator>=</Operator>{<Variable>{this.state.skin}</Variable>} <input type='range' data-key='skin' onChange={this.handleInput.bind(this)} min='1' max='6' value={this.state.skin} />
|
2016-10-19 01:21:10 +00:00
|
|
|
|
<br /> set<Operator>=</Operator><String>'{this.state.set}'</String>
|
2017-05-26 08:01:45 +00:00
|
|
|
|
<br /> custom<Operator>=</Operator>{<Variable>{'[…]'}</Variable>}
|
2017-04-24 01:37:45 +00:00
|
|
|
|
<br /> autoFocus<Operator>=</Operator>{<Variable>{this.state.autoFocus ? 'true' : 'false'}</Variable>}{this.state.autoFocus ? ' ' : ''} <input type='checkbox' data-key='autoFocus' data-mount={true} onChange={this.handleInput.bind(this)} checked={this.state.autoFocus} />
|
|
|
|
|
<div style={{ opacity: this.state.exclude.length ? 0.6 : 1 }}> include<Operator>=</Operator>[
|
|
|
|
|
{[0, 2, 4, 6, 8].map((i) => {
|
|
|
|
|
let category1 = CATEGORIES[i],
|
|
|
|
|
category2 = CATEGORIES[i + 1]
|
|
|
|
|
|
|
|
|
|
return <div key={i}>
|
|
|
|
|
<label style={{ width: '200px', display: 'inline-block' }}> <input type='checkbox' data-key='include' data-value={category1} data-mount={true} onChange={this.handleInput.bind(this)} disabled={this.state.exclude.length} /> <String>'{category1}'</String></label>
|
|
|
|
|
{category2 && <label><input type='checkbox' data-key='include' data-value={category2} data-mount={true} onChange={this.handleInput.bind(this)} disabled={this.state.exclude.length} /> <String>'{category2}'</String></label>}
|
|
|
|
|
</div>
|
|
|
|
|
})}
|
|
|
|
|
]
|
|
|
|
|
</div>
|
|
|
|
|
<div style={{ opacity: this.state.include.length ? 0.6 : 1 }}> exclude<Operator>=</Operator>[
|
|
|
|
|
{[0, 2, 4, 6, 8].map((i) => {
|
|
|
|
|
let category1 = CATEGORIES[i],
|
|
|
|
|
category2 = CATEGORIES[i + 1]
|
|
|
|
|
|
|
|
|
|
return <div key={i}>
|
|
|
|
|
<label style={{ width: '200px', display: 'inline-block' }}> <input type='checkbox' data-key='exclude' data-value={category1} data-mount={true} onChange={this.handleInput.bind(this)} disabled={this.state.include.length} /> <String>'{category1}'</String></label>
|
|
|
|
|
{category2 && <label><input type='checkbox' data-key='exclude' data-value={category2} data-mount={true} onChange={this.handleInput.bind(this)} disabled={this.state.include.length} /> <String>'{category2}'</String></label>}
|
|
|
|
|
</div>
|
|
|
|
|
})}
|
|
|
|
|
]
|
|
|
|
|
</div>
|
|
|
|
|
<Operator>/></Operator>
|
2016-05-31 14:36:52 +00:00
|
|
|
|
</pre>
|
|
|
|
|
|
2016-07-15 16:24:50 +00:00
|
|
|
|
{!this.state.hidden &&
|
|
|
|
|
<Picker
|
|
|
|
|
emojiSize={this.state.emojiSize}
|
|
|
|
|
perLine={this.state.perLine}
|
|
|
|
|
skin={this.state.skin}
|
2017-02-17 15:49:12 +00:00
|
|
|
|
native={this.state.native}
|
2016-10-19 01:21:10 +00:00
|
|
|
|
set={this.state.set}
|
2017-05-26 08:01:45 +00:00
|
|
|
|
custom={CUSTOM_EMOJIS}
|
2017-04-24 01:37:45 +00:00
|
|
|
|
autoFocus={this.state.autoFocus}
|
|
|
|
|
include={this.state.include}
|
|
|
|
|
exclude={this.state.exclude}
|
2017-04-23 15:31:40 +00:00
|
|
|
|
onClick={(emoji) => {
|
2017-06-27 21:24:00 +00:00
|
|
|
|
this.setState({ currentEmoji: emoji })
|
2017-04-23 15:31:40 +00:00
|
|
|
|
console.log(emoji)
|
|
|
|
|
}}
|
2016-07-15 16:24:50 +00:00
|
|
|
|
/>
|
|
|
|
|
}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<pre style={{
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
margin: '1em',
|
|
|
|
|
width: '370px',
|
|
|
|
|
}}>
|
|
|
|
|
<Operator>import</Operator> {Emoji} <Operator>from</Operator> <String>'emoji-mart'</String>
|
|
|
|
|
<br />
|
|
|
|
|
<br /><Operator><</Operator><Variable>Emoji</Variable>
|
2017-06-27 21:24:00 +00:00
|
|
|
|
<br /> emoji<Operator>=</Operator>{this.state.currentEmoji.custom ? (<Variable>{'{…}'}</Variable>) : (<String>'{this.state.currentEmoji.id}'</String>)}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
<br /> size<Operator>=</Operator>{<Variable>{64}</Variable>}
|
|
|
|
|
<br /><Operator>/></Operator>
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<span style={{ display: 'inline-block', marginTop: 60 }}>
|
2017-04-23 15:31:40 +00:00
|
|
|
|
{Emoji({
|
2017-06-27 21:24:00 +00:00
|
|
|
|
emoji: this.state.currentEmoji.custom ? this.state.currentEmoji : this.state.currentEmoji.id,
|
2017-04-23 15:31:40 +00:00
|
|
|
|
size: 64,
|
|
|
|
|
set: this.state.set,
|
|
|
|
|
})}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<pre style={{
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
margin: '1em',
|
|
|
|
|
width: '370px',
|
|
|
|
|
}}>
|
|
|
|
|
<br /><Operator><</Operator><Variable>Emoji</Variable>
|
2017-06-27 21:24:00 +00:00
|
|
|
|
<br /> emoji<Operator>=</Operator><String>':{this.state.currentEmoji.id}:'</String>
|
2016-11-01 15:54:46 +00:00
|
|
|
|
<br /> size<Operator>=</Operator>{<Variable>{64}</Variable>}
|
|
|
|
|
<br /><Operator>/></Operator>
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<span style={{ display: 'inline-block', marginTop: 40 }}>
|
2017-04-23 15:31:40 +00:00
|
|
|
|
{Emoji({
|
2017-06-27 21:24:00 +00:00
|
|
|
|
emoji: `:${this.state.currentEmoji.id}:`,
|
2017-04-23 15:31:40 +00:00
|
|
|
|
size: 64,
|
|
|
|
|
set: this.state.set,
|
|
|
|
|
})}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<pre style={{
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
margin: '1em',
|
|
|
|
|
width: '370px',
|
|
|
|
|
}}>
|
|
|
|
|
<br /><Operator><</Operator><Variable>Emoji</Variable>
|
2017-06-27 21:24:00 +00:00
|
|
|
|
<br /> emoji<Operator>=</Operator><String>':{this.state.currentEmoji.id}::skin-tone-3:'</String>
|
2016-11-01 15:54:46 +00:00
|
|
|
|
<br /> size<Operator>=</Operator>{<Variable>{64}</Variable>}
|
|
|
|
|
<br /><Operator>/></Operator>
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<span style={{ display: 'inline-block', marginTop: 40 }}>
|
2017-04-23 15:31:40 +00:00
|
|
|
|
{Emoji({
|
2017-06-27 21:24:00 +00:00
|
|
|
|
emoji: `:${this.state.currentEmoji.id}::skin-tone-3:`,
|
2017-04-23 15:31:40 +00:00
|
|
|
|
size: 64,
|
|
|
|
|
set: this.state.set,
|
|
|
|
|
})}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<pre style={{
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
verticalAlign: 'top',
|
|
|
|
|
margin: '1em',
|
|
|
|
|
width: '370px',
|
|
|
|
|
}}>
|
|
|
|
|
<br /><Operator><</Operator><Variable>Emoji</Variable>
|
2017-06-27 21:24:00 +00:00
|
|
|
|
<br /> emoji<Operator>=</Operator><String>':{this.state.currentEmoji.id}::skin-tone-3:'</String>
|
2016-11-01 15:54:46 +00:00
|
|
|
|
<br /> size<Operator>=</Operator>{<Variable>{64}</Variable>}
|
|
|
|
|
<br /> native<Operator>=</Operator>{<Variable>{'true'}</Variable>}
|
|
|
|
|
<br /><Operator>/></Operator>
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<span style={{ display: 'inline-block', marginTop: 60 }}>
|
2017-04-23 15:31:40 +00:00
|
|
|
|
{Emoji({
|
2017-06-27 21:24:00 +00:00
|
|
|
|
emoji: `:${this.state.currentEmoji.id}::skin-tone-3:`,
|
2017-04-23 15:31:40 +00:00
|
|
|
|
size: 64,
|
|
|
|
|
native: true,
|
|
|
|
|
})}
|
2016-11-01 15:54:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2016-05-31 14:36:52 +00:00
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Operator extends React.Component {
|
|
|
|
|
render() {
|
|
|
|
|
return <span style={{color: '#a71d5d'}}>
|
|
|
|
|
{this.props.children}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Variable extends React.Component {
|
|
|
|
|
render() {
|
|
|
|
|
return <span style={{color: '#0086b3'}}>
|
|
|
|
|
{this.props.children}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class String extends React.Component {
|
|
|
|
|
render() {
|
|
|
|
|
return <span style={{color: '#183691'}}>
|
|
|
|
|
{this.props.children}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReactDOM.render(<Example />, document.querySelector('div'))
|