{"size": 1198, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "bukinoshita/react-hash-avatar", "max_stars_repo_stars_event_min_datetime": "2017-05-23T08:48:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-02T04:41:03.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "bukinoshita/react-hash-avatar", "max_issues_repo_issues_event_min_datetime": "2017-06-12T22:08:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-01T18:22:10.000Z", "max_forks_repo_path": "index.js", "max_forks_repo_name": "bukinoshita/react-hash-avatar", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 9, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 27.2272727273, "max_line_length": 94, "alphanum_fraction": 0.6093489149}
// Packages
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import hash from 'string-hash'
import color from 'tinycolor2'

class ReactHashAvatar extends PureComponent {
  render() {
    const { name, height, width, radius } = this.props

    const n = hash(name)
    const c1 = color({ h: n % 360, s: 0.95, l: 0.5 })
    const c1_ = c1.toHexString()
    const c2 = c1.triad()[1].toHexString()

    return (
      <svg width={width} height={height} style={{ borderRadius: radius }} viewBox="0 0 80 80">
        <defs>
          <linearGradient x1="0%" y1="0%" x2="100%" y2="100%" id={name}>
            <stop stopColor={c1_} offset="0%"></stop>
            <stop stopColor={c2} offset="100%"></stop>
          </linearGradient>
        </defs>
        <g stroke="none" strokeWidth="1" fill="none">
          <rect fill={`url(#${name})`} x="0" y="0" width="80" height="80" />
        </g>
      </svg>
    )
  }
}

ReactHashAvatar.defaultProps = {
  radius: 0
}

ReactHashAvatar.propTypes = {
  name: PropTypes.string.isRequired,
  height: PropTypes.string.isRequired,
  width: PropTypes.string.isRequired,
  radius: PropTypes.string
}

export default ReactHashAvatar
