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.
Files changed (54) hide show
  1. package/dist/components/XeboDropdownView.d.ts +6 -2
  2. package/dist/components/XeboDropdownView.d.ts.map +1 -1
  3. package/dist/components/XeboDropdownView.js +26 -17
  4. package/dist/components/XeboMultiNPSView.d.ts +4 -2
  5. package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
  6. package/dist/components/XeboMultiNPSView.js +24 -17
  7. package/dist/components/XeboMultiRatingView.d.ts +4 -2
  8. package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
  9. package/dist/components/XeboMultiRatingView.js +23 -16
  10. package/dist/components/XeboMultipleChoiceView.d.ts +6 -2
  11. package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
  12. package/dist/components/XeboMultipleChoiceView.js +35 -38
  13. package/dist/components/XeboNPSView.d.ts +8 -2
  14. package/dist/components/XeboNPSView.d.ts.map +1 -1
  15. package/dist/components/XeboNPSView.js +303 -45
  16. package/dist/components/XeboPageView.d.ts +33 -0
  17. package/dist/components/XeboPageView.d.ts.map +1 -0
  18. package/dist/components/XeboPageView.js +190 -0
  19. package/dist/components/XeboRatingView.d.ts +20 -2
  20. package/dist/components/XeboRatingView.d.ts.map +1 -1
  21. package/dist/components/XeboRatingView.js +63 -37
  22. package/dist/components/XeboSingleChoiceView.d.ts +8 -2
  23. package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
  24. package/dist/components/XeboSingleChoiceView.js +42 -40
  25. package/dist/components/XeboSurveyModal.d.ts.map +1 -1
  26. package/dist/components/XeboSurveyModal.js +151 -35
  27. package/dist/components/XeboTextBoxView.d.ts +4 -2
  28. package/dist/components/XeboTextBoxView.d.ts.map +1 -1
  29. package/dist/components/XeboTextBoxView.js +27 -18
  30. package/dist/core/XeboLanguageService.d.ts.map +1 -1
  31. package/dist/core/XeboLanguageService.js +6 -0
  32. package/dist/core/XeboNetworkService.d.ts +12 -1
  33. package/dist/core/XeboNetworkService.d.ts.map +1 -1
  34. package/dist/core/XeboNetworkService.js +181 -64
  35. package/dist/core/XeboOfflineQueue.d.ts +2 -1
  36. package/dist/core/XeboOfflineQueue.d.ts.map +1 -1
  37. package/dist/core/XeboOfflineQueue.js +24 -10
  38. package/dist/core/XeboSurveyManager.d.ts +16 -1
  39. package/dist/core/XeboSurveyManager.d.ts.map +1 -1
  40. package/dist/core/XeboSurveyManager.js +120 -47
  41. package/dist/i18n/XeboRtl.d.ts +5 -0
  42. package/dist/i18n/XeboRtl.d.ts.map +1 -1
  43. package/dist/i18n/XeboRtl.js +11 -0
  44. package/dist/i18n/XeboStrings.d.ts +6 -0
  45. package/dist/i18n/XeboStrings.d.ts.map +1 -1
  46. package/dist/i18n/XeboStrings.js +19 -5
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/models/XeboAPIModels.d.ts +93 -0
  50. package/dist/models/XeboAPIModels.d.ts.map +1 -1
  51. package/dist/models/XeboModels.d.ts +86 -2
  52. package/dist/models/XeboModels.d.ts.map +1 -1
  53. package/dist/models/XeboModels.js +24 -0
  54. package/package.json +3 -4
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.XeboPageView = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const react_native_1 = require("react-native");
39
+ const XeboTheme_1 = require("../theme/XeboTheme");
40
+ const XeboStrings_1 = require("../i18n/XeboStrings");
41
+ const XeboRtl_1 = require("../i18n/XeboRtl");
42
+ /** One page of the survey: its questions, then Ok / Previous / Next-or-Submit like the web. */
43
+ exports.XeboPageView = (0, react_1.forwardRef)(({ questions, isLastPage, onOk, onNext, onFitHeight, previousLabel, previousIconOnly, canGoBack, onPreviousPage, buttonColors, }, ref) => {
44
+ var _a, _b;
45
+ const theme = (0, XeboTheme_1.getTheme)();
46
+ const scrollRef = (0, react_1.useRef)(null);
47
+ const offsets = (0, react_1.useRef)([]);
48
+ const heights = (0, react_1.useRef)({ layout: 0, content: 0 });
49
+ const reportFit = () => {
50
+ const { layout, content } = heights.current;
51
+ if (layout > 0 && content > 0)
52
+ onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
53
+ };
54
+ // Theme colours: Ok and Next fall back to the survey's primary button, then to the SDK theme.
55
+ const okColor = (_a = buttonColors === null || buttonColors === void 0 ? void 0 : buttonColors.ok) !== null && _a !== void 0 ? _a : buttonColors === null || buttonColors === void 0 ? void 0 : buttonColors.primary;
56
+ const nextColor = (_b = buttonColors === null || buttonColors === void 0 ? void 0 : buttonColors.next) !== null && _b !== void 0 ? _b : buttonColors === null || buttonColors === void 0 ? void 0 : buttonColors.primary;
57
+ const prevColor = buttonColors === null || buttonColors === void 0 ? void 0 : buttonColors.previous;
58
+ const scrollToQuestion = (index) => {
59
+ var _a, _b;
60
+ (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ y: (_b = offsets.current[index]) !== null && _b !== void 0 ? _b : 0, animated: true });
61
+ };
62
+ // Ok checks the question it belongs to, then scrolls the next one into view.
63
+ const handleOk = (index) => {
64
+ if (!onOk(questions[index].id))
65
+ return;
66
+ scrollToQuestion(index + 1);
67
+ };
68
+ // Previous goes to the question above, or from the page's first question back to the last page.
69
+ const handlePrevious = (index) => {
70
+ if (index > 0)
71
+ scrollToQuestion(index - 1);
72
+ else
73
+ onPreviousPage();
74
+ };
75
+ const hasPrevious = (index) => !!previousLabel && (index > 0 || canGoBack);
76
+ // The bottom row belongs to the page's last question.
77
+ const last = questions.length - 1;
78
+ // The web drops Ok / Next for an auto-advancing NPS only when Previous sits beside it, so a row
79
+ // is never empty (e.g. the survey's first question keeps Ok). Submit always stays.
80
+ const hidesForward = (index) => { var _a; return !!((_a = questions[index]) === null || _a === void 0 ? void 0 : _a.hidesButtons) && hasPrevious(index); };
81
+ const hidesNext = !isLastPage && hidesForward(last);
82
+ (0, react_1.useImperativeHandle)(ref, () => ({
83
+ // Only called for auto-advancing questions: scroll to the next one, or from the last go to the next page.
84
+ scrollToNext: (questionId) => {
85
+ const index = questions.findIndex(q => q.id === questionId);
86
+ if (index < 0)
87
+ return;
88
+ // Short pause so the respondent sees their pick before the page moves.
89
+ if (index < last)
90
+ setTimeout(() => scrollToQuestion(index + 1), 300);
91
+ else if (!isLastPage)
92
+ setTimeout(onNext, 300);
93
+ },
94
+ }), [questions, last, isLastPage, onNext]);
95
+ // In the bottom row Previous takes the same size as Next/Submit, like the web.
96
+ const previousButton = (index, bottom = false) => {
97
+ var _a, _b, _c;
98
+ return previousIconOnly ? (<react_native_1.TouchableOpacity style={[styles.iconButton, { backgroundColor: (_a = prevColor === null || prevColor === void 0 ? void 0 : prevColor.background) !== null && _a !== void 0 ? _a : '#F2F2F2', borderRadius: theme.cornerRadius }]} onPress={() => handlePrevious(index)} activeOpacity={0.8} accessibilityLabel={previousLabel}>
99
+ <react_native_1.Text style={[styles.iconText, { color: (_b = prevColor === null || prevColor === void 0 ? void 0 : prevColor.text) !== null && _b !== void 0 ? _b : '#1F2937' }]}>{(0, XeboRtl_1.isRtl)() ? '›' : '‹'}</react_native_1.Text>
100
+ </react_native_1.TouchableOpacity>) : (<react_native_1.TouchableOpacity style={[
101
+ bottom ? styles.button : styles.pairButton,
102
+ { borderRadius: theme.cornerRadius },
103
+ prevColor
104
+ ? { backgroundColor: prevColor.background }
105
+ : [styles.previousOutline, { borderColor: theme.primaryColor }],
106
+ ]} onPress={() => handlePrevious(index)} activeOpacity={0.8}>
107
+ <react_native_1.Text style={[styles.buttonText, bottom && styles.nextText, { color: prevColor ? (_c = prevColor.text) !== null && _c !== void 0 ? _c : '#FFFFFF' : theme.primaryColor, fontFamily: theme.fontFamily }]}>
108
+ {previousLabel}
109
+ </react_native_1.Text>
110
+ </react_native_1.TouchableOpacity>);
111
+ };
112
+ return (<react_native_1.View style={styles.container}>
113
+ <react_native_1.ScrollView ref={scrollRef} style={styles.scroll} keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false} onLayout={e => { heights.current.layout = e.nativeEvent.layout.height; reportFit(); }} onContentSizeChange={(_, h) => { heights.current.content = h; reportFit(); }}>
114
+ {questions.map((q, i) => {
115
+ var _a, _b, _c, _d;
116
+ return (<react_native_1.View key={q.id} onLayout={e => { offsets.current[i] = e.nativeEvent.layout.y; }}>
117
+ {q.view}
118
+ {/* Like the web, the last question's buttons sit under it and scroll with the page. */}
119
+ {i === last && (hasPrevious(last) || !hidesNext) && (<react_native_1.View style={styles.bottomRow}>
120
+ {hasPrevious(last) && previousButton(last, true)}
121
+ {!hidesNext && (<react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: (_a = nextColor === null || nextColor === void 0 ? void 0 : nextColor.background) !== null && _a !== void 0 ? _a : theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={onNext} activeOpacity={0.8}>
122
+ <react_native_1.Text style={[styles.buttonText, styles.nextText, { color: (_b = nextColor === null || nextColor === void 0 ? void 0 : nextColor.text) !== null && _b !== void 0 ? _b : '#FFFFFF', fontFamily: theme.fontFamily }]}>
123
+ {(0, XeboStrings_1.actionLabel)(isLastPage)}
124
+ </react_native_1.Text>
125
+ </react_native_1.TouchableOpacity>)}
126
+ </react_native_1.View>)}
127
+ {i < last && (<react_native_1.View style={styles.okRow}>
128
+ {hasPrevious(i) && previousButton(i)}
129
+ {!hidesForward(i) && (<react_native_1.TouchableOpacity style={[styles.pairButton, { backgroundColor: (_c = okColor === null || okColor === void 0 ? void 0 : okColor.background) !== null && _c !== void 0 ? _c : theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={() => handleOk(i)} activeOpacity={0.8}>
130
+ <react_native_1.Text style={[styles.buttonText, { color: (_d = okColor === null || okColor === void 0 ? void 0 : okColor.text) !== null && _d !== void 0 ? _d : '#FFFFFF', fontFamily: theme.fontFamily }]}>
131
+ {(0, XeboStrings_1.getStrings)().ok} ✓
132
+ </react_native_1.Text>
133
+ </react_native_1.TouchableOpacity>)}
134
+ </react_native_1.View>)}
135
+ </react_native_1.View>);
136
+ })}
137
+ </react_native_1.ScrollView>
138
+ </react_native_1.View>);
139
+ });
140
+ const styles = react_native_1.StyleSheet.create({
141
+ container: {
142
+ flex: 1,
143
+ paddingBottom: 10,
144
+ },
145
+ scroll: {
146
+ flex: 1,
147
+ },
148
+ okRow: {
149
+ flexDirection: 'row',
150
+ justifyContent: 'center',
151
+ gap: 12,
152
+ marginBottom: 16,
153
+ },
154
+ pairButton: {
155
+ paddingVertical: 10,
156
+ paddingHorizontal: 24,
157
+ justifyContent: 'center',
158
+ },
159
+ previousOutline: {
160
+ borderWidth: 1.5,
161
+ },
162
+ iconButton: {
163
+ width: 44,
164
+ alignItems: 'center',
165
+ justifyContent: 'center',
166
+ },
167
+ iconText: {
168
+ fontSize: 24,
169
+ lineHeight: 26,
170
+ },
171
+ bottomRow: {
172
+ flexDirection: 'row',
173
+ gap: 12,
174
+ marginTop: 4,
175
+ marginBottom: 8,
176
+ marginHorizontal: 20,
177
+ },
178
+ button: {
179
+ flex: 1,
180
+ paddingVertical: 14,
181
+ alignItems: 'center',
182
+ },
183
+ buttonText: {
184
+ fontSize: 15,
185
+ fontWeight: '600',
186
+ },
187
+ nextText: {
188
+ fontSize: 16,
189
+ },
190
+ });
@@ -1,10 +1,28 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Reports how much taller (or shorter) the sheet must be to fit the content without a gap. */
8
+ onFitHeight?: (delta: number) => void;
9
+ /** Shown with other questions on one page: no own button, sized to content. */
10
+ embedded?: boolean;
11
+ /** Fires when a rating is picked (drives auto-advance on a shared page). */
12
+ onSelect?: () => void;
7
13
  }
8
- export declare const XeboRatingView: React.FC<Props>;
14
+ export declare function FlatEmoji({ index, selected, hasSelection, outline, size, color, featureColor, }: {
15
+ /** 0 (saddest) to 4 (happiest). */
16
+ index: number;
17
+ selected: boolean;
18
+ hasSelection: boolean;
19
+ /** Coloured ring and features on a white face instead of a filled face. */
20
+ outline?: boolean;
21
+ size?: number;
22
+ /** Overrides the face colour and the eye/mouth colour (used by the NPS arc). */
23
+ color?: string;
24
+ featureColor?: string;
25
+ }): React.JSX.Element;
26
+ export declare const XeboRatingView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
27
  export {};
10
28
  //# sourceMappingURL=XeboRatingView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboRatingView.d.ts","sourceRoot":"","sources":["../../src/components/XeboRatingView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAWhD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKhE,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AA6ID,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgJ1C,CAAC"}
1
+ {"version":3,"file":"XeboRatingView.d.ts","sourceRoot":"","sources":["../../src/components/XeboRatingView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAWjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAc,MAAM,sBAAsB,CAAC;AAKhG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,+FAA+F;IAC/F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAYD,wBAAgB,SAAS,CAAC,EACxB,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAe,EAAE,IAAS,EAAE,KAAK,EAAE,YAAY,GAC/E,EAAE;IACD,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,qBAmDA;AAsFD,eAAO,MAAM,cAAc,kFAgKzB,CAAC"}
@@ -34,8 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.XeboRatingView = void 0;
37
+ exports.FlatEmoji = FlatEmoji;
37
38
  const react_1 = __importStar(require("react"));
38
39
  const react_native_1 = require("react-native");
40
+ const XeboModels_1 = require("../models/XeboModels");
39
41
  const XeboTheme_1 = require("../theme/XeboTheme");
40
42
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
43
  const XeboRtl_1 = require("../i18n/XeboRtl");
@@ -47,40 +49,46 @@ const FLAT_EMOJI_CONFIGS = [
47
49
  { bg: '#8AC926', mouth: 'smile' },
48
50
  { bg: '#21B573', mouth: 'bigSmile' },
49
51
  ];
50
- function FlatEmoji({ index, selected, hasSelection }) {
51
- const conf = FLAT_EMOJI_CONFIGS[Math.min(index, FLAT_EMOJI_CONFIGS.length - 1)];
52
- const size = 44;
53
- const eyeSize = 5;
54
- const mouthW = 18;
55
- const mouthH = 9;
52
+ function FlatEmoji({ index, selected, hasSelection, outline = false, size = 44, color, featureColor, }) {
53
+ const base = FLAT_EMOJI_CONFIGS[Math.min(index, FLAT_EMOJI_CONFIGS.length - 1)];
54
+ const conf = color ? Object.assign(Object.assign({}, base), { bg: color }) : base;
55
+ // Features are drawn for a 44pt face and scaled to the requested size.
56
+ const k = size / 44;
57
+ const eyeSize = 5 * k;
58
+ const mouthW = 18 * k;
59
+ const mouthH = 9 * k;
60
+ const stroke = Math.max(1.5, 2.5 * k);
56
61
  const opacity = hasSelection ? (selected ? 1 : 0.35) : 1;
62
+ const fg = featureColor !== null && featureColor !== void 0 ? featureColor : (outline ? conf.bg : '#fff');
57
63
  return (<react_native_1.View style={{
58
64
  width: size,
59
65
  height: size,
60
66
  borderRadius: size / 2,
61
- backgroundColor: conf.bg,
67
+ backgroundColor: outline ? '#fff' : conf.bg,
68
+ borderWidth: outline ? 2 : 0,
69
+ borderColor: conf.bg,
62
70
  opacity,
63
71
  alignItems: 'center',
64
72
  justifyContent: 'center',
65
73
  }}>
66
74
  {/* Eyes */}
67
- <react_native_1.View style={{ flexDirection: 'row', gap: 9, marginBottom: 6 }}>
68
- <react_native_1.View style={{ width: eyeSize, height: eyeSize, borderRadius: eyeSize / 2, backgroundColor: '#fff' }}/>
69
- <react_native_1.View style={{ width: eyeSize, height: eyeSize, borderRadius: eyeSize / 2, backgroundColor: '#fff' }}/>
75
+ <react_native_1.View style={{ flexDirection: 'row', gap: 9 * k, marginBottom: 6 * k }}>
76
+ <react_native_1.View style={{ width: eyeSize, height: eyeSize, borderRadius: eyeSize / 2, backgroundColor: fg }}/>
77
+ <react_native_1.View style={{ width: eyeSize, height: eyeSize, borderRadius: eyeSize / 2, backgroundColor: fg }}/>
70
78
  </react_native_1.View>
71
79
  {/* Mouth */}
72
- {conf.mouth === 'neutral' ? (<react_native_1.View style={{ width: mouthW, height: 2.5, borderRadius: 2, backgroundColor: '#fff' }}/>) : conf.mouth === 'frown' ? (
80
+ {conf.mouth === 'neutral' ? (<react_native_1.View style={{ width: mouthW, height: stroke, borderRadius: 2, backgroundColor: fg }}/>) : conf.mouth === 'frown' ? (
73
81
  // Top half of a ring = arch = frown
74
82
  <react_native_1.View style={{ width: mouthW, height: mouthH, overflow: 'hidden' }}>
75
- <react_native_1.View style={{ width: mouthW, height: mouthW, borderRadius: mouthW / 2, borderWidth: 2.5, borderColor: '#fff' }}/>
83
+ <react_native_1.View style={{ width: mouthW, height: mouthW, borderRadius: mouthW / 2, borderWidth: stroke, borderColor: fg }}/>
76
84
  </react_native_1.View>) : conf.mouth === 'smile' ? (
77
85
  // Bottom half of a ring = U = smile
78
86
  <react_native_1.View style={{ width: mouthW, height: mouthH, overflow: 'hidden' }}>
79
- <react_native_1.View style={{ width: mouthW, height: mouthW, borderRadius: mouthW / 2, borderWidth: 2.5, borderColor: '#fff', marginTop: -mouthH }}/>
87
+ <react_native_1.View style={{ width: mouthW, height: mouthW, borderRadius: mouthW / 2, borderWidth: stroke, borderColor: fg, marginTop: -mouthH }}/>
80
88
  </react_native_1.View>) : (
81
89
  // bigSmile: wider U
82
- <react_native_1.View style={{ width: 22, height: 11, overflow: 'hidden' }}>
83
- <react_native_1.View style={{ width: 22, height: 22, borderRadius: 11, borderWidth: 3, borderColor: '#fff', marginTop: -11 }}/>
90
+ <react_native_1.View style={{ width: 22 * k, height: 11 * k, overflow: 'hidden' }}>
91
+ <react_native_1.View style={{ width: 22 * k, height: 22 * k, borderRadius: 11 * k, borderWidth: Math.max(1.5, 3 * k), borderColor: fg, marginTop: -11 * k }}/>
84
92
  </react_native_1.View>)}
85
93
  </react_native_1.View>);
86
94
  }
@@ -130,6 +138,8 @@ function RatingIcon({ style, index, selected, filled, color, hasSelection, }) {
130
138
  return <FlatEmoji index={index} selected={selected} hasSelection={hasSelection}/>;
131
139
  case '3d_emoji':
132
140
  return <FlatEmoji index={index} selected={selected} hasSelection={hasSelection}/>;
141
+ case 'outline_emoji':
142
+ return <FlatEmoji index={index} selected={selected} hasSelection={hasSelection} outline/>;
133
143
  case 'star':
134
144
  default:
135
145
  return (<react_native_1.Text style={{ fontSize: 34, color: filled ? activeColor : '#E5E7EB' }}>
@@ -137,14 +147,19 @@ function RatingIcon({ style, index, selected, filled, color, hasSelection, }) {
137
147
  </react_native_1.Text>);
138
148
  }
139
149
  }
140
- const XeboRatingView = ({ question, isLastQuestion, onAnswer }) => {
150
+ exports.XeboRatingView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, onFitHeight, embedded, onSelect }, ref) => {
141
151
  var _a, _b, _c, _d;
142
152
  const theme = (0, XeboTheme_1.getTheme)();
153
+ const scrollHeights = (0, react_1.useRef)({ layout: 0, content: 0 });
154
+ const reportFit = () => {
155
+ const { layout, content } = scrollHeights.current;
156
+ if (layout > 0 && content > 0)
157
+ onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
158
+ };
143
159
  const ratingStyle = (_a = question.ratingStyle) !== null && _a !== void 0 ? _a : 'star';
144
160
  const ratingColor = (_b = question.ratingColor) !== null && _b !== void 0 ? _b : theme.primaryColor;
145
161
  const totalSteps = (_d = (_c = question.columns) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 5;
146
- console.log('[XeboRatingView] question:', JSON.stringify(question, null, 2));
147
- const [selected, setSelected] = (0, react_1.useState)(null);
162
+ const [selected, setSelected] = (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); });
148
163
  const [followUpText, setFollowUpText] = (0, react_1.useState)('');
149
164
  const [error, setError] = (0, react_1.useState)('');
150
165
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
@@ -162,27 +177,37 @@ const XeboRatingView = ({ question, isLastQuestion, onAnswer }) => {
162
177
  setSelected(index);
163
178
  setError('');
164
179
  setFollowUpText('');
180
+ // A comment box opens under the rating, so stay put when there is one.
181
+ if (!question.followUpQuestion)
182
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect();
165
183
  };
166
- const handleNext = () => {
184
+ const collect = () => {
167
185
  var _a, _b, _c, _d, _e, _f;
168
186
  if (question.isRequired && selected === null) {
169
187
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please select a rating.'));
170
188
  shake();
171
- return;
189
+ return null;
172
190
  }
173
191
  react_native_1.Keyboard.dismiss();
174
- const idx = selected !== null && selected !== void 0 ? selected : 0;
175
- const colId = (_c = (_b = (_a = question.columns) === null || _a === void 0 ? void 0 : _a[idx]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : idx.toString();
192
+ if (selected === null)
193
+ return { questionId: question.id, value: [] };
194
+ const colId = (_c = (_b = (_a = question.columns) === null || _a === void 0 ? void 0 : _a[selected]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : selected.toString();
176
195
  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 : 'rating';
177
- onAnswer({
196
+ return {
178
197
  questionId: question.id,
179
198
  value: [{ rowId, colId, text: followUpText || undefined }],
180
- });
199
+ };
200
+ };
201
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
202
+ const handleNext = () => {
203
+ const answer = collect();
204
+ if (answer)
205
+ onAnswer(answer);
181
206
  };
182
207
  return (
183
208
  // Outer view fills modal content area; button pinned at bottom outside ScrollView
184
- <react_native_1.View style={styles.outer}>
185
- <react_native_1.ScrollView style={styles.scroll} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false} keyboardShouldPersistTaps="handled">
209
+ <react_native_1.View style={[styles.outer, embedded && styles.embedded]}>
210
+ <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">
186
211
  <react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
187
212
  {question.title}
188
213
  </react_native_1.Text>
@@ -218,22 +243,21 @@ const XeboRatingView = ({ question, isLastQuestion, onAnswer }) => {
218
243
  <react_native_1.Text style={[styles.followUpTitle, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
219
244
  {question.followUpQuestion}
220
245
  </react_native_1.Text>
221
- <react_native_1.TextInput style={[styles.followUpInput, { borderColor: '#E5E7EB', color: theme.textColor, borderRadius: theme.cornerRadius }, (0, XeboRtl_1.rtlText)()]} placeholder="Your comment..." placeholderTextColor="#9CA3AF" value={followUpText} onChangeText={setFollowUpText} multiline numberOfLines={3} textAlignVertical="top"/>
246
+ <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"/>
222
247
  </react_native_1.View>)}
223
248
  </react_native_1.ScrollView>
224
249
 
225
250
  {/* Error + button always visible at bottom, outside scroll */}
226
251
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
227
- <react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
228
- <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius, opacity: selected === null ? 0.4 : 1 }]} onPress={handleNext} disabled={selected === null} activeOpacity={0.8}>
229
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
230
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
231
- </react_native_1.Text>
232
- </react_native_1.TouchableOpacity>
233
- </react_native_1.Animated.View>
252
+ {!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
253
+ <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius, opacity: selected === null ? 0.4 : 1 }]} onPress={handleNext} disabled={selected === null} activeOpacity={0.8}>
254
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
255
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
256
+ </react_native_1.Text>
257
+ </react_native_1.TouchableOpacity>
258
+ </react_native_1.Animated.View>)}
234
259
  </react_native_1.View>);
235
- };
236
- exports.XeboRatingView = XeboRatingView;
260
+ });
237
261
  const styles = react_native_1.StyleSheet.create({
238
262
  outer: {
239
263
  flex: 1,
@@ -241,7 +265,9 @@ const styles = react_native_1.StyleSheet.create({
241
265
  paddingBottom: 10,
242
266
  justifyContent: 'space-between',
243
267
  },
244
- scroll: { maxHeight: 320 },
268
+ // Fills the sheet so its measured height reveals any gap; the sheet itself caps at 75%.
269
+ scroll: { flex: 1 },
270
+ embedded: { flex: 0 },
245
271
  scrollContent: { paddingTop: 16, paddingBottom: 8 },
246
272
  title: { fontSize: 18, fontWeight: '700', marginBottom: 16 },
247
273
  subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
@@ -1,10 +1,16 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Reports how much taller (or shorter) the sheet must be to fit every option without scrolling. */
8
+ onFitHeight?: (delta: number) => void;
9
+ /** Shown with other questions on one page: no own button, sized to content. */
10
+ embedded?: boolean;
11
+ /** Fires when an option is picked (drives auto-advance on a shared page). */
12
+ onSelect?: () => void;
7
13
  }
8
- export declare const XeboSingleChoiceView: React.FC<Props>;
14
+ export declare const XeboSingleChoiceView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
15
  export {};
10
16
  //# sourceMappingURL=XeboSingleChoiceView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboSingleChoiceView.d.ts","sourceRoot":"","sources":["../../src/components/XeboSingleChoiceView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAC;AAK5E,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAsFhD,CAAC"}
1
+ {"version":3,"file":"XeboSingleChoiceView.d.ts","sourceRoot":"","sources":["../../src/components/XeboSingleChoiceView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AASjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKhG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,oGAAoG;IACpG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,eAAO,MAAM,oBAAoB,kFAyG/B,CAAC"}
@@ -39,10 +39,16 @@ const react_native_1 = require("react-native");
39
39
  const XeboTheme_1 = require("../theme/XeboTheme");
40
40
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
41
  const XeboRtl_1 = require("../i18n/XeboRtl");
42
- const XeboSingleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
43
- var _a;
42
+ exports.XeboSingleChoiceView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, onFitHeight, embedded, onSelect }, ref) => {
43
+ var _a, _b, _c, _d, _e, _f;
44
44
  const theme = (0, XeboTheme_1.getTheme)();
45
- const [selectedId, setSelectedId] = (0, react_1.useState)(null);
45
+ const listHeights = (0, react_1.useRef)({ layout: 0, content: 0 });
46
+ const reportFit = () => {
47
+ const { layout, content } = listHeights.current;
48
+ if (layout > 0 && content > 0)
49
+ onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
50
+ };
51
+ const [selectedId, setSelectedId] = (0, react_1.useState)((_e = (_c = (_b = (_a = question.previousAnswer) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.rowId) !== null && _c !== void 0 ? _c : (_d = question.autoSelectOptionIds) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : null);
46
52
  const [error, setError] = (0, react_1.useState)('');
47
53
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
48
54
  const shake = () => {
@@ -56,24 +62,29 @@ const XeboSingleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
56
62
  const handleSelect = (choice) => {
57
63
  setSelectedId(choice.id);
58
64
  setError('');
65
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect();
59
66
  };
60
- const handleNext = () => {
67
+ const collect = () => {
61
68
  var _a, _b;
62
69
  if (question.isRequired && !selectedId) {
63
70
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please select an option.'));
64
71
  shake();
65
- return;
66
- }
67
- if (!selectedId) {
68
- onAnswer({ questionId: question.id, value: [] });
69
- return;
72
+ return null;
70
73
  }
71
- onAnswer({
74
+ if (!selectedId)
75
+ return { questionId: question.id, value: [] };
76
+ return {
72
77
  questionId: question.id,
73
78
  value: [{ rowId: selectedId, text: (_b = (_a = question.options) === null || _a === void 0 ? void 0 : _a.find(o => o.id === selectedId)) === null || _b === void 0 ? void 0 : _b.text }],
74
- });
79
+ };
80
+ };
81
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
82
+ const handleNext = () => {
83
+ const answer = collect();
84
+ if (answer)
85
+ onAnswer(answer);
75
86
  };
76
- return (<react_native_1.View style={styles.container}>
87
+ return (<react_native_1.View style={[styles.container, embedded && styles.embedded]}>
77
88
  <react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
78
89
  {question.title}
79
90
  </react_native_1.Text>
@@ -81,35 +92,34 @@ const XeboSingleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
81
92
  {question.subtitle}
82
93
  </react_native_1.Text>)}
83
94
 
84
- <react_native_1.ScrollView style={styles.optionsList} showsVerticalScrollIndicator={false}>
85
- {((_a = question.options) !== null && _a !== void 0 ? _a : []).map(choice => {
95
+ <react_native_1.ScrollView style={[styles.optionsList, embedded && styles.embedded]} scrollEnabled={!embedded} showsVerticalScrollIndicator={false} onLayout={e => { listHeights.current.layout = e.nativeEvent.layout.height; reportFit(); }} onContentSizeChange={(_, h) => { listHeights.current.content = h; reportFit(); }}>
96
+ {((_f = question.options) !== null && _f !== void 0 ? _f : []).map(choice => {
86
97
  const selected = selectedId === choice.id;
87
98
  return (<react_native_1.TouchableOpacity key={choice.id} style={[
88
99
  styles.optionRow,
89
- { borderColor: selected ? theme.primaryColor : '#E5E7EB' },
100
+ selected
101
+ ? { borderColor: theme.primaryColor, backgroundColor: '#F3F4F6' }
102
+ : { borderColor: '#E5E7EB' },
90
103
  ]} onPress={() => handleSelect(choice)} activeOpacity={0.7}>
91
- <react_native_1.View style={[styles.radio, { borderColor: selected ? theme.primaryColor : '#9CA3AF' }]}>
92
- {selected && <react_native_1.View style={[styles.radioDot, { backgroundColor: theme.primaryColor }]}/>}
93
- </react_native_1.View>
94
104
  <react_native_1.Text style={[styles.optionText, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
95
105
  {choice.text}
96
106
  </react_native_1.Text>
107
+ {selected && <react_native_1.Text style={[styles.checkmark, { color: theme.primaryColor }]}>✓</react_native_1.Text>}
97
108
  </react_native_1.TouchableOpacity>);
98
109
  })}
99
110
  </react_native_1.ScrollView>
100
111
 
101
112
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
102
113
 
103
- <react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
104
- <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
105
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
106
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
107
- </react_native_1.Text>
108
- </react_native_1.TouchableOpacity>
109
- </react_native_1.Animated.View>
114
+ {!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
115
+ <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
116
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
117
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
118
+ </react_native_1.Text>
119
+ </react_native_1.TouchableOpacity>
120
+ </react_native_1.Animated.View>)}
110
121
  </react_native_1.View>);
111
- };
112
- exports.XeboSingleChoiceView = XeboSingleChoiceView;
122
+ });
113
123
  const styles = react_native_1.StyleSheet.create({
114
124
  container: {
115
125
  flex: 1,
@@ -117,6 +127,7 @@ const styles = react_native_1.StyleSheet.create({
117
127
  paddingTop: 16,
118
128
  paddingBottom: 10,
119
129
  },
130
+ embedded: { flex: 0 },
120
131
  title: {
121
132
  fontSize: 18,
122
133
  fontWeight: '700',
@@ -139,19 +150,10 @@ const styles = react_native_1.StyleSheet.create({
139
150
  padding: 14,
140
151
  marginBottom: 10,
141
152
  },
142
- radio: {
143
- width: 20,
144
- height: 20,
145
- borderRadius: 10,
146
- borderWidth: 2,
147
- alignItems: 'center',
148
- justifyContent: 'center',
149
- marginEnd: 12,
150
- },
151
- radioDot: {
152
- width: 10,
153
- height: 10,
154
- borderRadius: 5,
153
+ checkmark: {
154
+ fontSize: 16,
155
+ fontWeight: '700',
156
+ marginStart: 12,
155
157
  },
156
158
  optionText: {
157
159
  fontSize: 15,
@@ -1 +1 @@
1
- {"version":3,"file":"XeboSurveyModal.d.ts","sourceRoot":"","sources":["../../src/components/XeboSurveyModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAoFjF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAmUnC,CAAC"}
1
+ {"version":3,"file":"XeboSurveyModal.d.ts","sourceRoot":"","sources":["../../src/components/XeboSurveyModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAgHjF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAqbnC,CAAC"}