Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 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 | }); |
| 18 | |
| 19 | type Props = { |
| 20 | question: string, |
| 21 | updateAnswers: Function, |
| 22 | } |
| 23 | |
| 24 | export default function CustomQuestionInput(props: Props): React.ReactElement { |
| 25 | |
| 26 | const classes = userStyles(); |
| 27 | |
| 28 | const {question, updateAnswers} = props; |
| 29 | const [answer, setAnswer] = React.useState(''); |
| 30 | const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
| 31 | setAnswer(e.target.value); |
| 32 | updateAnswers(e.target.value); |
| 33 | }; |
| 34 | const getInnerHtml = ()=> { |
| 35 | return {__html: question}; |
| 36 | } |
| 37 | return ( |
| 38 | <> |
| 39 | <h3 dangerouslySetInnerHTML={getInnerHtml()} className={classes.head}/> |
| 40 | <OutlinedInput |
| 41 | value={answer} |
| 42 | onChange={handleChange} |
| 43 | className={classes.inputArea} |
| 44 | inputProps={{ maxLength: 1000 }} |
| 45 | /> |
| 46 | </> |
| 47 | ); |
| 48 | } |