@explorer02/cfm-survey-sdk 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +140 -33
- package/dist/cli/index.mjs +140 -33
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -1
- package/postinstall.js +8 -5
- package/templates/AGENT.md +62 -17
- package/templates/deploy-wizard-to-s3.sh +52 -0
- package/templates/docs/00-integration/agent-execution-flow.md +281 -0
- package/templates/docs/00-integration/agent-operating-contract.md +260 -0
- package/templates/docs/00-integration/analytics-events-catalog.md +54 -0
- package/templates/docs/00-integration/apply-ui-config.md +365 -0
- package/templates/docs/00-integration/canonical-survey-fixtures.md +94 -0
- package/templates/docs/00-integration/client-integration-guide.md +10 -8
- package/templates/docs/00-integration/client-lib-folder.md +115 -0
- package/templates/docs/00-integration/component-checklist.md +90 -54
- package/templates/docs/00-integration/constraints.md +13 -5
- package/templates/docs/00-integration/custom-field-logic-and-navigation.md +56 -0
- package/templates/docs/00-integration/display-logic-and-navigation.md +16 -1
- package/templates/docs/00-integration/file-upload-aws.md +116 -0
- package/templates/docs/00-integration/logic-fields-catalog.md +105 -0
- package/templates/docs/00-integration/partial-save-and-recovery.md +24 -0
- package/templates/docs/00-integration/progress.md +4 -2
- package/templates/docs/00-integration/question-type-sdk-matrix.md +11 -9
- package/templates/docs/00-integration/setup.md +15 -3
- package/templates/docs/00-integration/skip-logic-and-navigation.md +1 -1
- package/templates/docs/00-integration/survey-lifecycle-analytics.md +1 -1
- package/templates/docs/00-integration/ui-customization-wizard.md +144 -0
- package/templates/docs/00-integration/useSurveySDK.md +35 -1
- package/templates/docs/00-integration/wizard-api.md +134 -0
- package/templates/docs/00-integration/wizard-config-handoff.md +246 -0
- package/templates/docs/00-integration/wizard-preview-build-guide.md +400 -0
- package/templates/docs/00-integration/wizard-question-type-styling.md +195 -0
- package/templates/docs/01-components/01-survey-page.md +18 -8
- package/templates/docs/01-components/02-question.md +2 -2
- package/templates/docs/01-components/03-rating-scale.md +12 -18
- package/templates/docs/01-components/05-csat-matrix-scale.md +18 -26
- package/templates/docs/01-components/06-likert-matrix-scale.md +19 -38
- package/templates/docs/01-components/07-slider-matrix-scale.md +48 -33
- package/templates/docs/01-components/08-file-upload-scale.md +15 -52
- package/templates/docs/01-components/09-custom-slider-track.md +15 -25
- package/templates/docs/01-components/10-header-footer.md +23 -4
- package/templates/docs/01-components/11-progress-bar.md +14 -6
- package/templates/docs/01-components/13-matrix-dropdown.md +28 -33
- package/templates/docs/01-components/17-heatmap-scale.md +4 -4
- package/templates/docs/01-components/18-rank-order-scale.md +24 -31
- package/templates/docs/01-components/19-survey-sticky-chrome.md +79 -0
- package/templates/docs/01-components/README.md +2 -2
- package/templates/docs/02-reference/question-types/10-slider-matrix.md +38 -26
- package/templates/docs/02-reference/question-types/11-file-upload.md +36 -21
- package/templates/docs/02-reference/question-types/README.md +11 -1
- package/templates/docs/02-reference/routing-table.md +1 -0
- package/templates/docs/02-reference/value-derivation.md +1 -1
- package/templates/docs/03-ui-specs/00-question-shell.md +10 -0
- package/templates/docs/03-ui-specs/01-rating.md +28 -2
- package/templates/docs/03-ui-specs/02-radio.md +94 -24
- package/templates/docs/03-ui-specs/03-text.md +12 -1
- package/templates/docs/03-ui-specs/04-csat.md +90 -26
- package/templates/docs/03-ui-specs/06-slider.md +3 -1
- package/templates/docs/03-ui-specs/07-matrix-cfm.md +74 -35
- package/templates/docs/03-ui-specs/08-matrix-csat-rating.md +50 -16
- package/templates/docs/03-ui-specs/09-slider-matrix.md +70 -26
- package/templates/docs/03-ui-specs/10-file-upload.md +52 -20
- package/templates/docs/03-ui-specs/11-text-and-media.md +4 -0
- package/templates/docs/03-ui-specs/12-survey-chrome.md +92 -5
- package/templates/docs/03-ui-specs/13-heatmap.md +21 -3
- package/templates/docs/03-ui-specs/14-rank-order.md +108 -28
- package/templates/docs/03-ui-specs/README.md +11 -7
- package/templates/docs/03-ui-specs/shared/custom-slider-track.md +28 -35
- package/templates/docs/03-ui-specs/shared/matrix-dropdown.md +1 -1
- package/templates/docs/MANIFEST.json +187 -6
- package/templates/docs/index.md +116 -116
- package/templates/docs/templates/CsatMatrixScale.tsx +637 -0
- package/templates/docs/templates/CustomSliderTrack.tsx +144 -0
- package/templates/docs/templates/FileUploadScale.tsx +262 -0
- package/templates/docs/templates/HeatmapScale.tsx +114 -0
- package/templates/docs/templates/LikertMatrixScale.tsx +414 -0
- package/templates/docs/templates/MatrixDropdown.tsx +216 -0
- package/templates/docs/templates/Question.tsx +3 -0
- package/templates/docs/templates/RankOrderScale.tsx +353 -0
- package/templates/docs/templates/RatingScale.tsx +129 -0
- package/templates/docs/templates/SliderMatrixScale.tsx +248 -0
- package/templates/docs/templates/SurveyStickyChrome.tsx +24 -0
- package/templates/docs/templates/customFieldValues.ts +36 -0
- package/templates/docs/templates/implementation_plan.md +75 -8
- package/templates/docs/templates/labelStyles.ts +33 -0
- package/templates/docs/templates/selectionStyles.ts +100 -0
- package/templates/docs/templates/survey-inventory.schema.json +28 -23
- package/templates/docs/templates/surveyUiIcons.tsx +63 -0
- package/templates/docs/templates/surveyUiScaleUtils.ts +51 -0
- package/templates/docs/templates/verify-agent-build.sh +151 -0
- package/templates/preview-harness/preview-bridge.inline.js +201 -0
- package/templates/preview-harness/previewPages.js +108 -0
- package/templates/preview-harness/previewPages.ts +298 -0
- package/templates/preview-harness/vite-app/src/PreviewConfigContext.tsx +67 -0
- package/templates/preview-harness/vite-app/src/QuestionPreview.tsx +122 -0
- package/templates/preview-harness/vite-app/src/SurveyPagePreview.tsx +75 -0
- package/templates/preview-harness/vite-app/src/fixtures/questions.ts +311 -0
- package/templates/preview-harness/vite-app/src/globals.css +16 -0
- package/templates/preview-harness/vite-app/src/mount.tsx +9 -0
- package/templates/preview-harness/vite-app/src/preview-live-overrides.css +101 -0
- package/templates/preview-harness/vite-app/stubs/next-dynamic.tsx +25 -0
- package/templates/preview-harness/vite-app/stubs/next-image.tsx +29 -0
- package/templates/previewBridge.ts +153 -0
- package/templates/survey-theme.css +295 -0
- package/templates/survey-ui-config.schema.json +213 -0
- package/templates/wizard-dist/assets/PreviewMock-DgHfrVeb.js +1 -0
- package/templates/wizard-dist/assets/TypePanel-CFVC3Ptn.js +1 -0
- package/templates/wizard-dist/assets/index-BhWM50Yu.css +1 -0
- package/templates/wizard-dist/assets/index-DYK3X1e5.js +34 -0
- package/templates/wizard-dist/assets/vendor-BwkXDkd3.js +17 -0
- package/templates/wizard-dist/index.html +20 -0
- package/templates/wizard.html +13 -1129
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { CfmMatrixQuestion, MatrixRowAnswers } from '@explorer02/cfm-survey-sdk';
|
|
3
|
+
import { columnSubmitValue } from './surveyUiScaleUtils';
|
|
4
|
+
import MatrixDropdown from './MatrixDropdown';
|
|
5
|
+
|
|
6
|
+
type LikertMatrixScaleProps = {
|
|
7
|
+
question: CfmMatrixQuestion;
|
|
8
|
+
selectedValue?: MatrixRowAnswers;
|
|
9
|
+
onSelect: (value: MatrixRowAnswers) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// ── SUB-COMPONENT: Dropdown Layout ──────────────────────────────────────────
|
|
13
|
+
type DropdownLayoutProps = {
|
|
14
|
+
question: CfmMatrixQuestion;
|
|
15
|
+
selectedValue: MatrixRowAnswers;
|
|
16
|
+
isMultiple: boolean;
|
|
17
|
+
onCellSelect: (rowId: string, colValue: string | number | null | undefined) => void;
|
|
18
|
+
onSelectAll: (value: MatrixRowAnswers) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function LikertMatrixDropdownLayout({
|
|
22
|
+
question,
|
|
23
|
+
selectedValue,
|
|
24
|
+
isMultiple,
|
|
25
|
+
onCellSelect,
|
|
26
|
+
onSelectAll
|
|
27
|
+
}: DropdownLayoutProps) {
|
|
28
|
+
const { statementRows, scaleColumns } = question;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '24px' }}>
|
|
32
|
+
{statementRows.map(row => (
|
|
33
|
+
<div key={row.id} style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
34
|
+
<div style={{ fontSize: '15px', fontWeight: 500, color: '#374151' }} dangerouslySetInnerHTML={{ __html: row.statementText }} />
|
|
35
|
+
<MatrixDropdown
|
|
36
|
+
options={scaleColumns}
|
|
37
|
+
value={isMultiple ? (Array.isArray(selectedValue[row.id]) ? selectedValue[row.id] as any[] : []) : selectedValue[row.id]}
|
|
38
|
+
multiple={isMultiple}
|
|
39
|
+
onChange={(vals) => {
|
|
40
|
+
if (isMultiple) {
|
|
41
|
+
const multiVals = Array.isArray(vals) ? vals : [];
|
|
42
|
+
if (multiVals.length === 0) {
|
|
43
|
+
const next = { ...selectedValue };
|
|
44
|
+
delete next[row.id];
|
|
45
|
+
onSelectAll(next);
|
|
46
|
+
} else {
|
|
47
|
+
onSelectAll({ ...selectedValue, [row.id]: multiVals });
|
|
48
|
+
}
|
|
49
|
+
} else if (!Array.isArray(vals)) {
|
|
50
|
+
onCellSelect(row.id, vals);
|
|
51
|
+
}
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ── SUB-COMPONENT: Carousel Layout ──────────────────────────────────────────
|
|
61
|
+
type CarouselLayoutProps = {
|
|
62
|
+
question: CfmMatrixQuestion;
|
|
63
|
+
selectedValue: MatrixRowAnswers;
|
|
64
|
+
isMultiple: boolean;
|
|
65
|
+
onCellSelect: (rowId: string, colValue: string | number | null | undefined) => void;
|
|
66
|
+
isSelected: (rowId: string, colValue: string | number | null) => boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function LikertMatrixCarouselLayout({
|
|
70
|
+
question,
|
|
71
|
+
selectedValue,
|
|
72
|
+
isMultiple,
|
|
73
|
+
onCellSelect,
|
|
74
|
+
isSelected
|
|
75
|
+
}: CarouselLayoutProps) {
|
|
76
|
+
const { scaleColumns, statementRows } = question;
|
|
77
|
+
const [activeCarouselIndex, setActiveCarouselIndex] = useState(0);
|
|
78
|
+
|
|
79
|
+
const row = statementRows[activeCarouselIndex];
|
|
80
|
+
if (!row) return null;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', backgroundColor: '#fff', borderRadius: '12px', border: '1px solid #e5e5e5', padding: '32px', boxShadow: '0 4px 6px -1px rgba(0,0,0,0.05)', width: '100%', boxSizing: 'border-box' }}>
|
|
84
|
+
<h3 style={{ fontSize: '18px', fontWeight: 500, color: '#111827', marginBottom: '32px', textAlign: 'center' }} dangerouslySetInnerHTML={{ __html: row.statementText }} />
|
|
85
|
+
|
|
86
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: '20px 32px', width: '100%', maxWidth: '800px', marginBottom: '40px', justifyContent: 'center' }}>
|
|
87
|
+
{scaleColumns.map(col => {
|
|
88
|
+
const submitValue = columnSubmitValue(col);
|
|
89
|
+
const selected = isSelected(row.id, submitValue);
|
|
90
|
+
const isNaSelected = isSelected(row.id, null);
|
|
91
|
+
const isDisabled = isNaSelected && submitValue !== null;
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
key={col.id}
|
|
96
|
+
onClick={() => {
|
|
97
|
+
if (isDisabled) return;
|
|
98
|
+
if (!isMultiple && selected) {
|
|
99
|
+
onCellSelect(row.id, undefined);
|
|
100
|
+
} else {
|
|
101
|
+
onCellSelect(row.id, submitValue);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
style={{
|
|
105
|
+
display: 'flex', alignItems: 'center', gap: '12px',
|
|
106
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
107
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
108
|
+
transition: 'opacity 0.15s'
|
|
109
|
+
}}>
|
|
110
|
+
{isMultiple ? (
|
|
111
|
+
<div style={{
|
|
112
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
113
|
+
width: '18px', height: '18px', borderRadius: '4px',
|
|
114
|
+
border: selected ? '2px solid #e20074' : '2px solid #d1d5db',
|
|
115
|
+
backgroundColor: selected ? '#e20074' : '#fff',
|
|
116
|
+
flexShrink: 0, transition: 'all 0.15s'
|
|
117
|
+
}}>
|
|
118
|
+
{selected && (
|
|
119
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
|
|
120
|
+
<polyline points="20 6 9 17 4 12" />
|
|
121
|
+
</svg>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
) : (
|
|
125
|
+
<div style={{
|
|
126
|
+
display: 'flex', width: '18px', height: '18px', flexShrink: 0,
|
|
127
|
+
alignItems: 'center', justifyContent: 'center', borderRadius: '50%',
|
|
128
|
+
border: selected ? '2px solid #e20074' : '1.5px solid #9ca3af',
|
|
129
|
+
backgroundColor: '#fff',
|
|
130
|
+
}}>
|
|
131
|
+
{selected && <div style={{ width: '10px', height: '10px', borderRadius: '50%', backgroundColor: '#e20074' }} />}
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
<span style={{ fontSize: '15px', fontWeight: 400, color: '#374151', userSelect: 'none' }} dangerouslySetInnerHTML={{ __html: col.label }} />
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
})}
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}>
|
|
141
|
+
<button
|
|
142
|
+
type="button"
|
|
143
|
+
disabled={activeCarouselIndex === 0}
|
|
144
|
+
onClick={() => setActiveCarouselIndex(i => i - 1)}
|
|
145
|
+
style={{ padding: '8px', color: activeCarouselIndex === 0 ? '#d1d5db' : '#6b7280', cursor: activeCarouselIndex === 0 ? 'not-allowed' : 'pointer', background: 'none', border: 'none' }}
|
|
146
|
+
>
|
|
147
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>
|
|
148
|
+
</button>
|
|
149
|
+
|
|
150
|
+
<div style={{ display: 'flex', gap: '8px' }}>
|
|
151
|
+
{statementRows.map((_, i) => (
|
|
152
|
+
<div key={i} style={{
|
|
153
|
+
width: '10px', height: '10px', borderRadius: '50%',
|
|
154
|
+
backgroundColor: i === activeCarouselIndex ? '#2563eb' : '#e5e7eb',
|
|
155
|
+
cursor: 'pointer', transition: 'background-color 0.2s'
|
|
156
|
+
}} onClick={() => setActiveCarouselIndex(i)} />
|
|
157
|
+
))}
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
disabled={activeCarouselIndex === statementRows.length - 1}
|
|
163
|
+
onClick={() => setActiveCarouselIndex(i => i + 1)}
|
|
164
|
+
style={{ padding: '8px', color: activeCarouselIndex === statementRows.length - 1 ? '#d1d5db' : '#6b7280', cursor: activeCarouselIndex === statementRows.length - 1 ? 'not-allowed' : 'pointer', background: 'none', border: 'none' }}
|
|
165
|
+
>
|
|
166
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
|
|
167
|
+
</button>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── SUB-COMPONENT: Standard Grid Layout ──────────────────────────────────────
|
|
174
|
+
type GridLayoutProps = {
|
|
175
|
+
question: CfmMatrixQuestion;
|
|
176
|
+
isMultiple: boolean;
|
|
177
|
+
onCellSelect: (rowId: string, colValue: string | number | null | undefined) => void;
|
|
178
|
+
isSelected: (rowId: string, colValue: string | number | null) => boolean;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
function LikertMatrixGridLayout({
|
|
182
|
+
question,
|
|
183
|
+
isMultiple,
|
|
184
|
+
onCellSelect,
|
|
185
|
+
isSelected
|
|
186
|
+
}: GridLayoutProps) {
|
|
187
|
+
const {
|
|
188
|
+
scaleColumns, statementRows, transposeTable = false, repeatColumnHeaders = false,
|
|
189
|
+
showColumnHeaders = true
|
|
190
|
+
} = question;
|
|
191
|
+
|
|
192
|
+
const gridRows = transposeTable ? scaleColumns : statementRows;
|
|
193
|
+
const gridCols = transposeTable ? statementRows : scaleColumns;
|
|
194
|
+
const isBipolar = question.statementLayout === 'bipolar';
|
|
195
|
+
const labels = question.scaleAnchorLabels;
|
|
196
|
+
|
|
197
|
+
const renderHeader = () => {
|
|
198
|
+
const numCols = gridCols.length;
|
|
199
|
+
const hasLabels = isBipolar && labels && labels.length > 0;
|
|
200
|
+
|
|
201
|
+
if (!hasLabels && !showColumnHeaders) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div style={{ display: 'flex', flexDirection: 'column', marginBottom: '16px' }}>
|
|
207
|
+
{hasLabels && (
|
|
208
|
+
<div style={{ display: 'flex', alignItems: 'flex-end', minHeight: '24px', marginBottom: '8px' }}>
|
|
209
|
+
<div style={{ flex: '0 0 25%', paddingRight: '16px', boxSizing: 'border-box' }} />
|
|
210
|
+
<div style={{ flex: 1, position: 'relative', height: '20px' }}>
|
|
211
|
+
{labels.map((lbl, idx) => {
|
|
212
|
+
let leftPos = '50%';
|
|
213
|
+
if (idx === 0) leftPos = `${100 / (2 * numCols)}%`;
|
|
214
|
+
else if (idx === labels.length - 1 && labels.length > 1) leftPos = `${100 - 100 / (2 * numCols)}%`;
|
|
215
|
+
else if (labels.length === 3 && idx === 1) leftPos = '50%';
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<div key={idx} style={{
|
|
219
|
+
position: 'absolute', left: leftPos, transform: 'translateX(-50%)',
|
|
220
|
+
bottom: 0, display: 'flex', justifyContent: 'center', whiteSpace: 'nowrap'
|
|
221
|
+
}}>
|
|
222
|
+
<span style={{ fontSize: '13px', fontWeight: 600, color: '#111827' }}>{lbl}</span>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
})}
|
|
226
|
+
</div>
|
|
227
|
+
<div style={{ flex: '0 0 25%', paddingLeft: '16px', boxSizing: 'border-box' }} />
|
|
228
|
+
</div>
|
|
229
|
+
)}
|
|
230
|
+
{showColumnHeaders && (
|
|
231
|
+
<div style={{ display: 'flex', alignItems: 'flex-end', minHeight: '24px' }}>
|
|
232
|
+
<div style={{ flex: isBipolar ? '0 0 25%' : '0 0 180px', paddingRight: '16px', boxSizing: 'border-box' }} />
|
|
233
|
+
<div style={{ flex: 1, display: 'flex' }}>
|
|
234
|
+
<div style={{ flex: 1, display: 'grid', gridTemplateColumns: `repeat(${gridCols.length}, 1fr)` }}>
|
|
235
|
+
{gridCols.map((col) => (
|
|
236
|
+
<div key={col.id} style={{ display: 'flex', justifyContent: 'center', padding: '0 4px' }}>
|
|
237
|
+
<span style={{ fontSize: '13px', fontWeight: 500, color: '#4b5563', textAlign: 'center', lineHeight: 1.2 }}
|
|
238
|
+
dangerouslySetInnerHTML={{ __html: transposeTable ? ('statementText' in col ? col.statementText : col.label) : ('label' in col ? col.label : (col as { statementText: string }).statementText) }} />
|
|
239
|
+
</div>
|
|
240
|
+
))}
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
{isBipolar && <div style={{ flex: '0 0 25%', paddingLeft: '16px', boxSizing: 'border-box' }} />}
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div style={{ width: '100%' }}>
|
|
252
|
+
{!repeatColumnHeaders && renderHeader()}
|
|
253
|
+
|
|
254
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: repeatColumnHeaders ? '24px' : '0' }}>
|
|
255
|
+
{gridRows.map((rowItem, rowIdx) => {
|
|
256
|
+
return (
|
|
257
|
+
<div key={rowItem.id} style={{ display: 'flex', flexDirection: 'column' }}>
|
|
258
|
+
{repeatColumnHeaders && renderHeader()}
|
|
259
|
+
<div style={{
|
|
260
|
+
display: 'flex', alignItems: 'center', borderRadius: '8px',
|
|
261
|
+
padding: '12px 0', backgroundColor: !repeatColumnHeaders && rowIdx % 2 === 0 ? 'rgba(249, 250, 251, 0.8)' : '#fff',
|
|
262
|
+
boxSizing: 'border-box'
|
|
263
|
+
}}>
|
|
264
|
+
<div style={{ flex: isBipolar ? '0 0 25%' : '0 0 180px', padding: '0 16px', boxSizing: 'border-box' }}>
|
|
265
|
+
<span style={{ fontSize: '14px', fontWeight: 500, color: '#111827', lineHeight: 1.4, wordWrap: 'break-word', display: 'block' }}
|
|
266
|
+
dangerouslySetInnerHTML={{ __html: transposeTable ? ('label' in rowItem ? rowItem.label : '') : ('statementText' in rowItem ? rowItem.statementText : '') }} />
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
<div style={{ flex: 1, display: 'flex', boxSizing: 'border-box' }}>
|
|
270
|
+
<div style={{ flex: 1, display: 'grid', alignItems: 'center', gridTemplateColumns: `repeat(${gridCols.length}, 1fr)` }}>
|
|
271
|
+
{gridCols.map((colItem) => {
|
|
272
|
+
const actualRowId = transposeTable ? colItem.id : rowItem.id;
|
|
273
|
+
const actualColValue = transposeTable
|
|
274
|
+
? columnSubmitValue(rowItem as typeof scaleColumns[number])
|
|
275
|
+
: columnSubmitValue(colItem as typeof scaleColumns[number]);
|
|
276
|
+
const selected = isSelected(actualRowId, actualColValue);
|
|
277
|
+
const isNaSelected = isSelected(actualRowId, null);
|
|
278
|
+
const isDisabled = isNaSelected && actualColValue !== null;
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div key={colItem.id} style={{ display: 'flex', justifyContent: 'center' }}>
|
|
282
|
+
<label style={{
|
|
283
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
284
|
+
opacity: isDisabled ? 0.4 : 1,
|
|
285
|
+
padding: '8px', display: 'flex', alignItems: 'center', justifyContent: 'center'
|
|
286
|
+
}}>
|
|
287
|
+
<input
|
|
288
|
+
type={isMultiple ? "checkbox" : "radio"}
|
|
289
|
+
checked={selected}
|
|
290
|
+
disabled={isDisabled}
|
|
291
|
+
onClick={(e) => {
|
|
292
|
+
if (!isMultiple && selected) {
|
|
293
|
+
onCellSelect(actualRowId, undefined);
|
|
294
|
+
}
|
|
295
|
+
}}
|
|
296
|
+
onChange={(e) => {
|
|
297
|
+
if (isMultiple || !selected) {
|
|
298
|
+
onCellSelect(actualRowId, actualColValue);
|
|
299
|
+
}
|
|
300
|
+
}}
|
|
301
|
+
style={{
|
|
302
|
+
width: '18px', height: '18px', accentColor: '#e20074',
|
|
303
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
304
|
+
...(isMultiple ? { borderRadius: '4px' } : {})
|
|
305
|
+
}}
|
|
306
|
+
/>
|
|
307
|
+
</label>
|
|
308
|
+
</div>
|
|
309
|
+
);
|
|
310
|
+
})}
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
{isBipolar && (
|
|
315
|
+
<div style={{ flex: '0 0 25%', padding: '0 16px', textAlign: 'right', boxSizing: 'border-box' }}>
|
|
316
|
+
<span style={{ fontSize: '14px', fontWeight: 500, color: '#111827', lineHeight: 1.4, wordWrap: 'break-word', display: 'block' }}
|
|
317
|
+
dangerouslySetInnerHTML={{ __html: transposeTable ? '' : ('oppositeStatementText' in rowItem ? rowItem.oppositeStatementText ?? '' : '') }} />
|
|
318
|
+
</div>
|
|
319
|
+
)}
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
);
|
|
323
|
+
})}
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ── ORCHESTRATOR COMPONENT: LikertMatrixScale ────────────────────────────────
|
|
330
|
+
export function LikertMatrixScale({ question, selectedValue = {}, onSelect }: LikertMatrixScaleProps) {
|
|
331
|
+
const { gridLayout = 'standard', selectionMode = 'single' } = question;
|
|
332
|
+
const isMultiple = selectionMode === 'multiple';
|
|
333
|
+
|
|
334
|
+
const handleCellSelect = (rowId: string, colValue: string | number | null | undefined) => {
|
|
335
|
+
if (colValue === undefined) {
|
|
336
|
+
const next = { ...selectedValue };
|
|
337
|
+
delete next[rowId];
|
|
338
|
+
onSelect(next);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (isMultiple) {
|
|
343
|
+
const currentVals = Array.isArray(selectedValue[rowId]) ? selectedValue[rowId] as any[] : [];
|
|
344
|
+
if (colValue === null) {
|
|
345
|
+
if (currentVals.includes(null)) {
|
|
346
|
+
const next = { ...selectedValue };
|
|
347
|
+
delete next[rowId];
|
|
348
|
+
onSelect(next);
|
|
349
|
+
} else {
|
|
350
|
+
onSelect({ ...selectedValue, [rowId]: [null] });
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let nextVals = currentVals.filter(v => v !== null);
|
|
356
|
+
if (nextVals.includes(colValue)) {
|
|
357
|
+
nextVals = nextVals.filter(v => v !== colValue);
|
|
358
|
+
} else {
|
|
359
|
+
nextVals = [...nextVals, colValue];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (nextVals.length === 0) {
|
|
363
|
+
const next = { ...selectedValue };
|
|
364
|
+
delete next[rowId];
|
|
365
|
+
onSelect(next);
|
|
366
|
+
} else {
|
|
367
|
+
onSelect({ ...selectedValue, [rowId]: nextVals });
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
onSelect({ ...selectedValue, [rowId]: colValue });
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const isSelected = (rowId: string, colValue: string | number | null) => {
|
|
375
|
+
const val = selectedValue[rowId];
|
|
376
|
+
if (isMultiple) {
|
|
377
|
+
return Array.isArray(val) && val.includes(colValue);
|
|
378
|
+
}
|
|
379
|
+
return val === colValue;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
if (gridLayout === 'dropdown') {
|
|
383
|
+
return (
|
|
384
|
+
<LikertMatrixDropdownLayout
|
|
385
|
+
question={question}
|
|
386
|
+
selectedValue={selectedValue}
|
|
387
|
+
isMultiple={isMultiple}
|
|
388
|
+
onCellSelect={handleCellSelect}
|
|
389
|
+
onSelectAll={onSelect}
|
|
390
|
+
/>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (gridLayout === 'carousel') {
|
|
395
|
+
return (
|
|
396
|
+
<LikertMatrixCarouselLayout
|
|
397
|
+
question={question}
|
|
398
|
+
selectedValue={selectedValue}
|
|
399
|
+
isMultiple={isMultiple}
|
|
400
|
+
onCellSelect={handleCellSelect}
|
|
401
|
+
isSelected={isSelected}
|
|
402
|
+
/>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return (
|
|
407
|
+
<LikertMatrixGridLayout
|
|
408
|
+
question={question}
|
|
409
|
+
isMultiple={isMultiple}
|
|
410
|
+
onCellSelect={handleCellSelect}
|
|
411
|
+
isSelected={isSelected}
|
|
412
|
+
/>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Portable MatrixDropdown template — copy to src/components/MatrixDropdown.tsx
|
|
5
|
+
* Import SDK from your package.json: @explorer02/cfm-survey-sdk or @repo/sdk
|
|
6
|
+
* UI spec: docs/03-ui-specs/shared/matrix-dropdown.md
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
10
|
+
import type { ScaleColumn } from '@explorer02/cfm-survey-sdk';
|
|
11
|
+
import { matrixColumnStoredValue } from '@explorer02/cfm-survey-sdk';
|
|
12
|
+
|
|
13
|
+
type MatrixDropdownProps = {
|
|
14
|
+
options: ScaleColumn[];
|
|
15
|
+
value: string | number | null | Array<string | number | null> | undefined;
|
|
16
|
+
onChange: (val: string | number | null | Array<string | number | null>) => void;
|
|
17
|
+
multiple?: boolean;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default function MatrixDropdown({
|
|
22
|
+
options,
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
multiple = false,
|
|
26
|
+
placeholder = 'Select Answer',
|
|
27
|
+
}: MatrixDropdownProps) {
|
|
28
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
29
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
33
|
+
if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
|
|
34
|
+
setIsOpen(false);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
38
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const multiValues: Array<string | number | null> = Array.isArray(value) ? value : [];
|
|
42
|
+
const selectedOptionSingle = !multiple
|
|
43
|
+
? options.find(o => matrixColumnStoredValue(o) === value)
|
|
44
|
+
: null;
|
|
45
|
+
|
|
46
|
+
const toggleMultiOption = (val: string | number | null) => {
|
|
47
|
+
if (val === null) {
|
|
48
|
+
if (multiValues.includes(null)) onChange([]);
|
|
49
|
+
else onChange([null]);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let nextVals = multiValues.filter(v => v !== null);
|
|
54
|
+
if (nextVals.includes(val)) {
|
|
55
|
+
nextVals = nextVals.filter(v => v !== val);
|
|
56
|
+
} else {
|
|
57
|
+
nextVals = [...nextVals, val];
|
|
58
|
+
}
|
|
59
|
+
onChange(nextVals);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const removeMultiOption = (e: React.MouseEvent, val: string | number | null) => {
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
onChange(multiValues.filter(v => v !== val));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const renderTrigger = () => {
|
|
68
|
+
if (multiple) {
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
72
|
+
style={{
|
|
73
|
+
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px',
|
|
74
|
+
width: '100%', padding: '10px 14px', backgroundColor: '#fff',
|
|
75
|
+
border: `1px solid ${isOpen ? '#e20074' : '#d1d5db'}`, borderRadius: '8px',
|
|
76
|
+
cursor: 'pointer', transition: 'all 0.2s', minHeight: '44px',
|
|
77
|
+
boxShadow: isOpen ? '0 0 0 3px rgba(226, 0, 116, 0.1)' : '0 1px 2px rgba(0,0,0,0.05)',
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
{multiValues.length === 0 ? (
|
|
81
|
+
<span style={{ fontSize: '15px', color: '#6b7280', flex: 1 }}>{placeholder}</span>
|
|
82
|
+
) : (
|
|
83
|
+
multiValues.map(v => {
|
|
84
|
+
const opt = options.find(o => matrixColumnStoredValue(o) === v);
|
|
85
|
+
return (
|
|
86
|
+
<div
|
|
87
|
+
key={String(v)}
|
|
88
|
+
style={{
|
|
89
|
+
display: 'flex', alignItems: 'center', gap: '6px',
|
|
90
|
+
backgroundColor: '#f3f4f6', padding: '4px 8px', borderRadius: '4px',
|
|
91
|
+
fontSize: '14px', color: '#374151', fontWeight: 500,
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
<span dangerouslySetInnerHTML={{ __html: opt?.label || String(v) }} />
|
|
95
|
+
<div
|
|
96
|
+
onClick={e => removeMultiOption(e, v)}
|
|
97
|
+
style={{
|
|
98
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
99
|
+
width: '16px', height: '16px', borderRadius: '50%', backgroundColor: '#e5e7eb',
|
|
100
|
+
color: '#6b7280', cursor: 'pointer', fontSize: '12px', fontWeight: 'bold',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
×
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
})
|
|
108
|
+
)}
|
|
109
|
+
<div style={{ marginLeft: 'auto' }}>
|
|
110
|
+
<svg
|
|
111
|
+
style={{ width: '18px', height: '18px', color: '#6b7280', transform: isOpen ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform 0.2s' }}
|
|
112
|
+
fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
|
113
|
+
>
|
|
114
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
115
|
+
</svg>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div
|
|
123
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
124
|
+
style={{
|
|
125
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
126
|
+
width: '100%', padding: '14px 16px', backgroundColor: '#fff',
|
|
127
|
+
border: `1px solid ${isOpen ? '#e20074' : '#d1d5db'}`, borderRadius: '8px',
|
|
128
|
+
cursor: 'pointer', transition: 'all 0.2s',
|
|
129
|
+
boxShadow: isOpen ? '0 0 0 3px rgba(226, 0, 116, 0.1)' : '0 1px 2px rgba(0,0,0,0.05)',
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<span
|
|
133
|
+
style={{ fontSize: '15px', color: selectedOptionSingle ? '#111827' : '#6b7280', fontWeight: selectedOptionSingle ? 500 : 400 }}
|
|
134
|
+
dangerouslySetInnerHTML={{ __html: selectedOptionSingle ? selectedOptionSingle.label : placeholder }}
|
|
135
|
+
/>
|
|
136
|
+
<svg
|
|
137
|
+
style={{ width: '18px', height: '18px', color: '#6b7280', transform: isOpen ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform 0.2s' }}
|
|
138
|
+
fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
|
139
|
+
>
|
|
140
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
141
|
+
</svg>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div ref={containerRef} style={{ position: 'relative', width: '100%', userSelect: 'none' }}>
|
|
148
|
+
{renderTrigger()}
|
|
149
|
+
|
|
150
|
+
{isOpen && (
|
|
151
|
+
<div style={{
|
|
152
|
+
position: 'absolute', top: 'calc(100% + 8px)', left: 0, right: 0,
|
|
153
|
+
backgroundColor: '#fff', border: '1px solid #e5e5e5', borderRadius: '8px',
|
|
154
|
+
boxShadow: '0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)',
|
|
155
|
+
zIndex: 50, overflow: 'hidden', maxHeight: '280px', overflowY: 'auto',
|
|
156
|
+
}}>
|
|
157
|
+
{options.map(col => {
|
|
158
|
+
const submitValue = matrixColumnStoredValue(col);
|
|
159
|
+
const isSelected = multiple ? multiValues.includes(submitValue) : value === submitValue;
|
|
160
|
+
const isNaSelected = multiple && multiValues.includes(null);
|
|
161
|
+
const isDisabled = multiple && isNaSelected && submitValue !== null;
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<div
|
|
165
|
+
key={col.id}
|
|
166
|
+
style={{
|
|
167
|
+
padding: '12px 16px', cursor: isDisabled ? 'not-allowed' : 'pointer', transition: 'background-color 0.15s',
|
|
168
|
+
backgroundColor: isSelected ? '#fdf2f8' : '#fff',
|
|
169
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
170
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px',
|
|
171
|
+
}}
|
|
172
|
+
onMouseEnter={e => { if (!isDisabled) e.currentTarget.style.backgroundColor = '#fdf2f8'; }}
|
|
173
|
+
onMouseLeave={e => { if (!isDisabled) e.currentTarget.style.backgroundColor = isSelected ? '#fdf2f8' : '#fff'; }}
|
|
174
|
+
onClick={e => {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
if (isDisabled) return;
|
|
177
|
+
if (multiple) {
|
|
178
|
+
toggleMultiOption(submitValue);
|
|
179
|
+
} else {
|
|
180
|
+
onChange(submitValue);
|
|
181
|
+
setIsOpen(false);
|
|
182
|
+
}
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '12px', flex: 1 }}>
|
|
186
|
+
{multiple && (
|
|
187
|
+
<div style={{
|
|
188
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
189
|
+
width: '18px', height: '18px', borderRadius: '4px',
|
|
190
|
+
border: isSelected ? '2px solid #e20074' : '2px solid #d1d5db',
|
|
191
|
+
backgroundColor: isSelected ? '#e20074' : '#fff',
|
|
192
|
+
flexShrink: 0, transition: 'all 0.15s',
|
|
193
|
+
}}>
|
|
194
|
+
{isSelected && (
|
|
195
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
|
|
196
|
+
<polyline points="20 6 9 17 4 12" />
|
|
197
|
+
</svg>
|
|
198
|
+
)}
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
<span style={{ fontSize: '15px', fontWeight: isSelected ? 600 : 400, color: isSelected ? '#e20074' : '#374151', userSelect: 'none' }}
|
|
202
|
+
dangerouslySetInnerHTML={{ __html: col.label }} />
|
|
203
|
+
</div>
|
|
204
|
+
{!multiple && isSelected && (
|
|
205
|
+
<svg style={{ width: '18px', height: '18px', color: '#e20074', flexShrink: 0 }} fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
206
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M5 13l4 4L19 7" />
|
|
207
|
+
</svg>
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
})}
|
|
212
|
+
</div>
|
|
213
|
+
)}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -103,6 +103,9 @@ export default function Question({
|
|
|
103
103
|
return (
|
|
104
104
|
<section id={question.id} className="space-y-4 rounded-xl border border-gray-200 bg-white p-6 shadow-sm">
|
|
105
105
|
<h2 className="text-lg font-medium leading-relaxed text-gray-900">
|
|
106
|
+
{question.questionNumber != null && (
|
|
107
|
+
<span className="mr-1 font-semibold">{question.questionNumber}.</span>
|
|
108
|
+
)}
|
|
106
109
|
<span dangerouslySetInnerHTML={{ __html: displayQuestionText }} />
|
|
107
110
|
{question.required && <span className="text-red-500 ml-1">*</span>}
|
|
108
111
|
</h2>
|