Sha256: dda0611ce6f56936fbaeb816288f631ce6c31f98958301c0b20e1489f028d8b3

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

/* @flow */

import React from 'react'
import Icon from '../Icon/Icon'
import classnames from 'classnames'

import styles from './grade.scss'

type Props = {
  className: string,
  label: string,
  grade: number,
  starFullAt: number,
  starEmptyAt: number,
}

const gradeToStarIconName = (grade: number, starFullAt: number, starEmptyAt: number): string => {
  if (grade >= starFullAt) { return 'trophy-alt' }
  if (grade <= starEmptyAt) { return 'star' }

  return 'star-half'
}

class Grade extends React.Component<Props> {
  static defaultProps = {
    starFullAt: 10,
    starEmptyAt: 0,
    label: 'Grade'
  }
  props: Props

  render() {
    const { grade, label, starFullAt, starEmptyAt, className } = this.props
    const classes = [
      className,
      styles.grade
    ]

    return (
      <div className={classnames(classes)}>
        <Icon
            className={styles.star}
            label=""
            name={gradeToStarIconName(grade, starFullAt, starEmptyAt)}
        />
        <div>
          <p>{grade}</p>
          <label>{label}</label>
        </div>
      </div>
    )
  }
}

export default Grade

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
playbook_ui-2.7.2 components/Grade/Grade.jsx
playbook_ui-2.7.1 components/Grade/Grade.jsx
playbook_ui-2.7.0 components/Grade/Grade.jsx
playbook_ui-2.6.0 components/Grade/Grade.jsx
playbook_ui-2.5.0 components/Grade/Grade.jsx
nitro_sg-3.0.2 components/Grade/Grade.jsx