import React from 'react' import PropTypes from 'prop-types' import SVGs from '../svgs' export default class Anchors extends React.PureComponent { constructor(props) { super(props) let defaultCategory = props.categories.filter( (category) => category.first, )[0] this.state = { selected: defaultCategory.name, } this.handleClick = this.handleClick.bind(this) } getSVG(id) { this.SVGs || (this.SVGs = {}) if (this.SVGs[id]) { return this.SVGs[id] } else { let svg = ` ${SVGs[id]} ` this.SVGs[id] = svg return svg } } handleClick(e) { var index = e.currentTarget.getAttribute('data-index') var { categories, onAnchorClick } = this.props onAnchorClick(categories[index], index) } render() { var { categories, onAnchorClick, color, i18n } = this.props, { selected } = this.state return (
{categories.map((category, i) => { var { id, name, anchor } = category, isSelected = name == selected if (anchor === false) { return null } return (
) })}
) } } Anchors.propTypes = { categories: PropTypes.array, onAnchorClick: PropTypes.func, } Anchors.defaultProps = { categories: [], onAnchorClick: () => {}, }