Commit d24ccceb authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

onChange함수, UI수정

parent 9a60dc8a
import React, { useState } from "react"; import React, { useState } from "react";
import { EssayType, BasicQuestionType } from "./Question"; import { EssayType } from "./Question";
type Props = { type Props = {
element: EssayType; element: EssayType;
questionList: BasicQuestionType[]; QuestionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}; };
export const Q_Assay = ({ element, questionList }: Props) => { export const QAssay = ({ element, QuestionListChange }: Props) => {
console.log(questionList);
return ( return (
<div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2"> <div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2">
<div className="flex h-16 w-full place-content-between items-center"> <div className="flex h-16 w-full place-content-between items-center">
<p className="text-xl font-bold ml-6 border-b-2"> <input
<input type="text" placeholder={element.title}></input> type="text"
</p> name={element.name}
id="title"
className="text-xl font-bold ml-6 border-b-2 w-1/2"
placeholder={element.title}
onChange={QuestionListChange}
></input>
<select <select
id="Questions" id="Questions"
className="w-36 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-themeColor w-full mr-3 p-2.5" className="w-36 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-themeColor w-full mr-3 p-2.5"
...@@ -30,16 +34,18 @@ export const Q_Assay = ({ element, questionList }: Props) => { ...@@ -30,16 +34,18 @@ export const Q_Assay = ({ element, questionList }: Props) => {
<option value="Date">날짜</option> <option value="Date">날짜</option>
</select> </select>
</div> </div>
<div className="flex w-full"> <div className="flex w-full justify-center">
<textarea <input
className="border" type="text"
rows={1} name={element.name}
cols={80} id="comment"
className="border w-11/12"
placeholder="질문에 대한 설명을 입력해주세요" placeholder="질문에 대한 설명을 입력해주세요"
></textarea> onChange={QuestionListChange}
></input>
</div> </div>
<div id="commentarea" className="flex border mt-4"> <div id="commentarea" className="flex mt-4 w-full justify-center">
<textarea className="resize-none" readOnly></textarea> <input className="border w-11/12 h-16" disabled></input>
</div> </div>
<div className="flex w-full justify-end py-2"> <div className="flex w-full justify-end py-2">
<button className="w-1/12">필수</button> <button className="w-1/12">필수</button>
......
...@@ -5,7 +5,7 @@ type Props = { ...@@ -5,7 +5,7 @@ type Props = {
element: CheckboxType; element: CheckboxType;
}; };
export const Q_Checkbox = ({ element }: Props) => ( export const QCheckbox = ({ element }: Props) => (
<div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2"> <div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2">
<div className="flex flexgi-row h-16 w-full place-content-between items-center"> <div className="flex flexgi-row h-16 w-full place-content-between items-center">
<p className="text-xl font-bold ml-6 border-b-2"> <p className="text-xl font-bold ml-6 border-b-2">
......
...@@ -3,14 +3,20 @@ import { RadioType } from "./Question"; ...@@ -3,14 +3,20 @@ import { RadioType } from "./Question";
type Props = { type Props = {
element: RadioType; element: RadioType;
QuestionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}; };
export const Q_Radio = ({ element }: Props) => ( export const QRadio = ({ element, QuestionListChange }: Props) => (
<div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2"> <div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-2">
<div className="flex flexgi-row h-16 w-full place-content-between items-center"> <div className="flex h-16 w-full place-content-between items-center">
<p className="text-xl font-bold ml-6 border-b-2"> <input
<input type="text " placeholder={element.title}></input> type="text"
</p> name={element.name}
id="title"
className="text-xl font-bold ml-6 border-b-2 w-1/2"
placeholder={element.title}
onChange={QuestionListChange}
></input>
<select <select
id="Questions" id="Questions"
className="w-36 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-themeColor focus:themeColor block w-full mr-3 p-2.5" className="w-36 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-themeColor focus:themeColor block w-full mr-3 p-2.5"
...@@ -27,22 +33,26 @@ export const Q_Radio = ({ element }: Props) => ( ...@@ -27,22 +33,26 @@ export const Q_Radio = ({ element }: Props) => (
<option value="Date">날짜</option> <option value="Date">날짜</option>
</select> </select>
</div> </div>
<div className="flex "> <div className="flex w-full justify-center">
<textarea <input
className="border" type="text"
rows={1} name={element.name}
cols={80} id="comment"
className="border w-11/12"
placeholder="질문에 대한 설명을 입력해주세요" placeholder="질문에 대한 설명을 입력해주세요"
></textarea> onChange={QuestionListChange}
></input>
</div> </div>
<div id="commentarea" className="flex mt-4"> <div className="flex mt-4">
{element.content.choices.map((e: string) => ( {element.content.choices.map((e: string) => (
<div> <div>
<input type="radio" id={e} name="choice" value={e} checked={false} /> <input type="radio" id={e} name="choice" value={e} checked={false} />
<input <input
type="text" type="text"
name="content"
className="mx-2 border-b-2" className="mx-2 border-b-2"
placeholder={e} placeholder={e}
onChange={QuestionListChange}
></input> ></input>
<button></button> <button></button>
</div> </div>
......
import React from "react"; import React, { useState } from "react";
import { Q_Assay } from "./Q_Assay"; import { QAssay } from "./QAssay";
import { Q_Checkbox } from "./Q_Checkbox"; import { QCheckbox } from "./QCheckbox";
import { Q_Radio } from "./Q_Radio"; import { QRadio } from "./QRadio";
export interface BasicQuestionType { export interface BasicQuestionType {
type: string; type: string;
name: string; name: string;
title: string; title: string;
isRequired: boolean; isRequired: boolean;
comment: string;
content: any; content: any;
[key: string]: string | number | boolean | any;
} }
export interface EssayType extends BasicQuestionType {} export interface EssayType extends BasicQuestionType {}
let EssayQ: EssayType = {
type: "assay",
name: "Question1",
title: "Question1",
isRequired: false,
content: null,
};
export interface RadioType extends BasicQuestionType { export interface RadioType extends BasicQuestionType {
content: { content: {
hasOther: boolean; hasOther: boolean;
...@@ -27,47 +20,96 @@ export interface RadioType extends BasicQuestionType { ...@@ -27,47 +20,96 @@ export interface RadioType extends BasicQuestionType {
otherText: string; otherText: string;
}; };
} }
let RadioQ: RadioType = { export interface CheckboxType extends BasicQuestionType {
content: {
choices: any[];
maxCount: number;
};
}
const EssayQ: EssayType = {
type: "assay",
name: "Question1",
title: "Question1",
isRequired: false,
comment: "질문에 대한 설명을 입력해주세요",
content: null,
};
const RadioQ: RadioType = {
type: "radio", type: "radio",
name: "Question2", name: "Question2",
title: "Question2", title: "Question2",
isRequired: false, isRequired: false,
comment: "질문에 대한 설명을 입력해주세요",
content: { content: {
hasOther: false, hasOther: false,
otherText: "", otherText: "",
choices: ["1", "2", "3"], choices: ["1", "2", "3"],
}, },
}; };
const CheckboxQ: CheckboxType = {
export interface CheckboxType extends BasicQuestionType {
content: {
choices: any[];
maxCount: number;
};
}
let CheckboxQ: CheckboxType = {
type: "checkbox", type: "checkbox",
name: "Question3", name: "Question3",
title: "Question3", title: "Question3",
isRequired: false, isRequired: false,
comment: "질문에 대한 설명을 입력해주세요",
content: { content: {
choices: ["ch1", "ch2", "ch3"], choices: ["ch1", "ch2", "ch3"],
maxCount: 2, maxCount: 2,
}, },
}; };
let questionList: BasicQuestionType[] = [EssayQ, RadioQ, CheckboxQ]; // const questionList: BasicQuestionType[] = [EssayQ, RadioQ, CheckboxQ];
export const Question = () => ( export const Question = () => {
const [questionList, setQuestionList] = useState<BasicQuestionType[]>([
EssayQ,
RadioQ,
]);
// const [survey, setSurvey] = useState();
function QuestionListChange(e: React.ChangeEvent<HTMLInputElement>): void {
const newList: BasicQuestionType[] = [...questionList];
const targetId: any = e.target.id;
const obj: any = newList.find((a) => a.name === e.target.name);
obj[targetId] = e.target.value;
setQuestionList(newList);
}
return (
<> <>
{console.log(questionList)}
{questionList.map((element) => { {questionList.map((element) => {
if (element.type === "assay") { switch (element.type) {
return <Q_Assay questionList={questionList} element={element} />; case "assay":
} else if (element.type === "radio") { return (
return <Q_Radio element={element} />; <QAssay
} else if (element.type === "checkbox") { element={element}
return <Q_Checkbox element={element} />; QuestionListChange={QuestionListChange}
/>
);
case "radio":
return (
<QRadio
element={element}
QuestionListChange={QuestionListChange}
/>
);
case "checkbox":
return <QCheckbox element={element} />;
default:
break;
} }
// if (element.type === "assay") {
// return (
// <QAssay element={element} QuestionListChange={QuestionListChange} />
// );
// } else if (element.type === "radio") {
// return <QRadio element={element} />;
// } else if (element.type === "checkbox") {
// return <QCheckbox element={element} />;
// }
})} })}
</> </>
); );
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment