@constructor-io/constructorio-ui-quizzes 1.6.0 → 1.7.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.
@@ -11,6 +11,7 @@ const Spinner_1 = tslib_1.__importDefault(require("../Spinner/Spinner"));
11
11
  const useQuiz_1 = tslib_1.__importDefault(require("../../hooks/useQuiz"));
12
12
  const SessionPromptModal_1 = tslib_1.__importDefault(require("../SessionPromptModal/SessionPromptModal"));
13
13
  const utils_1 = require("../../utils");
14
+ const ProgressBar_1 = tslib_1.__importDefault(require("../ProgressBar/ProgressBar"));
14
15
  function CioQuiz(props) {
15
16
  var _a;
16
17
  const { cioClient, state, events: { hydrateQuiz, hasSessionStorageState, resetSessionStorageState }, getAddToCartButtonProps, getAddToFavoritesButtonProps, getCoverQuestionProps, getHydrateQuizButtonProps, getNextQuestionButtonProps, getOpenTextInputProps, getPreviousQuestionButtonProps, getQuizImageProps, getQuizResultButtonProps, getQuizResultLinkProps, getResetQuizButtonProps, getSelectInputProps, primaryColorStyles, } = (0, useQuiz_1.default)(props);
@@ -65,6 +66,7 @@ function CioQuiz(props) {
65
66
  (0, utils_1.convertPrimaryColorsToString)(primaryColorStyles)),
66
67
  react_1.default.createElement(SessionPromptModal_1.default, { resetStoredState: resetSessionStorageState, continueSession: hydrateQuiz, showSessionPrompt: showSessionPrompt, setShowSessionPrompt: setShowSessionPrompt }),
67
68
  react_1.default.createElement(context_1.default.Provider, { value: contextValue }, state.quiz.results || state.quiz.skipToResults ? (react_1.default.createElement(ResultContainer_1.default, { options: resultsPageOptions })) : (state.quiz.currentQuestion && (react_1.default.createElement(react_1.default.Fragment, null,
69
+ react_1.default.createElement(ProgressBar_1.default, null),
68
70
  react_1.default.createElement(QuizQuestions_1.default, null),
69
71
  react_1.default.createElement(ControlBar_1.default, { ctaButtonText: (questionData === null || questionData === void 0 ? void 0 : questionData.cta_text) || undefined })))))));
70
72
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
6
+ function ProgressBar() {
7
+ const { state } = (0, react_1.useContext)(context_1.default);
8
+ const currentQuestion = state === null || state === void 0 ? void 0 : state.quiz.currentQuestion;
9
+ if (!currentQuestion)
10
+ return null;
11
+ return (react_1.default.createElement("div", { className: 'cio-question-progress-affixed-container' },
12
+ react_1.default.createElement("div", { className: 'cio-question-progress-progress-container' },
13
+ react_1.default.createElement("div", { className: 'cio-question-progress-progress-bar', style: {
14
+ width: `${((currentQuestion.next_question.id - 1) / currentQuestion.total_questions) * 100}%`,
15
+ } }))));
16
+ }
17
+ exports.default = ProgressBar;
@@ -20,7 +20,16 @@ const getQuizResults = (cioClient, quizId, parameters) => tslib_1.__awaiter(void
20
20
  exports.getQuizResults = getQuizResults;
21
21
  // Tracking requests
22
22
  const trackQuizResultsLoaded = (cioClient, quizResults) => {
23
+ var _a;
23
24
  const { quiz_id, quiz_session_id, quiz_version_id, result_id, request, response } = quizResults;
25
+ const items = (_a = response === null || response === void 0 ? void 0 : response.results) === null || _a === void 0 ? void 0 : _a.map((result) => {
26
+ var _a, _b;
27
+ return ({
28
+ itemId: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.id,
29
+ variationId: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.variation_id,
30
+ itemName: result === null || result === void 0 ? void 0 : result.value,
31
+ });
32
+ });
24
33
  cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackQuizResultsLoaded({
25
34
  quizId: quiz_id,
26
35
  quizVersionId: quiz_version_id,
@@ -30,6 +39,7 @@ const trackQuizResultsLoaded = (cioClient, quizResults) => {
30
39
  resultCount: response === null || response === void 0 ? void 0 : response.total_num_results,
31
40
  resultPage: request === null || request === void 0 ? void 0 : request.page,
32
41
  resultId: result_id,
42
+ items,
33
43
  });
34
44
  };
35
45
  exports.trackQuizResultsLoaded = trackQuizResultsLoaded;
@@ -64,6 +64,7 @@ const getMockState = (question) => ({
64
64
  isSingleQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'single',
65
65
  isMultipleQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'multiple',
66
66
  isSelectQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'single',
67
+ total_questions: 1,
67
68
  },
68
69
  results: {
69
70
  response: {
@@ -8,6 +8,7 @@ import Spinner from '../Spinner/Spinner';
8
8
  import useQuiz from '../../hooks/useQuiz';
9
9
  import SessionPromptModal from '../SessionPromptModal/SessionPromptModal';
10
10
  import { convertPrimaryColorsToString, renderImages } from '../../utils';
11
+ import ProgressBar from '../ProgressBar/ProgressBar';
11
12
  export default function CioQuiz(props) {
12
13
  const { cioClient, state, events: { hydrateQuiz, hasSessionStorageState, resetSessionStorageState }, getAddToCartButtonProps, getAddToFavoritesButtonProps, getCoverQuestionProps, getHydrateQuizButtonProps, getNextQuestionButtonProps, getOpenTextInputProps, getPreviousQuestionButtonProps, getQuizImageProps, getQuizResultButtonProps, getQuizResultLinkProps, getResetQuizButtonProps, getSelectInputProps, primaryColorStyles, } = useQuiz(props);
13
14
  const [showSessionPrompt, setShowSessionPrompt] = useState(false);
@@ -61,6 +62,7 @@ export default function CioQuiz(props) {
61
62
  convertPrimaryColorsToString(primaryColorStyles)),
62
63
  React.createElement(SessionPromptModal, { resetStoredState: resetSessionStorageState, continueSession: hydrateQuiz, showSessionPrompt: showSessionPrompt, setShowSessionPrompt: setShowSessionPrompt }),
63
64
  React.createElement(QuizContext.Provider, { value: contextValue }, state.quiz.results || state.quiz.skipToResults ? (React.createElement(ResultContainer, { options: resultsPageOptions })) : (state.quiz.currentQuestion && (React.createElement(React.Fragment, null,
65
+ React.createElement(ProgressBar, null),
64
66
  React.createElement(QuizQuestions, null),
65
67
  React.createElement(ControlBar, { ctaButtonText: questionData?.cta_text || undefined })))))));
66
68
  }
@@ -0,0 +1,13 @@
1
+ import React, { useContext } from 'react';
2
+ import QuizContext from '../CioQuiz/context';
3
+ export default function ProgressBar() {
4
+ const { state } = useContext(QuizContext);
5
+ const currentQuestion = state?.quiz.currentQuestion;
6
+ if (!currentQuestion)
7
+ return null;
8
+ return (React.createElement("div", { className: 'cio-question-progress-affixed-container' },
9
+ React.createElement("div", { className: 'cio-question-progress-progress-container' },
10
+ React.createElement("div", { className: 'cio-question-progress-progress-bar', style: {
11
+ width: `${((currentQuestion.next_question.id - 1) / currentQuestion.total_questions) * 100}%`,
12
+ } }))));
13
+ }
@@ -14,6 +14,11 @@ export const getQuizResults = async (cioClient, quizId, parameters) => cioClient
14
14
  // Tracking requests
15
15
  export const trackQuizResultsLoaded = (cioClient, quizResults) => {
16
16
  const { quiz_id, quiz_session_id, quiz_version_id, result_id, request, response } = quizResults;
17
+ const items = response?.results?.map((result) => ({
18
+ itemId: result?.data?.id,
19
+ variationId: result?.data?.variation_id,
20
+ itemName: result?.value,
21
+ }));
17
22
  cioClient?.tracker.trackQuizResultsLoaded({
18
23
  quizId: quiz_id,
19
24
  quizVersionId: quiz_version_id,
@@ -23,6 +28,7 @@ export const trackQuizResultsLoaded = (cioClient, quizResults) => {
23
28
  resultCount: response?.total_num_results,
24
29
  resultPage: request?.page,
25
30
  resultId: result_id,
31
+ items,
26
32
  });
27
33
  };
28
34
  export const trackQuizResultClick = (cioClient, quizResults, result, position) => {
@@ -76,6 +76,7 @@ export const getMockState = (question) => ({
76
76
  isSingleQuestion: question?.type === 'single',
77
77
  isMultipleQuestion: question?.type === 'multiple',
78
78
  isSelectQuestion: question?.type === 'single',
79
+ total_questions: 1,
79
80
  },
80
81
  results: {
81
82
  response: {
package/lib/styles.css CHANGED
@@ -395,6 +395,35 @@
395
395
  margin-bottom: -1rem;
396
396
  }
397
397
 
398
+ /* Affixed progress bar */
399
+ .cio-quiz .cio-question-progress-affixed-container {
400
+ position: fixed;
401
+ top: 8px;
402
+ right: 16px;
403
+ z-index: 100;
404
+ display: flex;
405
+ flex-direction: row;
406
+ align-items: center;
407
+ gap: 7px;
408
+ font-size: 0.75rem;
409
+ padding: 8px;
410
+ color: white;
411
+ mix-blend-mode: difference;
412
+ }
413
+ .cio-quiz .cio-question-progress-progress-container {
414
+ width: 100px;
415
+ border-color: white;
416
+ height: 6px;
417
+ border-width: 1px;
418
+ border-style: solid;
419
+ background: transparent;
420
+ border-radius: 4px;
421
+ }
422
+ .cio-quiz .cio-question-progress-progress-bar {
423
+ background: white;
424
+ height: 100%;
425
+ }
426
+
398
427
  /* Results component */
399
428
  .cio-quiz .cio-results-container {
400
429
  width: 100%;
@@ -745,7 +774,6 @@
745
774
  flex-wrap: wrap;
746
775
  justify-content: center;
747
776
  margin-bottom: 2rem;
748
- margin-top: 0;
749
777
  }
750
778
  .cio-quiz .cio-question-option-container-text-only {
751
779
  margin: 0;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function ProgressBar(): JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
59
59
  },
60
60
  "peerDependencies": {
61
- "@constructor-io/constructorio-client-javascript": "^2.35.14",
61
+ "@constructor-io/constructorio-client-javascript": "^2.35.17",
62
62
  "react": ">=16.12.0",
63
63
  "react-dom": ">=16.12.0",
64
64
  "tslib": "^2.4.0"