@constructor-io/constructorio-ui-quizzes 1.12.6 → 1.13.1

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.
@@ -18,7 +18,7 @@ function CoverTypeQuestion() {
18
18
  return (react_1.default.createElement("div", { className: `
19
19
  cio-container${hasImage ? '--with-image' : ''}
20
20
  cio-cover-question-container${hasImage ? '--with-image' : ''}
21
- `, "data-question-key": question.key },
21
+ `, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
22
22
  hasImage ? (0, utils_1.renderImages)(question.images, 'cio-question-image-container') : '',
23
23
  react_1.default.createElement("div", { className: 'cio-question-content' },
24
24
  react_1.default.createElement(QuestionTitle_1.default, { title: question === null || question === void 0 ? void 0 : question.title }),
@@ -18,7 +18,7 @@ function OpenTextQuestion() {
18
18
  return (react_1.default.createElement("div", { className: `
19
19
  cio-container${hasImage ? '--with-image' : ''}
20
20
  cio-open-text-question-container${hasImage ? '--with-image' : ''}
21
- `, "data-question-key": question.key },
21
+ `, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
22
22
  hasImage ? (0, utils_1.renderImages)(question.images, 'cio-question-image-container') : '',
23
23
  react_1.default.createElement("div", { className: 'cio-question-content' },
24
24
  react_1.default.createElement(QuestionTitle_1.default, { title: question.title }),
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importDefault(require("react"));
5
+ const constants_1 = require("../../constants");
6
+ const utils_1 = require("../../utils");
7
+ const getSummaryVariables = ({ summary, matchedOptions = [] }) => {
8
+ if (summary === null) {
9
+ return {
10
+ summaryFirstPart: 'Based on your answers ',
11
+ summaryLastPart: ' we recommend these matches.',
12
+ itemsSeparator: ', ',
13
+ lastSeparator: ' and ',
14
+ isActiveSummary: true,
15
+ };
16
+ }
17
+ const { text = '', is_active: isActive, items_separator: itemsSeparator, last_separator: lastSeparator, } = summary;
18
+ const isActiveSummary = !!isActive && !!matchedOptions.length && !!(text === null || text === void 0 ? void 0 : text.length);
19
+ const [summaryFirstPart, summaryLastPart] = (text === null || text === void 0 ? void 0 : text.split(constants_1.MATCHED_OPTIONS_PLACEHOLDER)) || [];
20
+ return {
21
+ summaryFirstPart,
22
+ summaryLastPart,
23
+ itemsSeparator,
24
+ lastSeparator,
25
+ isActiveSummary,
26
+ };
27
+ };
28
+ function QuizResultsSummary({ summary, matchedOptions = [], }) {
29
+ const { summaryFirstPart, summaryLastPart, itemsSeparator, lastSeparator, isActiveSummary } = getSummaryVariables({ summary, matchedOptions });
30
+ const matchedOptionsTemplate = (0, utils_1.formatMatchedOptions)(matchedOptions, itemsSeparator, lastSeparator);
31
+ if (!isActiveSummary)
32
+ return null;
33
+ return (react_1.default.createElement("p", { className: 'cio-results-explanation' },
34
+ !!(summaryFirstPart === null || summaryFirstPart === void 0 ? void 0 : summaryFirstPart.length) && summaryFirstPart,
35
+ !!matchedOptionsTemplate.length && react_1.default.createElement("span", null, matchedOptionsTemplate),
36
+ !!(summaryLastPart === null || summaryLastPart === void 0 ? void 0 : summaryLastPart.length) && summaryLastPart));
37
+ }
38
+ exports.default = QuizResultsSummary;
@@ -4,15 +4,15 @@ const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
5
  const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
6
6
  const ShareButton_1 = tslib_1.__importDefault(require("../ShareButton/ShareButton"));
7
+ const QuizResultsSummary_1 = tslib_1.__importDefault(require("../QuizResultsSummary/QuizResultsSummary"));
7
8
  function ResultFiltersAndShare({ onShare, numberOfResults, showShareButton, }) {
8
- var _a;
9
+ var _a, _b, _c, _d, _e;
9
10
  const { state } = (0, react_1.useContext)(context_1.default);
10
- const matchedOptions = ((_a = state === null || state === void 0 ? void 0 : state.quiz) === null || _a === void 0 ? void 0 : _a.matchedOptions) || [];
11
+ const matchedOptions = (_a = state === null || state === void 0 ? void 0 : state.quiz) === null || _a === void 0 ? void 0 : _a.matchedOptions;
12
+ const summary = (_e = (_d = (_c = (_b = state === null || state === void 0 ? void 0 : state.quiz) === null || _b === void 0 ? void 0 : _b.resultsConfig) === null || _c === void 0 ? void 0 : _c.desktop) === null || _d === void 0 ? void 0 : _d.response_summary) !== null && _e !== void 0 ? _e : null;
11
13
  return (react_1.default.createElement("div", { className: 'cio-results-filter-and-redo-container cio-results-button-group' },
12
- react_1.default.createElement("div", { className: 'cio-results-filter-container' }, !!matchedOptions.length && (react_1.default.createElement("p", { className: 'cio-results-explanation' },
13
- "Based on your answers ",
14
- react_1.default.createElement("span", null, matchedOptions.join(', ')),
15
- " we recommend these matches."))),
14
+ react_1.default.createElement("div", { className: 'cio-results-filter-container' },
15
+ react_1.default.createElement(QuizResultsSummary_1.default, { summary: summary, matchedOptions: matchedOptions })),
16
16
  react_1.default.createElement("div", { className: 'cio-results-number-and-share-button-group' },
17
17
  numberOfResults,
18
18
  " ",
@@ -19,7 +19,7 @@ function SelectTypeQuestion() {
19
19
  instructions = (question === null || question === void 0 ? void 0 : question.type) === actions_1.QuestionTypes.MultipleSelect && 'Select one or more options';
20
20
  }
21
21
  if (question) {
22
- return (react_1.default.createElement("div", { className: 'cio-select-question-container', "data-question-key": question.key },
22
+ return (react_1.default.createElement("div", { className: 'cio-select-question-container', "data-cnstrc-question-type": question.type, "data-question-key": question.key },
23
23
  react_1.default.createElement("div", { className: 'cio-select-question-text' },
24
24
  react_1.default.createElement(QuestionTitle_1.default, { title: question.title }),
25
25
  (question === null || question === void 0 ? void 0 : question.description) ? react_1.default.createElement(QuestionDescription_1.default, { description: question.description }) : ''),
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestStates = exports.quizSessionStateKey = exports.quizId = exports.apiKey = void 0;
3
+ exports.MATCHED_OPTIONS_PLACEHOLDER = exports.RequestStates = exports.quizSessionStateKey = exports.quizId = exports.apiKey = void 0;
4
4
  // Autocomplete key index
5
5
  exports.apiKey = 'key_n4SkMH5PFWLdStQZ';
6
6
  exports.quizId = 'coffee-quiz';
@@ -13,3 +13,4 @@ var RequestStates;
13
13
  RequestStates["Success"] = "SUCCESS";
14
14
  RequestStates["Error"] = "ERROR";
15
15
  })(RequestStates = exports.RequestStates || (exports.RequestStates = {}));
16
+ exports.MATCHED_OPTIONS_PLACEHOLDER = '@matched_options';
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.sleep = exports.logger = exports.resetQuizSessionStorageState = exports.getStateFromSessionStorage = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.functionStrings = exports.renderImages = void 0;
3
+ exports.formatMatchedOptions = exports.convertPrimaryColorsToString = exports.rgbToHsl = exports.sleep = exports.logger = exports.resetQuizSessionStorageState = exports.getStateFromSessionStorage = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.functionStrings = exports.renderImages = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /* eslint-disable no-console */
6
6
  const react_1 = tslib_1.__importDefault(require("react"));
@@ -165,3 +165,11 @@ function convertPrimaryColorsToString(primaryColorStyles) {
165
165
  }`;
166
166
  }
167
167
  exports.convertPrimaryColorsToString = convertPrimaryColorsToString;
168
+ function formatMatchedOptions(options, separator, lastSeparator) {
169
+ if (!options.length || !separator || !lastSeparator) {
170
+ return '';
171
+ }
172
+ const firstPart = options.slice(0, -1).join(separator);
173
+ return [firstPart, lastSeparator, options.at(-1)].join('');
174
+ }
175
+ exports.formatMatchedOptions = formatMatchedOptions;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.12.6';
3
+ exports.default = '1.13.1';
@@ -14,7 +14,7 @@ export default function CoverTypeQuestion() {
14
14
  return (React.createElement("div", { className: `
15
15
  cio-container${hasImage ? '--with-image' : ''}
16
16
  cio-cover-question-container${hasImage ? '--with-image' : ''}
17
- `, "data-question-key": question.key },
17
+ `, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
18
18
  hasImage ? renderImages(question.images, 'cio-question-image-container') : '',
19
19
  React.createElement("div", { className: 'cio-question-content' },
20
20
  React.createElement(QuestionTitle, { title: question?.title }),
@@ -14,7 +14,7 @@ function OpenTextQuestion() {
14
14
  return (React.createElement("div", { className: `
15
15
  cio-container${hasImage ? '--with-image' : ''}
16
16
  cio-open-text-question-container${hasImage ? '--with-image' : ''}
17
- `, "data-question-key": question.key },
17
+ `, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
18
18
  hasImage ? renderImages(question.images, 'cio-question-image-container') : '',
19
19
  React.createElement("div", { className: 'cio-question-content' },
20
20
  React.createElement(QuestionTitle, { title: question.title }),
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { MATCHED_OPTIONS_PLACEHOLDER } from '../../constants';
3
+ import { formatMatchedOptions } from '../../utils';
4
+ const getSummaryVariables = ({ summary, matchedOptions = [] }) => {
5
+ if (summary === null) {
6
+ return {
7
+ summaryFirstPart: 'Based on your answers ',
8
+ summaryLastPart: ' we recommend these matches.',
9
+ itemsSeparator: ', ',
10
+ lastSeparator: ' and ',
11
+ isActiveSummary: true,
12
+ };
13
+ }
14
+ const { text = '', is_active: isActive, items_separator: itemsSeparator, last_separator: lastSeparator, } = summary;
15
+ const isActiveSummary = !!isActive && !!matchedOptions.length && !!text?.length;
16
+ const [summaryFirstPart, summaryLastPart] = text?.split(MATCHED_OPTIONS_PLACEHOLDER) || [];
17
+ return {
18
+ summaryFirstPart,
19
+ summaryLastPart,
20
+ itemsSeparator,
21
+ lastSeparator,
22
+ isActiveSummary,
23
+ };
24
+ };
25
+ export default function QuizResultsSummary({ summary, matchedOptions = [], }) {
26
+ const { summaryFirstPart, summaryLastPart, itemsSeparator, lastSeparator, isActiveSummary } = getSummaryVariables({ summary, matchedOptions });
27
+ const matchedOptionsTemplate = formatMatchedOptions(matchedOptions, itemsSeparator, lastSeparator);
28
+ if (!isActiveSummary)
29
+ return null;
30
+ return (React.createElement("p", { className: 'cio-results-explanation' },
31
+ !!summaryFirstPart?.length && summaryFirstPart,
32
+ !!matchedOptionsTemplate.length && React.createElement("span", null, matchedOptionsTemplate),
33
+ !!summaryLastPart?.length && summaryLastPart));
34
+ }
@@ -1,14 +1,14 @@
1
1
  import React, { useContext } from 'react';
2
2
  import QuizContext from '../CioQuiz/context';
3
3
  import ShareButton from '../ShareButton/ShareButton';
4
+ import QuizResultsSummary from '../QuizResultsSummary/QuizResultsSummary';
4
5
  function ResultFiltersAndShare({ onShare, numberOfResults, showShareButton, }) {
5
6
  const { state } = useContext(QuizContext);
6
- const matchedOptions = state?.quiz?.matchedOptions || [];
7
+ const matchedOptions = state?.quiz?.matchedOptions;
8
+ const summary = state?.quiz?.resultsConfig?.desktop?.response_summary ?? null;
7
9
  return (React.createElement("div", { className: 'cio-results-filter-and-redo-container cio-results-button-group' },
8
- React.createElement("div", { className: 'cio-results-filter-container' }, !!matchedOptions.length && (React.createElement("p", { className: 'cio-results-explanation' },
9
- "Based on your answers ",
10
- React.createElement("span", null, matchedOptions.join(', ')),
11
- " we recommend these matches."))),
10
+ React.createElement("div", { className: 'cio-results-filter-container' },
11
+ React.createElement(QuizResultsSummary, { summary: summary, matchedOptions: matchedOptions })),
12
12
  React.createElement("div", { className: 'cio-results-number-and-share-button-group' },
13
13
  numberOfResults,
14
14
  " ",
@@ -15,7 +15,7 @@ function SelectTypeQuestion() {
15
15
  instructions = question?.type === QuestionTypes.MultipleSelect && 'Select one or more options';
16
16
  }
17
17
  if (question) {
18
- return (React.createElement("div", { className: 'cio-select-question-container', "data-question-key": question.key },
18
+ return (React.createElement("div", { className: 'cio-select-question-container', "data-cnstrc-question-type": question.type, "data-question-key": question.key },
19
19
  React.createElement("div", { className: 'cio-select-question-text' },
20
20
  React.createElement(QuestionTitle, { title: question.title }),
21
21
  question?.description ? React.createElement(QuestionDescription, { description: question.description }) : ''),
@@ -10,3 +10,4 @@ export var RequestStates;
10
10
  RequestStates["Success"] = "SUCCESS";
11
11
  RequestStates["Error"] = "ERROR";
12
12
  })(RequestStates || (RequestStates = {}));
13
+ export const MATCHED_OPTIONS_PLACEHOLDER = '@matched_options';
package/lib/mjs/utils.js CHANGED
@@ -145,3 +145,10 @@ export function convertPrimaryColorsToString(primaryColorStyles) {
145
145
  --primary-color-l: ${primaryColorStyles['--primary-color-l']};
146
146
  }`;
147
147
  }
148
+ export function formatMatchedOptions(options, separator, lastSeparator) {
149
+ if (!options.length || !separator || !lastSeparator) {
150
+ return '';
151
+ }
152
+ const firstPart = options.slice(0, -1).join(separator);
153
+ return [firstPart, lastSeparator, options.at(-1)].join('');
154
+ }
@@ -1 +1 @@
1
- export default '1.12.6';
1
+ export default '1.13.1';
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { QuizResultsConfig } from '../../types';
3
+ interface QuizResultsSummaryProps {
4
+ summary: QuizResultsConfig['desktop']['response_summary'];
5
+ matchedOptions?: string[];
6
+ }
7
+ export default function QuizResultsSummary({ summary, matchedOptions, }: QuizResultsSummaryProps): JSX.Element | null;
8
+ export {};
@@ -7,3 +7,4 @@ export declare enum RequestStates {
7
7
  Success = "SUCCESS",
8
8
  Error = "ERROR"
9
9
  }
10
+ export declare const MATCHED_OPTIONS_PLACEHOLDER = "@matched_options";
@@ -36,3 +36,4 @@ export declare const logger: (action: any) => void;
36
36
  export declare function sleep(ms: any): Promise<unknown>;
37
37
  export declare function rgbToHsl(r: number, g: number, b: number): number[];
38
38
  export declare function convertPrimaryColorsToString(primaryColorStyles: PrimaryColorStyles): string;
39
+ export declare function formatMatchedOptions(options: string[], separator?: string | null, lastSeparator?: string | null): string;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.12.6";
1
+ declare const _default: "1.13.1";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.12.6",
3
+ "version": "1.13.1",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -61,7 +61,7 @@
61
61
  "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
62
62
  },
63
63
  "peerDependencies": {
64
- "@constructor-io/constructorio-client-javascript": "^2.42.0",
64
+ "@constructor-io/constructorio-client-javascript": "^2.42.1",
65
65
  "react": ">=16.12.0",
66
66
  "react-dom": ">=16.12.0",
67
67
  "tslib": "^2.4.0"