@constructor-io/constructorio-ui-quizzes 1.8.2 → 1.9.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 (192) hide show
  1. package/dist/constructorio-ui-quizzes-bundled.js +20 -20
  2. package/lib/cjs/package.json +105 -0
  3. package/lib/cjs/{components → src/components}/CioQuiz/actions.js +1 -0
  4. package/lib/cjs/{components → src/components}/CioQuiz/index.js +2 -1
  5. package/lib/cjs/{components → src/components}/CioQuiz/quizLocalReducer.js +21 -0
  6. package/lib/cjs/{components → src/components}/ControlBar/ControlBar.js +5 -2
  7. package/lib/cjs/src/components/SkipButton/SkipButton.js +13 -0
  8. package/lib/cjs/{constants.js → src/constants.js} +2 -0
  9. package/lib/cjs/{hooks → src/hooks}/usePropsGetters/index.js +4 -1
  10. package/lib/cjs/src/hooks/usePropsGetters/useSkipQuestionButtonProps.js +21 -0
  11. package/lib/cjs/{hooks → src/hooks}/useQuizEvents/index.js +3 -0
  12. package/lib/cjs/src/hooks/useQuizEvents/useQuizSkipClick.js +31 -0
  13. package/lib/cjs/{services → src/services}/index.js +2 -1
  14. package/lib/cjs/{stories → src/stories}/Quiz/tests/mocks.js +1 -0
  15. package/lib/cjs/{utils.js → src/utils.js} +1 -0
  16. package/lib/mjs/package.json +105 -0
  17. package/lib/mjs/{components → src/components}/CioQuiz/actions.js +1 -0
  18. package/lib/mjs/{components → src/components}/CioQuiz/index.js +2 -1
  19. package/lib/mjs/{components → src/components}/CioQuiz/quizLocalReducer.js +25 -0
  20. package/lib/mjs/src/components/ControlBar/ControlBar.js +15 -0
  21. package/lib/mjs/src/components/SkipButton/SkipButton.js +10 -0
  22. package/lib/mjs/{constants.js → src/constants.js} +2 -0
  23. package/lib/mjs/{hooks → src/hooks}/usePropsGetters/index.js +4 -1
  24. package/lib/mjs/src/hooks/usePropsGetters/useSkipQuestionButtonProps.js +17 -0
  25. package/lib/mjs/{hooks → src/hooks}/useQuizEvents/index.js +3 -0
  26. package/lib/mjs/src/hooks/useQuizEvents/useQuizSkipClick.js +31 -0
  27. package/lib/mjs/{services → src/services}/index.js +2 -1
  28. package/lib/mjs/{stories → src/stories}/Quiz/tests/mocks.js +4 -0
  29. package/lib/mjs/{utils.js → src/utils.js} +1 -0
  30. package/lib/styles.css +35 -1
  31. package/lib/types/{components → src/components}/CioQuiz/actions.d.ts +2 -1
  32. package/lib/types/{components → src/components}/CioQuiz/context.d.ts +2 -1
  33. package/lib/types/src/components/SkipButton/SkipButton.d.ts +6 -0
  34. package/lib/types/{constants.d.ts → src/constants.d.ts} +2 -2
  35. package/lib/types/{hooks → src/hooks}/usePropsGetters/index.d.ts +2 -1
  36. package/lib/types/src/hooks/usePropsGetters/useSkipQuestionButtonProps.d.ts +3 -0
  37. package/lib/types/src/hooks/useQuizEvents/useQuizSkipClick.d.ts +6 -0
  38. package/lib/types/{stories → src/stories}/Quiz/tests/mocks.d.ts +2 -2
  39. package/lib/types/{types.d.ts → src/types.d.ts} +13 -1
  40. package/lib/types/{utils.d.ts → src/utils.d.ts} +1 -0
  41. package/package.json +1 -1
  42. package/lib/mjs/components/ControlBar/ControlBar.js +0 -12
  43. /package/lib/cjs/{components → src/components}/BackButton/BackButton.js +0 -0
  44. /package/lib/cjs/{components → src/components}/CTAButton/CTAButton.js +0 -0
  45. /package/lib/cjs/{components → src/components}/CioQuiz/context.js +0 -0
  46. /package/lib/cjs/{components → src/components}/CioQuiz/quizApiReducer.js +0 -0
  47. /package/lib/cjs/{components → src/components}/CoverTypeQuestion/CoverTypeQuestion.js +0 -0
  48. /package/lib/cjs/{components → src/components}/OpenTextTypeQuestion/OpenTextTypeQuestion.js +0 -0
  49. /package/lib/cjs/{components → src/components}/ProgressBar/ProgressBar.js +0 -0
  50. /package/lib/cjs/{components → src/components}/QuestionDescription/QuestionDescription.js +0 -0
  51. /package/lib/cjs/{components → src/components}/QuestionTitle/QuestionTitle.js +0 -0
  52. /package/lib/cjs/{components → src/components}/QuizQuestions/index.js +0 -0
  53. /package/lib/cjs/{components → src/components}/RedoButton/RedoButton.js +0 -0
  54. /package/lib/cjs/{components → src/components}/RedoButton/RedoSVG.js +0 -0
  55. /package/lib/cjs/{components → src/components}/ResultCard/ResultCard.js +0 -0
  56. /package/lib/cjs/{components → src/components}/ResultContainer/ResultContainer.js +0 -0
  57. /package/lib/cjs/{components → src/components}/ResultCtaButton/ResultCtaButton.js +0 -0
  58. /package/lib/cjs/{components → src/components}/ResultFavoritesButton/ResultFavoritesButton.js +0 -0
  59. /package/lib/cjs/{components → src/components}/ResultFilters/ResultFilters.js +0 -0
  60. /package/lib/cjs/{components → src/components}/ResultHeroCard/ResultHeroCard.js +0 -0
  61. /package/lib/cjs/{components → src/components}/Results/Results.js +0 -0
  62. /package/lib/cjs/{components → src/components}/SelectTypeQuestion/SelectTypeQuestion.js +0 -0
  63. /package/lib/cjs/{components → src/components}/SessionPromptModal/SessionPromptModal.js +0 -0
  64. /package/lib/cjs/{components → src/components}/Spinner/Spinner.js +0 -0
  65. /package/lib/cjs/{components → src/components}/ZeroResults/ZeroResults.js +0 -0
  66. /package/lib/cjs/{hooks → src/hooks}/useCioClient.js +0 -0
  67. /package/lib/cjs/{hooks → src/hooks}/useConsoleErrors.js +0 -0
  68. /package/lib/cjs/{hooks → src/hooks}/usePrimaryColorStyles.js +0 -0
  69. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/useAddToFavoritesButtonProps.js +0 -0
  70. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/useCoverQuestionProps.js +0 -0
  71. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/useNextQuestionButtonProps.js +0 -0
  72. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/useOpenTextInputProps.js +0 -0
  73. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/usePreviousQuestionButtonProps.js +0 -0
  74. /package/lib/cjs/{hooks → src/hooks}/usePropsGetters/useSelectInputProps.js +0 -0
  75. /package/lib/cjs/{hooks → src/hooks}/useQuiz.js +0 -0
  76. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useHydrateQuizLocalState.js +0 -0
  77. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizAddToCart.js +0 -0
  78. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizAddToFavorites.js +0 -0
  79. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizAnswerChangeHandler.js +0 -0
  80. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizBackClick.js +0 -0
  81. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizNextClick.js +0 -0
  82. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizResetClick.js +0 -0
  83. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizResultClick.js +0 -0
  84. /package/lib/cjs/{hooks → src/hooks}/useQuizEvents/useQuizResultsLoaded.js +0 -0
  85. /package/lib/cjs/{hooks → src/hooks}/useQuizState/index.js +0 -0
  86. /package/lib/cjs/{hooks → src/hooks}/useQuizState/useQuizApiState.js +0 -0
  87. /package/lib/cjs/{hooks → src/hooks}/useQuizState/useQuizLocalState.js +0 -0
  88. /package/lib/cjs/{hooks → src/hooks}/useQuizState/useSessionStorageState.js +0 -0
  89. /package/lib/cjs/{index.js → src/index.js} +0 -0
  90. /package/lib/cjs/{stories → src/stories}/Quiz/argTypes.js +0 -0
  91. /package/lib/cjs/{types.js → src/types.js} +0 -0
  92. /package/lib/mjs/{components → src/components}/BackButton/BackButton.js +0 -0
  93. /package/lib/mjs/{components → src/components}/CTAButton/CTAButton.js +0 -0
  94. /package/lib/mjs/{components → src/components}/CioQuiz/context.js +0 -0
  95. /package/lib/mjs/{components → src/components}/CioQuiz/quizApiReducer.js +0 -0
  96. /package/lib/mjs/{components → src/components}/CoverTypeQuestion/CoverTypeQuestion.js +0 -0
  97. /package/lib/mjs/{components → src/components}/OpenTextTypeQuestion/OpenTextTypeQuestion.js +0 -0
  98. /package/lib/mjs/{components → src/components}/ProgressBar/ProgressBar.js +0 -0
  99. /package/lib/mjs/{components → src/components}/QuestionDescription/QuestionDescription.js +0 -0
  100. /package/lib/mjs/{components → src/components}/QuestionTitle/QuestionTitle.js +0 -0
  101. /package/lib/mjs/{components → src/components}/QuizQuestions/index.js +0 -0
  102. /package/lib/mjs/{components → src/components}/RedoButton/RedoButton.js +0 -0
  103. /package/lib/mjs/{components → src/components}/RedoButton/RedoSVG.js +0 -0
  104. /package/lib/mjs/{components → src/components}/ResultCard/ResultCard.js +0 -0
  105. /package/lib/mjs/{components → src/components}/ResultContainer/ResultContainer.js +0 -0
  106. /package/lib/mjs/{components → src/components}/ResultCtaButton/ResultCtaButton.js +0 -0
  107. /package/lib/mjs/{components → src/components}/ResultFavoritesButton/ResultFavoritesButton.js +0 -0
  108. /package/lib/mjs/{components → src/components}/ResultFilters/ResultFilters.js +0 -0
  109. /package/lib/mjs/{components → src/components}/ResultHeroCard/ResultHeroCard.js +0 -0
  110. /package/lib/mjs/{components → src/components}/Results/Results.js +0 -0
  111. /package/lib/mjs/{components → src/components}/SelectTypeQuestion/SelectTypeQuestion.js +0 -0
  112. /package/lib/mjs/{components → src/components}/SessionPromptModal/SessionPromptModal.js +0 -0
  113. /package/lib/mjs/{components → src/components}/Spinner/Spinner.js +0 -0
  114. /package/lib/mjs/{components → src/components}/ZeroResults/ZeroResults.js +0 -0
  115. /package/lib/mjs/{hooks → src/hooks}/useCioClient.js +0 -0
  116. /package/lib/mjs/{hooks → src/hooks}/useConsoleErrors.js +0 -0
  117. /package/lib/mjs/{hooks → src/hooks}/usePrimaryColorStyles.js +0 -0
  118. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/useAddToFavoritesButtonProps.js +0 -0
  119. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/useCoverQuestionProps.js +0 -0
  120. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/useNextQuestionButtonProps.js +0 -0
  121. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/useOpenTextInputProps.js +0 -0
  122. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/usePreviousQuestionButtonProps.js +0 -0
  123. /package/lib/mjs/{hooks → src/hooks}/usePropsGetters/useSelectInputProps.js +0 -0
  124. /package/lib/mjs/{hooks → src/hooks}/useQuiz.js +0 -0
  125. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useHydrateQuizLocalState.js +0 -0
  126. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizAddToCart.js +0 -0
  127. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizAddToFavorites.js +0 -0
  128. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizAnswerChangeHandler.js +0 -0
  129. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizBackClick.js +0 -0
  130. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizNextClick.js +0 -0
  131. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizResetClick.js +0 -0
  132. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizResultClick.js +0 -0
  133. /package/lib/mjs/{hooks → src/hooks}/useQuizEvents/useQuizResultsLoaded.js +0 -0
  134. /package/lib/mjs/{hooks → src/hooks}/useQuizState/index.js +0 -0
  135. /package/lib/mjs/{hooks → src/hooks}/useQuizState/useQuizApiState.js +0 -0
  136. /package/lib/mjs/{hooks → src/hooks}/useQuizState/useQuizLocalState.js +0 -0
  137. /package/lib/mjs/{hooks → src/hooks}/useQuizState/useSessionStorageState.js +0 -0
  138. /package/lib/mjs/{index.js → src/index.js} +0 -0
  139. /package/lib/mjs/{stories → src/stories}/Quiz/argTypes.js +0 -0
  140. /package/lib/mjs/{types.js → src/types.js} +0 -0
  141. /package/lib/types/{components → src/components}/BackButton/BackButton.d.ts +0 -0
  142. /package/lib/types/{components → src/components}/CTAButton/CTAButton.d.ts +0 -0
  143. /package/lib/types/{components → src/components}/CioQuiz/index.d.ts +0 -0
  144. /package/lib/types/{components → src/components}/CioQuiz/quizApiReducer.d.ts +0 -0
  145. /package/lib/types/{components → src/components}/CioQuiz/quizLocalReducer.d.ts +0 -0
  146. /package/lib/types/{components → src/components}/ControlBar/ControlBar.d.ts +0 -0
  147. /package/lib/types/{components → src/components}/CoverTypeQuestion/CoverTypeQuestion.d.ts +0 -0
  148. /package/lib/types/{components → src/components}/OpenTextTypeQuestion/OpenTextTypeQuestion.d.ts +0 -0
  149. /package/lib/types/{components → src/components}/ProgressBar/ProgressBar.d.ts +0 -0
  150. /package/lib/types/{components → src/components}/QuestionDescription/QuestionDescription.d.ts +0 -0
  151. /package/lib/types/{components → src/components}/QuestionTitle/QuestionTitle.d.ts +0 -0
  152. /package/lib/types/{components → src/components}/QuizQuestions/index.d.ts +0 -0
  153. /package/lib/types/{components → src/components}/RedoButton/RedoButton.d.ts +0 -0
  154. /package/lib/types/{components → src/components}/RedoButton/RedoSVG.d.ts +0 -0
  155. /package/lib/types/{components → src/components}/ResultCard/ResultCard.d.ts +0 -0
  156. /package/lib/types/{components → src/components}/ResultContainer/ResultContainer.d.ts +0 -0
  157. /package/lib/types/{components → src/components}/ResultCtaButton/ResultCtaButton.d.ts +0 -0
  158. /package/lib/types/{components → src/components}/ResultFavoritesButton/ResultFavoritesButton.d.ts +0 -0
  159. /package/lib/types/{components → src/components}/ResultFilters/ResultFilters.d.ts +0 -0
  160. /package/lib/types/{components → src/components}/ResultHeroCard/ResultHeroCard.d.ts +0 -0
  161. /package/lib/types/{components → src/components}/Results/Results.d.ts +0 -0
  162. /package/lib/types/{components → src/components}/SelectTypeQuestion/SelectTypeQuestion.d.ts +0 -0
  163. /package/lib/types/{components → src/components}/SessionPromptModal/SessionPromptModal.d.ts +0 -0
  164. /package/lib/types/{components → src/components}/Spinner/Spinner.d.ts +0 -0
  165. /package/lib/types/{components → src/components}/ZeroResults/ZeroResults.d.ts +0 -0
  166. /package/lib/types/{hooks → src/hooks}/useCioClient.d.ts +0 -0
  167. /package/lib/types/{hooks → src/hooks}/useConsoleErrors.d.ts +0 -0
  168. /package/lib/types/{hooks → src/hooks}/usePrimaryColorStyles.d.ts +0 -0
  169. /package/lib/types/{hooks → src/hooks}/usePropsGetters/useAddToFavoritesButtonProps.d.ts +0 -0
  170. /package/lib/types/{hooks → src/hooks}/usePropsGetters/useCoverQuestionProps.d.ts +0 -0
  171. /package/lib/types/{hooks → src/hooks}/usePropsGetters/useNextQuestionButtonProps.d.ts +0 -0
  172. /package/lib/types/{hooks → src/hooks}/usePropsGetters/useOpenTextInputProps.d.ts +0 -0
  173. /package/lib/types/{hooks → src/hooks}/usePropsGetters/usePreviousQuestionButtonProps.d.ts +0 -0
  174. /package/lib/types/{hooks → src/hooks}/usePropsGetters/useSelectInputProps.d.ts +0 -0
  175. /package/lib/types/{hooks → src/hooks}/useQuiz.d.ts +0 -0
  176. /package/lib/types/{hooks → src/hooks}/useQuizEvents/index.d.ts +0 -0
  177. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useHydrateQuizLocalState.d.ts +0 -0
  178. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizAddToCart.d.ts +0 -0
  179. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizAddToFavorites.d.ts +0 -0
  180. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizAnswerChangeHandler.d.ts +0 -0
  181. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizBackClick.d.ts +0 -0
  182. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizNextClick.d.ts +0 -0
  183. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizResetClick.d.ts +0 -0
  184. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizResultClick.d.ts +0 -0
  185. /package/lib/types/{hooks → src/hooks}/useQuizEvents/useQuizResultsLoaded.d.ts +0 -0
  186. /package/lib/types/{hooks → src/hooks}/useQuizState/index.d.ts +0 -0
  187. /package/lib/types/{hooks → src/hooks}/useQuizState/useQuizApiState.d.ts +0 -0
  188. /package/lib/types/{hooks → src/hooks}/useQuizState/useQuizLocalState.d.ts +0 -0
  189. /package/lib/types/{hooks → src/hooks}/useQuizState/useSessionStorageState.d.ts +0 -0
  190. /package/lib/types/{index.d.ts → src/index.d.ts} +0 -0
  191. /package/lib/types/{services → src/services}/index.d.ts +0 -0
  192. /package/lib/types/{stories → src/stories}/Quiz/argTypes.d.ts +0 -0
@@ -0,0 +1,31 @@
1
+ import { useCallback } from 'react';
2
+ import { QuestionTypes } from '../../components/CioQuiz/actions';
3
+ import { isFunction } from '../../utils';
4
+ const useQuizSkipClick = (quizApiState, quizLocalState, dispatchLocalState, onQuizSkipQuestion) => {
5
+ const quizSkipClickHandler = useCallback(() => {
6
+ const currentQuestion = quizApiState.quizCurrentQuestion?.next_question;
7
+ const currentQuestionId = currentQuestion?.id;
8
+ if (dispatchLocalState && currentQuestionId) {
9
+ if (!(currentQuestion?.type === 'cover')) {
10
+ dispatchLocalState({
11
+ type: QuestionTypes.Skip,
12
+ payload: quizApiState.quizCurrentQuestion,
13
+ });
14
+ }
15
+ const currentAnswerInput = {
16
+ ...quizLocalState.answerInputs[currentQuestionId],
17
+ value: currentQuestion?.type === 'open' ? 'false' : null,
18
+ };
19
+ if (currentQuestion && isFunction(onQuizSkipQuestion)) {
20
+ onQuizSkipQuestion({ ...currentQuestion, answer: currentAnswerInput });
21
+ }
22
+ }
23
+ }, [
24
+ dispatchLocalState,
25
+ onQuizSkipQuestion,
26
+ quizApiState.quizCurrentQuestion,
27
+ quizLocalState.answerInputs,
28
+ ]);
29
+ return quizSkipClickHandler;
30
+ };
31
+ export default useQuizSkipClick;
@@ -1,11 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
+ import { version as packageVersion } from '../../package.json';
3
4
  export const getCioClient = (apiKey) => {
4
5
  if (apiKey) {
5
6
  return new ConstructorIOClient({
6
7
  apiKey,
7
8
  sendTrackingEvents: true,
8
- version: 'cio-ui-quizzes',
9
+ version: `cio-ui-quizzes-${packageVersion}`,
9
10
  });
10
11
  }
11
12
  return undefined;
@@ -176,6 +176,10 @@ export const useMockContextValue = (question) => {
176
176
  ...mockElementProps,
177
177
  className: 'cio-question-cta-button',
178
178
  }),
179
+ getSkipQuestionButtonProps: () => ({
180
+ ...mockElementProps,
181
+ className: 'cio-question-skip-button',
182
+ }),
179
183
  getPreviousQuestionButtonProps: () => ({
180
184
  ...mockElementProps,
181
185
  className: 'cio-question-back-button',
@@ -42,6 +42,7 @@ export const functionStrings = {
42
42
  onAddToFavoritesClick: `(item) => console.dir(item)`,
43
43
  onQuizResultsLoaded: `(results) => console.dir(results)`,
44
44
  onQuizNextQuestion: `(question) => console.dir(question)`,
45
+ onQuizSkipQuestion: `(question) => console.dir(question)`,
45
46
  cioJsClient: `cioJsClient`,
46
47
  };
47
48
  export const stringifyWithDefaults = (obj) => {
package/lib/styles.css CHANGED
@@ -215,6 +215,14 @@
215
215
  background-color: rgba(255, 255, 255, 0.87);
216
216
  align-items: center;
217
217
  }
218
+ .cio-quiz .cio-question-buttons-group {
219
+ width: 20rem;
220
+ height: var(--bottom-bar-height);
221
+ padding: 8px 16px;
222
+ display: flex;
223
+ align-items: center;
224
+ margin-left: auto;
225
+ }
218
226
  .cio-quiz .cio-question-cta-button {
219
227
  background: var(--primary-color);
220
228
  color: #ffffff;
@@ -250,7 +258,27 @@
250
258
  cursor: auto;
251
259
  outline: none;
252
260
  }
253
-
261
+ .cio-quiz .cio-question-skip-button {
262
+ background: transparent;
263
+ color: var(--gray-dust-500);
264
+ border: none;
265
+ cursor: pointer;
266
+ padding: 0;
267
+ outline: none;
268
+ font-size: 1rem;
269
+ width: 100%;
270
+ text-decoration: underline;
271
+ text-decoration-color: transparent;
272
+ transition: text-decoration-color 0.2s ease-in-out;
273
+ }
274
+ .cio-quiz .cio-question-skip-button:hover,
275
+ .cio-quiz .cio-question-skip-button:focus {
276
+ text-decoration-color: var(--gray-dust-200);
277
+ }
278
+ .cio-quiz .cio-question-skip-button.hide {
279
+ visibility: hidden;
280
+ pointer-events: none;
281
+ }
254
282
  /* Back Button Component */
255
283
  .cio-quiz .cio-question-back-button {
256
284
  color: var(--primary-color);
@@ -639,6 +667,12 @@
639
667
 
640
668
  /* Container Queries */
641
669
 
670
+ @container quiz (max-width: 640px) {
671
+ .cio-quiz .cio-question-skip-button span {
672
+ display: none;
673
+ }
674
+ }
675
+
642
676
  /* Small Tablet */
643
677
  @container quiz (min-width: 640px) {
644
678
  .cio-quiz .cio-container {
@@ -6,6 +6,7 @@ export declare enum QuestionTypes {
6
6
  SingleSelect = "single",
7
7
  MultipleSelect = "multiple",
8
8
  Next = "next",
9
+ Skip = "skip",
9
10
  Back = "back",
10
11
  Reset = "reset",
11
12
  Hydrate = "hydrate",
@@ -24,7 +25,7 @@ interface Action<Type, Payload = {}> {
24
25
  payload?: Payload;
25
26
  }
26
27
  export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload> | Action<QuestionTypes.Cover, CoverQuestionPayload>;
27
- export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Complete> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
28
+ export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Skip, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Complete> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
28
29
  export declare enum QuizAPIActionTypes {
29
30
  SET_IS_LOADING = 0,
30
31
  SET_IS_ERROR = 1,
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { GetAddToCartButtonProps, GetAddToFavoritesButtonProps, GetCoverQuestionProps, GetHydrateQuizButtonProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetResetQuizButtonProps, GetSelectInputProps, PrimaryColorStyles, QuizReturnState } from '../../types';
3
+ import { GetAddToCartButtonProps, GetAddToFavoritesButtonProps, GetCoverQuestionProps, GetHydrateQuizButtonProps, GetNextQuestionButtonProps, GetSkipQuestionButtonProps, 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
7
  getOpenTextInputProps: GetOpenTextInputProps;
8
8
  getNextQuestionButtonProps: GetNextQuestionButtonProps;
9
+ getSkipQuestionButtonProps: GetSkipQuestionButtonProps;
9
10
  getPreviousQuestionButtonProps: GetPreviousQuestionButtonProps;
10
11
  getQuizImageProps: GetQuizImageProps;
11
12
  getSelectInputProps: GetSelectInputProps;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface SkipButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ propsGetters?: () => React.ButtonHTMLAttributes<HTMLButtonElement>;
4
+ }
5
+ declare function SkipButton(props: SkipButtonProps): JSX.Element;
6
+ export default SkipButton;
@@ -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 - `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 - `numResultsToDisplay` is an optional parameter that determines how many results should be displayed on results page\n- `callbacks` lets you pass callback functions that will be called on certain actions\n - `onQuizNextQuestion` is an optional callback function that will be called when user moves to the next question\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";
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 - `numResultsToDisplay` is an optional parameter that determines how many results should be displayed on results page\n- `callbacks` lets you pass callback functions that will be called on certain actions\n - `onQuizNextQuestion` is an optional callback function that will be called when user moves to the next question\n - `onQuizSkipQuestion` is an optional callback function that will be called when user skips a question\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 getSkipQuestionButtonProps: () => ({...})), // prop getter for jsx skip 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, GetAddToFavoritesButtonProps } from '../../types';
1
+ import { GetResetQuizButtonProps, GetCoverQuestionProps, GetNextQuestionButtonProps, GetOpenTextInputProps, GetPreviousQuestionButtonProps, GetQuizImageProps, GetSelectInputProps, QuizEventsReturn, GetHydrateQuizButtonProps, GetAddToCartButtonProps, GetQuizResultButtonProps, GetQuizResultLinkProps, GetSelectQuestionImageProps, GetAddToFavoritesButtonProps, GetSkipQuestionButtonProps } 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) => {
@@ -15,5 +15,6 @@ declare const usePropsGetters: (quizEvents: QuizEventsReturn, quizApiState: Quiz
15
15
  getAddToFavoritesButtonProps: GetAddToFavoritesButtonProps;
16
16
  getQuizResultButtonProps: GetQuizResultButtonProps;
17
17
  getQuizResultLinkProps: GetQuizResultLinkProps;
18
+ getSkipQuestionButtonProps: GetSkipQuestionButtonProps;
18
19
  };
19
20
  export default usePropsGetters;
@@ -0,0 +1,3 @@
1
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
2
+ import { GetSkipQuestionButtonProps, QuizEventsReturn } from '../../types';
3
+ export default function useSkipQuestionButtonProps(skipQuestion: QuizEventsReturn.SkipQuestion, quizApiState: QuizAPIReducerState): GetSkipQuestionButtonProps;
@@ -0,0 +1,6 @@
1
+ import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
2
+ import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
3
+ import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
4
+ import { QuizEventsReturn, OnQuizSkipQuestion } from '../../types';
5
+ declare const useQuizSkipClick: (quizApiState: QuizAPIReducerState, quizLocalState: QuizLocalReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>, onQuizSkipQuestion?: OnQuizSkipQuestion) => QuizEventsReturn.NextQuestion;
6
+ export default useQuizSkipClick;
@@ -7,7 +7,7 @@ export declare const getMockQuestion: (type: `${QuestionTypes}`) => {
7
7
  title: string;
8
8
  description: string;
9
9
  cta_text: string;
10
- type: "reset" | "open" | "cover" | "single" | "multiple" | "next" | "back" | "hydrate" | "complete";
10
+ type: "reset" | "open" | "cover" | "single" | "multiple" | "next" | "skip" | "back" | "hydrate" | "complete";
11
11
  input_placeholder: string;
12
12
  };
13
13
  export declare const getMockQuestionWithImage: (type: QuestionTypes) => {
@@ -18,7 +18,7 @@ export declare const getMockQuestionWithImage: (type: QuestionTypes) => {
18
18
  title: string;
19
19
  description: string;
20
20
  cta_text: string;
21
- type: "reset" | "open" | "cover" | "single" | "multiple" | "next" | "back" | "hydrate" | "complete";
21
+ type: "reset" | "open" | "cover" | "single" | "multiple" | "next" | "skip" | "back" | "hydrate" | "complete";
22
22
  input_placeholder: string;
23
23
  };
24
24
  export declare const questionOptionsWithImages: {
@@ -34,8 +34,10 @@ export type QuestionWithAnswer = Question & {
34
34
  answer: AnswerInput;
35
35
  };
36
36
  export type OnQuizNextQuestion = (question: QuestionWithAnswer) => void;
37
+ export type OnQuizSkipQuestion = (question: QuestionWithAnswer) => void;
37
38
  export interface Callbacks {
38
39
  onQuizNextQuestion?: OnQuizNextQuestion;
40
+ onQuizSkipQuestion?: OnQuizSkipQuestion;
39
41
  }
40
42
  export interface IQuizProps {
41
43
  apiKey?: string;
@@ -65,7 +67,7 @@ export interface QuizReturnState {
65
67
  }
66
68
  export type AnswerInput = {
67
69
  type: InputQuestionsTypes;
68
- value: string | string[];
70
+ value: string | string[] | null;
69
71
  };
70
72
  export type AnswerInputState = {
71
73
  [key: string]: AnswerInput;
@@ -87,6 +89,7 @@ export type CurrentQuestion = NextQuestionResponse & {
87
89
  export declare namespace QuizEventsReturn {
88
90
  type QuizAnswerChanged = (payload?: string | string[]) => void;
89
91
  type NextQuestion = () => void;
92
+ type SkipQuestion = () => void;
90
93
  type PreviousQuestion = () => void;
91
94
  type ResetQuiz = () => void;
92
95
  type ResultClick = (result: QuizResultDataPartial, position: number) => void;
@@ -97,6 +100,7 @@ export declare namespace QuizEventsReturn {
97
100
  }
98
101
  export interface QuizEventsReturn {
99
102
  nextQuestion: QuizEventsReturn.NextQuestion;
103
+ skipQuestion: QuizEventsReturn.SkipQuestion;
100
104
  quizAnswerChanged: QuizEventsReturn.QuizAnswerChanged;
101
105
  previousQuestion: QuizEventsReturn.PreviousQuestion;
102
106
  resetQuiz: QuizEventsReturn.ResetQuiz;
@@ -121,6 +125,12 @@ export interface NextQuestionButtonProps {
121
125
  disabled?: boolean;
122
126
  onClick: React.MouseEventHandler<HTMLElement>;
123
127
  }
128
+ export interface SkipQuestionButtonProps {
129
+ className: string;
130
+ type: 'submit' | 'reset' | 'button' | undefined;
131
+ disabled?: boolean;
132
+ onClick: React.MouseEventHandler<HTMLElement>;
133
+ }
124
134
  export interface PreviousQuestionButtonProps {
125
135
  className: string;
126
136
  type: 'submit' | 'reset' | 'button' | undefined;
@@ -175,6 +185,7 @@ export type GetOpenTextInputProps = () => OpenTextInputProps;
175
185
  export type GetCoverQuestionProps = () => CoverQuestionProps;
176
186
  export type GetSelectInputProps = (option: QuestionOption) => SelectInputProps;
177
187
  export type GetNextQuestionButtonProps = () => NextQuestionButtonProps;
188
+ export type GetSkipQuestionButtonProps = () => SkipQuestionButtonProps;
178
189
  export type GetPreviousQuestionButtonProps = () => PreviousQuestionButtonProps;
179
190
  export type GetResetQuizButtonProps = (stylesType?: 'primary' | 'secondary') => ResetQuizButtonProps;
180
191
  export type GetHydrateQuizButtonProps = () => HydrateQuizButtonProps;
@@ -200,6 +211,7 @@ export interface UseQuizReturn {
200
211
  events: QuizEventsReturn;
201
212
  getOpenTextInputProps: GetOpenTextInputProps;
202
213
  getNextQuestionButtonProps: GetNextQuestionButtonProps;
214
+ getSkipQuestionButtonProps: GetSkipQuestionButtonProps;
203
215
  getPreviousQuestionButtonProps: GetPreviousQuestionButtonProps;
204
216
  getQuizImageProps: GetQuizImageProps;
205
217
  getSelectQuestionImageProps: GetSelectQuestionImageProps;
@@ -18,6 +18,7 @@ export declare const functionStrings: {
18
18
  onAddToFavoritesClick: string;
19
19
  onQuizResultsLoaded: string;
20
20
  onQuizNextQuestion: string;
21
+ onQuizSkipQuestion: string;
21
22
  cioJsClient: string;
22
23
  };
23
24
  export declare const stringifyWithDefaults: (obj: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -1,12 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import BackButton from '../BackButton/BackButton';
3
- import CTAButton from '../CTAButton/CTAButton';
4
- import QuizContext from '../CioQuiz/context';
5
- function ControlBar(props) {
6
- const { ctaButtonText } = props;
7
- const { getNextQuestionButtonProps } = useContext(QuizContext);
8
- return (React.createElement("div", { className: 'cio-question-buttons-container' },
9
- React.createElement(BackButton, null),
10
- React.createElement(CTAButton, { ctaText: ctaButtonText, propsGetters: getNextQuestionButtonProps })));
11
- }
12
- export default ControlBar;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes