@constructor-io/constructorio-ui-quizzes 1.3.12 → 1.4.0

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 (124) hide show
  1. package/dist/constructorio-ui-quizzes-bundled.js +20 -20
  2. package/lib/cjs/components/BackButton/BackButton.js +12 -7
  3. package/lib/cjs/components/CTAButton/CTAButton.js +4 -3
  4. package/lib/cjs/components/CioQuiz/actions.js +1 -0
  5. package/lib/cjs/components/CioQuiz/index.js +16 -9
  6. package/lib/cjs/components/CioQuiz/quizApiReducer.js +15 -9
  7. package/lib/cjs/components/CioQuiz/quizLocalReducer.js +36 -8
  8. package/lib/cjs/components/ControlBar/ControlBar.js +6 -4
  9. package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +2 -7
  10. package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +4 -32
  11. package/lib/cjs/components/RedoButton/RedoButton.js +11 -4
  12. package/lib/cjs/components/ResultCard/ResultCard.js +3 -18
  13. package/lib/cjs/components/ResultContainer/ResultContainer.js +2 -2
  14. package/lib/cjs/components/ResultCtaButton/ResultCtaButton.js +8 -7
  15. package/lib/cjs/components/ResultHeroCard/ResultHeroCard.js +36 -0
  16. package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +6 -56
  17. package/lib/cjs/components/SessionPromptModal/SessionPromptModal.js +18 -6
  18. package/lib/cjs/components/ZeroResults/ZeroResults.js +5 -4
  19. package/lib/cjs/constants.js +40 -5
  20. package/lib/cjs/hooks/useConsoleErrors.js +2 -1
  21. package/lib/cjs/hooks/usePropsGetters/index.js +85 -0
  22. package/lib/cjs/hooks/usePropsGetters/useCoverQuestionProps.js +13 -0
  23. package/lib/cjs/hooks/usePropsGetters/useNextQuestionButtonProps.js +24 -0
  24. package/lib/cjs/hooks/usePropsGetters/useOpenTextInputProps.js +47 -0
  25. package/lib/cjs/hooks/usePropsGetters/usePreviousQuestionButtonProps.js +18 -0
  26. package/lib/cjs/hooks/usePropsGetters/useSelectInputProps.js +84 -0
  27. package/lib/cjs/hooks/useQuiz.js +14 -28
  28. package/lib/cjs/hooks/useQuizEvents/index.js +21 -16
  29. package/lib/cjs/hooks/useQuizEvents/useHydrateQuizLocalState.js +18 -0
  30. package/lib/cjs/hooks/useQuizEvents/useQuizAddToCart.js +2 -2
  31. package/lib/cjs/hooks/useQuizEvents/useQuizAnswerChangeHandler.js +48 -0
  32. package/lib/cjs/hooks/useQuizEvents/useQuizBackClick.js +5 -5
  33. package/lib/cjs/hooks/useQuizEvents/useQuizNextClick.js +13 -39
  34. package/lib/cjs/hooks/useQuizEvents/useQuizResetClick.js +20 -0
  35. package/lib/cjs/hooks/useQuizEvents/useQuizResultClick.js +2 -2
  36. package/lib/cjs/hooks/useQuizState/index.js +21 -0
  37. package/lib/cjs/hooks/{useQuizApiState.js → useQuizState/useQuizApiState.js} +15 -29
  38. package/lib/cjs/hooks/useQuizState/useQuizLocalState.js +30 -0
  39. package/lib/cjs/index.js +25 -0
  40. package/lib/cjs/services/index.js +3 -3
  41. package/lib/cjs/stories/Quiz/tests/mocks.js +69 -14
  42. package/lib/cjs/utils.js +23 -1
  43. package/lib/mjs/components/BackButton/BackButton.js +12 -7
  44. package/lib/mjs/components/CTAButton/CTAButton.js +4 -3
  45. package/lib/mjs/components/CioQuiz/actions.js +1 -0
  46. package/lib/mjs/components/CioQuiz/index.js +16 -9
  47. package/lib/mjs/components/CioQuiz/quizApiReducer.js +19 -7
  48. package/lib/mjs/components/CioQuiz/quizLocalReducer.js +36 -7
  49. package/lib/mjs/components/ControlBar/ControlBar.js +6 -4
  50. package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +2 -7
  51. package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +5 -32
  52. package/lib/mjs/components/RedoButton/RedoButton.js +11 -4
  53. package/lib/mjs/components/ResultCard/ResultCard.js +3 -15
  54. package/lib/mjs/components/ResultContainer/ResultContainer.js +2 -2
  55. package/lib/mjs/components/ResultCtaButton/ResultCtaButton.js +8 -7
  56. package/lib/mjs/components/ResultHeroCard/ResultHeroCard.js +31 -0
  57. package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +6 -55
  58. package/lib/mjs/components/SessionPromptModal/SessionPromptModal.js +18 -6
  59. package/lib/mjs/components/ZeroResults/ZeroResults.js +5 -4
  60. package/lib/mjs/constants.js +39 -4
  61. package/lib/mjs/hooks/useConsoleErrors.js +2 -1
  62. package/lib/mjs/hooks/usePropsGetters/index.js +72 -0
  63. package/lib/mjs/hooks/usePropsGetters/useCoverQuestionProps.js +10 -0
  64. package/lib/mjs/hooks/usePropsGetters/useNextQuestionButtonProps.js +20 -0
  65. package/lib/mjs/hooks/usePropsGetters/useOpenTextInputProps.js +43 -0
  66. package/lib/mjs/hooks/usePropsGetters/usePreviousQuestionButtonProps.js +14 -0
  67. package/lib/mjs/hooks/usePropsGetters/useSelectInputProps.js +79 -0
  68. package/lib/mjs/hooks/useQuiz.js +13 -21
  69. package/lib/mjs/hooks/useQuizEvents/index.js +21 -16
  70. package/lib/mjs/hooks/useQuizEvents/useHydrateQuizLocalState.js +16 -0
  71. package/lib/mjs/hooks/useQuizEvents/useQuizAddToCart.js +2 -2
  72. package/lib/mjs/hooks/useQuizEvents/useQuizAnswerChangeHandler.js +45 -0
  73. package/lib/mjs/hooks/useQuizEvents/useQuizBackClick.js +5 -5
  74. package/lib/mjs/hooks/useQuizEvents/useQuizNextClick.js +12 -38
  75. package/lib/mjs/hooks/useQuizEvents/useQuizResetClick.js +18 -0
  76. package/lib/mjs/hooks/useQuizEvents/useQuizResultClick.js +2 -2
  77. package/lib/mjs/hooks/useQuizState/index.js +18 -0
  78. package/lib/mjs/hooks/{useQuizApiState.js → useQuizState/useQuizApiState.js} +15 -28
  79. package/lib/mjs/hooks/useQuizState/useQuizLocalState.js +26 -0
  80. package/lib/mjs/index.js +14 -0
  81. package/lib/mjs/services/index.js +1 -1
  82. package/lib/mjs/stories/Quiz/tests/mocks.js +75 -12
  83. package/lib/mjs/utils.js +17 -0
  84. package/lib/styles.css +4 -0
  85. package/lib/types/components/BackButton/BackButton.d.ts +2 -2
  86. package/lib/types/components/CTAButton/CTAButton.d.ts +1 -0
  87. package/lib/types/components/CioQuiz/actions.d.ts +5 -6
  88. package/lib/types/components/CioQuiz/context.d.ts +13 -6
  89. package/lib/types/components/CioQuiz/quizApiReducer.d.ts +2 -2
  90. package/lib/types/components/CioQuiz/quizLocalReducer.d.ts +3 -5
  91. package/lib/types/components/ControlBar/ControlBar.d.ts +0 -4
  92. package/lib/types/components/OpenTextTypeQuestion/OpenTextTypeQuestion.d.ts +2 -6
  93. package/lib/types/components/RedoButton/RedoButton.d.ts +1 -1
  94. package/lib/types/components/ResultCtaButton/ResultCtaButton.d.ts +1 -2
  95. package/lib/types/components/ResultHeroCard/ResultHeroCard.d.ts +7 -0
  96. package/lib/types/components/SelectTypeQuestion/SelectTypeQuestion.d.ts +3 -0
  97. package/lib/types/components/ZeroResults/ZeroResults.d.ts +2 -5
  98. package/lib/types/constants.d.ts +5 -4
  99. package/lib/types/hooks/useConsoleErrors.d.ts +2 -2
  100. package/lib/types/hooks/usePropsGetters/index.d.ts +18 -0
  101. package/lib/types/hooks/usePropsGetters/useCoverQuestionProps.d.ts +2 -0
  102. package/lib/types/hooks/usePropsGetters/useNextQuestionButtonProps.d.ts +4 -0
  103. package/lib/types/hooks/usePropsGetters/useOpenTextInputProps.d.ts +2 -0
  104. package/lib/types/hooks/usePropsGetters/usePreviousQuestionButtonProps.d.ts +3 -0
  105. package/lib/types/hooks/usePropsGetters/useSelectInputProps.d.ts +2 -0
  106. package/lib/types/hooks/useQuizEvents/index.d.ts +4 -16
  107. package/lib/types/hooks/useQuizEvents/useHydrateQuizLocalState.d.ts +4 -0
  108. package/lib/types/hooks/useQuizEvents/useQuizAnswerChangeHandler.d.ts +5 -0
  109. package/lib/types/hooks/useQuizEvents/useQuizBackClick.d.ts +2 -1
  110. package/lib/types/hooks/useQuizEvents/useQuizNextClick.d.ts +2 -1
  111. package/lib/types/hooks/useQuizEvents/useQuizResetClick.d.ts +4 -0
  112. package/lib/types/hooks/useQuizState/index.d.ts +16 -0
  113. package/lib/types/hooks/useQuizState/useQuizApiState.d.ts +12 -0
  114. package/lib/types/hooks/useQuizState/useQuizLocalState.d.ts +8 -0
  115. package/lib/types/index.d.ts +11 -0
  116. package/lib/types/services/index.d.ts +1 -1
  117. package/lib/types/stories/Quiz/tests/mocks.d.ts +5 -2
  118. package/lib/types/types.d.ts +121 -11
  119. package/lib/types/utils.d.ts +4 -0
  120. package/package.json +1 -1
  121. package/lib/cjs/hooks/useQuizLocalState.js +0 -54
  122. package/lib/mjs/hooks/useQuizLocalState.js +0 -48
  123. package/lib/types/hooks/useQuizApiState.d.ts +0 -11
  124. package/lib/types/hooks/useQuizLocalState.d.ts +0 -10
@@ -1,9 +1,14 @@
1
+ import { RequestStates } from '../../../constants';
2
+ import useOpenTextInputProps from '../../../hooks/usePropsGetters/useOpenTextInputProps';
3
+ import useCoverQuestionProps from '../../../hooks/usePropsGetters/useCoverQuestionProps';
4
+ import useSelectInputProps from '../../../hooks/usePropsGetters/useSelectInputProps';
1
5
  export const getMockQuestion = (type) => ({
2
6
  id: 1,
3
7
  title: 'This is question title',
4
8
  description: 'This is question description',
5
9
  cta_text: 'Continue',
6
10
  type,
11
+ input_placeholder: 'Answer here...',
7
12
  });
8
13
  const getMockImages = () => ({
9
14
  images: {
@@ -50,16 +55,26 @@ export const questionOptions = [
50
55
  ];
51
56
  export const getMockState = (question) => ({
52
57
  answers: {
53
- inputs: { 1: '' },
58
+ inputs: {
59
+ 1: {
60
+ type: question?.type,
61
+ value: '',
62
+ },
63
+ },
54
64
  isLastAnswer: false,
55
65
  },
56
66
  quiz: {
57
- requestState: 1,
67
+ requestState: RequestStates.Success,
58
68
  versionId: '',
59
69
  sessionId: '',
60
- isFirstQuestion: false,
61
70
  currentQuestion: {
62
71
  next_question: question,
72
+ isFirstQuestion: false,
73
+ isOpenQuestion: question?.type === 'open',
74
+ isCoverQuestion: question?.type === 'cover',
75
+ isSingleQuestion: question?.type === 'single',
76
+ isMultipleQuestion: question?.type === 'multiple',
77
+ isSelectQuestion: question?.type === 'single',
63
78
  },
64
79
  results: {
65
80
  response: {
@@ -91,17 +106,65 @@ export const getMockState = (question) => ({
91
106
  },
92
107
  },
93
108
  ],
109
+ facets: [],
110
+ groups: [],
111
+ sort_options: [],
112
+ refined_content: [],
113
+ total_num_results: 10,
114
+ features: [],
115
+ result_sources: {},
94
116
  },
117
+ quiz_id: '',
118
+ quiz_session_id: '',
119
+ quiz_version_id: '',
95
120
  },
96
121
  resultsFilters: ['Chocolate', 'Medium'],
97
122
  },
98
123
  });
99
- export const getMockContextValue = (question) => ({
100
- state: getMockState(question),
101
- previousQuestion: () => { },
102
- nextQuestion: () => { },
103
- addToCart: () => { },
104
- customClickItemCallback: false,
105
- resetQuiz: () => { },
106
- resultClick: () => { },
107
- });
124
+ const mockElementProps = {
125
+ className: '',
126
+ type: 'submit',
127
+ onClick: () => { },
128
+ onChange: () => { },
129
+ onKeyDown: () => { },
130
+ role: 'button',
131
+ tabIndex: 0,
132
+ key: 0,
133
+ style: {},
134
+ placeholder: '',
135
+ value: '',
136
+ };
137
+ export const useMockContextValue = (question) => {
138
+ const getOpenTextInputProps = useOpenTextInputProps(() => { }, () => { }, question);
139
+ const getCoverQuestionProps = useCoverQuestionProps(() => { }, question);
140
+ const getSelectInputProps = useSelectInputProps(() => { }, () => { }, question);
141
+ return {
142
+ state: getMockState(question),
143
+ getCoverQuestionProps,
144
+ getOpenTextInputProps,
145
+ getSelectInputProps,
146
+ getAddToCartButtonProps: () => ({ ...mockElementProps, className: 'cio-question-cta-button' }),
147
+ getHydrateQuizButtonProps: () => ({
148
+ ...mockElementProps,
149
+ className: 'cio-question-cta-button',
150
+ }),
151
+ getNextQuestionButtonProps: () => ({
152
+ ...mockElementProps,
153
+ className: 'cio-question-cta-button',
154
+ }),
155
+ getPreviousQuestionButtonProps: () => ({
156
+ ...mockElementProps,
157
+ className: 'cio-question-back-button',
158
+ }),
159
+ getQuizImageProps: () => mockElementProps,
160
+ getQuizResultButtonProps: () => mockElementProps,
161
+ getQuizResultLinkProps: () => mockElementProps,
162
+ getResetQuizButtonProps: () => ({ ...mockElementProps, className: 'cio-question-redo-button' }),
163
+ primaryColorStyles: {
164
+ '--primary-color-h': '12',
165
+ '--primary-color-s': '14',
166
+ '--primary-color-l': '14',
167
+ },
168
+ customClickItemCallback: false,
169
+ };
170
+ };
package/lib/mjs/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  import React from 'react';
2
3
  import { QuestionTypes } from './components/CioQuiz/actions';
3
4
  export const renderImages = (images, cssClasses) => {
@@ -110,6 +111,22 @@ export const getFilterValuesFromExpression = (exp) => {
110
111
  }
111
112
  return [];
112
113
  };
114
+ export const getStateFromSessionStorage = (quizStateKey) => {
115
+ const state = window?.sessionStorage?.getItem(quizStateKey);
116
+ if (state) {
117
+ return JSON.parse(state);
118
+ }
119
+ return null;
120
+ };
121
+ export const resetQuizSessionStorageState = (quizStateKey) => () => {
122
+ window?.sessionStorage?.removeItem(quizStateKey);
123
+ };
124
+ export const logger = (action) => {
125
+ console.group(`%cAction:%c ${action.type}`, 'color: red; font-weight: bold;', 'color: green; font-weight: lighter;');
126
+ console.log('%c type:', 'color: #9E9E9E; font-weight: 700;', action.type);
127
+ console.log('%c payload:', 'color: #00A7F7; font-weight: 700;', action.payload);
128
+ console.groupEnd();
129
+ };
113
130
  // Function to emulate pausing between interactions
114
131
  export function sleep(ms) {
115
132
  // eslint-disable-next-line
package/lib/styles.css CHANGED
@@ -255,6 +255,10 @@
255
255
  .cio-question-back-button:focus {
256
256
  outline: 3px solid var(--primary-color-variant-100);
257
257
  }
258
+ .cio-question-back-button.disabled {
259
+ display: none;
260
+ }
261
+
258
262
  .cio-question-back-button svg {
259
263
  display: inline;
260
264
  }
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
- declare function BackButton(props: React.ButtonHTMLAttributes<HTMLButtonElement>): JSX.Element;
1
+ /// <reference types="react" />
2
+ declare function BackButton(): JSX.Element | null;
3
3
  export default BackButton;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  interface CTAButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
3
  ctaText?: string;
4
+ propsGetters?: () => React.ButtonHTMLAttributes<HTMLButtonElement>;
4
5
  }
5
6
  declare function CTAButton(props: CTAButtonProps): JSX.Element;
6
7
  export default CTAButton;
@@ -1,10 +1,11 @@
1
- import { NextQuestionResponse, QuizResultsResponse } from '../../types';
1
+ import { CurrentQuestion, NextQuestionResponse, QuizResultsResponse } from '../../types';
2
2
  import type { QuizLocalReducerState } from './quizLocalReducer';
3
3
  export declare enum QuestionTypes {
4
4
  OpenText = "open",
5
5
  Cover = "cover",
6
6
  SingleSelect = "single",
7
7
  MultipleSelect = "multiple",
8
+ Next = "next",
8
9
  Back = "back",
9
10
  Reset = "reset",
10
11
  Hydrate = "hydrate"
@@ -16,15 +17,13 @@ export interface QuestionAnswer<Value> {
16
17
  }
17
18
  export type SelectQuestionPayload = QuestionAnswer<string[]>;
18
19
  export type OpenTextQuestionPayload = QuestionAnswer<string>;
19
- export type CoverQuestionPayload = {
20
- isLastQuestion?: boolean;
21
- };
20
+ export type CoverQuestionPayload = QuestionAnswer<string>;
22
21
  interface Action<Type, Payload = {}> {
23
22
  type: Type;
24
23
  payload?: Payload;
25
24
  }
26
- export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload>;
27
- export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Cover, CoverQuestionPayload> | Action<QuestionTypes.Back> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
25
+ export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload> | Action<QuestionTypes.Cover, CoverQuestionPayload>;
26
+ export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
28
27
  export declare enum QuizAPIActionTypes {
29
28
  SET_IS_LOADING = 0,
30
29
  SET_IS_ERROR = 1,
@@ -1,14 +1,21 @@
1
1
  import React from 'react';
2
2
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { QuizEventsReturn, QuizReturnState } from '../../types';
3
+ import { GetAddToCartButtonProps, 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;
7
- resetQuiz: QuizEventsReturn.ResetQuiz;
8
- nextQuestion?: QuizEventsReturn.NextQuestion;
9
- previousQuestion?: QuizEventsReturn.PreviousQuestion;
10
- addToCart: QuizEventsReturn.AddToCart;
11
- resultClick: QuizEventsReturn.ResultClick;
7
+ getOpenTextInputProps: GetOpenTextInputProps;
8
+ getNextQuestionButtonProps: GetNextQuestionButtonProps;
9
+ getPreviousQuestionButtonProps: GetPreviousQuestionButtonProps;
10
+ getQuizImageProps: GetQuizImageProps;
11
+ getSelectInputProps: GetSelectInputProps;
12
+ getCoverQuestionProps: GetCoverQuestionProps;
13
+ getResetQuizButtonProps: GetResetQuizButtonProps;
14
+ getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
15
+ getAddToCartButtonProps: GetAddToCartButtonProps;
16
+ getQuizResultButtonProps: GetQuizResultButtonProps;
17
+ getQuizResultLinkProps: GetQuizResultLinkProps;
18
+ primaryColorStyles: PrimaryColorStyles;
12
19
  customClickItemCallback: boolean;
13
20
  }
14
21
  declare const _default: React.Context<Partial<QuizContextValue>>;
@@ -1,10 +1,10 @@
1
1
  import { RequestStates } from '../../constants';
2
- import { NextQuestionResponse, QuizResultsResponse } from '../../types';
2
+ import { CurrentQuestion, NextQuestionResponse, QuizResultsResponse } from '../../types';
3
3
  import { ActionQuizAPI } from './actions';
4
4
  export type QuizAPIReducerState = {
5
5
  quizRequestState: RequestStates;
6
+ quizCurrentQuestion?: CurrentQuestion;
6
7
  quizFirstQuestion?: NextQuestionResponse;
7
- quizCurrentQuestion?: NextQuestionResponse;
8
8
  quizResults?: QuizResultsResponse;
9
9
  quizResultsFilters?: string[];
10
10
  };
@@ -1,14 +1,12 @@
1
- import { ActionAnswerQuestion, OpenTextQuestionPayload, SelectQuestionPayload } from './actions';
1
+ import { AnswerInputState } from '../../types';
2
+ import { ActionAnswerQuestion } from './actions';
2
3
  export type Answers = string[][];
3
4
  export type QuizLocalReducerState = {
4
5
  answers: Answers;
5
- answerInputs: {};
6
+ answerInputs: AnswerInputState;
6
7
  isLastAnswer: boolean;
7
8
  quizVersionId?: string;
8
9
  quizSessionId?: string;
9
10
  };
10
- export type AnswerInputState = {
11
- [key: string]: OpenTextQuestionPayload | SelectQuestionPayload;
12
- };
13
11
  export declare const initialState: QuizLocalReducerState;
14
12
  export default function quizLocalReducer(state: QuizLocalReducerState, action: ActionAnswerQuestion): QuizLocalReducerState;
@@ -1,9 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  interface ControlBarProps {
3
- showBackButton?: boolean;
4
- isNextButtonDisabled?: boolean;
5
- backButtonHandler?: () => void;
6
- nextButtonHandler: () => void;
7
3
  ctaButtonText?: string;
8
4
  }
9
5
  declare function ControlBar(props: ControlBarProps): JSX.Element;
@@ -1,7 +1,3 @@
1
- import React from 'react';
2
- interface OpenTextQuestionProps {
3
- initialValue?: string;
4
- onChangeHandler?: React.ChangeEventHandler<HTMLInputElement>;
5
- }
6
- declare function OpenTextQuestion(props: OpenTextQuestionProps): JSX.Element | null;
1
+ /// <reference types="react" />
2
+ declare function OpenTextQuestion(): JSX.Element | null;
7
3
  export default OpenTextQuestion;
@@ -2,5 +2,5 @@ import React from 'react';
2
2
  interface RedoButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
3
  redoText?: string;
4
4
  }
5
- declare function RedoButton(props: RedoButtonProps): JSX.Element;
5
+ declare function RedoButton(props: RedoButtonProps): JSX.Element | null;
6
6
  export default RedoButton;
@@ -2,8 +2,7 @@
2
2
  import { QuizResultDataPartial } from '../../types';
3
3
  interface ResultCtaButtonProps {
4
4
  item: QuizResultDataPartial;
5
- className?: string;
6
5
  price?: number;
7
6
  }
8
- export default function ResultCtaButton(props: ResultCtaButtonProps): JSX.Element;
7
+ export default function ResultCtaButton(props: ResultCtaButtonProps): JSX.Element | null;
9
8
  export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { BrowseResultData } from '../../types';
3
+ interface ResultHeroCardProps {
4
+ heroItem: Partial<BrowseResultData>;
5
+ }
6
+ export default function ResultHeroCard(props: ResultHeroCardProps): JSX.Element;
7
+ export {};
@@ -1,3 +1,6 @@
1
1
  /// <reference types="react" />
2
+ export interface Selected {
3
+ [key: number]: boolean;
4
+ }
2
5
  declare function SelectTypeQuestion(): JSX.Element | null;
3
6
  export default SelectTypeQuestion;
@@ -1,6 +1,3 @@
1
- import React from 'react';
2
- interface ZeroResultsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
- resetQuizClickHandler?: () => {};
4
- }
5
- declare function ZeroResults(props: ZeroResultsProps): JSX.Element;
1
+ /// <reference types="react" />
2
+ declare function ZeroResults(): JSX.Element;
6
3
  export default ZeroResults;
@@ -2,13 +2,14 @@ export declare const apiKey = "key_wJSdZSiesX5hiVLt";
2
2
  export declare const quizId = "coffee-quiz";
3
3
  export declare const quizSessionStateKey = "constructorIOQuizState";
4
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- 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";
5
6
  export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
6
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)";
7
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";
8
9
  export declare const changePrimaryColorDescription = "\nIf you would like to use a different primary color, pass a `primaryColor` string in RGB format ('R, G, B').\n\nAccent colors for borders and different states (hover, focus, active) will be calculated automatically based on the primary color you provided.\n\nBy default, the primary color has a value of \"35, 71, 199\" (Constructor Blue).\n\nIn the example below, the `primaryColor` prop has been used to override this color to \"255, 82, 48\" (Orange).\n\n> Advanced Option: Instead of passing a primaryColor prop, you can also override `--primary-color-h`, `--primary-color-s`, and `--primary-color-l` CSS variables within a `.cio-quiz` container element. If explicitly given a value in your CSS, then the values of these variables will be used as the HSL values for your quiz.\n";
9
10
  export declare enum RequestStates {
10
- Stale = 0,
11
- Loading = 1,
12
- Success = 2,
13
- Error = 3
11
+ Stale = "STALE",
12
+ Loading = "LOADING",
13
+ Success = "SUCCESS",
14
+ Error = "ERROR"
14
15
  }
@@ -1,3 +1,3 @@
1
- import { ResultsPageOptions } from '../types';
2
- declare const useConsoleErrors: (quizId: string, resultsPageOptions: ResultsPageOptions) => void;
1
+ import { IQuizProps } from '../types';
2
+ declare const useConsoleErrors: (quizOptions: IQuizProps) => void;
3
3
  export default useConsoleErrors;
@@ -0,0 +1,18 @@
1
+ import { GetResetQuizButtonProps, GetCoverQuestionProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetSelectInputProps, QuizEventsReturn, GetHydrateQuizButtonProps, GetAddToCartButtonProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetSelectQuestionImageProps } from '../../types';
2
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
4
+ declare const usePropsGetters: (quizEvents: QuizEventsReturn, quizApiState: QuizAPIReducerState, quizLocalState: QuizLocalReducerState) => {
5
+ getOpenTextInputProps: GetOpenTextInputProps;
6
+ getNextQuestionButtonProps: GetNextQuestionButtonProps;
7
+ getPreviousQuestionButtonProps: GetPreviousQuestionButtonProps;
8
+ getQuizImageProps: GetQuizImageProps;
9
+ getSelectQuestionImageProps: GetSelectQuestionImageProps;
10
+ getSelectInputProps: GetSelectInputProps;
11
+ getCoverQuestionProps: GetCoverQuestionProps;
12
+ getResetQuizButtonProps: GetResetQuizButtonProps;
13
+ getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
14
+ getAddToCartButtonProps: GetAddToCartButtonProps;
15
+ getQuizResultButtonProps: GetQuizResultButtonProps;
16
+ getQuizResultLinkProps: GetQuizResultLinkProps;
17
+ };
18
+ export default usePropsGetters;
@@ -0,0 +1,2 @@
1
+ import { GetCoverQuestionProps, Question, QuizEventsReturn } from '../../types';
2
+ export default function useCoverQuestionProps(setQuizAnswers: QuizEventsReturn.QuizAnswerChanged, currentQuestionData?: Question): GetCoverQuestionProps;
@@ -0,0 +1,4 @@
1
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
2
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
3
+ import { GetNextQuestionButtonProps, QuizEventsReturn } from '../../types';
4
+ export default function useNextQuestionButtonProps(nextQuestion: QuizEventsReturn.NextQuestion, quizApiState: QuizAPIReducerState, quizLocalState: QuizLocalReducerState): GetNextQuestionButtonProps;
@@ -0,0 +1,2 @@
1
+ import { AnswerInputState, GetOpenTextInputProps, Question, QuizEventsReturn } from '../../types';
2
+ export default function useOpenTextInputProps(setQuizAnswers: QuizEventsReturn.QuizAnswerChanged, nextQuestion: QuizEventsReturn.NextQuestion, currentQuestionData?: Question, answerInputs?: AnswerInputState): GetOpenTextInputProps;
@@ -0,0 +1,3 @@
1
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
2
+ import { GetPreviousQuestionButtonProps, QuizEventsReturn } from '../../types';
3
+ export default function usePreviousQuestionButtonProps(quizApiState: QuizAPIReducerState, previousQuestion: QuizEventsReturn.PreviousQuestion): GetPreviousQuestionButtonProps;
@@ -0,0 +1,2 @@
1
+ import { AnswerInputState, GetSelectInputProps, Question, QuizEventsReturn } from '../../types';
2
+ export default function useSelectInputProps(quizAnswerChanged: QuizEventsReturn.QuizAnswerChanged, nextQuestion: QuizEventsReturn.NextQuestion, currentQuestionData?: Question, answerInputs?: AnswerInputState): GetSelectInputProps;
@@ -1,18 +1,6 @@
1
- /// <reference types="react" />
2
1
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
4
- import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
5
- import { QuizEventsReturn, ResultsPageOptions } from '../../types';
6
- export type UseQuizEventOptions = {
7
- cioClient: ConstructorIOClient;
8
- quizApiState: QuizAPIReducerState;
9
- resultsPageOptions: ResultsPageOptions;
10
- dispatchLocalState: React.Dispatch<ActionAnswerQuestion>;
11
- resetQuizApiState: () => void;
12
- resetQuizLocalState: () => void;
13
- hydrateQuizLocalState: () => void;
14
- resetQuizStoredState: () => void;
15
- hasQuizStoredState: () => boolean;
16
- };
17
- declare const useQuizEvents: (options: UseQuizEventOptions) => QuizEventsReturn;
2
+ import { IQuizProps, QuizEventsReturn } from '../../types';
3
+ import useQuizState from '../useQuizState';
4
+ type UseQuizEvents = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizState: ReturnType<typeof useQuizState>) => QuizEventsReturn;
5
+ declare const useQuizEvents: UseQuizEvents;
18
6
  export default useQuizEvents;
@@ -0,0 +1,4 @@
1
+ import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
+ import { QuizEventsReturn } from '../../types';
3
+ declare const useHydrateQuizLocalState: (quizStateKey: string, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.NextQuestion;
4
+ export default useHydrateQuizLocalState;
@@ -0,0 +1,5 @@
1
+ import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
+ import { QuizEventsReturn } from '../../types';
4
+ declare const useQuizAnswerChangeHandler: (quizApiState: QuizAPIReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.QuizAnswerChanged;
5
+ export default useQuizAnswerChangeHandler;
@@ -1,4 +1,5 @@
1
1
  import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
2
3
  import { QuizEventsReturn } from '../../types';
3
- declare const useQuizBackClick: (dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.PreviousQuestion;
4
+ declare const useQuizBackClick: (quizApiState: QuizAPIReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.PreviousQuestion;
4
5
  export default useQuizBackClick;
@@ -1,5 +1,6 @@
1
1
  import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
2
  import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
3
4
  import { QuizEventsReturn } from '../../types';
4
- declare const useQuizNextClick: (quizApiState: QuizAPIReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.NextQuestion;
5
+ declare const useQuizNextClick: (quizApiState: QuizAPIReducerState, quizLocalState: QuizLocalReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.NextQuestion;
5
6
  export default useQuizNextClick;
@@ -0,0 +1,4 @@
1
+ import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/actions';
2
+ import { QuizEventsReturn, QuizResultsResponse } from '../../types';
3
+ declare const useQuizResetClick: (quizStateKey: string, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>, dispatchApiState: React.Dispatch<ActionQuizAPI>, quizResults?: QuizResultsResponse) => QuizEventsReturn.NextQuestion;
4
+ export default useQuizResetClick;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
+ import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/actions';
4
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
5
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
6
+ import { IQuizProps } from '../../types';
7
+ type UseQuizState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient) => {
8
+ quizApiState: QuizAPIReducerState;
9
+ quizLocalState: QuizLocalReducerState;
10
+ dispatchApiState: React.Dispatch<ActionQuizAPI>;
11
+ dispatchLocalState: React.Dispatch<ActionAnswerQuestion>;
12
+ hasQuizStoredState: () => boolean;
13
+ quizStateKey: string;
14
+ };
15
+ declare const useQuizState: UseQuizState;
16
+ export default useQuizState;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
+ import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/actions';
4
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
5
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
6
+ import { IQuizProps } from '../../types';
7
+ type UseQuizApiState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizLocalState: QuizLocalReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => {
8
+ quizApiState: QuizAPIReducerState;
9
+ dispatchApiState: React.Dispatch<ActionQuizAPI>;
10
+ };
11
+ declare const useQuizApiState: UseQuizApiState;
12
+ export default useQuizApiState;
@@ -0,0 +1,8 @@
1
+ import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
+ declare const useQuizLocalState: (sessionStateKey?: string) => {
3
+ quizLocalState: import("../../components/CioQuiz/quizLocalReducer").QuizLocalReducerState;
4
+ hasQuizStoredState: () => boolean;
5
+ dispatchLocalState: (action: ActionAnswerQuestion) => void;
6
+ quizStateKey: string;
7
+ };
8
+ export default useQuizLocalState;
@@ -1,2 +1,13 @@
1
1
  import CioQuiz from './components/CioQuiz';
2
+ export { default as useCioQuiz } from './hooks/useQuiz';
3
+ export { default as QuizQuestions } from './components/QuizQuestions/index';
4
+ export { default as OpenTextQuestion } from './components/OpenTextTypeQuestion/OpenTextTypeQuestion';
5
+ export { default as CoverQuestion } from './components/CoverTypeQuestion/CoverTypeQuestion';
6
+ export { default as SelectQuestion } from './components/SelectTypeQuestion/SelectTypeQuestion';
7
+ export { default as Results } from './components/Results/Results';
8
+ export { default as ResultCard } from './components/ResultCard/ResultCard';
9
+ export { default as ResultContainer } from './components/ResultContainer/ResultContainer';
10
+ export { default as ResultFilters } from './components/ResultFilters/ResultFilters';
11
+ export { default as ResultHeroCard } from './components/ResultHeroCard/ResultHeroCard';
12
+ export * from './types';
2
13
  export default CioQuiz;
@@ -1,7 +1,7 @@
1
1
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
2
  import { QuizzesParameters, QuizzesResultsParameters, NextQuestionResponse, QuizResultsResponse, QuizResultDataPartial } from '../types';
3
3
  export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | undefined;
4
- export declare const nextQuestion: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesParameters) => Promise<NextQuestionResponse>;
4
+ export declare const getNextQuestion: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesParameters) => Promise<NextQuestionResponse>;
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;
@@ -1,4 +1,5 @@
1
1
  import { Question } from '@constructor-io/constructorio-client-javascript/lib/types';
2
+ import { QuizReturnState } from '../../../types';
2
3
  import { QuestionTypes } from '../../../components/CioQuiz/actions';
3
4
  import { QuizContextValue } from '../../../components/CioQuiz/context';
4
5
  export declare const getMockQuestion: (type: QuestionTypes) => {
@@ -7,6 +8,7 @@ export declare const getMockQuestion: (type: QuestionTypes) => {
7
8
  description: string;
8
9
  cta_text: string;
9
10
  type: QuestionTypes;
11
+ input_placeholder: string;
10
12
  };
11
13
  export declare const getMockQuestionWithImage: (type: QuestionTypes) => {
12
14
  images: {
@@ -17,6 +19,7 @@ export declare const getMockQuestionWithImage: (type: QuestionTypes) => {
17
19
  description: string;
18
20
  cta_text: string;
19
21
  type: QuestionTypes;
22
+ input_placeholder: string;
20
23
  };
21
24
  export declare const questionOptionsWithImages: {
22
25
  images: {
@@ -37,5 +40,5 @@ export declare const questionOptions: {
37
40
  value: any;
38
41
  };
39
42
  }[];
40
- export declare const getMockState: (question?: Question) => any;
41
- export declare const getMockContextValue: (question?: Question) => QuizContextValue;
43
+ export declare const getMockState: (question?: Question) => QuizReturnState;
44
+ export declare const useMockContextValue: (question?: Question) => QuizContextValue;