-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSurveyCreator.tsx
37 lines (30 loc) · 1.16 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
36
37
'use client'
import { useState } from "react";
import { ICreatorOptions } from "survey-creator-core";
import { SurveyCreatorComponent, SurveyCreator } from "survey-creator-react";
import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";
// Enable Ace Editor in the JSON Editor tab
import "ace-builds/src-noconflict/ace";
import "ace-builds/src-noconflict/ext-searchbox";
import { json as defaultJson } from "../../data/survey_json";
const defaultCreatorOptions: ICreatorOptions = {
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>
);
}