import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { intlShape, injectIntl } from '../../util/reactIntl'; import { Field } from 'react-final-form'; import classNames from 'classnames'; import { IconReviewStar, ValidationError } from '../../components'; import css from './FieldReviewRating.css'; class FieldReviewRatingComponent extends Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); } handleChange(event) { this.props.input.onChange(event.target.value); } render() { /* eslint-disable no-unused-vars */ const { rootClassName, className, inputRootClass, customErrorText, id, intl, label, input, meta, ...rest } = this.props; /* eslint-enable no-unused-vars */ const { touched, error } = meta; const errorText = customErrorText || error; const fieldMeta = { touched, error: errorText }; const { value, ...restInputProps } = input; const inputProps = { ...restInputProps, type: 'radio', name: 'rating', ...rest }; const classes = classNames(rootClassName || css.root, className); const createStarRating = starCount => { let inputsAndLabels = []; // Star inpu order: reverse order expected (5 -> 1) and also input before label // This is due to CSS selectors. // Sibling combinator (~) selects following siblings, but we want to select previous siblings for (let i = starCount; i > 0; i--) { const inputValue = `${i}`; const starId = `star${i}`; const inputId = `${id}.${starId}`; inputsAndLabels.push( ); inputsAndLabels.push( ); } return inputsAndLabels; }; return (