react-native-my-survey-sdk 3.1.3 β 4.0.1
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 +28 -19
- package/dist/components/XeboLanguageView.js +1 -1
- package/dist/components/XeboMultiNPSView.d.ts +4 -2
- package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
- package/dist/components/XeboMultiNPSView.js +25 -27
- package/dist/components/XeboMultiRatingView.d.ts +4 -2
- package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
- package/dist/components/XeboMultiRatingView.js +27 -20
- 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 +307 -59
- 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 +72 -46
- 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 +152 -37
- package/dist/components/XeboTextBoxView.d.ts +4 -2
- package/dist/components/XeboTextBoxView.d.ts.map +1 -1
- package/dist/components/XeboTextBoxView.js +28 -19
- 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/dist/theme/XeboTheme.d.ts +7 -0
- package/dist/theme/XeboTheme.d.ts.map +1 -1
- package/dist/theme/XeboTheme.js +27 -13
- 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)
|
|
@@ -52,20 +85,16 @@ function npsColor(score, npsLabels) {
|
|
|
52
85
|
return (_b = npsLabels === null || npsLabels === void 0 ? void 0 : npsLabels.passiveColor) !== null && _b !== void 0 ? _b : PASSIVE_COLOR;
|
|
53
86
|
return (_c = npsLabels === null || npsLabels === void 0 ? void 0 : npsLabels.promoterColor) !== null && _c !== void 0 ? _c : PROMOTER_COLOR;
|
|
54
87
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
58
|
-
if (!m)
|
|
59
|
-
return false;
|
|
60
|
-
const r = parseInt(m[1], 16) / 255;
|
|
61
|
-
const g = parseInt(m[2], 16) / 255;
|
|
62
|
-
const b = parseInt(m[3], 16) / 255;
|
|
63
|
-
return 0.299 * r + 0.587 * g + 0.114 * b < 0.5;
|
|
64
|
-
}
|
|
65
|
-
const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
66
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
88
|
+
exports.XeboNPSView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, onFitHeight, embedded, onSelect }, ref) => {
|
|
89
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
90
|
const theme = (0, XeboTheme_1.getTheme)();
|
|
68
|
-
const
|
|
91
|
+
const scrollHeights = (0, react_1.useRef)({ layout: 0, content: 0 });
|
|
92
|
+
const reportFit = () => {
|
|
93
|
+
const { layout, content } = scrollHeights.current;
|
|
94
|
+
if (layout > 0 && content > 0)
|
|
95
|
+
onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
|
|
96
|
+
};
|
|
97
|
+
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
98
|
const [followUpText, setFollowUpText] = (0, react_1.useState)('');
|
|
70
99
|
const [followUpChoice, setFollowUpChoice] = (0, react_1.useState)(null);
|
|
71
100
|
const [error, setError] = (0, react_1.useState)('');
|
|
@@ -79,29 +108,187 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
79
108
|
react_native_1.Animated.timing(shakeAnim, { toValue: 0, duration: 60, useNativeDriver: true }),
|
|
80
109
|
]).start();
|
|
81
110
|
};
|
|
111
|
+
// Animated style: white cells; picking a score fills 0..score and keeps the picked cell raised.
|
|
112
|
+
const isAnimated = question.npsStyle === 'animated_nps';
|
|
113
|
+
// 'default' is the platform's uncoloured style: white cells, grey highlight on the picked one.
|
|
114
|
+
const isPlain = question.npsStyle === 'default';
|
|
115
|
+
// 'graphical' (gauge), 'nps_arc', 'nps_arc_emoji': 0β10 round a ring coloured by NPS zone,
|
|
116
|
+
// 30Β° apart with 5 on top, filled from 0 to the picked score. All but 'nps_arc' show an emoji.
|
|
117
|
+
const isArc = ['graphical', 'nps_arc', 'nps_arc_emoji'].includes((_a = question.npsStyle) !== null && _a !== void 0 ? _a : '');
|
|
118
|
+
// Emoji styles (e.g. 'emojis_flat'): one emoji per score in a bordered cell, sized so all 11 fit.
|
|
119
|
+
const isEmoji = !!((_b = question.npsStyle) === null || _b === void 0 ? void 0 : _b.includes('emoji')) && !isArc;
|
|
120
|
+
const holdsRaised = isAnimated || isPlain || isEmoji;
|
|
121
|
+
const { width: windowWidth } = (0, react_native_1.useWindowDimensions)();
|
|
122
|
+
const emojiSize = Math.min(28, ((windowWidth - 40 - 30) / 11) * 0.8);
|
|
123
|
+
const gaugeSize = Math.min(260, windowWidth - 80);
|
|
124
|
+
// A 262Β° horseshoe of 11 segments split by thin lines.
|
|
125
|
+
// 'nps_arc': fixed-colour segments, white numbers, β on the picked one.
|
|
126
|
+
// 'nps_arc_emoji': grey segments with a face over each number; the picked segment darkens.
|
|
127
|
+
const renderSegmentedArc = (withFaces) => {
|
|
128
|
+
const c = gaugeSize / 2;
|
|
129
|
+
const band = gaugeSize * 0.2;
|
|
130
|
+
const bandRadius = c - band / 2;
|
|
131
|
+
const span = 262;
|
|
132
|
+
const slice = span / 11;
|
|
133
|
+
const strips = 12;
|
|
134
|
+
const stripDeg = slice / strips;
|
|
135
|
+
const stripLen = (c * stripDeg * Math.PI) / 180 + 1;
|
|
136
|
+
const dot = 34;
|
|
137
|
+
const faceSize = gaugeSize * 0.075;
|
|
138
|
+
const at = (deg, w, h, r = bandRadius) => {
|
|
139
|
+
const a = (deg * Math.PI) / 180;
|
|
140
|
+
return { left: c + r * Math.sin(a) - w / 2, top: c - r * Math.cos(a) - h / 2 };
|
|
141
|
+
};
|
|
142
|
+
const startOf = (i) => -span / 2 + i * slice;
|
|
143
|
+
const segmentColor = (i) => {
|
|
144
|
+
if (!withFaces)
|
|
145
|
+
return NPS_ARC_SEGMENT_COLORS[i];
|
|
146
|
+
return selectedScore === i ? '#AEB3BF' : '#EDEEF3';
|
|
147
|
+
};
|
|
148
|
+
const parts = [];
|
|
149
|
+
for (let i = 0; i < 11; i += 1) {
|
|
150
|
+
for (let k = 0; k < strips; k += 1) {
|
|
151
|
+
const deg = startOf(i) + (k + 0.5) * stripDeg;
|
|
152
|
+
parts.push(<react_native_1.View key={`s${i}-${k}`} style={[
|
|
153
|
+
styles.arcDot,
|
|
154
|
+
at(deg, stripLen, band),
|
|
155
|
+
{ width: stripLen, height: band, backgroundColor: segmentColor(i), transform: [{ rotate: `${deg}deg` }] },
|
|
156
|
+
]}/>);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const divider = withFaces ? { width: 1, color: '#E5E3F9' } : { width: 2, color: theme.backgroundColor };
|
|
160
|
+
for (let i = 1; i < 11; i += 1) {
|
|
161
|
+
const deg = startOf(i);
|
|
162
|
+
parts.push(<react_native_1.View key={`d${i}`} style={[
|
|
163
|
+
styles.arcDot,
|
|
164
|
+
at(deg, divider.width, band + 2),
|
|
165
|
+
{ width: divider.width, height: band + 2, backgroundColor: divider.color, transform: [{ rotate: `${deg}deg` }] },
|
|
166
|
+
]}/>);
|
|
167
|
+
}
|
|
168
|
+
// The horseshoe's lowest point is its end corners at Β±131Β°, so trim the empty space below.
|
|
169
|
+
const height = c + c * Math.cos(((180 - span / 2) * Math.PI) / 180) + 2;
|
|
170
|
+
return (<react_native_1.View style={[styles.gauge, { width: gaugeSize, height }]}>
|
|
171
|
+
{parts}
|
|
172
|
+
{Array.from({ length: 11 }, (_, i) => {
|
|
173
|
+
const deg = startOf(i) + slice / 2;
|
|
174
|
+
const selected = selectedScore === i;
|
|
175
|
+
if (withFaces) {
|
|
176
|
+
// Red frown for 0β6, yellow frown for 7β8, green smile for 9β10.
|
|
177
|
+
const face = i <= 6 ? { index: 0, color: '#ED464E' } : i <= 8 ? { index: 1, color: '#E5BB4F' } : { index: 3, color: '#6CA077' };
|
|
178
|
+
// Face sits in the outer part of the segment, the number in the inner part.
|
|
179
|
+
return (<react_1.default.Fragment key={i}>
|
|
180
|
+
<react_native_1.View style={[styles.arcDot, at(deg, faceSize, faceSize, c - band * 0.4)]}>
|
|
181
|
+
<XeboRatingView_1.FlatEmoji index={face.index} color={face.color} featureColor="#6E351D" size={faceSize} selected hasSelection={false}/>
|
|
182
|
+
</react_native_1.View>
|
|
183
|
+
<react_native_1.Text style={[styles.arcDot, styles.arcFaceNumber, at(deg, 24, 16, c - band * 0.84)]}>{i}</react_native_1.Text>
|
|
184
|
+
<react_native_1.TouchableOpacity onPress={() => handleScorePress(i)} activeOpacity={0.7} style={[styles.arcDot, at(deg, band, band), { width: band, height: band }]}/>
|
|
185
|
+
</react_1.default.Fragment>);
|
|
186
|
+
}
|
|
187
|
+
return (<react_native_1.TouchableOpacity key={i} onPress={() => handleScorePress(i)} activeOpacity={0.7} style={[styles.gaugeNumber, at(deg, dot, dot), { width: dot, height: dot }]}>
|
|
188
|
+
<react_native_1.Text style={[styles.gaugeNumberText, { color: '#FFFFFF', fontSize: 15 }]}>{i}</react_native_1.Text>
|
|
189
|
+
{selected && (<react_native_1.View style={styles.arcCheck}>
|
|
190
|
+
<react_native_1.Text style={[styles.arcCheckText, { color: NPS_ARC_SEGMENT_COLORS[i] }]}>β</react_native_1.Text>
|
|
191
|
+
</react_native_1.View>)}
|
|
192
|
+
</react_native_1.TouchableOpacity>);
|
|
193
|
+
})}
|
|
194
|
+
</react_native_1.View>);
|
|
195
|
+
};
|
|
196
|
+
// No SVG dependency: the band is short rotated segments (straight cuts between zones);
|
|
197
|
+
// the picked fill adds round caps at its two ends, like the web.
|
|
198
|
+
const renderArc = () => {
|
|
199
|
+
if (question.npsStyle === 'nps_arc')
|
|
200
|
+
return renderSegmentedArc(false);
|
|
201
|
+
if (question.npsStyle === 'nps_arc_emoji')
|
|
202
|
+
return renderSegmentedArc(true);
|
|
203
|
+
const c = gaugeSize / 2;
|
|
204
|
+
const band = gaugeSize * 0.17;
|
|
205
|
+
const bandRadius = c - band / 2;
|
|
206
|
+
const dot = 34;
|
|
207
|
+
const step = 2.5;
|
|
208
|
+
// Sized to the outer edge so neighbouring segments leave no seams.
|
|
209
|
+
const segLen = (c * step * Math.PI) / 180 + 1;
|
|
210
|
+
const capDeg = (band / 2 / bandRadius) * (180 / Math.PI);
|
|
211
|
+
const toPoint = (deg, size) => {
|
|
212
|
+
const a = (deg * Math.PI) / 180;
|
|
213
|
+
return { left: c + bandRadius * Math.sin(a) - size / 2, top: c - bandRadius * Math.cos(a) - size / 2 };
|
|
214
|
+
};
|
|
215
|
+
const segment = (key, deg, color) => {
|
|
216
|
+
const a = (deg * Math.PI) / 180;
|
|
217
|
+
return (<react_native_1.View key={key} style={[
|
|
218
|
+
styles.arcDot,
|
|
219
|
+
{
|
|
220
|
+
left: c + bandRadius * Math.sin(a) - segLen / 2,
|
|
221
|
+
top: c - bandRadius * Math.cos(a) - band / 2,
|
|
222
|
+
width: segLen,
|
|
223
|
+
height: band,
|
|
224
|
+
backgroundColor: color,
|
|
225
|
+
transform: [{ rotate: `${deg}deg` }],
|
|
226
|
+
},
|
|
227
|
+
]}/>);
|
|
228
|
+
};
|
|
229
|
+
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 }]}/>);
|
|
230
|
+
// Each score owns a 30Β° slice centred on its number; together they span -165Β°..165Β°.
|
|
231
|
+
const sliceOf = (deg) => Math.min(10, Math.floor((deg + 165) / 30));
|
|
232
|
+
const dots = [];
|
|
233
|
+
for (let deg = -165 + step / 2; deg < 165; deg += step) {
|
|
234
|
+
dots.push(segment(`b${deg}`, deg, arcZoneColor(sliceOf(deg))));
|
|
235
|
+
}
|
|
236
|
+
if (selectedScore !== null) {
|
|
237
|
+
const fill = arcFillColor(selectedScore);
|
|
238
|
+
const start = -165 + capDeg;
|
|
239
|
+
const end = (selectedScore - 5) * 30 + 15 - capDeg;
|
|
240
|
+
for (let deg = start; deg <= end; deg += step)
|
|
241
|
+
dots.push(segment(`f${deg}`, deg, fill));
|
|
242
|
+
dots.push(cap('fs', start, fill), cap('fe', end, fill));
|
|
243
|
+
}
|
|
244
|
+
return (<react_native_1.View style={[styles.gauge, { width: gaugeSize, height: gaugeSize }]}>
|
|
245
|
+
{dots}
|
|
246
|
+
{question.npsStyle !== 'nps_arc' && (<react_native_1.View style={[styles.gaugeCenter, { left: 0, top: 0, width: gaugeSize, height: gaugeSize }]} pointerEvents="none">
|
|
247
|
+
<react_native_1.Text style={{ fontSize: gaugeSize * 0.15 }}>{NPS_EMOJIS[selectedScore !== null && selectedScore !== void 0 ? selectedScore : 9]}</react_native_1.Text>
|
|
248
|
+
</react_native_1.View>)}
|
|
249
|
+
{Array.from({ length: 11 }, (_, i) => {
|
|
250
|
+
// White numbers only on the strong detractor fill; every other band colour is light.
|
|
251
|
+
const onDark = selectedScore !== null && i <= selectedScore && selectedScore <= 6;
|
|
252
|
+
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 }]}>
|
|
253
|
+
<react_native_1.Text style={[styles.gaugeNumberText, { color: onDark ? '#FFFFFF' : '#374151' }]}>{i}</react_native_1.Text>
|
|
254
|
+
</react_native_1.TouchableOpacity>);
|
|
255
|
+
})}
|
|
256
|
+
</react_native_1.View>);
|
|
257
|
+
};
|
|
82
258
|
const handleScorePress = (score) => {
|
|
259
|
+
var _a;
|
|
260
|
+
if (holdsRaised && selectedScore !== null && selectedScore !== score) {
|
|
261
|
+
react_native_1.Animated.spring(scaleAnim[selectedScore], { toValue: 1, useNativeDriver: true }).start();
|
|
262
|
+
}
|
|
83
263
|
setSelectedScore(score);
|
|
84
264
|
setError('');
|
|
85
265
|
setFollowUpText('');
|
|
86
266
|
setFollowUpChoice(null);
|
|
87
267
|
react_native_1.Animated.spring(scaleAnim[score], { toValue: 1.15, useNativeDriver: true }).start(() => {
|
|
88
|
-
|
|
268
|
+
if (!holdsRaised)
|
|
269
|
+
react_native_1.Animated.spring(scaleAnim[score], { toValue: 1, useNativeDriver: true }).start();
|
|
89
270
|
});
|
|
271
|
+
// A follow-up opens under the scale for some scores, so stay put when it does.
|
|
272
|
+
const opensFollowUp = ((_a = question.conditionalFollowUps) !== null && _a !== void 0 ? _a : []).some(f => score >= f.minRating && score <= f.maxRating);
|
|
273
|
+
if (!opensFollowUp && !question.followUpQuestion)
|
|
274
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect();
|
|
90
275
|
};
|
|
91
276
|
// Find applicable conditional follow-up
|
|
92
277
|
const activeFollowUp = selectedScore !== null
|
|
93
|
-
? ((
|
|
278
|
+
? ((_c = question.conditionalFollowUps) !== null && _c !== void 0 ? _c : []).find(f => selectedScore >= f.minRating && selectedScore <= f.maxRating)
|
|
94
279
|
: undefined;
|
|
95
280
|
const hasTextFollowUp = !!question.followUpQuestion && !activeFollowUp;
|
|
96
|
-
const
|
|
281
|
+
const collect = () => {
|
|
97
282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
98
283
|
if (question.isRequired && selectedScore === null) {
|
|
99
284
|
setError((0, XeboStrings_1.requiredMessage)(question, 'Please select a score.'));
|
|
100
285
|
shake();
|
|
101
|
-
return;
|
|
286
|
+
return null;
|
|
102
287
|
}
|
|
103
288
|
react_native_1.Keyboard.dismiss();
|
|
104
|
-
|
|
289
|
+
if (selectedScore === null)
|
|
290
|
+
return { questionId: question.id, value: [] };
|
|
291
|
+
const score = selectedScore;
|
|
105
292
|
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
293
|
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
294
|
// NPS Pro: conditional follow-up has its own questionId β submit as a separate answer entry
|
|
@@ -122,19 +309,24 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
122
309
|
value: [{ rowId: activeFollowUp.questionId, text: followUpText }],
|
|
123
310
|
});
|
|
124
311
|
}
|
|
125
|
-
|
|
126
|
-
return;
|
|
312
|
+
return answers;
|
|
127
313
|
}
|
|
128
314
|
// Simple text follow-up
|
|
129
|
-
|
|
315
|
+
return {
|
|
130
316
|
questionId: question.id,
|
|
131
317
|
value: [{ rowId, colId, text: hasTextFollowUp ? followUpText : undefined }],
|
|
132
|
-
}
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
(0, react_1.useImperativeHandle)(ref, () => ({ collect }));
|
|
321
|
+
const handleNext = () => {
|
|
322
|
+
const answer = collect();
|
|
323
|
+
if (answer)
|
|
324
|
+
onAnswer(answer);
|
|
133
325
|
};
|
|
134
326
|
return (
|
|
135
327
|
// 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">
|
|
328
|
+
<react_native_1.View style={[styles.outer, embedded && styles.embedded]}>
|
|
329
|
+
<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
330
|
<react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
139
331
|
{question.title}
|
|
140
332
|
</react_native_1.Text>
|
|
@@ -143,74 +335,109 @@ const XeboNPSView = ({ question, isLastQuestion, onAnswer }) => {
|
|
|
143
335
|
</react_native_1.Text>)}
|
|
144
336
|
|
|
145
337
|
{/* NPS Scale β single row, always-visible category colors */}
|
|
146
|
-
<react_native_1.View style={styles.scaleRow}>
|
|
338
|
+
{isArc ? renderArc() : (<react_native_1.View style={[styles.scaleRow, isAnimated && styles.animatedRow]}>
|
|
147
339
|
{Array.from({ length: 11 }, (_, i) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
340
|
+
const selected = selectedScore === i;
|
|
341
|
+
const color = npsColor(i, question.npsLabels);
|
|
342
|
+
const filled = selectedScore !== null && i <= selectedScore;
|
|
343
|
+
// Animated: each filled cell keeps its own zone colour, joined into one bar with rounded ends.
|
|
344
|
+
const fill = ANIMATED_NPS_COLORS[i];
|
|
345
|
+
if (isEmoji) {
|
|
346
|
+
return (<react_native_1.Animated.View key={i} style={[styles.scoreCell, { transform: [{ scale: scaleAnim[i] }] }]}>
|
|
347
|
+
<react_native_1.TouchableOpacity style={[
|
|
348
|
+
styles.scoreButton,
|
|
349
|
+
styles.emojiCell,
|
|
350
|
+
{ backgroundColor: theme.surfaceColor, borderColor: theme.strongBorderColor },
|
|
351
|
+
selected && { backgroundColor: theme.selectedSurfaceColor, borderColor: '#8188A2', borderWidth: 1.5 },
|
|
352
|
+
]} onPress={() => handleScorePress(i)} activeOpacity={0.8}>
|
|
353
|
+
<react_native_1.Text style={{ fontSize: emojiSize }}>{NPS_EMOJIS[i]}</react_native_1.Text>
|
|
354
|
+
</react_native_1.TouchableOpacity>
|
|
355
|
+
</react_native_1.Animated.View>);
|
|
356
|
+
}
|
|
357
|
+
return (<react_native_1.Animated.View key={i} style={[styles.scoreCell, { transform: [{ scale: scaleAnim[i] }], zIndex: selected ? 1 : 0 }]}>
|
|
151
358
|
<react_native_1.TouchableOpacity style={[
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
359
|
+
styles.scoreButton,
|
|
360
|
+
isPlain
|
|
361
|
+
? {
|
|
362
|
+
backgroundColor: selected ? theme.selectedSurfaceColor : theme.surfaceColor,
|
|
363
|
+
borderColor: selected ? '#8188A2' : theme.borderColor,
|
|
364
|
+
borderWidth: selected ? 1.5 : 1,
|
|
365
|
+
}
|
|
366
|
+
: isAnimated
|
|
367
|
+
? {
|
|
368
|
+
backgroundColor: filled ? fill : theme.surfaceColor,
|
|
369
|
+
borderColor: filled ? fill : theme.borderColor,
|
|
370
|
+
borderWidth: 1,
|
|
371
|
+
borderRadius: selected ? 8 : 0,
|
|
372
|
+
borderTopLeftRadius: selected || i === 0 ? 8 : 0,
|
|
373
|
+
borderBottomLeftRadius: selected || i === 0 ? 8 : 0,
|
|
374
|
+
borderTopRightRadius: selected || i === 10 ? 8 : 0,
|
|
375
|
+
borderBottomRightRadius: selected || i === 10 ? 8 : 0,
|
|
376
|
+
}
|
|
377
|
+
: {
|
|
378
|
+
backgroundColor: color,
|
|
379
|
+
borderColor: selected ? '#000000' : color,
|
|
380
|
+
borderWidth: selected ? 2.5 : 1.5,
|
|
381
|
+
},
|
|
382
|
+
]} onPress={() => handleScorePress(i)} activeOpacity={0.8}>
|
|
159
383
|
<react_native_1.Text style={[
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
384
|
+
styles.scoreText,
|
|
385
|
+
isPlain
|
|
386
|
+
? { color: theme.textColor }
|
|
387
|
+
: isAnimated
|
|
388
|
+
? { color: filled ? '#FFFFFF' : theme.textColor, fontWeight: '500' }
|
|
389
|
+
: { color: (0, XeboTheme_1.isColorDark)(color) ? '#FFFFFF' : selected ? '#111111' : '#444444' },
|
|
390
|
+
]}>
|
|
163
391
|
{i}
|
|
164
392
|
</react_native_1.Text>
|
|
165
393
|
</react_native_1.TouchableOpacity>
|
|
166
394
|
</react_native_1.Animated.View>);
|
|
167
|
-
|
|
168
|
-
</react_native_1.View>
|
|
395
|
+
})}
|
|
396
|
+
</react_native_1.View>)}
|
|
169
397
|
|
|
170
398
|
{/* Lower / Upper labels */}
|
|
171
|
-
{(((
|
|
399
|
+
{(((_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
400
|
<react_native_1.Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
173
|
-
{(
|
|
401
|
+
{(_g = (_f = question.npsLabels) === null || _f === void 0 ? void 0 : _f.lower) !== null && _g !== void 0 ? _g : ''}
|
|
174
402
|
</react_native_1.Text>
|
|
175
403
|
<react_native_1.Text style={[styles.label, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
176
|
-
{(
|
|
404
|
+
{(_j = (_h = question.npsLabels) === null || _h === void 0 ? void 0 : _h.upper) !== null && _j !== void 0 ? _j : ''}
|
|
177
405
|
</react_native_1.Text>
|
|
178
406
|
</react_native_1.View>)}
|
|
179
407
|
|
|
180
408
|
{/* Conditional follow-up (NPS Pro) */}
|
|
181
|
-
{selectedScore !== null && activeFollowUp && (<react_native_1.View style={[styles.followUpCard, { borderColor:
|
|
409
|
+
{selectedScore !== null && activeFollowUp && (<react_native_1.View style={[styles.followUpCard, { borderColor: theme.borderColor, borderRadius: theme.cornerRadius }]}>
|
|
182
410
|
<react_native_1.Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
183
411
|
{activeFollowUp.followUpQuestion}
|
|
184
412
|
</react_native_1.Text>
|
|
185
413
|
{activeFollowUp.followUpType === XeboModels_1.XeboQuestionType.singleChoice && activeFollowUp.followUpOptions.length > 0 ? (activeFollowUp.followUpOptions.map(opt => (<react_native_1.TouchableOpacity key={opt.id} style={[
|
|
186
414
|
styles.followUpOption,
|
|
187
|
-
followUpChoice === opt.id
|
|
415
|
+
{ borderColor: followUpChoice === opt.id ? theme.primaryColor : theme.borderColor },
|
|
188
416
|
]} onPress={() => setFollowUpChoice(opt.id)} activeOpacity={0.7}>
|
|
189
417
|
<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:
|
|
418
|
+
</react_native_1.TouchableOpacity>))) : (<react_native_1.TextInput style={[styles.followUpInput, { borderColor: theme.borderColor, 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
419
|
</react_native_1.View>)}
|
|
192
420
|
|
|
193
421
|
{/* Simple text follow-up */}
|
|
194
|
-
{selectedScore !== null && hasTextFollowUp && (<react_native_1.View style={[styles.followUpCard, { borderColor:
|
|
422
|
+
{selectedScore !== null && hasTextFollowUp && (<react_native_1.View style={[styles.followUpCard, { borderColor: theme.borderColor, borderRadius: theme.cornerRadius }]}>
|
|
195
423
|
<react_native_1.Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
|
|
196
424
|
{question.followUpQuestion}
|
|
197
425
|
</react_native_1.Text>
|
|
198
|
-
<react_native_1.TextInput style={[styles.followUpInput, { borderColor:
|
|
426
|
+
<react_native_1.TextInput style={[styles.followUpInput, { borderColor: theme.borderColor, 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
427
|
</react_native_1.View>)}
|
|
200
428
|
</react_native_1.ScrollView>
|
|
201
429
|
|
|
202
430
|
{/* Error + button always visible at bottom, outside scroll */}
|
|
203
431
|
{!!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
|
-
|
|
432
|
+
{!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
|
|
433
|
+
<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}>
|
|
434
|
+
<react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
|
|
435
|
+
{(0, XeboStrings_1.actionLabel)(isLastQuestion)}
|
|
436
|
+
</react_native_1.Text>
|
|
437
|
+
</react_native_1.TouchableOpacity>
|
|
438
|
+
</react_native_1.Animated.View>)}
|
|
211
439
|
</react_native_1.View>);
|
|
212
|
-
};
|
|
213
|
-
exports.XeboNPSView = XeboNPSView;
|
|
440
|
+
});
|
|
214
441
|
const styles = react_native_1.StyleSheet.create({
|
|
215
442
|
outer: {
|
|
216
443
|
flex: 1,
|
|
@@ -218,17 +445,20 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
218
445
|
paddingBottom: 10,
|
|
219
446
|
},
|
|
220
447
|
scroll: { flex: 1, minHeight: 0 },
|
|
448
|
+
embedded: { flex: 0 },
|
|
221
449
|
scrollContent: {
|
|
222
450
|
paddingTop: 16,
|
|
223
451
|
paddingBottom: 8,
|
|
224
452
|
},
|
|
225
|
-
title: { fontSize: 18, fontWeight: '700', marginBottom:
|
|
453
|
+
title: { fontSize: 18, fontWeight: '700', marginBottom: 16 },
|
|
226
454
|
subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
|
|
227
455
|
scaleRow: {
|
|
228
456
|
flexDirection: 'row',
|
|
229
457
|
gap: 3,
|
|
230
458
|
marginBottom: 8,
|
|
231
459
|
},
|
|
460
|
+
// Animated cells touch so the filled part reads as one bar.
|
|
461
|
+
animatedRow: { gap: 0 },
|
|
232
462
|
scoreCell: {
|
|
233
463
|
flex: 1,
|
|
234
464
|
},
|
|
@@ -239,6 +469,25 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
239
469
|
justifyContent: 'center',
|
|
240
470
|
},
|
|
241
471
|
scoreText: { fontSize: 13, fontWeight: '700' },
|
|
472
|
+
gauge: { alignSelf: 'center', marginVertical: 8 },
|
|
473
|
+
gaugeCenter: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },
|
|
474
|
+
gaugeNumber: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },
|
|
475
|
+
gaugeNumberText: { fontSize: 14, fontWeight: '500' },
|
|
476
|
+
arcDot: { position: 'absolute' },
|
|
477
|
+
arcCheck: {
|
|
478
|
+
position: 'absolute',
|
|
479
|
+
right: 0,
|
|
480
|
+
top: 2,
|
|
481
|
+
width: 14,
|
|
482
|
+
height: 14,
|
|
483
|
+
borderRadius: 7,
|
|
484
|
+
backgroundColor: '#FFFFFF',
|
|
485
|
+
alignItems: 'center',
|
|
486
|
+
justifyContent: 'center',
|
|
487
|
+
},
|
|
488
|
+
arcCheckText: { fontSize: 9, fontWeight: '800' },
|
|
489
|
+
arcFaceNumber: { width: 24, height: 16, textAlign: 'center', fontSize: 12, fontWeight: '500', color: '#4B5563' },
|
|
490
|
+
emojiCell: { borderWidth: 1, borderRadius: 2 },
|
|
242
491
|
labelsRow: {
|
|
243
492
|
flexDirection: 'row',
|
|
244
493
|
justifyContent: 'space-between',
|
|
@@ -253,7 +502,6 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
253
502
|
followUpTitle: { fontSize: 15, fontWeight: '600', marginBottom: 12 },
|
|
254
503
|
followUpOption: {
|
|
255
504
|
borderWidth: 1.5,
|
|
256
|
-
borderColor: '#E5E7EB',
|
|
257
505
|
borderRadius: 8,
|
|
258
506
|
padding: 10,
|
|
259
507
|
marginBottom: 8,
|
|
@@ -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"}
|