Skip to content

Commit 94cfe37

Browse files
authored
Merge pull request #32 from surveyjs/creator-nextjs-demo-fix-styling
Fix UI rendering and styles and survey creation dates
2 parents 9c2c4ba + 2275de9 commit 94cfe37

File tree

9 files changed

+87
-133
lines changed

9 files changed

+87
-133
lines changed

blogpost-apps/nextjs-form-builder/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"next": "15.4.1",
1515
"react": "19.1.0",
1616
"react-dom": "19.1.0",
17-
"survey-core": "2.2.5",
18-
"survey-creator-core": "2.2.5",
19-
"survey-creator-react": "2.2.5",
20-
"survey-pdf": "2.2.5",
21-
"survey-react-ui": "2.2.5"
17+
"survey-core": "2.2.6",
18+
"survey-creator-core": "2.2.6",
19+
"survey-creator-react": "2.2.6",
20+
"survey-pdf": "2.2.6",
21+
"survey-react-ui": "2.2.6"
2222
},
2323
"devDependencies": {
2424
"@eslint/eslintrc": "^3",
Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1 @@
11
@import "tailwindcss";
2-
3-
:root {
4-
--background: #ffffff;
5-
--foreground: #171717;
6-
}
7-
8-
@media (prefers-color-scheme: dark) {
9-
:root {
10-
--background: #0a0a0a;
11-
--foreground: #ededed;
12-
}
13-
}
14-
15-
html,
16-
body {
17-
max-width: 100vw;
18-
overflow-x: hidden;
19-
}
20-
21-
body {
22-
color: var(--foreground);
23-
background: var(--background);
24-
font-family: Arial, Helvetica, sans-serif;
25-
-webkit-font-smoothing: antialiased;
26-
-moz-osx-font-smoothing: grayscale;
27-
}
28-
29-
* {
30-
box-sizing: border-box;
31-
padding: 0;
32-
margin: 0;
33-
}
34-
35-
a {
36-
color: inherit;
37-
text-decoration: none;
38-
}
39-
40-
@media (prefers-color-scheme: dark) {
41-
html {
42-
color-scheme: dark;
43-
}
44-
}

blogpost-apps/nextjs-form-builder/src/app/page.tsx

Lines changed: 69 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const FormBuilderComponent = dynamic(() => import('@/components/FormBuilder'), {
1717
const STORAGE_KEY = 'surveyjs-form-definitions';
1818

1919
export default function Home() {
20+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2021
const [surveyJson, setSurveyJson] = useState<any>(null);
22+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2123
const [savedSurveys, setSavedSurveys] = useState<any[]>([]);
2224
const [currentSurveyName, setCurrentSurveyName] = useState<string>('');
2325
const [isLoading, setIsLoading] = useState(true);
@@ -28,15 +30,19 @@ export default function Home() {
2830
const savedList = saved ? JSON.parse(saved) : [];
2931

3032
const preloaded = [courseEvaluationForm, healthAndWellnessAssessment, marketResearchForm, volunteerSignUpForm, websiteUsabilityForm];
31-
const merged = [...preloaded, ...savedList.filter(s => !preloaded.some(p => p.id === s.id))];
33+
const merged = [
34+
...preloaded,
35+
...savedList.filter((s: { id: string }) => !preloaded.some(p => p.id === s.id))
36+
];
37+
3238

3339
setSavedSurveys(merged);
3440
setIsLoading(false);
3541
}
3642

3743
loadInitialSurveys();
3844
}, []);
39-
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4046
const handleSurveyChange = useCallback((json: any) => {
4147
setSurveyJson(json);
4248
}, []);
@@ -60,7 +66,7 @@ export default function Home() {
6066
setCurrentSurveyName('');
6167
alert('Survey saved successfully!');
6268
}, [surveyJson, currentSurveyName, savedSurveys]);
63-
69+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6470
const loadSurvey = useCallback((survey: any) => {
6571
setSurveyJson(survey.json);
6672
setCurrentSurveyName(survey.name);
@@ -87,86 +93,75 @@ export default function Home() {
8793

8894
return (
8995
<div className="min-h-screen bg-gray-50">
90-
{/* Header */}
91-
<header className="bg-white shadow-sm border-b border-gray-200 py-6">
92-
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
93-
<div className="flex flex-col sm:flex-row sm:justify-between sm:items-center space-y-4 sm:space-y-0">
94-
<h1 className="text-2xl font-bold text-gray-900">SurveyJS Form Builder</h1>
95-
<div className="flex items-center gap-x-6">
96-
<input
97-
type="text"
98-
placeholder="Enter survey name..."
99-
value={currentSurveyName}
100-
onChange={(e) => setCurrentSurveyName(e.target.value)}
101-
className="px-5 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 w-64"
102-
/>
96+
<div className="flex h-[calc(100vh-6rem)]">
97+
<aside className="hidden lg:block xl:w-96 bg-white shadow-sm border-r border-gray-200 overflow-y-auto p-4">
98+
<div className="flex justify-between items-center mb-4">
99+
<h2 className="font-medium text-gray-800 tracking-wide uppercase text-[17px]">
100+
Saved Surveys
101+
</h2>
102+
{savedSurveys.length > 0 && (
103103
<button
104-
onClick={saveSurvey}
105-
className="px-10 py-5 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 transition"
104+
onClick={clearAllSurveys}
105+
className="cursor-pointer text-red-600 hover:text-red-800 transition text-[17px]"
106106
>
107-
Save Survey
107+
Clear All
108108
</button>
109-
</div>
109+
)}
110110
</div>
111-
</div>
112-
</header>
113111

114-
<div className="flex h-[calc(100vh-6rem)]">
115-
{/* Sidebar */}
116-
<aside className="w-80 bg-white shadow-sm border-r border-gray-200 overflow-y-auto">
117-
<div className="p-6">
118-
<div className="flex justify-between items-center mb-12 px-2">
119-
<h2 className="text-lg font-semibold text-gray-900">Saved Surveys</h2>
120-
{savedSurveys.length > 0 && (
121-
<button
122-
onClick={clearAllSurveys}
123-
className="text-sm text-red-600 hover:text-red-800 transition"
124-
>
125-
Clear All
126-
</button>
127-
)}
128-
</div>
112+
<div className="flex flex-col gap-4 mb-8">
113+
<input
114+
type="text"
115+
placeholder="Enter survey name"
116+
value={currentSurveyName}
117+
onChange={(e) => setCurrentSurveyName(e.target.value)}
118+
className="px-2 py-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-base"
119+
/>
120+
<button
121+
onClick={saveSurvey}
122+
className="cursor-pointer py-3 px-2 bg-blue-600 text-white text-base font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 transition"
123+
>
124+
Save Survey
125+
</button>
126+
</div>
129127

130-
{savedSurveys.length === 0 ? (
131-
<p className="text-gray-500 text-sm">No saved surveys yet.</p>
132-
) : (
133-
<div className="space-y-6">
134-
{savedSurveys.map((survey) => (
135-
<div
136-
key={survey.id}
137-
className="p-5 bg-gray-50 rounded-lg hover:bg-gray-100 transition"
138-
>
139-
<div className="flex justify-between items-start gap-6">
140-
<div className="flex-1">
141-
<h3 className="font-medium text-gray-900 mb-2">{survey.name}</h3>
142-
<p className="text-sm text-gray-500">
143-
Created: {new Date(survey.createdAt).toLocaleDateString()}
144-
</p>
145-
</div>
146-
<div className="flex gap-4 ml-2">
147-
<button
148-
onClick={() => loadSurvey(survey)}
149-
className="text-blue-600 hover:text-blue-800 text-sm transition"
150-
>
151-
Load
152-
</button>
153-
<button
154-
onClick={() => deleteSurvey(survey.id)}
155-
className="text-red-600 hover:text-red-800 text-sm transition"
156-
>
157-
Delete
158-
</button>
159-
</div>
128+
{savedSurveys.length === 0 ? (
129+
<p className="text-gray-500">No saved surveys yet.</p>
130+
) : (
131+
<div>
132+
{savedSurveys.map((survey) => (
133+
<div key={survey.id} className="mb-6">
134+
<div className="flex justify-between items-start">
135+
<div className="flex-1 pr-8">
136+
<h3 className="font-medium text-gray-900 mb-1 text-base">
137+
{survey.name}
138+
</h3>
139+
<p className="text-gray-500">
140+
Created: {new Date(survey.createdAt).toLocaleDateString()}
141+
</p>
142+
</div>
143+
<div className="flex flex-row items-center gap-3 min-w-[70px]">
144+
<button
145+
onClick={() => loadSurvey(survey)}
146+
className="cursor-pointer text-blue-600 hover:text-blue-800 transition py-1"
147+
>
148+
Load
149+
</button>
150+
<button
151+
onClick={() => deleteSurvey(survey.id)}
152+
className="cursor-pointer text-red-600 hover:text-red-800 transition py-1"
153+
>
154+
Delete
155+
</button>
160156
</div>
161157
</div>
162-
))}
163-
</div>
164-
)}
165-
</div>
158+
</div>
159+
))}
160+
</div>
161+
)}
166162
</aside>
167163

168-
{/* Main Content */}
169-
<main className="flex-1 p-8">
164+
<main className="flex-1 overflow-y-auto">
170165
<FormBuilderComponent
171166
onSaveSurvey={handleSurveyChange}
172167
json={surveyJson}
@@ -175,4 +170,4 @@ export default function Home() {
175170
</div>
176171
</div>
177172
);
178-
}
173+
}

blogpost-apps/nextjs-form-builder/src/components/FormBuilder.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function addCustomTheme(theme: ICreatorTheme, userFriendlyThemeName: string) {
3232
addCustomTheme(creatorTheme, 'Custom Theme');
3333

3434
const defaultCreatorOptions: ICreatorOptions = {
35-
showTranslationTab: true
35+
showTranslationTab: true,
36+
showThemeTab: true
3637
};
3738

3839
export default function FormBuilderComponent(props: {
@@ -82,6 +83,7 @@ export default function FormBuilderComponent(props: {
8283
visible: new ComputedUpdater(() => creator.activeTab === 'preview'),
8384
enabled: true,
8485
action: () => {
86+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8587
const surveyModel = (creator.getPlugin("preview") as any).model.survey as SurveyModel;
8688
savePdf(surveyModel);
8789
}

blogpost-apps/nextjs-form-builder/src/formSamples/courseEvaluationForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ const courseEvaluationSurvey = {
164164
id: 'courseEvaluationForm',
165165
name: "Course Evaluation Form",
166166
json: courseEvaluationForm,
167-
createdAt: "2023-01-01T00:00:00.000Z",
168-
updatedAt: "2023-01-01T00:00:00.000Z"
167+
createdAt: "2025-01-01T00:00:00.000Z",
168+
updatedAt: "2025-01-01T00:00:00.000Z"
169169
};
170170

171171
export default courseEvaluationSurvey;

blogpost-apps/nextjs-form-builder/src/formSamples/healthAndWellnessAssessment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ const healthWellnessForm = {
221221
id: 'healthWellnessForm',
222222
name: "Health and Wellness Survey",
223223
json: healthWellnessFormJson,
224-
createdAt: "2023-01-01T00:00:00.000Z",
225-
updatedAt: "2023-01-01T00:00:00.000Z"
224+
createdAt: "2025-01-01T00:00:00.000Z",
225+
updatedAt: "2025-01-01T00:00:00.000Z"
226226
};
227227

228228
export default healthWellnessForm;

blogpost-apps/nextjs-form-builder/src/formSamples/marketResearchForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ const marketResearchForm = {
137137
id: 'marketResearchForm',
138138
name: "Market Research Form",
139139
json: marketResearchFormJson,
140-
createdAt: "2023-01-01T00:00:00.000Z",
141-
updatedAt: "2023-01-01T00:00:00.000Z"
140+
createdAt: "2025-01-01T00:00:00.000Z",
141+
updatedAt: "2025-01-01T00:00:00.000Z"
142142
};
143143

144144
export default marketResearchForm;

blogpost-apps/nextjs-form-builder/src/formSamples/volunteerSignUpForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ const volunteerSignUpForm = {
133133
id: 'volunteerSignUpForm',
134134
name: "Volunteer Sign Up Form",
135135
json: volunteerSignUpFormJson,
136-
createdAt: "2023-01-01T00:00:00.000Z",
137-
updatedAt: "2023-01-01T00:00:00.000Z"
136+
createdAt: "2025-01-01T00:00:00.000Z",
137+
updatedAt: "2025-01-01T00:00:00.000Z"
138138
};
139139

140140
export default volunteerSignUpForm;

blogpost-apps/nextjs-form-builder/src/formSamples/websiteUsabilityForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ const websiteUsabilityForm = {
179179
id: 'websiteUsabilityForm',
180180
name: "Website Usability Form",
181181
json: websiteUsabilityFormJson,
182-
createdAt: "2023-01-01T00:00:00.000Z",
183-
updatedAt: "2023-01-01T00:00:00.000Z"
182+
createdAt: "2025-01-01T00:00:00.000Z",
183+
updatedAt: "2025-01-01T00:00:00.000Z"
184184
};
185185

186186
export default websiteUsabilityForm;

0 commit comments

Comments
 (0)