@constructor-io/constructorio-ui-quizzes 1.4.7 → 1.5.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.
Files changed (40) hide show
  1. package/dist/constructorio-ui-quizzes-bundled.js +14 -14
  2. package/lib/cjs/components/CioQuiz/index.js +14 -3
  3. package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +1 -3
  4. package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +1 -3
  5. package/lib/cjs/components/ResultCard/ResultCard.js +3 -1
  6. package/lib/cjs/components/ResultFavoritesButton/ResultFavoritesButton.js +18 -0
  7. package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +1 -3
  8. package/lib/cjs/constants.js +2 -0
  9. package/lib/cjs/hooks/usePropsGetters/index.js +4 -1
  10. package/lib/cjs/hooks/usePropsGetters/useAddToFavoritesButtonProps.js +25 -0
  11. package/lib/cjs/hooks/useQuizEvents/index.js +4 -1
  12. package/lib/cjs/hooks/useQuizEvents/useQuizAddToFavorites.js +22 -0
  13. package/lib/cjs/services/index.js +4 -1
  14. package/lib/cjs/stories/Quiz/tests/mocks.js +3 -1
  15. package/lib/cjs/utils.js +1 -0
  16. package/lib/mjs/components/CioQuiz/index.js +14 -4
  17. package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +1 -3
  18. package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +1 -3
  19. package/lib/mjs/components/ResultCard/ResultCard.js +3 -1
  20. package/lib/mjs/components/ResultFavoritesButton/ResultFavoritesButton.js +14 -0
  21. package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +1 -3
  22. package/lib/mjs/constants.js +2 -0
  23. package/lib/mjs/hooks/usePropsGetters/index.js +4 -1
  24. package/lib/mjs/hooks/usePropsGetters/useAddToFavoritesButtonProps.js +18 -0
  25. package/lib/mjs/hooks/useQuizEvents/index.js +4 -1
  26. package/lib/mjs/hooks/useQuizEvents/useQuizAddToFavorites.js +20 -0
  27. package/lib/mjs/services/index.js +4 -1
  28. package/lib/mjs/stories/Quiz/tests/mocks.js +9 -1
  29. package/lib/mjs/utils.js +1 -0
  30. package/lib/styles.css +55 -27
  31. package/lib/types/components/CioQuiz/context.d.ts +3 -1
  32. package/lib/types/components/ResultFavoritesButton/ResultFavoritesButton.d.ts +11 -0
  33. package/lib/types/constants.d.ts +2 -2
  34. package/lib/types/hooks/usePropsGetters/index.d.ts +2 -1
  35. package/lib/types/hooks/usePropsGetters/useAddToFavoritesButtonProps.d.ts +2 -0
  36. package/lib/types/hooks/useQuizEvents/useQuizAddToFavorites.d.ts +5 -0
  37. package/lib/types/services/index.d.ts +1 -1
  38. package/lib/types/types.d.ts +6 -0
  39. package/lib/types/utils.d.ts +1 -0
  40. package/package.json +1 -1
@@ -43,7 +43,9 @@ export const trackQuizResultClick = (cioClient, quizResults, result, position) =
43
43
  });
44
44
  }
45
45
  };
46
- export const trackQuizConversion = (cioClient, quizResults, result, price) => {
46
+ export const trackQuizConversion = (cioClient, quizResults, result, price, type
47
+ // eslint-disable-next-line max-params
48
+ ) => {
47
49
  if (quizResults.request) {
48
50
  const { quiz_id, quiz_session_id, quiz_version_id, request: { section }, } = quizResults;
49
51
  cioClient?.tracker.trackQuizConversion({
@@ -55,6 +57,7 @@ export const trackQuizConversion = (cioClient, quizResults, result, price) => {
55
57
  section,
56
58
  variationId: result.data?.variation_id,
57
59
  revenue: (price && String(price)) || undefined,
60
+ type,
58
61
  });
59
62
  }
60
63
  };
@@ -155,7 +155,14 @@ export const useMockContextValue = (question) => {
155
155
  getCoverQuestionProps,
156
156
  getOpenTextInputProps,
157
157
  getSelectInputProps,
158
- getAddToCartButtonProps: () => ({ ...mockElementProps, className: 'cio-question-cta-button' }),
158
+ getAddToCartButtonProps: () => ({
159
+ ...mockElementProps,
160
+ className: 'cio-result-card-cta-button',
161
+ }),
162
+ getAddToFavoritesButtonProps: () => ({
163
+ ...mockElementProps,
164
+ className: 'cio-result-card-favorites-button',
165
+ }),
159
166
  getHydrateQuizButtonProps: () => ({
160
167
  ...mockElementProps,
161
168
  className: 'cio-question-cta-button',
@@ -178,5 +185,6 @@ export const useMockContextValue = (question) => {
178
185
  '--primary-color-l': '14',
179
186
  },
180
187
  customClickItemCallback: false,
188
+ customAddToFavoritesCallback: true,
181
189
  };
182
190
  };
package/lib/mjs/utils.js CHANGED
@@ -39,6 +39,7 @@ ${templateCode}
39
39
  export const functionStrings = {
40
40
  onAddToCartClick: `(item) => console.dir(item)`,
41
41
  onQuizResultClick: `(result, position) => console.dir(result, position)`,
42
+ onAddToFavoritesClick: `(item) => console.dir(item)`,
42
43
  onQuizResultsLoaded: `(results) => console.dir(results)`,
43
44
  cioJsClient: `cioJsClient`,
44
45
  };
package/lib/styles.css CHANGED
@@ -57,13 +57,17 @@
57
57
  min-height: 100%;
58
58
  height: 100%;
59
59
  overflow: auto;
60
- display: flex;
61
- justify-content: center;
62
60
  background-color: #ffffff;
63
61
  color: var(--gray-dust-500);
64
62
  font-size: 16px;
65
63
  }
66
64
 
65
+ /* Container for the loading spinner */
66
+ .cio-quiz.cio-quiz-loading {
67
+ display: flex;
68
+ justify-content: center;
69
+ }
70
+
67
71
  .cio-quiz button {
68
72
  cursor: pointer;
69
73
  }
@@ -77,7 +81,7 @@
77
81
  width: 100%;
78
82
  position: relative;
79
83
  align-self: start;
80
- min-height: calc(100% - 2rem); /* Full height - margin */
84
+ height: calc(100% - 2rem - var(--bottom-bar-height)); /* Full height - margin - control bar */
81
85
  }
82
86
  .cio-container--with-image {
83
87
  display: flex;
@@ -86,7 +90,15 @@
86
90
  padding-bottom: var(--bottom-bar-height);
87
91
  position: relative;
88
92
  align-self: start;
89
- min-height: 100%;
93
+ height: calc(100% - var(--bottom-bar-height)); /* Full height - margin - control bar */
94
+ }
95
+
96
+ /* Background image */
97
+ .cio-question-background-image {
98
+ height: calc(100% - 4px);
99
+ width: 100%;
100
+ position: absolute;
101
+ z-index: -1;
90
102
  }
91
103
 
92
104
  /* Session Prompt Modal */
@@ -163,8 +175,9 @@
163
175
  width: 100%;
164
176
  object-fit: cover;
165
177
  max-height: var(--container-image-small-height);
166
- height: var(--container-image-small-height); /* Fixed height for layout shifts*/
178
+ height: var(--container-image-small-height); /* Fixed height for layout shifts */
167
179
  display: flex;
180
+ align-self: stretch;
168
181
  }
169
182
 
170
183
  /* Input */
@@ -192,7 +205,7 @@
192
205
  height: var(--bottom-bar-height);
193
206
  padding: 8px 16px;
194
207
  display: flex;
195
- position: absolute;
208
+ position: sticky;
196
209
  bottom: 0px;
197
210
  left: 0px;
198
211
  background: white;
@@ -202,7 +215,7 @@
202
215
  .cio-question-cta-button {
203
216
  background: var(--primary-color);
204
217
  color: #ffffff;
205
- border: 1px solid var(--primary-color);
218
+ border: 2px solid var(--primary-color);
206
219
  border-radius: 4px;
207
220
  height: 3rem;
208
221
  font-size: 1rem;
@@ -280,6 +293,7 @@
280
293
  display: flex;
281
294
  flex-direction: column;
282
295
  cursor: pointer;
296
+ background-color: white;
283
297
  }
284
298
  .cio-question-option-container.selected {
285
299
  outline: 3px solid var(--primary-color-variant-600);
@@ -302,12 +316,13 @@
302
316
  display: flex;
303
317
  flex-direction: column;
304
318
  align-items: center;
305
- align-self: start;
306
319
  max-width: 1200px;
307
320
  padding: 1rem;
308
321
  margin-top: 2rem;
309
- min-height: calc(100% - 3rem); /* Full height - padding - margin */
322
+ min-height: calc(100% - 2rem - var(--bottom-bar-height)); /* Full height - padding - margin */
310
323
  width: 100%;
324
+ margin-right: auto;
325
+ margin-left: auto;
311
326
  }
312
327
  .cio-question-options-container {
313
328
  display: flex;
@@ -337,6 +352,7 @@
337
352
  width: 100%;
338
353
  margin: auto;
339
354
  cursor: pointer;
355
+ background-color: white;
340
356
  }
341
357
 
342
358
  /* Option Image */
@@ -383,6 +399,8 @@
383
399
  padding: 2rem 1rem;
384
400
  display: flex;
385
401
  flex-direction: column;
402
+ margin-right: auto;
403
+ margin-left: auto;
386
404
  }
387
405
  .cio-results-title {
388
406
  margin-top: 0;
@@ -510,10 +528,28 @@
510
528
  .cio-result-card-rating-score {
511
529
  margin-right: 5px;
512
530
  }
513
- .cio-result-card-discount {
514
- font-weight: normal;
515
- font-size: .9em;
516
- margin-top: 4px;
531
+
532
+ /* Result Favorites Button*/
533
+ .cio-result-card-favorites-button {
534
+ background: none;
535
+ color: inherit;
536
+ border: none;
537
+ padding: 0;
538
+ font: inherit;
539
+ cursor: pointer;
540
+ outline: inherit;
541
+ width: 25px;
542
+ margin-left: auto;
543
+ margin-bottom: 1rem;
544
+ }
545
+
546
+ .cio-result-card-favorites-button.favorited svg{
547
+ fill: red;
548
+ }
549
+
550
+ .cio-result-card-favorites-button svg:hover {
551
+ stroke: black;
552
+ stroke-width: 1px;
517
553
  }
518
554
 
519
555
  /* Result CTA Button */
@@ -521,7 +557,7 @@
521
557
  padding: 0.75rem 2.5rem;
522
558
  height: 3rem;
523
559
  background: var(--primary-color);
524
- border: 1px solid var(--primary-color);
560
+ border: 2px solid var(--primary-color);
525
561
  border-radius: 4px;
526
562
  color: #ffffff;
527
563
  font-size: 1rem;
@@ -579,7 +615,6 @@
579
615
 
580
616
  /* Image */
581
617
  .cio-question-image-container {
582
- height: 100%;
583
618
  flex-basis: 50%;
584
619
  flex-shrink: 0;
585
620
  border-radius: 4px;
@@ -628,6 +663,7 @@
628
663
  .cio-container {
629
664
  align-items: center;
630
665
  margin-top: 0;
666
+ height: calc(100% - var(--bottom-bar-height)); /* Full height - control bar */
631
667
  }
632
668
  .cio-container--with-image {
633
669
  padding: 6% 2%;
@@ -646,10 +682,8 @@
646
682
 
647
683
  /* Image */
648
684
  .cio-question-image-container {
649
- max-height: 100%;
650
- }
651
- .cio-cover-question-container--with-image .cio-question-image-container {
652
685
  max-height: unset;
686
+ height: unset;
653
687
  }
654
688
 
655
689
  /* Content */
@@ -667,14 +701,6 @@
667
701
  margin-bottom: 2rem;
668
702
  }
669
703
 
670
- /* CTA Button Component */
671
- .cio-question-buttons-container {
672
- position: sticky;
673
- padding: 0;
674
- margin: 0;
675
- align-items: center;
676
- }
677
-
678
704
  /* Cover Component */
679
705
  .cio-cover-question-container--with-image {
680
706
  padding: 0;
@@ -691,9 +717,11 @@
691
717
  }
692
718
  .cio-select-question-container {
693
719
  justify-content: center;
694
- margin: 0;
720
+ margin-bottom: 0;
721
+ margin-top: 0;
695
722
  padding: 2rem;
696
723
  padding-bottom: 0;
724
+ min-height: calc(100% - var(--bottom-bar-height)); /* Full height - padding - margin */
697
725
  }
698
726
  .cio-question-option-container {
699
727
  width: calc(25% - 13px);
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { GetAddToCartButtonProps, GetCoverQuestionProps, GetHydrateQuizButtonProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetResetQuizButtonProps, GetSelectInputProps, PrimaryColorStyles, QuizReturnState } from '../../types';
3
+ import { GetAddToCartButtonProps, GetAddToFavoritesButtonProps, GetCoverQuestionProps, GetHydrateQuizButtonProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetResetQuizButtonProps, GetSelectInputProps, PrimaryColorStyles, QuizReturnState } from '../../types';
4
4
  export interface QuizContextValue {
5
5
  cioClient?: ConstructorIOClient;
6
6
  state?: QuizReturnState;
@@ -13,10 +13,12 @@ export interface QuizContextValue {
13
13
  getResetQuizButtonProps: GetResetQuizButtonProps;
14
14
  getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
15
15
  getAddToCartButtonProps: GetAddToCartButtonProps;
16
+ getAddToFavoritesButtonProps: GetAddToFavoritesButtonProps;
16
17
  getQuizResultButtonProps: GetQuizResultButtonProps;
17
18
  getQuizResultLinkProps: GetQuizResultLinkProps;
18
19
  primaryColorStyles: PrimaryColorStyles;
19
20
  customClickItemCallback: boolean;
21
+ customAddToFavoritesCallback: boolean;
20
22
  }
21
23
  declare const _default: React.Context<Partial<QuizContextValue>>;
22
24
  export default _default;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { QuizResultDataPartial } from '../../types';
3
+ interface ResultFavoritesButtonProps {
4
+ item: QuizResultDataPartial;
5
+ price?: number;
6
+ }
7
+ export interface Favorited {
8
+ [key: string]: boolean;
9
+ }
10
+ export default function ResultFavoritesButton(props: ResultFavoritesButtonProps): JSX.Element | null;
11
+ export {};
@@ -1,8 +1,8 @@
1
1
  export declare const apiKey = "key_wJSdZSiesX5hiVLt";
2
2
  export declare const quizId = "coffee-quiz";
3
3
  export declare const quizSessionStateKey = "constructorIOQuizState";
4
- export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `onAddToCartClick` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `onQuizResultClick` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `onQuizResultsLoaded` is an optional callback function that will be called when the quiz results are loaded\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price \n - `resultCardRatingCountKey` is an optional parameter that specifies the metadata field name for the ratings count \n - `resultCardRatingScoreKey` is an optional parameter that specifies the metadata field name for the ratings score \n - `renderResultCardPriceDetails` is an optional render function to render custom prices section in result card \n- `sessionStateOptions` lets you configure the session modal behavior\n - `showSessionModal` is a boolean used to decide whether to show the session modal. The default behavior is to show the session modal\n - `showSessionModalOnResults` is a boolean to decide whether to show the session modal after reaching the results page. The default behavior is to not show the session modal\n - `sessionStateKey` is a custom string that will be used as a session storage key\n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
5
- export declare const hookDescription = "- import `useCioQuiz` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n- Since the markup is controlled by you, the default styles might not be applied if you have a different DOM structure\n- To use this hook, an `apiKey` and `quizId` are required, and `resultsPageOptions` must be passed to the `useCioQuiz` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\nCalling the `useCioQuiz` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n state: QuizReturnState, // Quiz state\n events: [{...}], // array of quiz events\n getAddToCartButtonProps: () => ({...})), // prop getter for jsx add to cart button for quiz result,\n getCoverQuestionProps: () => ({...})), // prop getter for jsx quiz cover question,\n getHydrateQuizButtonProps: () => ({...})), // prop getter for jsx hydrate quiz button,\n getNextQuestionButtonProps: () => ({...})), // prop getter for jsx next button to traverse the quiz,\n getPreviousQuestionButtonProps: () => ({...})), // prop getter for jsx back button to traverse the quiz, \n getOpenTextInputProps: () => ({...})), // prop getter for jsx open text input,\n getSelectInputProps: () => ({...})), // prop getter for jsx select input for select type questions,\n getQuizImageProps: () => ({...})), // prop getter for jsx quiz image,\n getQuizResultButtonProps: () => ({...})), // prop getter for jsx result card click as a button,\n getQuizResultLinkProps: () => ({...})), // prop getter for jsx result card click as a link. Should be spread into <a> tags,\n getResetQuizButtonProps: () => ({...})), // prop getter for jsx reset quiz button,\n cioClient, // instance of constructorio-client-javascript\n } = useCioQuiz(args);\n```\n\n> Note: when we say `cioClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
4
+ export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `onAddToCartClick` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `onAddToFavoritesClick` is an optional callback function that will be called when the \"Add To Favorites\" heart icon is clicked\n - `onQuizResultClick` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `onQuizResultsLoaded` is an optional callback function that will be called when the quiz results are loaded\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price \n - `resultCardRatingCountKey` is an optional parameter that specifies the metadata field name for the ratings count \n - `resultCardRatingScoreKey` is an optional parameter that specifies the metadata field name for the ratings score \n - `renderResultCardPriceDetails` is an optional render function to render custom prices section in result card \n- `sessionStateOptions` lets you configure the session modal behavior\n - `showSessionModal` is a boolean used to decide whether to show the session modal. The default behavior is to show the session modal\n - `showSessionModalOnResults` is a boolean to decide whether to show the session modal after reaching the results page. The default behavior is to not show the session modal\n - `sessionStateKey` is a custom string that will be used as a session storage key\n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
5
+ export declare const hookDescription = "- import `useCioQuiz` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n- Since the markup is controlled by you, the default styles might not be applied if you have a different DOM structure\n- To use this hook, an `apiKey` and `quizId` are required, and `resultsPageOptions` must be passed to the `useCioQuiz` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\nCalling the `useCioQuiz` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n state: QuizReturnState, // Quiz state\n events: [{...}], // array of quiz events\n getAddToCartButtonProps: () => ({...})), // prop getter for jsx add to cart button for quiz result,\n getAddToFavoritesButtonProps: () => ({...})), // prop getter for jsx add to favorites button for quiz result,\n getCoverQuestionProps: () => ({...})), // prop getter for jsx quiz cover question,\n getHydrateQuizButtonProps: () => ({...})), // prop getter for jsx hydrate quiz button,\n getNextQuestionButtonProps: () => ({...})), // prop getter for jsx next button to traverse the quiz,\n getPreviousQuestionButtonProps: () => ({...})), // prop getter for jsx back button to traverse the quiz, \n getOpenTextInputProps: () => ({...})), // prop getter for jsx open text input,\n getSelectInputProps: () => ({...})), // prop getter for jsx select input for select type questions,\n getQuizImageProps: () => ({...})), // prop getter for jsx quiz image,\n getQuizResultButtonProps: () => ({...})), // prop getter for jsx result card click as a button,\n getQuizResultLinkProps: () => ({...})), // prop getter for jsx result card click as a link. Should be spread into <a> tags,\n getResetQuizButtonProps: () => ({...})), // prop getter for jsx reset quiz button,\n cioClient, // instance of constructorio-client-javascript\n } = useCioQuiz(args);\n```\n\n> Note: when we say `cioClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
6
6
  export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
7
7
  export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from Constructor's servers\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)";
8
8
  export declare const smallContainerDescription = "If you are using the provided styles, CioQuiz component will respect the height and width of its parent container and use responsive styles based on the parent container's dimensions";
@@ -1,4 +1,4 @@
1
- import { GetResetQuizButtonProps, GetCoverQuestionProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetSelectInputProps, QuizEventsReturn, GetHydrateQuizButtonProps, GetAddToCartButtonProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetSelectQuestionImageProps } from '../../types';
1
+ import { GetResetQuizButtonProps, GetCoverQuestionProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetSelectInputProps, QuizEventsReturn, GetHydrateQuizButtonProps, GetAddToCartButtonProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetSelectQuestionImageProps, GetAddToFavoritesButtonProps } from '../../types';
2
2
  import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
3
  import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
4
4
  declare const usePropsGetters: (quizEvents: QuizEventsReturn, quizApiState: QuizAPIReducerState, quizLocalState: QuizLocalReducerState) => {
@@ -12,6 +12,7 @@ declare const usePropsGetters: (quizEvents: QuizEventsReturn, quizApiState: Quiz
12
12
  getResetQuizButtonProps: GetResetQuizButtonProps;
13
13
  getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
14
14
  getAddToCartButtonProps: GetAddToCartButtonProps;
15
+ getAddToFavoritesButtonProps: GetAddToFavoritesButtonProps;
15
16
  getQuizResultButtonProps: GetQuizResultButtonProps;
16
17
  getQuizResultLinkProps: GetQuizResultLinkProps;
17
18
  };
@@ -0,0 +1,2 @@
1
+ import { GetAddToFavoritesButtonProps, QuizEventsReturn } from '../../types';
2
+ export default function useAddToFavoritesButtonProps(addToFavorites: QuizEventsReturn.AddToFavorites): GetAddToFavoritesButtonProps;
@@ -0,0 +1,5 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
+ import { QuizEventsReturn, QuizResultsEventsProps } from '../../types';
4
+ declare const useQuizAddToFavorites: (cioClient: ConstructorIOClient, quizApiState: QuizAPIReducerState, onAddToFavoritesClick?: QuizResultsEventsProps.OnAddToFavoritesClick) => QuizEventsReturn.AddToFavorites;
5
+ export default useQuizAddToFavorites;
@@ -5,4 +5,4 @@ export declare const getNextQuestion: (cioClient: ConstructorIOClient, quizId: s
5
5
  export declare const getQuizResults: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesResultsParameters) => Promise<QuizResultsResponse>;
6
6
  export declare const trackQuizResultsLoaded: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse) => void;
7
7
  export declare const trackQuizResultClick: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse, result: QuizResultDataPartial, position: number) => void;
8
- export declare const trackQuizConversion: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse, result: QuizResultDataPartial, price?: number) => void;
8
+ export declare const trackQuizConversion: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse, result: QuizResultDataPartial, price?: number, type?: string) => void;
@@ -16,12 +16,14 @@ export declare namespace QuizResultsEventsProps {
16
16
  type OnQuizResultsLoaded = (results: QuizResultDataPartial) => void;
17
17
  type OnQuizResultClick = (result: QuizResultDataPartial, position: number) => void;
18
18
  type OnAddToCartClick = (result: QuizResultDataPartial) => void;
19
+ type OnAddToFavoritesClick = (result: QuizResultDataPartial) => void;
19
20
  }
20
21
  export interface ResultsPageOptions extends ResultCardProps {
21
22
  numResultsToDisplay?: number;
22
23
  onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded;
23
24
  onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick;
24
25
  onAddToCartClick: QuizResultsEventsProps.OnAddToCartClick;
26
+ onAddToFavoritesClick?: QuizResultsEventsProps.OnAddToFavoritesClick;
25
27
  }
26
28
  export interface SessionStateOptions {
27
29
  showSessionModal?: boolean;
@@ -74,6 +76,7 @@ export declare namespace QuizEventsReturn {
74
76
  type ResetQuiz = () => void;
75
77
  type ResultClick = (result: QuizResultDataPartial, position: number) => void;
76
78
  type AddToCart = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number) => void;
79
+ type AddToFavorites = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number, sendEvent?: boolean) => void;
77
80
  type HydrateQuiz = () => void;
78
81
  type HasSessionStorageState = () => boolean;
79
82
  type ResetSessionStorageState = () => void;
@@ -85,6 +88,7 @@ export interface QuizEventsReturn {
85
88
  resetQuiz: QuizEventsReturn.ResetQuiz;
86
89
  resultClick: QuizEventsReturn.ResultClick;
87
90
  addToCart: QuizEventsReturn.AddToCart;
91
+ addToFavorites: QuizEventsReturn.AddToFavorites;
88
92
  hydrateQuiz: QuizEventsReturn.HydrateQuiz;
89
93
  hasSessionStorageState: QuizEventsReturn.HasSessionStorageState;
90
94
  resetSessionStorageState: QuizEventsReturn.ResetSessionStorageState;
@@ -162,6 +166,7 @@ export type GetPreviousQuestionButtonProps = () => PreviousQuestionButtonProps;
162
166
  export type GetResetQuizButtonProps = (stylesType?: 'primary' | 'secondary') => ResetQuizButtonProps;
163
167
  export type GetHydrateQuizButtonProps = () => HydrateQuizButtonProps;
164
168
  export type GetAddToCartButtonProps = (result: QuizResultDataPartial, price?: number) => AddToCartButtonProps;
169
+ export type GetAddToFavoritesButtonProps = (result: QuizResultDataPartial, price?: number, clickHandler?: () => void) => AddToCartButtonProps;
165
170
  export type GetQuizImageProps = () => QuizImageProps;
166
171
  export type GetSelectQuestionImageProps = (option: QuestionOption) => QuizImageProps;
167
172
  export interface QuizResultOptions<T = 'button' | 'link'> {
@@ -190,6 +195,7 @@ export interface UseQuizReturn {
190
195
  getResetQuizButtonProps: GetResetQuizButtonProps;
191
196
  getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
192
197
  getAddToCartButtonProps: GetAddToCartButtonProps;
198
+ getAddToFavoritesButtonProps: GetAddToFavoritesButtonProps;
193
199
  getQuizResultButtonProps: GetQuizResultButtonProps;
194
200
  getQuizResultLinkProps: GetQuizResultLinkProps;
195
201
  primaryColorStyles: PrimaryColorStyles;
@@ -15,6 +15,7 @@ export declare const getStoryParams: (storyCode: any, templateCode: any, importC
15
15
  export declare const functionStrings: {
16
16
  onAddToCartClick: string;
17
17
  onQuizResultClick: string;
18
+ onAddToFavoritesClick: string;
18
19
  onQuizResultsLoaded: string;
19
20
  cioJsClient: string;
20
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.4.7",
3
+ "version": "1.5.1",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",