Advertisement
Guest User

Untitled

a guest
Jan 11th, 2022
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import React, { useState } from "react";
  2. import { Field } from "formik";
  3. import styles from "./Style_SurveyCheckbox";
  4. import { useMediaQuery, mobileQuery } from "../../helpers/mediaQuery";
  5. import whiteCheck from '../../assets/icons/whiteCheck.svg';
  6.  
  7. const SurveyCheck = ({label, setAnswer, answer, name}) => {
  8.  
  9. const [checked, setChecked] = useState(false);
  10. let btn_class = checked ? styles.surveyCheckbox : {...styles.surveyCheckbox, backgroundColor: "transparent"};
  11. let isMobile = useMediaQuery(mobileQuery);
  12.  
  13. return (
  14. <label style={{...styles.checkLabel, ...isMobile && styles.mobCheckLabel }}>
  15. <span style={{ ...btn_class, ...styles.span }}>
  16. <img
  17. style={styles.img}
  18. src={whiteCheck} alt='whiteCheck'/>
  19. <Field
  20. style={styles.defaultCheck}
  21. type="checkbox"
  22. name={name}
  23. // value={value}
  24. onClick={() => {
  25. console.log("label:", label);
  26. setChecked(!checked);
  27. setAnswer((prevState)=>[...prevState, label])
  28. console.log("answers:", answer)
  29. if(answer.includes(label)) {
  30. setAnswer(answer.filter(answer => answer !== label))
  31. } else {
  32. setAnswer([...answer, label])
  33. }
  34. }}
  35. />
  36. </span>
  37. <div style={{
  38. ...styles.checkDiv,
  39. ...isMobile && styles.checkDivMobile
  40. }}
  41. >
  42. {label}
  43. </div>
  44. </label>
  45. );
  46. };
  47.  
  48. export default SurveyCheck;
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement