react-native-my-survey-sdk 3.1.3 β 4.0.0
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/components/XeboDropdownView.d.ts +6 -2
- package/dist/components/XeboDropdownView.d.ts.map +1 -1
- package/dist/components/XeboDropdownView.js +26 -17
- package/dist/components/XeboMultiNPSView.d.ts +4 -2
- package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
- package/dist/components/XeboMultiNPSView.js +24 -17
- package/dist/components/XeboMultiRatingView.d.ts +4 -2
- package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
- package/dist/components/XeboMultiRatingView.js +23 -16
- package/dist/components/XeboMultipleChoiceView.d.ts +6 -2
- package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboMultipleChoiceView.js +35 -38
- package/dist/components/XeboNPSView.d.ts +8 -2
- package/dist/components/XeboNPSView.d.ts.map +1 -1
- package/dist/components/XeboNPSView.js +303 -45
- package/dist/components/XeboPageView.d.ts +33 -0
- package/dist/components/XeboPageView.d.ts.map +1 -0
- package/dist/components/XeboPageView.js +190 -0
- package/dist/components/XeboRatingView.d.ts +20 -2
- package/dist/components/XeboRatingView.d.ts.map +1 -1
- package/dist/components/XeboRatingView.js +63 -37
- package/dist/components/XeboSingleChoiceView.d.ts +8 -2
- package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
- package/dist/components/XeboSingleChoiceView.js +42 -40
- package/dist/components/XeboSurveyModal.d.ts.map +1 -1
- package/dist/components/XeboSurveyModal.js +151 -35
- package/dist/components/XeboTextBoxView.d.ts +4 -2
- package/dist/components/XeboTextBoxView.d.ts.map +1 -1
- package/dist/components/XeboTextBoxView.js +27 -18
- package/dist/core/XeboLanguageService.d.ts.map +1 -1
- package/dist/core/XeboLanguageService.js +6 -0
- package/dist/core/XeboNetworkService.d.ts +12 -1
- package/dist/core/XeboNetworkService.d.ts.map +1 -1
- package/dist/core/XeboNetworkService.js +181 -64
- package/dist/core/XeboOfflineQueue.d.ts +2 -1
- package/dist/core/XeboOfflineQueue.d.ts.map +1 -1
- package/dist/core/XeboOfflineQueue.js +24 -10
- package/dist/core/XeboSurveyManager.d.ts +16 -1
- package/dist/core/XeboSurveyManager.d.ts.map +1 -1
- package/dist/core/XeboSurveyManager.js +120 -47
- package/dist/i18n/XeboRtl.d.ts +5 -0
- package/dist/i18n/XeboRtl.d.ts.map +1 -1
- package/dist/i18n/XeboRtl.js +11 -0
- package/dist/i18n/XeboStrings.d.ts +6 -0
- package/dist/i18n/XeboStrings.d.ts.map +1 -1
- package/dist/i18n/XeboStrings.js +19 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/models/XeboAPIModels.d.ts +93 -0
- package/dist/models/XeboAPIModels.d.ts.map +1 -1
- package/dist/models/XeboModels.d.ts +86 -2
- package/dist/models/XeboModels.d.ts.map +1 -1
- package/dist/models/XeboModels.js +24 -0
- package/package.json +3 -4
|
@@ -38,12 +38,45 @@ const react_1 = __importStar(require("react"));
|
|
|
38
38
|
const react_native_1 = require("react-native");
|
|
39
39
|
const XeboModels_1 = require("../models/XeboModels");
|
|
40
40
|
const XeboTheme_1 = require("../theme/XeboTheme");
|
|
41
|
+
const XeboRatingView_1 = require("./XeboRatingView");
|
|
41
42
|
const XeboStrings_1 = require("../i18n/XeboStrings");
|
|
42
43
|
const XeboRtl_1 = require("../i18n/XeboRtl");
|
|
43
44
|
// NPS zone colors β matches iOS SDK defaults
|
|
44
45
|
const DETRACTOR_COLOR = '#F24236';
|
|
45
46
|
const PASSIVE_COLOR = '#FFC208';
|
|
46
47
|
const PROMOTER_COLOR = '#2ECC70';
|
|
48
|
+
// Fill colors of the platform's default 'animated_nps' style (detractor sampled from the web).
|
|
49
|
+
const ANIMATED_DETRACTOR_COLOR = '#CD1B3C';
|
|
50
|
+
// Emoji per score for the emoji NPS styles, matching the web's sequence from 0 to 10.
|
|
51
|
+
const NPS_EMOJIS = ['π£', 'π', 'π¦', 'π«', 'π', 'π³', 'π', 'π', 'π', 'π', 'π'];
|
|
52
|
+
// Arc style colours sampled from the web: unpicked zones, and the fill from 0 to the picked score.
|
|
53
|
+
// Passive/promoter fills are darker shades chosen to match; only the detractor fill was sampled.
|
|
54
|
+
function arcZoneColor(score) {
|
|
55
|
+
if (score <= 6)
|
|
56
|
+
return '#EB8281';
|
|
57
|
+
if (score <= 8)
|
|
58
|
+
return '#FFDB94';
|
|
59
|
+
return '#99E5C5';
|
|
60
|
+
}
|
|
61
|
+
// 'nps_arc' segment colours from 0 to 10, sampled from the web.
|
|
62
|
+
const NPS_ARC_SEGMENT_COLORS = [
|
|
63
|
+
'#DF3F2C', '#E13F2C', '#E44139', '#E65454', '#E96D6E', '#EB8281',
|
|
64
|
+
'#EF9E9E', '#FAB847', '#F8A630', '#A1C320', '#809B16',
|
|
65
|
+
];
|
|
66
|
+
function arcFillColor(score) {
|
|
67
|
+
if (score <= 6)
|
|
68
|
+
return '#E65454';
|
|
69
|
+
if (score <= 8)
|
|
70
|
+
return '#FFC24D';
|
|
71
|
+
return '#4CC99A';
|
|
72
|
+
}
|
|
73
|
+
// 'animated_nps' fill per cell from 0 to 10, sampled from the web. Its bar blends between zones;
|
|
74
|
+
// 9 carries the orangeβgreen blend because a gradient needs an extra dependency.
|
|
75
|
+
const ANIMATED_NPS_COLORS = [
|
|
76
|
+
ANIMATED_DETRACTOR_COLOR, ANIMATED_DETRACTOR_COLOR, ANIMATED_DETRACTOR_COLOR, ANIMATED_DETRACTOR_COLOR,
|
|
77
|
+
ANIMATED_DETRACTOR_COLOR, ANIMATED_DETRACTOR_COLOR, ANIMATED_DETRACTOR_COLOR,
|
|
78
|
+
'#F59601', '#F59700', '#C19204', '#40860E',
|
|
79
|
+
];
|
|
47
80
|
function npsColor(score, npsLabels) {
|
|
48
81
|
var _a, _b, _c;
|
|
49
82
|
if (score <= 6)
|
|
@@ -62,10 +95,16 @@ function isColorDark(hex) {
|
|
|
62
95
|
const b = parseInt(m[3], 16) / 255;
|
|
63
96
|
return 0.299 * r + 0.587 * g + 0.114 * b < 0.5;
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
98
|
+
exports.XeboNPSView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, onFitHeight, embedded, onSelect }, ref) => {
|
|
99
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
100
|
const theme = (0, XeboTheme_1.getTheme)();
|
|
68
|
-
const
|
|
101
|
+
const scrollHeights = (0, react_1.useRef)({ layout: 0, content: 0 });
|
|
102
|
+
const reportFit = () => {
|
|
103
|
+
const { layout, content } = scrollHeights.current;
|
|
104
|
+
if (layout > 0 && content > 0)
|
|
105
|
+
onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
|
|
106
|
+
};
|
|
107
|
+
const [selectedScore, setSelectedScore] = (0, react_1.useState)(() => { var _a, _b; return (0, XeboModels_1.scaleIndex)(question, (_b = (_a = question.previousAnswer) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.colId); });
|
|
69
108
|
const [followUpText, setFollowUpText] = (0, react_1.useState)('');
|
|
70
109
|
const [followUpChoice, setFollowUpChoice] = (0, react_1.useState)(null);
|
|
71
110
|
const [error, setError] = (0, react_1.useState)('');
|
|
@@ -79,29 +118,187 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
79
118
|
react_native_1.Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
80
119
|
]).start();
|
|
81
120
|
};
|
|
121
|
+
// Animated style: white cells; picking a score fills 0..score and keeps the picked cell raised.
|
|
122
|
+
const isAnimated = question.npsStyle === 'animated_nps';
|
|
123
|
+
// 'default' is the platform's uncoloured style: white cells, grey highlight on the picked one.
|
|
124
|
+
const isPlain = question.npsStyle === 'default';
|
|
125
|
+
// 'graphical' (gauge), 'nps_arc', 'nps_arc_emoji': 0β10 round a ring coloured by NPS zone,
|
|
126
|
+
// 30Β° apart with 5 on top, filled from 0 to the picked score. All but 'nps_arc' show an emoji.
|
|
127
|
+
const isArc = ['graphical', 'nps_arc', 'nps_arc_emoji'].includes((_a = question.npsStyle) !== null && _a !== void 0 ? _a : '');
|
|
128
|
+
// Emoji styles (e.g. 'emojis_flat'): one emoji per score in a bordered cell, sized so all 11 fit.
|
|
129
|
+
const isEmoji = !!((_b = question.npsStyle) === null || _b === void 0 ? void 0 : _b.includes('emoji')) && !isArc;
|
|
130
|
+
const holdsRaised = isAnimated || isPlain || isEmoji;
|
|
131
|
+
const { width: windowWidth } = (0, react_native_1.useWindowDimensions)();
|
|
132
|
+
const emojiSize = Math.min(28, ((windowWidth - 40 - 30) / 11) * 0.8);
|
|
133
|
+
const gaugeSize = Math.min(260, windowWidth - 80);
|
|
134
|
+
// A 262Β° horseshoe of 11 segments split by thin lines.
|
|
135
|
+
// 'nps_arc': fixed-colour segments, white numbers, β on the picked one.
|
|
136
|
+
// 'nps_arc_emoji': grey segments with a face over each number; the picked segment darkens.
|
|
137
|
+
const renderSegmentedArc = (withFaces) => {
|
|
138
|
+
const c = gaugeSize / 2;
|
|
139
|
+
const band = gaugeSize * 0.2;
|
|
140
|
+
const bandRadius = c - band / 2;
|
|
141
|
+
const span = 262;
|
|
142
|
+
const slice = span / 11;
|
|
143
|
+
const strips = 12;
|
|
144
|
+
const stripDeg = slice / strips;
|
|
145
|
+
const stripLen = (c * stripDeg * Math.PI) / 180 + 1;
|
|
146
|
+
const dot = 34;
|
|
147
|
+
const faceSize = gaugeSize * 0.075;
|
|
148
|
+
const at = (deg, w, h, r = bandRadius) => {
|
|
149
|
+
const a = (deg * Math.PI) / 180;
|
|
150
|
+
return { left: c + r * Math.sin(a) - w / 2, top: c - r * Math.cos(a) - h / 2 };
|
|
151
|
+
};
|
|
152
|
+
const startOf = (i) => -span / 2 + i * slice;
|
|
153
|
+
const segmentColor = (i) => {
|
|
154
|
+
if (!withFaces)
|
|
155
|
+
return NPS_ARC_SEGMENT_COLORS[i];
|
|
156
|
+
return selectedScore === i ? '#AEB3BF' : '#EDEEF3';
|
|
157
|
+
};
|
|
158
|
+
const parts = [];
|
|
159
|
+
for (let i = 0; i < 11; i += 1) {
|
|
160
|
+
for (let k = 0; k < strips; k += 1) {
|
|
161
|
+
const deg = startOf(i) + (k + 0.5) * stripDeg;
|
|
162
|
+
parts.push(<react_native_1.View key={`s${i}-${k}`} style={[
|
|
163
|
+
styles.arcDot,
|
|
164
|
+
at(deg, stripLen, band),
|
|
165
|
+
{ width: stripLen, height: band, backgroundColor: segmentColor(i), transform: [{ rotate: `${deg}deg` }] },
|
|
166
|
+
]}/>);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const divider = withFaces ? { width: 1, color: '#E5E3F9' } : { width: 2, color: theme.backgroundColor };
|
|
170
|
+
for (let i = 1; i < 11; i += 1) {
|
|
171
|
+
const deg = startOf(i);
|
|
172
|
+
parts.push(<react_native_1.View key={`d${i}`} style={[
|
|
173
|
+
styles.arcDot,
|
|
174
|
+
at(deg, divider.width, band + 2),
|
|
175
|
+
{ width: divider.width, height: band + 2, backgroundColor: divider.color, transform: [{ rotate: `${deg}deg` }] },
|
|
176
|
+
]}/>);
|
|
177
|
+
}
|
|
178
|
+
// The horseshoe's lowest point is its end corners at Β±131Β°, so trim the empty space below.
|
|
179
|
+
const height = c + c * Math.cos(((180 - span / 2) * Math.PI) / 180) + 2;
|
|
180
|
+
return (<react_native_1.View style={[styles.gauge, { width: gaugeSize, height }]}>
|
|
181
|
+
{parts}
|
|
182
|
+
{Array.from({ length: 11 }, (_, i) => {
|
|
183
|
+
const deg = startOf(i) + slice / 2;
|
|
184
|
+
const selected = selectedScore === i;
|
|
185
|
+
if (withFaces) {
|
|
186
|
+
// Red frown for 0β6, yellow frown for 7β8, green smile for 9β10.
|
|
187
|
+
const face = i <= 6 ? { index: 0, color: '#ED464E' } : i <= 8 ? { index: 1, color: '#E5BB4F' } : { index: 3, color: '#6CA077' };
|
|
188
|
+
// Face sits in the outer part of the segment, the number in the inner part.
|
|
189
|
+
return (<react_1.default.Fragment key={i}>
|
|
190
|
+
<react_native_1.View style={[styles.arcDot, at(deg, faceSize, faceSize, c - band * 0.4)]}>
|
|
191
|
+
<XeboRatingView_1.FlatEmoji index={face.index} color={face.color} featureColor="#6E351D" size={faceSize} selected hasSelection={false}/>
|
|
192
|
+
</react_native_1.View>
|
|
193
|
+
<react_native_1.Text style={[styles.arcDot, styles.arcFaceNumber, at(deg, 24, 16, c - band * 0.84)]}>{i}</react_native_1.Text>
|
|
194
|
+
<react_native_1.TouchableOpacity onPress={() => handleScorePress(i)} activeOpacity={0.7} style={[styles.arcDot, at(deg, band, band), { width: band, height: band }]}/>
|
|
195
|
+
</react_1.default.Fragment>);
|
|
196
|
+
}
|
|
197
|
+
return (<react_native_1.TouchableOpacity key={i} onPress={() => handleScorePress(i)} activeOpacity={0.7} style={[styles.gaugeNumber, at(deg, dot, dot), { width: dot, height: dot }]}>
|
|
198
|
+
<react_native_1.Text style={[styles.gaugeNumberText, { color: '#FFFFFF', fontSize: 15 }]}>{i}</react_native_1.Text>
|
|
199
|
+
{selected && (<react_native_1.View style={styles.arcCheck}>
|
|
200
|
+
<react_native_1.Text style={[styles.arcCheckText, { color: NPS_ARC_SEGMENT_COLORS[i] }]}>β</react_native_1.Text>
|
|
201
|
+
</react_native_1.View>)}
|
|
202
|
+
</react_native_1.TouchableOpacity>);
|
|
203
|
+
})}
|
|
204
|
+
</react_native_1.View>);
|
|
205
|
+
};
|
|
206
|
+
// No SVG dependency: the band is short rotated segments (straight cuts between zones);
|
|
207
|
+
// the picked fill adds round caps at its two ends, like the web.
|
|
208
|
+
const renderArc = () => {
|
|
209
|
+
if (question.npsStyle === 'nps_arc')
|
|
210
|
+
return renderSegmentedArc(false);
|
|
211
|
+
if (question.npsStyle === 'nps_arc_emoji')
|
|
212
|
+
return renderSegmentedArc(true);
|
|
213
|
+
const c = gaugeSize / 2;
|
|
214
|
+
const band = gaugeSize * 0.17;
|
|
215
|
+
const bandRadius = c - band / 2;
|
|
216
|
+
const dot = 34;
|
|
217
|
+
const step = 2.5;
|
|
218
|
+
// Sized to the outer edge so neighbouring segments leave no seams.
|
|
219
|
+
const segLen = (c * step * Math.PI) / 180 + 1;
|
|
220
|
+
const capDeg = (band / 2 / bandRadius) * (180 / Math.PI);
|
|
221
|
+
const toPoint = (deg, size) => {
|
|
222
|
+
const a = (deg * Math.PI) / 180;
|
|
223
|
+
return { left: c + bandRadius * Math.sin(a) - size / 2, top: c - bandRadius * Math.cos(a) - size / 2 };
|
|
224
|
+
};
|
|
225
|
+
const segment = (key, deg, color) => {
|
|
226
|
+
const a = (deg * Math.PI) / 180;
|
|
227
|
+
return (<react_native_1.View key={key} style={[
|
|
228
|
+
styles.arcDot,
|
|
229
|
+
{
|
|
230
|
+
left: c + bandRadius * Math.sin(a) - segLen / 2,
|
|
231
|
+
top: c - bandRadius * Math.cos(a) - band / 2,
|
|
232
|
+
width: segLen,
|
|
233
|
+
height: band,
|
|
234
|
+
backgroundColor: color,
|
|
235
|
+
transform: [{ rotate: `${deg}deg` }],
|
|
236
|
+
},
|
|
237
|
+
]}/>);
|
|
238
|
+
};
|
|
239
|
+
const cap = (key, deg, color) => (<react_native_1.View key={key} style={[styles.arcDot, toPoint(deg, band), { width: band, height: band, borderRadius: band / 2, backgroundColor: color }]}/>);
|
|
240
|
+
// Each score owns a 30Β° slice centred on its number; together they span -165Β°..165Β°.
|
|
241
|
+
const sliceOf = (deg) => Math.min(10, Math.floor((deg + 165) / 30));
|
|
242
|
+
const dots = [];
|
|
243
|
+
for (let deg = -165 + step / 2; deg < 165; deg += step) {
|
|
244
|
+
dots.push(segment(`b${deg}`, deg, arcZoneColor(sliceOf(deg))));
|
|
245
|
+
}
|
|
246
|
+
if (selectedScore !== null) {
|
|
247
|
+
const fill = arcFillColor(selectedScore);
|
|
248
|
+
const start = -165 + capDeg;
|
|
249
|
+
const end = (selectedScore - 5) * 30 + 15 - capDeg;
|
|
250
|
+
for (let deg = start; deg <= end; deg += step)
|
|
251
|
+
dots.push(segment(`f${deg}`, deg, fill));
|
|
252
|
+
dots.push(cap('fs', start, fill), cap('fe', end, fill));
|
|
253
|
+
}
|
|
254
|
+
return (<react_native_1.View style={[styles.gauge, { width: gaugeSize, height: gaugeSize }]}>
|
|
255
|
+
{dots}
|
|
256
|
+
{question.npsStyle !== 'nps_arc' && (<react_native_1.View style={[styles.gaugeCenter, { left: 0, top: 0, width: gaugeSize, height: gaugeSize }]} pointerEvents="none">
|
|
257
|
+
<react_native_1.Text style={{ fontSize: gaugeSize * 0.15 }}>{NPS_EMOJIS[selectedScore !== null && selectedScore !== void 0 ? selectedScore : 9]}</react_native_1.Text>
|
|
258
|
+
</react_native_1.View>)}
|
|
259
|
+
{Array.from({ length: 11 }, (_, i) => {
|
|
260
|
+
// White numbers only on the strong detractor fill; every other band colour is light.
|
|
261
|
+
const onDark = selectedScore !== null && i <= selectedScore && selectedScore <= 6;
|
|
262
|
+
return (<react_native_1.TouchableOpacity key={i} onPress={() => handleScorePress(i)} activeOpacity={0.7} style={[styles.gaugeNumber, toPoint((i - 5) * 30, dot), { width: dot, height: dot }]}>
|
|
263
|
+
<react_native_1.Text style={[styles.gaugeNumberText, { color: onDark ? '#FFFFFF' : '#374151' }]}>{i}</react_native_1.Text>
|
|
264
|
+
</react_native_1.TouchableOpacity>);
|
|
265
|
+
})}
|
|
266
|
+
</react_native_1.View>);
|
|
267
|
+
};
|
|
82
268
|
const handleScorePress = (score) => {
|
|
269
|
+
var _a;
|
|
270
|
+
if (holdsRaised && selectedScore !== null && selectedScore !== score) {
|
|
271
|
+
react_native_1.Animated.spring(scaleAnim[selectedScore], { toValue: 1, useNativeDriver: true }).start();
|
|
272
|
+
}
|
|
83
273
|
setSelectedScore(score);
|
|
84
274
|
setError('');
|
|
85
275
|
setFollowUpText('');
|
|
86
276
|
setFollowUpChoice(null);
|
|
87
277
|
react_native_1.Animated.spring(scaleAnim[score], { toValue: 1.15, useNativeDriver: true }).start(() => {
|
|
88
|
-
|
|
278
|
+
if (!holdsRaised)
|
|
279
|
+
react_native_1.Animated.spring(scaleAnim[score], { toValue: 1, useNativeDriver: true }).start();
|
|
89
280
|
});
|
|
281
|
+
// A follow-up opens under the scale for some scores, so stay put when it does.
|
|
282
|
+
const opensFollowUp = ((_a = question.conditionalFollowUps) !== null && _a !== void 0 ? _a : []).some(f => score >= f.minRating && score <= f.maxRating);
|
|
283
|
+
if (!opensFollowUp && !question.followUpQuestion)
|
|
284
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect();
|
|
90
285
|
};
|
|
91
286
|
// Find applicable conditional follow-up
|
|
92
287
|
const activeFollowUp = selectedScore !== null
|
|
93
|
-
? ((
|
|
288
|
+
? ((_c = question.conditionalFollowUps) !== null && _c !== void 0 ? _c : []).find(f => selectedScore >= f.minRating && selectedScore <= f.maxRating)
|
|
94
289
|
: undefined;
|
|
95
290
|
const hasTextFollowUp = !!question.followUpQuestion && !activeFollowUp;
|
|
96
|
-
const
|
|
291
|
+
const collect = () => {
|
|
97
292
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
98
293
|
if (question.isRequired && selectedScore === null) {
|
|
99
294
|
setError((0, XeboStrings_1.requiredMessage)(question, 'Please select a score.'));
|
|
100
295
|
shake();
|
|
101
|
-
return;
|
|
296
|
+
return null;
|
|
102
297
|
}
|
|
103
298
|
react_native_1.Keyboard.dismiss();
|
|
104
|
-
|
|
299
|
+
if (selectedScore === null)
|
|
300
|
+
return { questionId: question.id, value: [] };
|
|
301
|
+
const score = selectedScore;
|
|
105
302
|
const colId = (_c = (_b = (_a = question.columns) === null || _a === void 0 ? void 0 : _a[score]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : score.toString();
|
|
106
303
|
const rowId = (_f = (_e = (_d = question.options) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : score.toString();
|
|
107
304
|
// NPS Pro: conditional follow-up has its own questionId β submit as a separate answer entry
|
|
@@ -122,19 +319,24 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
122
319
|
value: [{ rowId: activeFollowUp.questionId, text: followUpText }],
|
|
123
320
|
});
|
|
124
321
|
}
|
|
125
|
-
|
|
126
|
-
return;
|
|
322
|
+
return answers;
|
|
127
323
|
}
|
|
128
324
|
// Simple text follow-up
|
|
129
|
-
|
|
325
|
+
return {
|
|
130
326
|
questionId: question.id,
|
|
131
327
|
value: [{ rowId, colId, text: hasTextFollowUp ? followUpText : undefined }],
|
|
132
|
-
}
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
(0, react_1.useImperativeHandle)(ref, () => ({ collect }));
|
|
331
|
+
const handleNext = () => {
|
|
332
|
+
const answer = collect();
|
|
333
|
+
if (answer)
|
|
334
|
+
onAnswer(answer);
|
|
133
335
|
};
|
|
134
336
|
return (
|
|
135
337
|
// Outer view fills modal content area; button pinned at bottom outside ScrollView
|
|
136
|
-
<react_native_1.View style={styles.outer}>
|
|
137
|
-
<react_native_1.ScrollView style={styles.scroll} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false} keyboardShouldPersistTaps="handled">
|
|
338
|
+
<react_native_1.View style={[styles.outer, embedded && styles.embedded]}>
|
|
339
|
+
<react_native_1.ScrollView style={[styles.scroll, embedded && styles.embedded]} scrollEnabled={!embedded} onLayout={e => { scrollHeights.current.layout = e.nativeEvent.layout.height; reportFit(); }} onContentSizeChange={(_, h) => { scrollHeights.current.content = h; reportFit(); }} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false} keyboardShouldPersistTaps="handled">
|
|
138
340
|
<react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
139
341
|
{question.title}
|
|
140
342
|
</react_native_1.Text>
|
|
@@ -143,37 +345,72 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
143
345
|
</react_native_1.Text>)}
|
|
144
346
|
|
|
145
347
|
{/* NPS Scale β single row, always-visible category colors */}
|
|
146
|
-
<react_native_1.View style={styles.scaleRow}>
|
|
348
|
+
{isArc ? renderArc() : (<react_native_1.View style={[styles.scaleRow, isAnimated && styles.animatedRow]}>
|
|
147
349
|
{Array.from({ length: 11 }, (_, i) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
350
|
+
const selected = selectedScore === i;
|
|
351
|
+
const color = npsColor(i, question.npsLabels);
|
|
352
|
+
const filled = selectedScore !== null && i <= selectedScore;
|
|
353
|
+
// Animated: each filled cell keeps its own zone colour, joined into one bar with rounded ends.
|
|
354
|
+
const fill = ANIMATED_NPS_COLORS[i];
|
|
355
|
+
if (isEmoji) {
|
|
356
|
+
return (<react_native_1.Animated.View key={i} style={[styles.scoreCell, { transform: [{ scale: scaleAnim[i] }] }]}>
|
|
357
|
+
<react_native_1.TouchableOpacity style={[
|
|
358
|
+
styles.scoreButton,
|
|
359
|
+
styles.emojiCell,
|
|
360
|
+
selected && { backgroundColor: '#F2F2F2', borderColor: '#8188A2', borderWidth: 1.5 },
|
|
361
|
+
]} onPress={() => handleScorePress(i)} activeOpacity={0.8}>
|
|
362
|
+
<react_native_1.Text style={{ fontSize: emojiSize }}>{NPS_EMOJIS[i]}</react_native_1.Text>
|
|
363
|
+
</react_native_1.TouchableOpacity>
|
|
364
|
+
</react_native_1.Animated.View>);
|
|
365
|
+
}
|
|
366
|
+
return (<react_native_1.Animated.View key={i} style={[styles.scoreCell, { transform: [{ scale: scaleAnim[i] }], zIndex: selected ? 1 : 0 }]}>
|
|
151
367
|
<react_native_1.TouchableOpacity style={[
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
368
|
+
styles.scoreButton,
|
|
369
|
+
isPlain
|
|
370
|
+
? {
|
|
371
|
+
backgroundColor: selected ? '#F2F2F2' : '#FFFFFF',
|
|
372
|
+
borderColor: selected ? '#8188A2' : '#EEF0F4',
|
|
373
|
+
borderWidth: selected ? 1.5 : 1,
|
|
374
|
+
}
|
|
375
|
+
: isAnimated
|
|
376
|
+
? {
|
|
377
|
+
backgroundColor: filled ? fill : '#FFFFFF',
|
|
378
|
+
borderColor: filled ? fill : '#E5E7EB',
|
|
379
|
+
borderWidth: 1,
|
|
380
|
+
borderRadius: selected ? 8 : 0,
|
|
381
|
+
borderTopLeftRadius: selected || i === 0 ? 8 : 0,
|
|
382
|
+
borderBottomLeftRadius: selected || i === 0 ? 8 : 0,
|
|
383
|
+
borderTopRightRadius: selected || i === 10 ? 8 : 0,
|
|
384
|
+
borderBottomRightRadius: selected || i === 10 ? 8 : 0,
|
|
385
|
+
}
|
|
386
|
+
: {
|
|
387
|
+
backgroundColor: color,
|
|
388
|
+
borderColor: selected ? '#000000' : color,
|
|
389
|
+
borderWidth: selected ? 2.5 : 1.5,
|
|
390
|
+
},
|
|
391
|
+
]} onPress={() => handleScorePress(i)} activeOpacity={0.8}>
|
|
159
392
|
<react_native_1.Text style={[
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
393
|
+
styles.scoreText,
|
|
394
|
+
isPlain
|
|
395
|
+
? { color: '#374151' }
|
|
396
|
+
: isAnimated
|
|
397
|
+
? { color: filled ? '#FFFFFF' : '#374151', fontWeight: '500' }
|
|
398
|
+
: { color: isColorDark(color) ? '#FFFFFF' : selected ? '#111111' : '#444444' },
|
|
399
|
+
]}>
|
|
163
400
|
{i}
|
|
164
401
|
</react_native_1.Text>
|
|
165
402
|
</react_native_1.TouchableOpacity>
|
|
166
403
|
</react_native_1.Animated.View>);
|
|
167
|
-
|
|
168
|
-
</react_native_1.View>
|
|
404
|
+
})}
|
|
405
|
+
</react_native_1.View>)}
|
|
169
406
|
|
|
170
407
|
{/* Lower / Upper labels */}
|
|
171
|
-
{(((
|
|
408
|
+
{(((_d = question.npsLabels) === null || _d === void 0 ? void 0 : _d.lower) || ((_e = question.npsLabels) === null || _e === void 0 ? void 0 : _e.upper)) && (<react_native_1.View style={styles.labelsRow}>
|
|
172
409
|
<react_native_1.Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
173
|
-
{(
|
|
410
|
+
{(_g = (_f = question.npsLabels) === null || _f === void 0 ? void 0 : _f.lower) !== null && _g !== void 0 ? _g : ''}
|
|
174
411
|
</react_native_1.Text>
|
|
175
412
|
<react_native_1.Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
176
|
-
{(
|
|
413
|
+
{(_j = (_h = question.npsLabels) === null || _h === void 0 ? void 0 : _h.upper) !== null && _j !== void 0 ? _j : ''}
|
|
177
414
|
</react_native_1.Text>
|
|
178
415
|
</react_native_1.View>)}
|
|
179
416
|
|
|
@@ -187,7 +424,7 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
187
424
|
followUpChoice === opt.id && { borderColor: theme.primaryColor },
|
|
188
425
|
]} onPress={() => setFollowUpChoice(opt.id)} activeOpacity={0.7}>
|
|
189
426
|
<react_native_1.Text style={[styles.followUpOptionText, { color: theme.textColor }, (0, XeboRtl_1.rtlText)()]}>{opt.text}</react_native_1.Text>
|
|
190
|
-
</react_native_1.TouchableOpacity>))) : (<react_native_1.TextInput style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }, (0, XeboRtl_1.
|
|
427
|
+
</react_native_1.TouchableOpacity>))) : (<react_native_1.TextInput style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }, (0, XeboRtl_1.rtlInput)()]} placeholder="Your comment..." placeholderTextColor="#9CA3AF" value={followUpText} onChangeText={setFollowUpText} multiline numberOfLines={3} textAlignVertical="top"/>)}
|
|
191
428
|
</react_native_1.View>)}
|
|
192
429
|
|
|
193
430
|
{/* Simple text follow-up */}
|
|
@@ -195,22 +432,21 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
195
432
|
<react_native_1.Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
196
433
|
{question.followUpQuestion}
|
|
197
434
|
</react_native_1.Text>
|
|
198
|
-
<react_native_1.TextInput style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }, (0, XeboRtl_1.
|
|
435
|
+
<react_native_1.TextInput style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }, (0, XeboRtl_1.rtlInput)()]} placeholder="Your comment..." placeholderTextColor="#9CA3AF" value={followUpText} onChangeText={setFollowUpText} multiline numberOfLines={3} textAlignVertical="top"/>
|
|
199
436
|
</react_native_1.View>)}
|
|
200
437
|
</react_native_1.ScrollView>
|
|
201
438
|
|
|
202
439
|
{/* Error + button always visible at bottom, outside scroll */}
|
|
203
440
|
{!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
|
|
204
|
-
<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
441
|
+
{!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
442
|
+
<react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius, opacity: selectedScore === null ? 0.4 : 1 }]} onPress={handleNext} disabled={selectedScore === null} activeOpacity={0.8}>
|
|
443
|
+
<react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
444
|
+
{(0, XeboStrings_1.actionLabel)(isLastQuestion)}
|
|
445
|
+
</react_native_1.Text>
|
|
446
|
+
</react_native_1.TouchableOpacity>
|
|
447
|
+
</react_native_1.Animated.View>)}
|
|
211
448
|
</react_native_1.View>);
|
|
212
|
-
};
|
|
213
|
-
exports.XeboNPSView = XeboNPSView;
|
|
449
|
+
});
|
|
214
450
|
const styles = react_native_1.StyleSheet.create({
|
|
215
451
|
outer: {
|
|
216
452
|
flex: 1,
|
|
@@ -218,17 +454,20 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
218
454
|
paddingBottom: 10,
|
|
219
455
|
},
|
|
220
456
|
scroll: { flex: 1, minHeight: 0 },
|
|
457
|
+
embedded: { flex: 0 },
|
|
221
458
|
scrollContent: {
|
|
222
459
|
paddingTop: 16,
|
|
223
460
|
paddingBottom: 8,
|
|
224
461
|
},
|
|
225
|
-
title: { fontSize: 18, fontWeight: '700', marginBottom:
|
|
462
|
+
title: { fontSize: 18, fontWeight: '700', marginBottom: 16 },
|
|
226
463
|
subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
|
|
227
464
|
scaleRow: {
|
|
228
465
|
flexDirection: 'row',
|
|
229
466
|
gap: 3,
|
|
230
467
|
marginBottom: 8,
|
|
231
468
|
},
|
|
469
|
+
// Animated cells touch so the filled part reads as one bar.
|
|
470
|
+
animatedRow: { gap: 0 },
|
|
232
471
|
scoreCell: {
|
|
233
472
|
flex: 1,
|
|
234
473
|
},
|
|
@@ -239,6 +478,25 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
239
478
|
justifyContent: 'center',
|
|
240
479
|
},
|
|
241
480
|
scoreText: { fontSize: 13, fontWeight: '700' },
|
|
481
|
+
gauge: { alignSelf: 'center', marginVertical: 8 },
|
|
482
|
+
gaugeCenter: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },
|
|
483
|
+
gaugeNumber: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },
|
|
484
|
+
gaugeNumberText: { fontSize: 14, fontWeight: '500' },
|
|
485
|
+
arcDot: { position: 'absolute' },
|
|
486
|
+
arcCheck: {
|
|
487
|
+
position: 'absolute',
|
|
488
|
+
right: 0,
|
|
489
|
+
top: 2,
|
|
490
|
+
width: 14,
|
|
491
|
+
height: 14,
|
|
492
|
+
borderRadius: 7,
|
|
493
|
+
backgroundColor: '#FFFFFF',
|
|
494
|
+
alignItems: 'center',
|
|
495
|
+
justifyContent: 'center',
|
|
496
|
+
},
|
|
497
|
+
arcCheckText: { fontSize: 9, fontWeight: '800' },
|
|
498
|
+
arcFaceNumber: { width: 24, height: 16, textAlign: 'center', fontSize: 12, fontWeight: '500', color: '#4B5563' },
|
|
499
|
+
emojiCell: { backgroundColor: '#FFFFFF', borderColor: '#CBD1DC', borderWidth: 1, borderRadius: 2 },
|
|
242
500
|
labelsRow: {
|
|
243
501
|
flexDirection: 'row',
|
|
244
502
|
justifyContent: 'space-between',
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { XeboSurvey } from '../models/XeboModels';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The page's questions in order, each already rendered. */
|
|
5
|
+
questions: Array<{
|
|
6
|
+
id: string;
|
|
7
|
+
view: React.ReactNode;
|
|
8
|
+
/** Auto-advance moves on when this is answered and, like the web, it shows no Ok / Next. */
|
|
9
|
+
hidesButtons?: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
isLastPage: boolean;
|
|
12
|
+
/** Validates one question; true when the respondent can move on to the next. */
|
|
13
|
+
onOk: (questionId: string) => boolean;
|
|
14
|
+
onNext: () => void;
|
|
15
|
+
/** Reports how much taller (or shorter) the sheet must be to fit every question without scrolling. */
|
|
16
|
+
onFitHeight?: (delta: number) => void;
|
|
17
|
+
/** Label of the "Previous" button; omitted when the survey turns it off. */
|
|
18
|
+
previousLabel?: string;
|
|
19
|
+
/** Show Previous as a small "βΉ" button, as the web does when its text is blank. */
|
|
20
|
+
previousIconOnly?: boolean;
|
|
21
|
+
/** True when an earlier page exists, so Previous on this page's first question can go there. */
|
|
22
|
+
canGoBack: boolean;
|
|
23
|
+
onPreviousPage: () => void;
|
|
24
|
+
buttonColors?: XeboSurvey['buttonColors'];
|
|
25
|
+
}
|
|
26
|
+
export interface XeboPageViewHandle {
|
|
27
|
+
/** Auto-advance: brings the next question into view, or from the page's last question moves to the next page. */
|
|
28
|
+
scrollToNext: (questionId: string) => void;
|
|
29
|
+
}
|
|
30
|
+
/** One page of the survey: its questions, then Ok / Previous / Next-or-Submit like the web. */
|
|
31
|
+
export declare const XeboPageView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboPageViewHandle>>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=XeboPageView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XeboPageView.d.ts","sourceRoot":"","sources":["../../src/components/XeboPageView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAIvE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,UAAU,KAAK;IACb,4DAA4D;IAC5D,SAAS,EAAE,KAAK,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;QACtB,4FAA4F;QAC5F,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC,CAAC;IACH,UAAU,EAAE,OAAO,CAAC;IACpB,gFAAgF;IAChF,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sGAAsG;IACtG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gGAAgG;IAChG,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,kBAAkB;IACjC,iHAAiH;IACjH,YAAY,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED,+FAA+F;AAC/F,eAAO,MAAM,YAAY,kFAmIvB,CAAC"}
|