Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import './pictureCard.css'
  3. import '../../../../app.css'
  4. import MaterialIcon from 'react-google-material-icons'
  5. import { connect } from 'react-redux'
  6. import { Field, reduxForm, formValueSelector } from 'redux-form'
  7.  
  8. class PictureCard extends Component {
  9. constructor(props) {
  10. super(props)
  11. this.state = {
  12. isChecked: ''
  13. }
  14. }
  15.  
  16. handleTick = () => {
  17. this.setState(prevState => {
  18. return { isChecked: !prevState.isChecked }
  19. })
  20. }
  21.  
  22. render() {
  23. const {
  24. tabOrder,
  25. cardName,
  26. cardKey,
  27. cardLabel,
  28. thumbnail,
  29. thumbnailAlt
  30. } = this.props
  31.  
  32. return (
  33. <li
  34. className={
  35. this.props.ReduxValue1 === cardLabel ||
  36. this.props.ReduxValue2 === cardLabel
  37. ? 'question__choice question__checkbox--selected'
  38. : 'question__choice'
  39. }
  40. tabIndex={tabOrder}
  41. onChange={this.handleTick}
  42. >
  43. <Field
  44. name={cardName}
  45. type="radio"
  46. component="input"
  47. value={cardLabel}
  48. />
  49. <div className="question__tick-wrap">
  50. <MaterialIcon icon="check" />
  51. </div>
  52. {thumbnail === undefined ? null : (
  53. <div className="question__image-wrap">
  54. <img src={thumbnail} alt={thumbnailAlt} />
  55. </div>
  56. )}
  57. <div className="question__text-wrap flex flex--center-vertical">
  58. <div className="question__label">
  59. <div className="question__letter">
  60. <span>{cardKey}</span>
  61. </div>
  62. </div>
  63. <div className="question__text-label">{cardLabel}</div>
  64. </div>
  65. <div className="question__bg" />
  66. </li>
  67. )
  68. }
  69. }
  70.  
  71. // Decorate with redux-form
  72. PictureCard = reduxForm({
  73. form: 'wizard' // a unique identifier for this form
  74. })(PictureCard)
  75.  
  76. // Decorate with connect to read form values
  77. const selector = formValueSelector('wizard') // <-- same as form name
  78. PictureCard = connect(state => {
  79. // can select values individually
  80. const ReduxValue1 = selector(state, 'di-gender')
  81. const ReduxValue2 = selector(state, 'di-handedness')
  82. return {
  83. ReduxValue1,
  84. ReduxValue2
  85. }
  86. })(PictureCard)
  87.  
  88. export default PictureCard
Add Comment
Please, Sign In to add comment