Adrià Vilanova MartÃnez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import React from 'react'; |
| 6 | import OutlinedInput from "@material-ui/core/OutlinedInput"; |
| 7 | import {makeStyles} from '@material-ui/styles'; |
| 8 | |
| 9 | const userStyles = makeStyles({ |
| 10 | head: { |
| 11 | marginTop: '1.5rem', |
| 12 | fontSize: '1rem' |
| 13 | }, |
| 14 | inputArea: { |
| 15 | width: '100%', |
| 16 | }, |
| 17 | tip: { |
| 18 | margin: '0.5rem 0' |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | type Props = { |
| 23 | question: string, |
| 24 | tip?: string, |
| 25 | updateAnswers: Function, |
| 26 | } |
| 27 | |
| 28 | export default function CustomQuestionTextarea(props: Props): React.ReactElement { |
| 29 | |
| 30 | const classes = userStyles(); |
| 31 | |
| 32 | const {question, updateAnswers, tip} = props; |
| 33 | const [answer, setAnswer] = React.useState(''); |
| 34 | const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
| 35 | setAnswer(e.target.value); |
| 36 | updateAnswers(e.target.value); |
| 37 | }; |
| 38 | |
| 39 | const getQuestionInnerHtml = ()=> { |
| 40 | return {__html: question}; |
| 41 | } |
| 42 | |
| 43 | const getTipInnerHtml = ()=> { |
| 44 | return {__html: tip}; |
| 45 | } |
| 46 | return ( |
| 47 | <> |
| 48 | <h3 dangerouslySetInnerHTML={getQuestionInnerHtml()} className={classes.head}/> |
| 49 | {tip? <div dangerouslySetInnerHTML={getTipInnerHtml()} className={classes.tip}/> : null} |
| 50 | <OutlinedInput |
| 51 | multiline={true} |
| 52 | rows={3} |
| 53 | value={answer} |
| 54 | onChange={handleChange} |
| 55 | className={classes.inputArea} |
| 56 | /> |
| 57 | </> |
| 58 | ); |
| 59 | } |