parent
f59a890d14
commit
38e7771575
3 changed files with 82 additions and 8 deletions
@ -0,0 +1,68 @@ |
||||
import React, { useEffect, useState } from "react"; |
||||
|
||||
const AnswerSheet = ({questionsQuantity, optionsQuantity }) => { |
||||
const [data, setData] = useState([]); |
||||
const [options, setOptions] = useState([]); |
||||
useEffect(() => { |
||||
let array = []; |
||||
let optionsArray = []; |
||||
for(var i =1; i <= questionsQuantity; i++){ |
||||
array.push({ |
||||
questionId : i, |
||||
answer: null, |
||||
}); |
||||
} |
||||
for(var i =1; i<= optionsQuantity; i++){ |
||||
optionsArray.push({ |
||||
id: i, |
||||
active: false, |
||||
}) |
||||
} |
||||
setOptions(optionsArray); |
||||
setData(array) |
||||
console.log(data, options) |
||||
}, []) |
||||
|
||||
return( |
||||
<div className="w-full flex flex-col border border-gray-200 rounded-xl bg-white"> |
||||
{ |
||||
data.map((item, index) => ( |
||||
<div className="w-full flex items-center justify-between h-14 border-b border-gray-200"> |
||||
<p className="w-14 flex items-center h-full justify-center border-l border-gray-200"> |
||||
{item.questionId} |
||||
</p> |
||||
<form className="flex w-full h-full px-8 items-center justify-between border-l border-gray-200"> |
||||
|
||||
{ |
||||
options.map( |
||||
(option) => ( |
||||
|
||||
<p type='radio' value={option.id} className={`w-8 h-6 rounded-full border border-gray-400 cursor-pointer ${option.id == item.answer ? 'bg-green-500' : 'bg-white'}`} onClick={() => { |
||||
var newArray = [...data]; |
||||
|
||||
newArray[index].answer = option.id; |
||||
|
||||
setData(newArray) |
||||
console.log(data) |
||||
}} /> |
||||
|
||||
|
||||
) |
||||
) |
||||
} |
||||
|
||||
</form> |
||||
|
||||
|
||||
<div className="w-32 "> |
||||
نمره : ۱ |
||||
</div> |
||||
|
||||
</div> |
||||
)) |
||||
} |
||||
</div> |
||||
) |
||||
} |
||||
|
||||
export default AnswerSheet |
Loading…
Reference in new issue