@constructor-io/constructorio-ui-quizzes 1.5.0 → 1.5.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.
Files changed (34) hide show
  1. package/dist/constructorio-ui-quizzes-bundled.js +15 -15
  2. package/lib/cjs/components/CioQuiz/index.js +3 -1
  3. package/lib/cjs/components/ResultCard/ResultCard.js +3 -1
  4. package/lib/cjs/components/ResultFavoritesButton/ResultFavoritesButton.js +18 -0
  5. package/lib/cjs/constants.js +2 -0
  6. package/lib/cjs/hooks/usePropsGetters/index.js +4 -1
  7. package/lib/cjs/hooks/usePropsGetters/useAddToFavoritesButtonProps.js +25 -0
  8. package/lib/cjs/hooks/useQuizEvents/index.js +4 -1
  9. package/lib/cjs/hooks/useQuizEvents/useQuizAddToFavorites.js +22 -0
  10. package/lib/cjs/services/index.js +4 -1
  11. package/lib/cjs/stories/Quiz/tests/mocks.js +3 -1
  12. package/lib/cjs/utils.js +1 -0
  13. package/lib/mjs/components/CioQuiz/index.js +3 -1
  14. package/lib/mjs/components/ResultCard/ResultCard.js +3 -1
  15. package/lib/mjs/components/ResultFavoritesButton/ResultFavoritesButton.js +14 -0
  16. package/lib/mjs/constants.js +2 -0
  17. package/lib/mjs/hooks/usePropsGetters/index.js +4 -1
  18. package/lib/mjs/hooks/usePropsGetters/useAddToFavoritesButtonProps.js +18 -0
  19. package/lib/mjs/hooks/useQuizEvents/index.js +4 -1
  20. package/lib/mjs/hooks/useQuizEvents/useQuizAddToFavorites.js +20 -0
  21. package/lib/mjs/services/index.js +4 -1
  22. package/lib/mjs/stories/Quiz/tests/mocks.js +9 -1
  23. package/lib/mjs/utils.js +1 -0
  24. package/lib/styles.css +149 -132
  25. package/lib/types/components/CioQuiz/context.d.ts +3 -1
  26. package/lib/types/components/ResultFavoritesButton/ResultFavoritesButton.d.ts +11 -0
  27. package/lib/types/constants.d.ts +2 -2
  28. package/lib/types/hooks/usePropsGetters/index.d.ts +2 -1
  29. package/lib/types/hooks/usePropsGetters/useAddToFavoritesButtonProps.d.ts +2 -0
  30. package/lib/types/hooks/useQuizEvents/useQuizAddToFavorites.d.ts +5 -0
  31. package/lib/types/services/index.d.ts +1 -1
  32. package/lib/types/types.d.ts +6 -0
  33. package/lib/types/utils.d.ts +1 -0
  34. package/package.json +1 -1
@@ -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.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",