Question.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import * as React from 'react';
  2. import { Remove as RemoveIcon, Add as AddIcon } from '@mui/icons-material';
  3. import {
  4. Card,CardContent,Avatar,Checkbox,List,Tooltip,Fade,
  5. ListItem,ListItemButton,ListItemIcon,ListItemText,
  6. } from '@mui/material'
  7. import { deepPurple } from '@mui/material/colors';
  8. function CheckboxexHeader(prop) {
  9. return (
  10. <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
  11. <ListItem>
  12. <Avatar sx={{ bgcolor: deepPurple[500] }}>{prop.group}</Avatar>
  13. <ListItemButton role={undefined} dense>
  14. <ListItemText style={{marginRight :25, color:'silver'}} primary={prop.title} />
  15. <ListItemIcon>
  16. <AddIcon />
  17. </ListItemIcon>
  18. <ListItemIcon>
  19. <RemoveIcon />
  20. </ListItemIcon>
  21. </ListItemButton>
  22. </ListItem>
  23. </List>
  24. );
  25. }
  26. function CheckboxesGroup(props) {
  27. const [checkA, setCheckA] = React.useState(0);
  28. const [checkB, setCheckB] = React.useState(0);
  29. const changeA = (event) => {
  30. let { id } = event.target
  31. if(parseInt( checkB ) !== parseInt(id) ){
  32. setCheckA(parseInt( id ))
  33. }
  34. };
  35. const changeB = (event) => {
  36. let { id } = event.target
  37. if(parseInt( checkA ) !== parseInt( id )){
  38. setCheckB(parseInt( id ))
  39. }
  40. };
  41. return (
  42. <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
  43. {props.quiz.map((value) => {
  44. const labelId = `checkbox-list-label-${value.id}`;
  45. return (
  46. <ListItem key={value.id}>
  47. <ListItemButton dense>
  48. <Tooltip title={value.decription} placement="top-start" arrow>
  49. <ListItemText
  50. sx={{
  51. '& .MuiTypography-root' : {
  52. fontWeight:'bold'
  53. }}}
  54. className="checkbox_label_question"
  55. id={labelId}
  56. primary={value.nombre}
  57. />
  58. </Tooltip>
  59. <ListItemIcon>
  60. <Checkbox
  61. id={value.id.toString()}
  62. sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }}
  63. color="error"
  64. edge="start"
  65. disableRipple
  66. inputProps={{ 'aria-labelledby': value.id }}
  67. checked={parseInt( checkA ) === parseInt( value.id )}
  68. onChange={changeA}
  69. />
  70. </ListItemIcon>
  71. <ListItemIcon>
  72. <Checkbox
  73. id={value.id.toString()}
  74. sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }}
  75. color="error"
  76. edge="start"
  77. disableRipple
  78. inputProps={{ 'aria-labelledby': value.id }}
  79. checked={parseInt( checkB ) === parseInt( value.id )}
  80. onChange={changeB}
  81. />
  82. </ListItemIcon>
  83. </ListItemButton>
  84. </ListItem>
  85. );
  86. })}
  87. </List>
  88. );
  89. }
  90. export function Question({quiz, index, current}) {
  91. let { instrucciondepregunta, respuestas} = quiz
  92. let checked = index === current;
  93. return (
  94. <Fade in={checked} unmountOnExit>
  95. <Card className="question_form">
  96. <CardContent>
  97. <div variant="body2">
  98. <List>
  99. <CheckboxexHeader group={index} title={instrucciondepregunta}/>
  100. </List>
  101. <CheckboxesGroup quiz={respuestas} />
  102. </div>
  103. </CardContent>
  104. </Card>
  105. </Fade>
  106. );
  107. }