emoji-mart-lazyload/example/index.js

234 lines
6.8 KiB
JavaScript
Raw Normal View History

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
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,
native: true,
2016-05-31 14:36:52 +00:00
set: 'apple',
hidden: false,
currentEmoji: 'thumbsup',
2016-05-31 14:36:52 +00:00
}
}
handleInput(e) {
var { currentTarget } = e,
2017-02-17 15:49:12 +00:00
{ value, type, checked } = currentTarget,
2016-05-31 14:36:52 +00:00
key = currentTarget.getAttribute('data-key'),
state = {}
2017-02-17 15:49:12 +00:00
if (type == 'checkbox') {
state[key] = checked
} else {
state[key] = parseInt(value)
}
2016-05-31 14:36:52 +00:00
this.setState(state)
}
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">
{['native', 'apple', 'google', 'twitter', 'emojione'].map((set) => {
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}
onClick={() => {
if (set == 'native') {
this.setState({ native: true })
} else {
this.setState({ set: set, native: false })
}
}}
2016-05-31 14:36:52 +00:00
{...props}>
{set}
2016-05-31 14:36:52 +00:00
</button>
})}
</div>
2016-07-29 16:08:30 +00:00
<div className="row">
<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> &#123;Picker&#125; <Operator>from</Operator> <String>'emoji-mart'</String>
2016-05-31 14:36:52 +00:00
<br />
<br /><Operator>&lt;</Operator><Variable>Picker</Variable>
<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} />
2016-06-09 00:22:06 +00:00
<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} />
2016-05-31 23:36:50 +00:00
<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 /> set<Operator>=</Operator><String>'{this.state.set}'</String>
2016-05-31 14:36:52 +00:00
<br /> onClick<Operator>=</Operator>&#123;(<Variable>emoji</Variable>) => console.log(<Variable>emoji</Variable>)&#125;
<br /><Operator>/&gt;</Operator>
</pre>
{!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}
set={this.state.set}
onClick={(emoji) => {
this.setState({ currentEmoji: emoji.id })
console.log(emoji)
}}
/>
}
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> &#123;Emoji&#125; <Operator>from</Operator> <String>'emoji-mart'</String>
<br />
<br /><Operator>&lt;</Operator><Variable>Emoji</Variable>
<br /> emoji<Operator>=</Operator><String>'thumbsup'</String>
<br /> size<Operator>=</Operator>&#123;<Variable>{64}</Variable>&#125;
<br /><Operator>/&gt;</Operator>
</pre>
<span style={{ display: 'inline-block', marginTop: 60 }}>
{Emoji({
emoji: this.state.currentEmoji,
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>&lt;</Operator><Variable>Emoji</Variable>
<br /> emoji<Operator>=</Operator><String>':thumbsup:'</String>
<br /> size<Operator>=</Operator>&#123;<Variable>{64}</Variable>&#125;
<br /><Operator>/&gt;</Operator>
</pre>
<span style={{ display: 'inline-block', marginTop: 40 }}>
{Emoji({
emoji: `:${this.state.currentEmoji}:`,
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>&lt;</Operator><Variable>Emoji</Variable>
<br /> emoji<Operator>=</Operator><String>':thumbsup::skin-tone-3:'</String>
<br /> size<Operator>=</Operator>&#123;<Variable>{64}</Variable>&#125;
<br /><Operator>/&gt;</Operator>
</pre>
<span style={{ display: 'inline-block', marginTop: 40 }}>
{Emoji({
emoji: `:${this.state.currentEmoji}::skin-tone-3:`,
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>&lt;</Operator><Variable>Emoji</Variable>
<br /> emoji<Operator>=</Operator><String>':thumbsup::skin-tone-3:'</String>
<br /> size<Operator>=</Operator>&#123;<Variable>{64}</Variable>&#125;
<br /> native<Operator>=</Operator>&#123;<Variable>{'true'}</Variable>&#125;
<br /><Operator>/&gt;</Operator>
</pre>
<span style={{ display: 'inline-block', marginTop: 60 }}>
{Emoji({
emoji: `:${this.state.currentEmoji}::skin-tone-3:`,
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'))