Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import React from 'react'
import { EMPTY_STRING, toFunction } from 'exotic'
import { RatingsProps } from './typings'
import {
  renderCount as defaultRenderCount,
  renderEmpty as defaultRenderEmpty,
  renderStarList as defaultRenderStarList,
  renderTotal as defaultRenderTotal,
  renderWrap as defaultRenderWrap,
} from './renderProps'

class Rating extends React.PureComponent<RatingsProps> {
  // seo
  static schema = 'https://schema.org/Rating'
  static defaultProps = {
    // styled
    className: '',
    renderWrap: defaultRenderWrap,
    // count
    shouldShowCount: true,
    renderCount: defaultRenderCount,
    count: 12,
    // value
    value: 4.5,
    renderTotal: defaultRenderTotal,
    renderStarList: defaultRenderStarList,
    // empty
    renderEmpty: defaultRenderEmpty,
  }

  render() {
    const {
      count,
      value,
      renderWrap,
      renderCount,
      renderEmpty,
      renderStarList,
      renderTotal,
      shouldShowCount,
    } = this.props

    const formattedCount = shouldShowCount && renderCount(this.props, count)
    const totalView = renderTotal(this.props, formattedCount)

    const shouldShowStar = Boolean(count || value)
    const starView =
      count || value ? renderStarList(this.props) : renderEmpty(this.props)

    const children = [totalView, starView]
    return renderWrap({ ...this.props, children })
  }
}

export { Rating }
export default Rating