@constructor-io/constructorio-ui-quizzes 1.4.4 → 1.4.6

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 (41) hide show
  1. package/README.md +14 -0
  2. package/dist/constructorio-ui-quizzes-bundled.js +13 -13
  3. package/lib/cjs/components/CioQuiz/actions.js +1 -0
  4. package/lib/cjs/components/CioQuiz/index.js +7 -5
  5. package/lib/cjs/components/CioQuiz/quizLocalReducer.js +9 -6
  6. package/lib/cjs/components/RedoButton/RedoButton.js +1 -1
  7. package/lib/cjs/components/ResultCard/ResultCard.js +1 -1
  8. package/lib/cjs/components/ResultContainer/ResultContainer.js +3 -1
  9. package/lib/cjs/components/ZeroResults/ZeroResults.js +1 -1
  10. package/lib/cjs/constants.js +4 -0
  11. package/lib/cjs/hooks/useQuiz.js +2 -1
  12. package/lib/cjs/hooks/useQuizEvents/index.js +1 -1
  13. package/lib/cjs/hooks/useQuizEvents/useQuizResetClick.js +3 -4
  14. package/lib/cjs/hooks/useQuizState/index.js +3 -2
  15. package/lib/cjs/hooks/useQuizState/useQuizApiState.js +8 -2
  16. package/lib/cjs/hooks/useQuizState/useQuizLocalState.js +6 -2
  17. package/lib/cjs/stories/Quiz/tests/mocks.js +1 -0
  18. package/lib/mjs/components/CioQuiz/actions.js +1 -0
  19. package/lib/mjs/components/CioQuiz/index.js +7 -5
  20. package/lib/mjs/components/CioQuiz/quizLocalReducer.js +12 -0
  21. package/lib/mjs/components/RedoButton/RedoButton.js +1 -1
  22. package/lib/mjs/components/ResultCard/ResultCard.js +1 -1
  23. package/lib/mjs/components/ResultContainer/ResultContainer.js +3 -1
  24. package/lib/mjs/components/ZeroResults/ZeroResults.js +1 -1
  25. package/lib/mjs/constants.js +4 -0
  26. package/lib/mjs/hooks/useQuiz.js +2 -1
  27. package/lib/mjs/hooks/useQuizEvents/index.js +1 -1
  28. package/lib/mjs/hooks/useQuizEvents/useQuizResetClick.js +3 -4
  29. package/lib/mjs/hooks/useQuizState/index.js +3 -2
  30. package/lib/mjs/hooks/useQuizState/useQuizApiState.js +8 -2
  31. package/lib/mjs/hooks/useQuizState/useQuizLocalState.js +5 -2
  32. package/lib/mjs/stories/Quiz/tests/mocks.js +1 -0
  33. package/lib/types/components/CioQuiz/actions.d.ts +3 -2
  34. package/lib/types/components/CioQuiz/quizLocalReducer.d.ts +1 -0
  35. package/lib/types/constants.d.ts +1 -1
  36. package/lib/types/hooks/useQuizEvents/useQuizResetClick.d.ts +1 -1
  37. package/lib/types/hooks/useQuizState/index.d.ts +1 -0
  38. package/lib/types/hooks/useQuizState/useQuizApiState.d.ts +1 -1
  39. package/lib/types/hooks/useQuizState/useQuizLocalState.d.ts +3 -1
  40. package/lib/types/types.d.ts +2 -0
  41. package/package.json +5 -1
@@ -1,7 +1,7 @@
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- 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";
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- `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
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";
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)";
@@ -1,4 +1,4 @@
1
1
  import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/actions';
2
2
  import { QuizEventsReturn, QuizResultsResponse } from '../../types';
3
- declare const useQuizResetClick: (quizStateKey: string, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>, dispatchApiState: React.Dispatch<ActionQuizAPI>, quizResults?: QuizResultsResponse) => QuizEventsReturn.NextQuestion;
3
+ declare const useQuizResetClick: (resetQuizSessionStorageState: () => void, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>, dispatchApiState: React.Dispatch<ActionQuizAPI>, quizResults?: QuizResultsResponse) => QuizEventsReturn.NextQuestion;
4
4
  export default useQuizResetClick;
@@ -10,6 +10,7 @@ type UseQuizState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient) =>
10
10
  dispatchApiState: React.Dispatch<ActionQuizAPI>;
11
11
  dispatchLocalState: React.Dispatch<ActionAnswerQuestion>;
12
12
  hasQuizStoredState: () => boolean;
13
+ skipToResults: boolean;
13
14
  quizStateKey: string;
14
15
  };
15
16
  declare const useQuizState: UseQuizState;
@@ -4,7 +4,7 @@ import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/ac
4
4
  import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
5
5
  import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
6
6
  import { IQuizProps } from '../../types';
7
- type UseQuizApiState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizLocalState: QuizLocalReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => {
7
+ type UseQuizApiState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizLocalState: QuizLocalReducerState, skipToResults: boolean, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => {
8
8
  quizApiState: QuizAPIReducerState;
9
9
  dispatchApiState: React.Dispatch<ActionQuizAPI>;
10
10
  };
@@ -1,8 +1,10 @@
1
1
  import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
- declare const useQuizLocalState: (sessionStateKey?: string) => {
2
+ import { SessionStateOptions } from '../../types';
3
+ declare const useQuizLocalState: (sessionStateOptions?: SessionStateOptions) => {
3
4
  quizLocalState: import("../../components/CioQuiz/quizLocalReducer").QuizLocalReducerState;
4
5
  hasQuizStoredState: () => boolean;
5
6
  dispatchLocalState: (action: ActionAnswerQuestion) => void;
7
+ skipToResults: boolean;
6
8
  quizStateKey: string;
7
9
  };
8
10
  export default useQuizLocalState;
@@ -24,6 +24,7 @@ export interface ResultsPageOptions extends ResultCardProps {
24
24
  }
25
25
  export interface SessionStateOptions {
26
26
  showSessionModal?: boolean;
27
+ showSessionModalOnResults?: boolean;
27
28
  sessionStateKey?: string;
28
29
  }
29
30
  export interface IQuizProps {
@@ -46,6 +47,7 @@ export interface QuizReturnState {
46
47
  sessionId?: string;
47
48
  currentQuestion?: CurrentQuestion | undefined;
48
49
  results?: QuizResultsResponse | undefined;
50
+ skipToResults: boolean;
49
51
  selectedOptionsWithAttributes?: string[];
50
52
  };
51
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -26,6 +26,10 @@
26
26
  ".": {
27
27
  "import": "./lib/mjs/index.js",
28
28
  "require": "./lib/cjs/index.js"
29
+ },
30
+ "./cjs": {
31
+ "import": "./lib/cjs/index.js",
32
+ "require": "./lib/cjs/index.js"
29
33
  }
30
34
  },
31
35
  "files": [