-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSurveyCreator.tsx
35 lines (28 loc) · 1.05 KB
/
SurveyCreator.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use client'
import { useState } from "react";
import { ICreatorOptions } from "survey-creator-core";
import { SurveyCreatorComponent, SurveyCreator } from "survey-creator-react";
import "survey-core/defaultV2.css";
import "survey-creator-core/survey-creator-core.css";
import { json as defaultJson } from "../../data/survey_json";
const defaultCreatorOptions: ICreatorOptions = {
showLogicTab: true,
showTranslationTab: true
};
export default function SurveyCreatorWidget(props: { json?: Object, options?: ICreatorOptions }) {
let [creator, setCreator] = useState<SurveyCreator>();
if (!creator) {
creator = new SurveyCreator(props.options || defaultCreatorOptions);
creator.saveSurveyFunc = (no: number, callback: (num: number, status: boolean) => void) => {
console.log(JSON.stringify(creator?.JSON));
callback(no, true);
};
setCreator(creator);
}
creator.JSON = props.json || defaultJson;
return (
<div style={{ height: "80vh", width: "100%" }}>
<SurveyCreatorComponent creator={creator} />
</div>
);
}