@opengovsg/confetti 0.0.1 → 0.0.2
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/index.d.ts +16 -4
- package/build/index.js +24 -10
- package/package.json +3 -3
package/build/index.d.ts
CHANGED
|
@@ -131,6 +131,11 @@ declare const publicGetSurveyOutputSchema: z.ZodMiniObject<{
|
|
|
131
131
|
}, z.core.$strip>], "type">;
|
|
132
132
|
}, z.core.$strip>], "type">;
|
|
133
133
|
}, z.core.$strip>>;
|
|
134
|
+
confirmation: z.ZodMiniObject<{
|
|
135
|
+
title: z.ZodMiniString<string>;
|
|
136
|
+
description: z.ZodMiniString<string>;
|
|
137
|
+
buttonText: z.ZodMiniString<string>;
|
|
138
|
+
}, z.core.$strip>;
|
|
134
139
|
}, z.core.$strip>;
|
|
135
140
|
type PublicGetSurveyOutput = z.infer<typeof publicGetSurveyOutputSchema>;
|
|
136
141
|
//#endregion
|
|
@@ -195,7 +200,7 @@ interface ConfettiProviderProps {
|
|
|
195
200
|
surveyId: string;
|
|
196
201
|
publishableKey: string;
|
|
197
202
|
respondent?: string;
|
|
198
|
-
metadata
|
|
203
|
+
metadata?: Record<string, string>;
|
|
199
204
|
apiBaseUrl?: string;
|
|
200
205
|
isSurveyVisible?: boolean | ((_: {
|
|
201
206
|
lastRespondedAt: Date | null;
|
|
@@ -216,6 +221,7 @@ declare const useConfetti: () => ConfettiContextValue;
|
|
|
216
221
|
interface ConfettiProps extends Omit<ConfettiProviderProps, 'children'>, Pick<ConfettiControllerProps, 'onFinished' | 'shouldAutoSubmit'> {}
|
|
217
222
|
declare const Confetti: ({
|
|
218
223
|
children,
|
|
224
|
+
onFinished,
|
|
219
225
|
shouldAutoSubmit,
|
|
220
226
|
...props
|
|
221
227
|
}: ConfettiProps & Pick<ConfettiControllerProps, "children" | "shouldAutoSubmit">) => react_jsx_runtime3.JSX.Element;
|
|
@@ -235,11 +241,11 @@ declare const ThankYouMessage: ({
|
|
|
235
241
|
title,
|
|
236
242
|
description,
|
|
237
243
|
classNames
|
|
238
|
-
}: ThankYouMessageProps) => react_jsx_runtime3.JSX.Element;
|
|
244
|
+
}: ThankYouMessageProps) => react_jsx_runtime3.JSX.Element | null;
|
|
239
245
|
//#endregion
|
|
240
246
|
//#region src/components/container/PopoverContainer.d.ts
|
|
241
247
|
interface PopoverContainerProps {
|
|
242
|
-
closeOnFinishMs?: number;
|
|
248
|
+
closeOnFinishMs?: number | null;
|
|
243
249
|
classNames?: {
|
|
244
250
|
dialog?: string;
|
|
245
251
|
closeButton?: string;
|
|
@@ -431,7 +437,13 @@ declare const EmbeddedConfetti: (props: ConfettiProps) => react_jsx_runtime3.JSX
|
|
|
431
437
|
//#endregion
|
|
432
438
|
//#region src/templates/PopoverConfetti.d.ts
|
|
433
439
|
interface PopoverConfettiProps extends ConfettiProps {
|
|
434
|
-
|
|
440
|
+
/**
|
|
441
|
+
* The popover will automatically close this many milliseconds
|
|
442
|
+
* after the survey is finished.
|
|
443
|
+
* Set to `null` to disable automatic closing.
|
|
444
|
+
* @default 3000
|
|
445
|
+
*/
|
|
446
|
+
closeOnFinishMs?: number | null;
|
|
435
447
|
}
|
|
436
448
|
declare const PopoverConfetti: ({
|
|
437
449
|
closeOnFinishMs,
|
package/build/index.js
CHANGED
|
@@ -123,6 +123,11 @@ const multiSelectAnswerSchemaFactory = ({ maxSelected, maxLength }, { required }
|
|
|
123
123
|
|
|
124
124
|
//#endregion
|
|
125
125
|
//#region ../validators/src/survey.ts
|
|
126
|
+
const surveyConfirmationSchema = z.object({
|
|
127
|
+
title: z.string().check(z.trim()),
|
|
128
|
+
description: z.string().check(z.trim()),
|
|
129
|
+
buttonText: z.string().check(z.trim())
|
|
130
|
+
});
|
|
126
131
|
const publicGetSurveyOutputSchema = z.object({
|
|
127
132
|
title: z.string(),
|
|
128
133
|
description: z.nullable(z.string()),
|
|
@@ -134,7 +139,8 @@ const publicGetSurveyOutputSchema = z.object({
|
|
|
134
139
|
required: z.boolean(),
|
|
135
140
|
properties: questionPropertiesSchema,
|
|
136
141
|
routingLogic: routingLogicSchema
|
|
137
|
-
}))
|
|
142
|
+
})),
|
|
143
|
+
confirmation: surveyConfirmationSchema
|
|
138
144
|
});
|
|
139
145
|
|
|
140
146
|
//#endregion
|
|
@@ -165,7 +171,7 @@ const client = ky.create({
|
|
|
165
171
|
//#endregion
|
|
166
172
|
//#region src/core/ConfettiProvider.tsx
|
|
167
173
|
const ConfettiContext = createContext(null);
|
|
168
|
-
const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, metadata, isSurveyVisible: isSurveyVisibleInput, apiBaseUrl }) => {
|
|
174
|
+
const ConfettiProvider = ({ children, surveyId, publishableKey, respondent, metadata = {}, isSurveyVisible: isSurveyVisibleInput, apiBaseUrl }) => {
|
|
169
175
|
const [survey, setSurvey] = useState();
|
|
170
176
|
const [lastRespondedAt, setLastRespondedAt] = useState();
|
|
171
177
|
const responseId = useMemo(() => crypto.randomUUID(), []);
|
|
@@ -466,13 +472,14 @@ const ConfettiController = ({ current: currentProp, shouldAutoSubmit, onFinished
|
|
|
466
472
|
|
|
467
473
|
//#endregion
|
|
468
474
|
//#region src/components/Confetti.tsx
|
|
469
|
-
const Confetti = ({ children, shouldAutoSubmit, ...props }) => {
|
|
475
|
+
const Confetti = ({ children, onFinished, shouldAutoSubmit, ...props }) => {
|
|
470
476
|
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
471
477
|
fallback: /* @__PURE__ */ jsx(Fragment, {}),
|
|
472
478
|
children: /* @__PURE__ */ jsx(ConfettiProvider, {
|
|
473
479
|
...props,
|
|
474
480
|
children: /* @__PURE__ */ jsx(ConfettiController, {
|
|
475
481
|
shouldAutoSubmit,
|
|
482
|
+
onFinished,
|
|
476
483
|
children
|
|
477
484
|
})
|
|
478
485
|
})
|
|
@@ -482,29 +489,36 @@ const Confetti = ({ children, shouldAutoSubmit, ...props }) => {
|
|
|
482
489
|
//#endregion
|
|
483
490
|
//#region src/components/ThankYouMessage.tsx
|
|
484
491
|
const ThankYouMessage = ({ title, description, classNames }) => {
|
|
485
|
-
|
|
492
|
+
const { survey, dismiss } = useConfetti();
|
|
493
|
+
if (!survey) return null;
|
|
494
|
+
const descriptionText = description || survey.confirmation.description;
|
|
495
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
486
496
|
className: clsx("cf-question", classNames?.question),
|
|
487
497
|
children: /* @__PURE__ */ jsxs("div", {
|
|
488
498
|
className: clsx("cf-header", classNames?.header),
|
|
489
499
|
children: [/* @__PURE__ */ jsx(Label, {
|
|
490
500
|
className: clsx("cf-title", classNames?.title),
|
|
491
|
-
children: title
|
|
492
|
-
}), /* @__PURE__ */ jsx(Text, {
|
|
501
|
+
children: title || survey.confirmation.title || "Feedback submitted!"
|
|
502
|
+
}), descriptionText && /* @__PURE__ */ jsx(Text, {
|
|
493
503
|
slot: "description",
|
|
494
504
|
className: clsx("cf-description", classNames?.description),
|
|
495
|
-
children:
|
|
505
|
+
children: descriptionText
|
|
496
506
|
})]
|
|
497
507
|
})
|
|
498
|
-
})
|
|
508
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
509
|
+
className: "cf-submit-button",
|
|
510
|
+
onPress: dismiss,
|
|
511
|
+
children: survey.confirmation.buttonText || "Close"
|
|
512
|
+
})] });
|
|
499
513
|
};
|
|
500
514
|
|
|
501
515
|
//#endregion
|
|
502
516
|
//#region src/components/container/PopoverContainer.tsx
|
|
503
517
|
const PopoverContainer = ({ children, classNames, containerProps, onDismiss, closeOnFinishMs = 3e3 }) => {
|
|
504
|
-
const { surveyId, dismiss } = useConfetti();
|
|
518
|
+
const { surveyId, survey, dismiss } = useConfetti();
|
|
505
519
|
const [isFinished, setIsFinished] = useState(false);
|
|
506
520
|
useTimeout(() => {
|
|
507
|
-
dismiss();
|
|
521
|
+
if (survey) dismiss();
|
|
508
522
|
}, isFinished ? closeOnFinishMs : null);
|
|
509
523
|
return /* @__PURE__ */ jsxs("div", {
|
|
510
524
|
className: clsx("confetti-dialog", classNames?.dialog),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengovsg/confetti",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Widgets for Confetti",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"typescript": "^5.9.3",
|
|
41
41
|
"@confetti/tsconfig": "0.0.0",
|
|
42
42
|
"@confetti/validators": "0.0.0",
|
|
43
|
-
"@confetti/
|
|
44
|
-
"@confetti/
|
|
43
|
+
"@confetti/eslint-config": "0.0.0",
|
|
44
|
+
"@confetti/prettier-config": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"prettier": "@confetti/prettier-config",
|
|
47
47
|
"scripts": {
|