2016-06-02 15:26:48 +00:00
|
|
|
import React from 'react'
|
2017-05-05 01:38:03 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2017-09-29 18:33:08 +00:00
|
|
|
import SVGs from '../svgs'
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2017-09-29 14:46:29 +00:00
|
|
|
export default class Anchors extends React.PureComponent {
|
2016-06-02 15:26:48 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
2017-11-09 06:34:35 +00:00
|
|
|
let defaultCategory = props.categories.filter(category => category.first)[0]
|
2016-07-08 17:56:29 +00:00
|
|
|
|
2016-06-02 15:26:48 +00:00
|
|
|
this.state = {
|
2017-10-07 04:02:02 +00:00
|
|
|
selected: defaultCategory.name,
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
2017-09-29 14:46:29 +00:00
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this)
|
|
|
|
}
|
|
|
|
|
2017-11-09 06:34:35 +00:00
|
|
|
getSVG(name) {
|
|
|
|
this.SVGs || (this.SVGs = {})
|
|
|
|
|
|
|
|
if (this.SVGs[name]) {
|
|
|
|
return this.SVGs[name]
|
|
|
|
} else {
|
|
|
|
let svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
|
|
${SVGs[name]}
|
|
|
|
</svg>`
|
|
|
|
|
|
|
|
this.SVGs[name] = svg
|
|
|
|
return svg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
handleClick(e) {
|
2017-09-29 14:46:29 +00:00
|
|
|
var index = e.currentTarget.getAttribute('data-index')
|
|
|
|
var { categories, onAnchorClick } = this.props
|
|
|
|
|
|
|
|
onAnchorClick(categories[index], index)
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-10-27 03:22:59 +00:00
|
|
|
var { categories, onAnchorClick, color, i18n } = this.props,
|
2017-10-07 04:02:02 +00:00
|
|
|
{ selected } = this.state
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
return (
|
|
|
|
<div className="emoji-mart-anchors">
|
|
|
|
{categories.map((category, i) => {
|
|
|
|
var { name, anchor } = category,
|
2017-09-29 18:33:08 +00:00
|
|
|
isSelected = name == selected
|
2016-07-08 17:56:29 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
if (anchor === false) {
|
|
|
|
return null
|
|
|
|
}
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
return (
|
|
|
|
<span
|
|
|
|
key={name}
|
|
|
|
title={i18n.categories[name.toLowerCase()]}
|
|
|
|
data-index={i}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
className={`emoji-mart-anchor ${isSelected
|
|
|
|
? 'emoji-mart-anchor-selected'
|
|
|
|
: ''}`}
|
|
|
|
style={{ color: isSelected ? color : null }}
|
|
|
|
>
|
2017-11-09 06:34:35 +00:00
|
|
|
<div dangerouslySetInnerHTML={{ __html: this.getSVG(name) }} />
|
2017-10-07 04:02:02 +00:00
|
|
|
<span
|
|
|
|
className="emoji-mart-anchor-bar"
|
|
|
|
style={{ backgroundColor: color }}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Anchors.propTypes = {
|
2017-05-05 01:38:03 +00:00
|
|
|
categories: PropTypes.array,
|
|
|
|
onAnchorClick: PropTypes.func,
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Anchors.defaultProps = {
|
|
|
|
categories: [],
|
2017-10-07 04:02:02 +00:00
|
|
|
onAnchorClick: () => {},
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|