@opengovsg/confetti 0.0.2 → 0.0.3
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/build/confetti.css +10 -10
- package/build/index.d.ts +4 -4
- package/build/index.js +27 -5
- package/package.json +1 -1
package/build/confetti.css
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
:root {
|
|
2
|
+
--confetti-font-scale: 16px;
|
|
2
3
|
/* Define CSS Variables with defaults */
|
|
3
|
-
--confetti-font-family:
|
|
4
|
-
-apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', Helvetica,
|
|
5
|
-
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
6
4
|
--confetti-box-padding: 20px 24px;
|
|
7
5
|
--confetti-max-width: 300px;
|
|
8
6
|
--confetti-z-index: 2147483647;
|
|
@@ -39,6 +37,7 @@
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
.confetti-dialog {
|
|
40
|
+
width: 100%;
|
|
42
41
|
max-width: var(--confetti-max-width);
|
|
43
42
|
background: transparent;
|
|
44
43
|
position: relative;
|
|
@@ -79,6 +78,7 @@
|
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
.confetti {
|
|
81
|
+
font-family: var(--confetti-font-family);
|
|
82
82
|
overflow: hidden;
|
|
83
83
|
padding: 24px;
|
|
84
84
|
border-radius: var(--confetti-border-radius);
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
flex-direction: column;
|
|
88
88
|
gap: 16px;
|
|
89
89
|
color: var(--confetti-text-primary-color);
|
|
90
|
-
font-size:
|
|
90
|
+
font-size: var(--confetti-font-scale);
|
|
91
91
|
width: 100%;
|
|
92
92
|
background: var(--confetti-background-color);
|
|
93
93
|
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
border-radius: 8px;
|
|
102
102
|
cursor: pointer;
|
|
103
103
|
transition: transform 200ms;
|
|
104
|
-
font-size:
|
|
104
|
+
font-size: 0.875em;
|
|
105
105
|
font-weight: 500;
|
|
106
106
|
line-height: 20px;
|
|
107
107
|
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
.cf-choice {
|
|
157
|
-
font-size:
|
|
157
|
+
font-size: 1em;
|
|
158
158
|
cursor: pointer;
|
|
159
159
|
padding: 8px 10px;
|
|
160
160
|
border-radius: 6px;
|
|
@@ -336,7 +336,7 @@
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
.cf-description {
|
|
339
|
-
font-size:
|
|
339
|
+
font-size: 0.875em;
|
|
340
340
|
line-height: 20px;
|
|
341
341
|
font-weight: 400;
|
|
342
342
|
color: var(--confetti-text-subtle-color);
|
|
@@ -369,7 +369,7 @@
|
|
|
369
369
|
|
|
370
370
|
.cf-rating-emoji,
|
|
371
371
|
.cf-rating-star {
|
|
372
|
-
font-size:
|
|
372
|
+
font-size: 1em;
|
|
373
373
|
background-color: transparent;
|
|
374
374
|
border: none;
|
|
375
375
|
padding: 0;
|
|
@@ -405,10 +405,10 @@
|
|
|
405
405
|
.cf-rating-text {
|
|
406
406
|
display: flex;
|
|
407
407
|
justify-content: space-between;
|
|
408
|
-
font-size:
|
|
408
|
+
font-size: 0.75em;
|
|
409
409
|
color: var(--confetti-text-subtle-color);
|
|
410
410
|
font-weight: 500;
|
|
411
|
-
line-height:
|
|
411
|
+
line-height: 1;
|
|
412
412
|
|
|
413
413
|
.cf-rating-text-lower {
|
|
414
414
|
flex: 1;
|
package/build/index.d.ts
CHANGED
|
@@ -404,9 +404,7 @@ declare const MultiChoice: ({
|
|
|
404
404
|
}: MultiChoiceProps) => react_jsx_runtime3.JSX.Element;
|
|
405
405
|
//#endregion
|
|
406
406
|
//#region src/components/presentation/Flow.d.ts
|
|
407
|
-
type ChildField = ({
|
|
408
|
-
onChange
|
|
409
|
-
}: {
|
|
407
|
+
type ChildField = (_: {
|
|
410
408
|
onChange: (answer: Answer) => void;
|
|
411
409
|
question: Question$1;
|
|
412
410
|
error?: string;
|
|
@@ -415,11 +413,13 @@ interface FlowProps {
|
|
|
415
413
|
onSubmit: (answer: Answer) => void;
|
|
416
414
|
children: ChildField;
|
|
417
415
|
question: Question$1;
|
|
416
|
+
isLastQuestion: boolean;
|
|
418
417
|
}
|
|
419
418
|
declare const Flow: ({
|
|
420
419
|
onSubmit,
|
|
421
420
|
children,
|
|
422
|
-
question
|
|
421
|
+
question,
|
|
422
|
+
isLastQuestion
|
|
423
423
|
}: FlowProps) => react_jsx_runtime3.JSX.Element;
|
|
424
424
|
//#endregion
|
|
425
425
|
//#region src/components/presentation/Embed.d.ts
|
package/build/index.js
CHANGED
|
@@ -192,7 +192,7 @@ const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, meta
|
|
|
192
192
|
setSurvey(parseResult.data);
|
|
193
193
|
});
|
|
194
194
|
if (!respondent && !internalRespondentId) return;
|
|
195
|
-
client$1.get(`v1/cfti/${surveyId}/respondent/${respondent
|
|
195
|
+
client$1.get(`v1/cfti/${surveyId}/respondent/${respondent || internalRespondentId}`).json().then((data) => {
|
|
196
196
|
const parseResult = publicGetRespondentOutputSchema.safeParse(data);
|
|
197
197
|
if (!parseResult.success) {
|
|
198
198
|
setLastRespondedAt(null);
|
|
@@ -209,7 +209,7 @@ const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, meta
|
|
|
209
209
|
]);
|
|
210
210
|
const submit = useCallback(async ({ answers }) => {
|
|
211
211
|
await client$1.put(`v1/cfti/${surveyId}/response/${responseId}`, { json: {
|
|
212
|
-
respondent: respondent
|
|
212
|
+
respondent: respondent || internalRespondentId,
|
|
213
213
|
data: answers,
|
|
214
214
|
metadata
|
|
215
215
|
} });
|
|
@@ -357,11 +357,12 @@ const getNextQuestionState = ({ originalQuestions, answers, errors, pointer = -1
|
|
|
357
357
|
for (let i = 0; i < questions.length; i++) {
|
|
358
358
|
const question = questions[i];
|
|
359
359
|
if (!question) continue;
|
|
360
|
-
|
|
360
|
+
const visible = isVisible({
|
|
361
361
|
index: i,
|
|
362
362
|
questions,
|
|
363
363
|
answers
|
|
364
364
|
});
|
|
365
|
+
question.visible = pointer === i || visible;
|
|
365
366
|
}
|
|
366
367
|
let nextIndex = questions.findIndex((q, i) => i > pointer && q.visible && answers[q.id] === void 0);
|
|
367
368
|
if (nextIndex === -1) nextIndex = questions.findLastIndex((q) => !!q.visible);
|
|
@@ -1108,7 +1109,7 @@ const getInitialState = (type) => {
|
|
|
1108
1109
|
default: return "";
|
|
1109
1110
|
}
|
|
1110
1111
|
};
|
|
1111
|
-
const Flow = ({ onSubmit, children, question }) => {
|
|
1112
|
+
const Flow = ({ onSubmit, children, question, isLastQuestion }) => {
|
|
1112
1113
|
const [answer, setAnswer] = useState(getInitialState(question.properties.type));
|
|
1113
1114
|
const validator = useMemo(() => getAnswerValidator(question.properties, { required: question.required }), [question.properties, question.required]);
|
|
1114
1115
|
const error = useMemo(() => {
|
|
@@ -1116,13 +1117,30 @@ const Flow = ({ onSubmit, children, question }) => {
|
|
|
1116
1117
|
if (parseResult.success) return;
|
|
1117
1118
|
return prettifyError(parseResult.error);
|
|
1118
1119
|
}, [answer, validator]);
|
|
1120
|
+
const hasNextQuestion = useMemo(() => {
|
|
1121
|
+
const rule = question.routingLogic;
|
|
1122
|
+
if (rule.type !== "always" && (answer === "" || Array.isArray(answer) && answer.length === 0) && question.required) return true;
|
|
1123
|
+
const match = rule.type === "always" ? rule.target : rule.cases.find((condition) => evaluateCondition({
|
|
1124
|
+
answer,
|
|
1125
|
+
condition
|
|
1126
|
+
}))?.target ?? rule.default;
|
|
1127
|
+
if (match.type === "end") return false;
|
|
1128
|
+
if (match.type === "next") return !isLastQuestion;
|
|
1129
|
+
return true;
|
|
1130
|
+
}, [
|
|
1131
|
+
answer,
|
|
1132
|
+
isLastQuestion,
|
|
1133
|
+
question.required,
|
|
1134
|
+
question.routingLogic
|
|
1135
|
+
]);
|
|
1119
1136
|
return /* @__PURE__ */ jsxs(Fragment, { children: [children({
|
|
1120
1137
|
onChange: setAnswer,
|
|
1121
1138
|
question,
|
|
1122
1139
|
error
|
|
1123
1140
|
}), /* @__PURE__ */ jsx(SubmitButton, {
|
|
1124
1141
|
isDisabled: !!error,
|
|
1125
|
-
onPress: () => onSubmit(answer)
|
|
1142
|
+
onPress: () => onSubmit(answer),
|
|
1143
|
+
children: hasNextQuestion ? "Next" : "Submit"
|
|
1126
1144
|
})] });
|
|
1127
1145
|
};
|
|
1128
1146
|
|
|
@@ -1172,10 +1190,12 @@ const PopoverConfetti = ({ closeOnFinishMs, ...props }) => {
|
|
|
1172
1190
|
props.onFinished?.();
|
|
1173
1191
|
},
|
|
1174
1192
|
children: ({ current, questions, update, isSubmitted }) => {
|
|
1193
|
+
const isLastQuestion = current === questions.length - 1;
|
|
1175
1194
|
if (isSubmitted) return /* @__PURE__ */ jsx(ThankYouMessage, {});
|
|
1176
1195
|
const currentQuestion = questions[current];
|
|
1177
1196
|
if (!currentQuestion) return /* @__PURE__ */ jsx(Fragment, {});
|
|
1178
1197
|
return /* @__PURE__ */ jsx(Flow, {
|
|
1198
|
+
isLastQuestion,
|
|
1179
1199
|
question: currentQuestion,
|
|
1180
1200
|
onSubmit: (answer) => {
|
|
1181
1201
|
return update({
|
|
@@ -1198,10 +1218,12 @@ const StepperConfetti = (props) => {
|
|
|
1198
1218
|
...props,
|
|
1199
1219
|
shouldAutoSubmit: true,
|
|
1200
1220
|
children: ({ current, questions, update, isSubmitted }) => {
|
|
1221
|
+
const isLastQuestion = current === questions.length - 1;
|
|
1201
1222
|
if (isSubmitted) return /* @__PURE__ */ jsx(ThankYouMessage, {});
|
|
1202
1223
|
const currentQuestion = questions[current];
|
|
1203
1224
|
if (!currentQuestion) return /* @__PURE__ */ jsx(Fragment, {});
|
|
1204
1225
|
return /* @__PURE__ */ jsx(Flow, {
|
|
1226
|
+
isLastQuestion,
|
|
1205
1227
|
question: currentQuestion,
|
|
1206
1228
|
onSubmit: (answer) => {
|
|
1207
1229
|
return update({
|