emoji-mart-lazyload/src/components/skins.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-06-09 00:22:06 +00:00
import React from 'react'
import PropTypes from 'prop-types'
2016-06-09 00:22:06 +00:00
export default class Skins extends React.Component {
constructor(props) {
super(props)
this.state = {
opened: false,
}
}
handleClick(skin) {
var { onChange } = this.props
if (!this.state.opened) {
this.setState({ opened: true })
} else {
this.setState({ opened: false })
if (skin != this.props.skin) {
onChange(skin)
}
2016-06-09 00:22:06 +00:00
}
}
render() {
var { skin } = this.props,
{ opened } = this.state
return <div>
2016-07-27 15:35:12 +00:00
<div className={`emoji-mart-skin-swatches ${opened ? 'emoji-mart-skin-swatches-opened' : ''}`}>
2017-06-23 09:29:01 +00:00
{/* Use Array.prototype.fill() when it is more widely supported. */}
{[...Array(6)].map((_, i) => {
2016-06-09 00:22:06 +00:00
var skinTone = i + 1,
selected = skinTone == skin
2016-07-27 15:35:12 +00:00
return <span key={`skin-tone-${skinTone}`} className={`emoji-mart-skin-swatch ${selected ? 'emoji-mart-skin-swatch-selected' : ''}`}>
2016-06-09 00:22:06 +00:00
<span
onClick={() => this.handleClick(skinTone)}
2016-07-27 15:35:12 +00:00
className={`emoji-mart-skin emoji-mart-skin-tone-${skinTone}`}>
2016-06-09 00:22:06 +00:00
</span>
</span>
})}
</div>
</div>
}
}
Skins.propTypes = {
onChange: PropTypes.func,
skin: PropTypes.number.isRequired,
2016-06-09 00:22:06 +00:00
}
Skins.defaultProps = {
onChange: (() => {}),
}