@constructor-io/constructorio-ui-quizzes 1.3.5 → 1.3.7
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.
- package/dist/constructorio-ui-quizzes-bundled.js +17 -17
- package/lib/cjs/components/ControlBar/ControlBar.js +2 -1
- package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +3 -1
- package/lib/cjs/services/index.js +22 -22
- package/lib/cjs/stories/Quiz/tests/mocks.js +96 -0
- package/lib/cjs/utils.js +7 -1
- package/lib/mjs/components/ControlBar/ControlBar.js +2 -1
- package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +3 -1
- package/lib/mjs/services/index.js +22 -22
- package/lib/mjs/stories/Quiz/tests/mocks.js +107 -0
- package/lib/mjs/utils.js +5 -0
- package/lib/styles.css +13 -0
- package/lib/types/components/ControlBar/ControlBar.d.ts +1 -0
- package/lib/types/stories/Quiz/tests/mocks.d.ts +41 -0
- package/lib/types/utils.d.ts +1 -0
- package/package.json +5 -4
|
@@ -5,9 +5,10 @@ const react_1 = tslib_1.__importDefault(require("react"));
|
|
|
5
5
|
const BackButton_1 = tslib_1.__importDefault(require("../BackButton/BackButton"));
|
|
6
6
|
const CTAButton_1 = tslib_1.__importDefault(require("../CTAButton/CTAButton"));
|
|
7
7
|
function ControlBar(props) {
|
|
8
|
-
const { showBackButton, backButtonHandler, ctaButtonText, nextButtonHandler, isNextButtonDisabled, } = props;
|
|
8
|
+
const { showBackButton, backButtonHandler, ctaButtonText, nextButtonHandler, isNextButtonDisabled, instructions, } = props;
|
|
9
9
|
return (react_1.default.createElement("div", { className: 'cio-question-buttons-container' },
|
|
10
10
|
showBackButton && react_1.default.createElement(BackButton_1.default, { onClick: backButtonHandler }),
|
|
11
|
+
instructions && react_1.default.createElement("div", { className: 'cio-question-buttons-container-text' }, instructions),
|
|
11
12
|
react_1.default.createElement(CTAButton_1.default, { disabled: isNextButtonDisabled, ctaText: ctaButtonText, onClick: nextButtonHandler })));
|
|
12
13
|
}
|
|
13
14
|
exports.default = ControlBar;
|
|
@@ -14,10 +14,12 @@ function SelectTypeQuestion() {
|
|
|
14
14
|
let question;
|
|
15
15
|
let type;
|
|
16
16
|
let hasImages = false;
|
|
17
|
+
let instructions;
|
|
17
18
|
if (state === null || state === void 0 ? void 0 : state.quiz.currentQuestion) {
|
|
18
19
|
question = state.quiz.currentQuestion.next_question;
|
|
19
20
|
type = question.type;
|
|
20
21
|
hasImages = question.options.some((option) => option.images);
|
|
22
|
+
instructions = type === actions_1.QuestionTypes.MultipleSelect && 'Select one or more options';
|
|
21
23
|
}
|
|
22
24
|
const [selected, setSelected] = (0, react_1.useState)({});
|
|
23
25
|
const isDisabled = Object.keys(selected).length === 0;
|
|
@@ -76,7 +78,7 @@ function SelectTypeQuestion() {
|
|
|
76
78
|
}, role: 'button', tabIndex: 0, key: option.id },
|
|
77
79
|
option.images ? (0, utils_1.renderImages)(option.images, 'cio-question-option-image') : '',
|
|
78
80
|
react_1.default.createElement("div", { className: 'cio-question-option-value' }, option === null || option === void 0 ? void 0 : option.value))))),
|
|
79
|
-
react_1.default.createElement(ControlBar_1.default, { nextButtonHandler: onNextClick, isNextButtonDisabled: isDisabled, backButtonHandler: previousQuestion, showBackButton: !(state === null || state === void 0 ? void 0 : state.quiz.isFirstQuestion), ctaButtonText: question === null || question === void 0 ? void 0 : question.cta_text })));
|
|
81
|
+
react_1.default.createElement(ControlBar_1.default, { nextButtonHandler: onNextClick, isNextButtonDisabled: isDisabled, backButtonHandler: previousQuestion, showBackButton: !(state === null || state === void 0 ? void 0 : state.quiz.isFirstQuestion), ctaButtonText: question === null || question === void 0 ? void 0 : question.cta_text, instructions: instructions })));
|
|
80
82
|
}
|
|
81
83
|
return null;
|
|
82
84
|
}
|
|
@@ -22,14 +22,14 @@ exports.getQuizResults = getQuizResults;
|
|
|
22
22
|
const trackQuizResultsLoaded = (cioClient, quizResults) => {
|
|
23
23
|
const { quiz_id, quiz_session_id, quiz_version_id, result_id, request, response } = quizResults;
|
|
24
24
|
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackQuizResultsLoaded({
|
|
25
|
-
quiz_id,
|
|
26
|
-
quiz_version_id,
|
|
27
|
-
quiz_session_id,
|
|
25
|
+
quizId: quiz_id,
|
|
26
|
+
quizVersionId: quiz_version_id,
|
|
27
|
+
quizSessionId: quiz_session_id,
|
|
28
28
|
url: window.location.href,
|
|
29
29
|
section: request === null || request === void 0 ? void 0 : request.section,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
result_id,
|
|
30
|
+
resultCount: response === null || response === void 0 ? void 0 : response.total_num_results,
|
|
31
|
+
resultPage: request === null || request === void 0 ? void 0 : request.page,
|
|
32
|
+
resultId: result_id,
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
exports.trackQuizResultsLoaded = trackQuizResultsLoaded;
|
|
@@ -38,17 +38,17 @@ const trackQuizResultClick = (cioClient, quizResults, result, position) => {
|
|
|
38
38
|
if (quizResults.request && quizResults.response) {
|
|
39
39
|
const { quiz_id, quiz_session_id, quiz_version_id, result_id, request: { section, page, num_results_per_page }, response: { total_num_results }, } = quizResults;
|
|
40
40
|
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackQuizResultClick({
|
|
41
|
-
quiz_id,
|
|
42
|
-
quiz_version_id,
|
|
43
|
-
quiz_session_id,
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
quizId: quiz_id,
|
|
42
|
+
quizVersionId: quiz_version_id,
|
|
43
|
+
quizSessionId: quiz_session_id,
|
|
44
|
+
itemId: (_a = result.data) === null || _a === void 0 ? void 0 : _a.id,
|
|
45
|
+
itemName: result === null || result === void 0 ? void 0 : result.value,
|
|
46
46
|
section,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
result_id,
|
|
50
|
-
|
|
51
|
-
num_results_per_page,
|
|
47
|
+
resultCount: total_num_results,
|
|
48
|
+
resultPage: page,
|
|
49
|
+
resultId: result_id,
|
|
50
|
+
resultPositionOnPage: position,
|
|
51
|
+
numResultsPerPage: num_results_per_page,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
};
|
|
@@ -58,13 +58,13 @@ const trackQuizConversion = (cioClient, quizResults, result, price) => {
|
|
|
58
58
|
if (quizResults.request) {
|
|
59
59
|
const { quiz_id, quiz_session_id, quiz_version_id, request: { section }, } = quizResults;
|
|
60
60
|
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackQuizConversion({
|
|
61
|
-
quiz_id,
|
|
62
|
-
quiz_version_id,
|
|
63
|
-
quiz_session_id,
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
quizId: quiz_id,
|
|
62
|
+
quizVersionId: quiz_version_id,
|
|
63
|
+
quizSessionId: quiz_session_id,
|
|
64
|
+
itemId: (_a = result.data) === null || _a === void 0 ? void 0 : _a.id,
|
|
65
|
+
itemName: result.value,
|
|
66
66
|
section,
|
|
67
|
-
|
|
67
|
+
variationId: (_b = result.data) === null || _b === void 0 ? void 0 : _b.variation_id,
|
|
68
68
|
revenue: (price && String(price)) || undefined,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMockContextValue = exports.getMockState = exports.questionOptions = exports.questionOptionsWithImages = exports.getMockQuestionWithImage = exports.getMockQuestion = void 0;
|
|
4
|
+
const getMockQuestion = (type) => ({
|
|
5
|
+
id: 1,
|
|
6
|
+
title: 'This is question title',
|
|
7
|
+
description: 'This is question description',
|
|
8
|
+
cta_text: 'Continue',
|
|
9
|
+
type,
|
|
10
|
+
});
|
|
11
|
+
exports.getMockQuestion = getMockQuestion;
|
|
12
|
+
const getMockImages = () => ({
|
|
13
|
+
images: {
|
|
14
|
+
primary_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const getMockQuestionWithImage = (type) => (Object.assign(Object.assign({}, (0, exports.getMockQuestion)(type)), getMockImages()));
|
|
18
|
+
exports.getMockQuestionWithImage = getMockQuestionWithImage;
|
|
19
|
+
const getMockOption = (id, value) => ({
|
|
20
|
+
id,
|
|
21
|
+
value,
|
|
22
|
+
attribute: {
|
|
23
|
+
name: value,
|
|
24
|
+
value,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const getMockOptionWithImage = (id, value) => (Object.assign(Object.assign({}, getMockOption(id, value)), getMockImages()));
|
|
28
|
+
exports.questionOptionsWithImages = [
|
|
29
|
+
Object.assign({}, getMockOptionWithImage(0, 'coffee')),
|
|
30
|
+
Object.assign({}, getMockOptionWithImage(1, 'tea')),
|
|
31
|
+
Object.assign({}, getMockOptionWithImage(2, 'water')),
|
|
32
|
+
];
|
|
33
|
+
exports.questionOptions = [
|
|
34
|
+
Object.assign({}, getMockOption(0, 'coffee')),
|
|
35
|
+
Object.assign({}, getMockOption(1, 'tea')),
|
|
36
|
+
Object.assign({}, getMockOption(2, 'water')),
|
|
37
|
+
];
|
|
38
|
+
const getMockState = (question) => ({
|
|
39
|
+
answers: {
|
|
40
|
+
inputs: { 1: '' },
|
|
41
|
+
isLastAnswer: false,
|
|
42
|
+
},
|
|
43
|
+
quiz: {
|
|
44
|
+
requestState: 1,
|
|
45
|
+
versionId: '',
|
|
46
|
+
sessionId: '',
|
|
47
|
+
isFirstQuestion: false,
|
|
48
|
+
currentQuestion: {
|
|
49
|
+
next_question: question,
|
|
50
|
+
},
|
|
51
|
+
results: {
|
|
52
|
+
response: {
|
|
53
|
+
results: [
|
|
54
|
+
{
|
|
55
|
+
value: 'This is a result card item',
|
|
56
|
+
data: {
|
|
57
|
+
id: '0',
|
|
58
|
+
price: 100,
|
|
59
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
value: 'This is a result card item',
|
|
64
|
+
data: {
|
|
65
|
+
id: '1',
|
|
66
|
+
price: 200,
|
|
67
|
+
salePrice: 150,
|
|
68
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
value: 'This is a result card item',
|
|
73
|
+
data: {
|
|
74
|
+
id: '2',
|
|
75
|
+
price: 300,
|
|
76
|
+
salePrice: 250,
|
|
77
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
resultsFilters: ['Chocolate', 'Medium'],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
exports.getMockState = getMockState;
|
|
87
|
+
const getMockContextValue = (question) => ({
|
|
88
|
+
state: (0, exports.getMockState)(question),
|
|
89
|
+
previousQuestion: () => { },
|
|
90
|
+
nextQuestion: () => { },
|
|
91
|
+
addToCart: () => { },
|
|
92
|
+
customClickItemCallback: false,
|
|
93
|
+
resetQuiz: () => { },
|
|
94
|
+
resultClick: () => { },
|
|
95
|
+
});
|
|
96
|
+
exports.getMockContextValue = getMockContextValue;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertPrimaryColorsToString = exports.rgbToHsl = exports.getFilterValuesFromExpression = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.defaultOnQuizResultsLoadedCode = exports.defaultOnQuizResultClickCode = exports.defaultOnAddToCartClickCode = exports.getStoryParams = exports.renderImages = void 0;
|
|
3
|
+
exports.convertPrimaryColorsToString = exports.rgbToHsl = exports.sleep = exports.getFilterValuesFromExpression = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.defaultOnQuizResultsLoadedCode = exports.defaultOnQuizResultClickCode = exports.defaultOnAddToCartClickCode = exports.getStoryParams = exports.renderImages = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const actions_1 = require("./components/CioQuiz/actions");
|
|
@@ -117,6 +117,12 @@ const getFilterValuesFromExpression = (exp) => {
|
|
|
117
117
|
return [];
|
|
118
118
|
};
|
|
119
119
|
exports.getFilterValuesFromExpression = getFilterValuesFromExpression;
|
|
120
|
+
// Function to emulate pausing between interactions
|
|
121
|
+
function sleep(ms) {
|
|
122
|
+
// eslint-disable-next-line
|
|
123
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
124
|
+
}
|
|
125
|
+
exports.sleep = sleep;
|
|
120
126
|
function rgbToHsl(r, g, b) {
|
|
121
127
|
const rConverted = r / 255;
|
|
122
128
|
const gConverted = g / 255;
|
|
@@ -2,9 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import BackButton from '../BackButton/BackButton';
|
|
3
3
|
import CTAButton from '../CTAButton/CTAButton';
|
|
4
4
|
function ControlBar(props) {
|
|
5
|
-
const { showBackButton, backButtonHandler, ctaButtonText, nextButtonHandler, isNextButtonDisabled, } = props;
|
|
5
|
+
const { showBackButton, backButtonHandler, ctaButtonText, nextButtonHandler, isNextButtonDisabled, instructions, } = props;
|
|
6
6
|
return (React.createElement("div", { className: 'cio-question-buttons-container' },
|
|
7
7
|
showBackButton && React.createElement(BackButton, { onClick: backButtonHandler }),
|
|
8
|
+
instructions && React.createElement("div", { className: 'cio-question-buttons-container-text' }, instructions),
|
|
8
9
|
React.createElement(CTAButton, { disabled: isNextButtonDisabled, ctaText: ctaButtonText, onClick: nextButtonHandler })));
|
|
9
10
|
}
|
|
10
11
|
export default ControlBar;
|
|
@@ -10,10 +10,12 @@ function SelectTypeQuestion() {
|
|
|
10
10
|
let question;
|
|
11
11
|
let type;
|
|
12
12
|
let hasImages = false;
|
|
13
|
+
let instructions;
|
|
13
14
|
if (state?.quiz.currentQuestion) {
|
|
14
15
|
question = state.quiz.currentQuestion.next_question;
|
|
15
16
|
type = question.type;
|
|
16
17
|
hasImages = question.options.some((option) => option.images);
|
|
18
|
+
instructions = type === QuestionTypes.MultipleSelect && 'Select one or more options';
|
|
17
19
|
}
|
|
18
20
|
const [selected, setSelected] = useState({});
|
|
19
21
|
const isDisabled = Object.keys(selected).length === 0;
|
|
@@ -71,7 +73,7 @@ function SelectTypeQuestion() {
|
|
|
71
73
|
}, role: 'button', tabIndex: 0, key: option.id },
|
|
72
74
|
option.images ? renderImages(option.images, 'cio-question-option-image') : '',
|
|
73
75
|
React.createElement("div", { className: 'cio-question-option-value' }, option?.value))))),
|
|
74
|
-
React.createElement(ControlBar, { nextButtonHandler: onNextClick, isNextButtonDisabled: isDisabled, backButtonHandler: previousQuestion, showBackButton: !state?.quiz.isFirstQuestion, ctaButtonText: question?.cta_text })));
|
|
76
|
+
React.createElement(ControlBar, { nextButtonHandler: onNextClick, isNextButtonDisabled: isDisabled, backButtonHandler: previousQuestion, showBackButton: !state?.quiz.isFirstQuestion, ctaButtonText: question?.cta_text, instructions: instructions })));
|
|
75
77
|
}
|
|
76
78
|
return null;
|
|
77
79
|
}
|
|
@@ -15,31 +15,31 @@ export const getQuizResults = async (cioClient, quizId, parameters) => cioClient
|
|
|
15
15
|
export const trackQuizResultsLoaded = (cioClient, quizResults) => {
|
|
16
16
|
const { quiz_id, quiz_session_id, quiz_version_id, result_id, request, response } = quizResults;
|
|
17
17
|
cioClient?.tracker.trackQuizResultsLoaded({
|
|
18
|
-
quiz_id,
|
|
19
|
-
quiz_version_id,
|
|
20
|
-
quiz_session_id,
|
|
18
|
+
quizId: quiz_id,
|
|
19
|
+
quizVersionId: quiz_version_id,
|
|
20
|
+
quizSessionId: quiz_session_id,
|
|
21
21
|
url: window.location.href,
|
|
22
22
|
section: request?.section,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
result_id,
|
|
23
|
+
resultCount: response?.total_num_results,
|
|
24
|
+
resultPage: request?.page,
|
|
25
|
+
resultId: result_id,
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
export const trackQuizResultClick = (cioClient, quizResults, result, position) => {
|
|
29
29
|
if (quizResults.request && quizResults.response) {
|
|
30
30
|
const { quiz_id, quiz_session_id, quiz_version_id, result_id, request: { section, page, num_results_per_page }, response: { total_num_results }, } = quizResults;
|
|
31
31
|
cioClient?.tracker.trackQuizResultClick({
|
|
32
|
-
quiz_id,
|
|
33
|
-
quiz_version_id,
|
|
34
|
-
quiz_session_id,
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
quizId: quiz_id,
|
|
33
|
+
quizVersionId: quiz_version_id,
|
|
34
|
+
quizSessionId: quiz_session_id,
|
|
35
|
+
itemId: result.data?.id,
|
|
36
|
+
itemName: result?.value,
|
|
37
37
|
section,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
result_id,
|
|
41
|
-
|
|
42
|
-
num_results_per_page,
|
|
38
|
+
resultCount: total_num_results,
|
|
39
|
+
resultPage: page,
|
|
40
|
+
resultId: result_id,
|
|
41
|
+
resultPositionOnPage: position,
|
|
42
|
+
numResultsPerPage: num_results_per_page,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
};
|
|
@@ -47,13 +47,13 @@ export const trackQuizConversion = (cioClient, quizResults, result, price) => {
|
|
|
47
47
|
if (quizResults.request) {
|
|
48
48
|
const { quiz_id, quiz_session_id, quiz_version_id, request: { section }, } = quizResults;
|
|
49
49
|
cioClient?.tracker.trackQuizConversion({
|
|
50
|
-
quiz_id,
|
|
51
|
-
quiz_version_id,
|
|
52
|
-
quiz_session_id,
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
quizId: quiz_id,
|
|
51
|
+
quizVersionId: quiz_version_id,
|
|
52
|
+
quizSessionId: quiz_session_id,
|
|
53
|
+
itemId: result.data?.id,
|
|
54
|
+
itemName: result.value,
|
|
55
55
|
section,
|
|
56
|
-
|
|
56
|
+
variationId: result.data?.variation_id,
|
|
57
57
|
revenue: (price && String(price)) || undefined,
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const getMockQuestion = (type) => ({
|
|
2
|
+
id: 1,
|
|
3
|
+
title: 'This is question title',
|
|
4
|
+
description: 'This is question description',
|
|
5
|
+
cta_text: 'Continue',
|
|
6
|
+
type,
|
|
7
|
+
});
|
|
8
|
+
const getMockImages = () => ({
|
|
9
|
+
images: {
|
|
10
|
+
primary_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
export const getMockQuestionWithImage = (type) => ({
|
|
14
|
+
...getMockQuestion(type),
|
|
15
|
+
...getMockImages(),
|
|
16
|
+
});
|
|
17
|
+
const getMockOption = (id, value) => ({
|
|
18
|
+
id,
|
|
19
|
+
value,
|
|
20
|
+
attribute: {
|
|
21
|
+
name: value,
|
|
22
|
+
value,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const getMockOptionWithImage = (id, value) => ({
|
|
26
|
+
...getMockOption(id, value),
|
|
27
|
+
...getMockImages(),
|
|
28
|
+
});
|
|
29
|
+
export const questionOptionsWithImages = [
|
|
30
|
+
{
|
|
31
|
+
...getMockOptionWithImage(0, 'coffee'),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
...getMockOptionWithImage(1, 'tea'),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
...getMockOptionWithImage(2, 'water'),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
export const questionOptions = [
|
|
41
|
+
{
|
|
42
|
+
...getMockOption(0, 'coffee'),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
...getMockOption(1, 'tea'),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
...getMockOption(2, 'water'),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
export const getMockState = (question) => ({
|
|
52
|
+
answers: {
|
|
53
|
+
inputs: { 1: '' },
|
|
54
|
+
isLastAnswer: false,
|
|
55
|
+
},
|
|
56
|
+
quiz: {
|
|
57
|
+
requestState: 1,
|
|
58
|
+
versionId: '',
|
|
59
|
+
sessionId: '',
|
|
60
|
+
isFirstQuestion: false,
|
|
61
|
+
currentQuestion: {
|
|
62
|
+
next_question: question,
|
|
63
|
+
},
|
|
64
|
+
results: {
|
|
65
|
+
response: {
|
|
66
|
+
results: [
|
|
67
|
+
{
|
|
68
|
+
value: 'This is a result card item',
|
|
69
|
+
data: {
|
|
70
|
+
id: '0',
|
|
71
|
+
price: 100,
|
|
72
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
value: 'This is a result card item',
|
|
77
|
+
data: {
|
|
78
|
+
id: '1',
|
|
79
|
+
price: 200,
|
|
80
|
+
salePrice: 150,
|
|
81
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: 'This is a result card item',
|
|
86
|
+
data: {
|
|
87
|
+
id: '2',
|
|
88
|
+
price: 300,
|
|
89
|
+
salePrice: 250,
|
|
90
|
+
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
resultsFilters: ['Chocolate', 'Medium'],
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
export const getMockContextValue = (question) => ({
|
|
100
|
+
state: getMockState(question),
|
|
101
|
+
previousQuestion: () => { },
|
|
102
|
+
nextQuestion: () => { },
|
|
103
|
+
addToCart: () => { },
|
|
104
|
+
customClickItemCallback: false,
|
|
105
|
+
resetQuiz: () => { },
|
|
106
|
+
resultClick: () => { },
|
|
107
|
+
});
|
package/lib/mjs/utils.js
CHANGED
|
@@ -104,6 +104,11 @@ export const getFilterValuesFromExpression = (exp) => {
|
|
|
104
104
|
}
|
|
105
105
|
return [];
|
|
106
106
|
};
|
|
107
|
+
// Function to emulate pausing between interactions
|
|
108
|
+
export function sleep(ms) {
|
|
109
|
+
// eslint-disable-next-line
|
|
110
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
111
|
+
}
|
|
107
112
|
export function rgbToHsl(r, g, b) {
|
|
108
113
|
const rConverted = r / 255;
|
|
109
114
|
const gConverted = g / 255;
|
package/lib/styles.css
CHANGED
|
@@ -192,6 +192,9 @@
|
|
|
192
192
|
background-color: rgba(255, 255, 255, 0.87);
|
|
193
193
|
align-items: center;
|
|
194
194
|
}
|
|
195
|
+
.cio-question-buttons-container-text {
|
|
196
|
+
display: none;
|
|
197
|
+
}
|
|
195
198
|
.cio-question-cta-button {
|
|
196
199
|
background: var(--primary-color);
|
|
197
200
|
color: #ffffff;
|
|
@@ -455,6 +458,7 @@
|
|
|
455
458
|
height: 240px;
|
|
456
459
|
margin-left: auto;
|
|
457
460
|
margin-right: auto;
|
|
461
|
+
margin-bottom: 10px;
|
|
458
462
|
}
|
|
459
463
|
.cio-result-card-image img {
|
|
460
464
|
height: 100%;
|
|
@@ -593,6 +597,15 @@
|
|
|
593
597
|
.cio-result-card {
|
|
594
598
|
flex-basis: 30%;
|
|
595
599
|
}
|
|
600
|
+
|
|
601
|
+
/* Control Bar Instructions */
|
|
602
|
+
.cio-question-buttons-container-text {
|
|
603
|
+
text-align: center;
|
|
604
|
+
flex-grow: 1;
|
|
605
|
+
color: var(--gray-dust-100);
|
|
606
|
+
font-size: 1.125rem;
|
|
607
|
+
display: block;
|
|
608
|
+
}
|
|
596
609
|
}
|
|
597
610
|
|
|
598
611
|
/* Big Tablet */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Question } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
2
|
+
import { QuestionTypes } from '../../../components/CioQuiz/actions';
|
|
3
|
+
import { QuizContextValue } from '../../../components/CioQuiz/context';
|
|
4
|
+
export declare const getMockQuestion: (type: QuestionTypes) => {
|
|
5
|
+
id: number;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
cta_text: string;
|
|
9
|
+
type: QuestionTypes;
|
|
10
|
+
};
|
|
11
|
+
export declare const getMockQuestionWithImage: (type: QuestionTypes) => {
|
|
12
|
+
images: {
|
|
13
|
+
primary_url: string;
|
|
14
|
+
};
|
|
15
|
+
id: number;
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
cta_text: string;
|
|
19
|
+
type: QuestionTypes;
|
|
20
|
+
};
|
|
21
|
+
export declare const questionOptionsWithImages: {
|
|
22
|
+
images: {
|
|
23
|
+
primary_url: string;
|
|
24
|
+
};
|
|
25
|
+
id: any;
|
|
26
|
+
value: any;
|
|
27
|
+
attribute: {
|
|
28
|
+
name: any;
|
|
29
|
+
value: any;
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
export declare const questionOptions: {
|
|
33
|
+
id: any;
|
|
34
|
+
value: any;
|
|
35
|
+
attribute: {
|
|
36
|
+
name: any;
|
|
37
|
+
value: any;
|
|
38
|
+
};
|
|
39
|
+
}[];
|
|
40
|
+
export declare const getMockState: (question?: Question) => any;
|
|
41
|
+
export declare const getMockContextValue: (question?: Question) => QuizContextValue;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -34,5 +34,6 @@ export declare const getQuestionTypes: (questionType?: `${QuestionTypes}`) => {
|
|
|
34
34
|
export declare function getPreferredColorScheme(): string;
|
|
35
35
|
export declare function isFunction(fn: any): boolean;
|
|
36
36
|
export declare const getFilterValuesFromExpression: (exp: FilterExpression | null) => string[];
|
|
37
|
+
export declare function sleep(ms: any): Promise<unknown>;
|
|
37
38
|
export declare function rgbToHsl(r: number, g: number, b: number): number[];
|
|
38
39
|
export declare function convertPrimaryColorsToString(primaryColorStyles: PrimaryColorStyles): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-ui-quizzes",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "Constructor.io Quizzes UI library for web applications",
|
|
5
5
|
"author": "constructor.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,12 +54,13 @@
|
|
|
54
54
|
"check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@constructor-io/constructorio-client-javascript": "^2.35.
|
|
57
|
+
"@constructor-io/constructorio-client-javascript": "^2.35.12",
|
|
58
58
|
"react": ">=16.12.0",
|
|
59
59
|
"react-dom": ">=16.12.0",
|
|
60
60
|
"tslib": "^2.4.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"@axe-core/react": "^4.7.0",
|
|
63
64
|
"@cspell/eslint-plugin": "^6.18.1",
|
|
64
65
|
"@storybook/addon-a11y": "^7.0.11",
|
|
65
66
|
"@storybook/addon-actions": "7.0.11",
|
|
@@ -91,8 +92,8 @@
|
|
|
91
92
|
"start-server-and-test": "^2.0.0",
|
|
92
93
|
"storybook": "7.0.11",
|
|
93
94
|
"typescript": "^4.9.4",
|
|
94
|
-
"webpack": "^5.75.0",
|
|
95
95
|
"vite": "^4.2.1",
|
|
96
|
-
"vite-plugin-css-injected-by-js": "^3.1.0"
|
|
96
|
+
"vite-plugin-css-injected-by-js": "^3.1.0",
|
|
97
|
+
"webpack": "^5.75.0"
|
|
97
98
|
}
|
|
98
99
|
}
|