@constructor-io/constructorio-ui-quizzes 1.3.0 → 1.3.2

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.
@@ -5,7 +5,7 @@ const react_1 = tslib_1.__importDefault(require("react"));
5
5
  function BackButton(props) {
6
6
  // eslint-disable-next-line
7
7
  const { disabled } = props;
8
- return (react_1.default.createElement("button", Object.assign({ type: 'button', className: `cio-question-back-button ${disabled ? 'disabled' : ''}` }, props),
8
+ return (react_1.default.createElement("button", Object.assign({ title: 'Quiz Back Button', type: 'button', className: `cio-question-back-button ${disabled ? 'disabled' : ''}` }, props),
9
9
  react_1.default.createElement("svg", { width: '8', height: '12', viewBox: '0 0 8 12', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
10
10
  react_1.default.createElement("path", { d: 'M6.06313 1.06268L0.964522 5.43176C0.882383 5.50218 0.816449 5.58954 0.771245 5.68785C0.726041 5.78615 0.702637 5.89306 0.702637 6.00126C0.702637 6.10946 0.726041 6.21637 0.771245 6.31467C0.816449 6.41297 0.882383 6.50033 0.964522 6.57076L6.06313 10.9398C6.5498 11.3568 7.30153 11.0111 7.30153 10.3703V1.63093C7.30153 0.990168 6.5498 0.644468 6.06313 1.06268Z', fill: 'currentColor' }))));
11
11
  }
@@ -35,13 +35,15 @@ function ResultCard(props) {
35
35
  salePrice),
36
36
  regularPrice && (react_1.default.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
37
37
  "$",
38
- regularPrice)))),
39
- react_1.default.createElement(ResultCtaButton_1.default, { item: result, price: salePrice || regularPrice })));
38
+ regularPrice))))));
40
39
  };
40
+ const resultCardContentWithoutLink = () => (react_1.default.createElement("div", { className: 'cio-result-card-container', onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e), role: 'button', tabIndex: 0 }, resultCardContent()));
41
41
  const resultCardContentWithLink = () => {
42
42
  var _a;
43
- return (react_1.default.createElement("a", { className: 'cio-result-card-anchor', href: (_a = result.data) === null || _a === void 0 ? void 0 : _a.url }, resultCardContent()));
43
+ return (react_1.default.createElement("a", { className: 'cio-result-card-anchor', href: (_a = result.data) === null || _a === void 0 ? void 0 : _a.url, onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e) }, resultCardContent()));
44
44
  };
45
- return (react_1.default.createElement("div", { onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e), className: 'cio-result-card', role: 'button', tabIndex: 0 }, !customClickItemCallback ? resultCardContentWithLink() : resultCardContent()));
45
+ return (react_1.default.createElement("div", { className: 'cio-result-card' },
46
+ !customClickItemCallback ? resultCardContentWithLink() : resultCardContentWithoutLink(),
47
+ react_1.default.createElement(ResultCtaButton_1.default, { item: result, price: salePrice || regularPrice })));
46
48
  }
47
49
  exports.default = ResultCard;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestStates = exports.cioJsClientDescription = exports.basicDescription = exports.componentDescription = exports.quizId = exports.apiKey = void 0;
3
+ exports.RequestStates = exports.smallContainerDescription = exports.cioJsClientDescription = exports.basicDescription = exports.componentDescription = exports.quizId = exports.apiKey = void 0;
4
4
  // Autocomplete key index
5
5
  exports.apiKey = 'key_wJSdZSiesX5hiVLt';
6
6
  exports.quizId = 'coffee-quiz';
@@ -28,6 +28,7 @@ exports.basicDescription = `Pass an \`apiKey\` and a \`quizId\` to request quest
28
28
  exports.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
29
29
 
30
30
  > Note: \`cioJsClient\` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)`;
31
+ exports.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`;
31
32
  var RequestStates;
32
33
  (function (RequestStates) {
33
34
  RequestStates[RequestStates["Stale"] = 0] = "Stale";
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  function BackButton(props) {
3
3
  // eslint-disable-next-line
4
4
  const { disabled } = props;
5
- return (React.createElement("button", { type: 'button', className: `cio-question-back-button ${disabled ? 'disabled' : ''}`, ...props },
5
+ return (React.createElement("button", { title: 'Quiz Back Button', type: 'button', className: `cio-question-back-button ${disabled ? 'disabled' : ''}`, ...props },
6
6
  React.createElement("svg", { width: '8', height: '12', viewBox: '0 0 8 12', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
7
7
  React.createElement("path", { d: 'M6.06313 1.06268L0.964522 5.43176C0.882383 5.50218 0.816449 5.58954 0.771245 5.68785C0.726041 5.78615 0.702637 5.89306 0.702637 6.00126C0.702637 6.10946 0.726041 6.21637 0.771245 6.31467C0.816449 6.41297 0.882383 6.50033 0.964522 6.57076L6.06313 10.9398C6.5498 11.3568 7.30153 11.0111 7.30153 10.3703V1.63093C7.30153 0.990168 6.5498 0.644468 6.06313 1.06268Z', fill: 'currentColor' }))));
8
8
  }
@@ -29,8 +29,10 @@ export default function ResultCard(props) {
29
29
  salePrice),
30
30
  regularPrice && (React.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
31
31
  "$",
32
- regularPrice)))),
32
+ regularPrice))))));
33
+ const resultCardContentWithoutLink = () => (React.createElement("div", { className: 'cio-result-card-container', onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e), role: 'button', tabIndex: 0 }, resultCardContent()));
34
+ const resultCardContentWithLink = () => (React.createElement("a", { className: 'cio-result-card-anchor', href: result.data?.url, onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e) }, resultCardContent()));
35
+ return (React.createElement("div", { className: 'cio-result-card' },
36
+ !customClickItemCallback ? resultCardContentWithLink() : resultCardContentWithoutLink(),
33
37
  React.createElement(ResultCtaButton, { item: result, price: salePrice || regularPrice })));
34
- const resultCardContentWithLink = () => (React.createElement("a", { className: 'cio-result-card-anchor', href: result.data?.url }, resultCardContent()));
35
- return (React.createElement("div", { onClick: () => clickHandler(), onKeyDown: (e) => keyDownHandler(e), className: 'cio-result-card', role: 'button', tabIndex: 0 }, !customClickItemCallback ? resultCardContentWithLink() : resultCardContent()));
36
38
  }
@@ -25,6 +25,7 @@ export const basicDescription = `Pass an \`apiKey\` and a \`quizId\` to request
25
25
  export 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
26
26
 
27
27
  > Note: \`cioJsClient\` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)`;
28
+ export 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`;
28
29
  export var RequestStates;
29
30
  (function (RequestStates) {
30
31
  RequestStates[RequestStates["Stale"] = 0] = "Stale";
package/lib/styles.css CHANGED
@@ -31,6 +31,7 @@
31
31
  --bottom-bar-height: 80px;
32
32
  --primary-color: var(--blue-denim-400);
33
33
  --container-image-small-height: 250px;
34
+ container: quiz / inline-size;
34
35
  }
35
36
 
36
37
  /* Mobile + global styles */
@@ -40,8 +41,11 @@
40
41
  font-family: 'Inter', sans-serif;
41
42
  }
42
43
  .cio-quiz {
44
+ position: relative;
43
45
  min-width: 100%;
44
46
  min-height: 100%;
47
+ height: 100%;
48
+ overflow: auto;
45
49
  display: flex;
46
50
  justify-content: center;
47
51
  background-color: #ffffff;
@@ -109,17 +113,18 @@
109
113
  width: 100%;
110
114
  padding: 0.5rem;
111
115
  border: 0;
112
- border-bottom: 1px solid var(--blue-denim-100);
116
+ border-bottom: 1px solid var(--gray-dust-100);
113
117
  color: var(--blue-denim-500);
114
118
  padding: 0.8rem;
115
119
  outline: none;
116
120
  font-size: 1rem;
117
121
  }
118
- .cio-question-input-text:focus {
122
+ .cio-question-input-text:focus,
123
+ .cio-question-input-text:active {
119
124
  border-bottom: 1px solid var(--blue-denim-500);
120
125
  }
121
126
  .cio-question-input-text::placeholder {
122
- color: var(--blue-denim-100);
127
+ color: var(--gray-dust-100);
123
128
  }
124
129
 
125
130
  /* CTA Button Component */
@@ -128,7 +133,7 @@
128
133
  height: var(--bottom-bar-height);
129
134
  padding: 8px 16px;
130
135
  display: flex;
131
- position: fixed;
136
+ position: absolute;
132
137
  bottom: 0px;
133
138
  left: 0px;
134
139
  background: white;
@@ -160,10 +165,15 @@
160
165
  background: var(--blue-denim-700);
161
166
  border: 2px solid var(--blue-denim-800);
162
167
  }
168
+ .cio-question-cta-button:focus {
169
+ outline: 3px solid var(--blue-denim-100);
170
+ }
163
171
  .cio-question-cta-button:disabled,
164
172
  .cio-question-cta-button.disabled {
165
- background: var(--blue-denim-200);
166
- border: 2px solid var(--blue-denim-100);
173
+ background: var(--gray-dust-200);
174
+ border: 2px solid var(--gray-dust-200);
175
+ cursor: auto;
176
+ outline: none;
167
177
  }
168
178
 
169
179
  /* Back Button Component */
@@ -183,6 +193,9 @@
183
193
  .cio-question-back-button:active {
184
194
  border: 2px solid var(--blue-denim-700);
185
195
  }
196
+ .cio-question-back-button:focus {
197
+ outline: 3px solid var(--blue-denim-100);
198
+ }
186
199
  .cio-question-back-button svg {
187
200
  display: inline;
188
201
  }
@@ -223,14 +236,15 @@
223
236
  box-shadow: 0px 4px 10px rgba(93, 124, 232, 0.25);
224
237
  }
225
238
  .cio-select-question-container {
239
+ position: relative;
226
240
  display: flex;
227
241
  flex-direction: column;
228
242
  align-items: center;
229
- justify-content: center;
243
+ align-self: start;
230
244
  max-width: 1200px;
231
- margin-bottom: var(--bottom-bar-height);
232
245
  padding: 1rem;
233
246
  margin-top: 2rem;
247
+ min-height: calc(100% - 3rem); /* Full height - padding - margin */
234
248
  width: 100%;
235
249
  }
236
250
  .cio-question-options-container {
@@ -239,7 +253,7 @@
239
253
  flex-wrap: wrap;
240
254
  gap: 1rem;
241
255
  width: 100%;
242
- margin-bottom: auto;
256
+ margin-bottom: var(--bottom-bar-height);
243
257
  margin-top: 2rem;
244
258
  }
245
259
  .cio-question-options-container-text-only {
@@ -374,7 +388,8 @@
374
388
  display: flex;
375
389
  flex-direction: column;
376
390
  }
377
- .cio-result-card-anchor {
391
+ .cio-result-card-anchor,
392
+ .cio-result-card-container {
378
393
  text-decoration: none;
379
394
  background-color: transparent;
380
395
  color: inherit;
@@ -399,6 +414,7 @@
399
414
  display: flex;
400
415
  flex-direction: column;
401
416
  justify-content: space-between;
417
+ text-decoration: none;
402
418
  }
403
419
  .cio-result-card-title {
404
420
  color: var(--gray-dust-500);
@@ -440,6 +456,9 @@
440
456
  background: var(--blue-denim-700);
441
457
  border: 2px solid var(--blue-denim-800);
442
458
  }
459
+ .cio-result-card-cta-button:focus {
460
+ outline: 3px solid var(--blue-denim-100);
461
+ }
443
462
  .cio-result-card-cta-button:disabled,
444
463
  .cio-result-card-cta-button.disabled {
445
464
  background: var(--blue-denim-200);
@@ -464,13 +483,18 @@
464
483
  /* Media Queries */
465
484
 
466
485
  /* Small Tablet */
467
- @media screen and (min-width: 640px) {
468
- /* Container */
486
+ @container quiz (min-width: 640px) {
487
+ .cio-container {
488
+ padding-bottom: 0;
489
+ }
490
+
491
+ /* Container */
469
492
  .cio-container--with-image {
470
493
  display: flex;
471
494
  justify-content: center;
472
495
  align-items: center;
473
496
  margin-bottom: 0;
497
+ padding-bottom: 0;
474
498
  }
475
499
 
476
500
  /* Image */
@@ -485,6 +509,7 @@
485
509
  .cio-cover-question-container--with-image {
486
510
  justify-content: center;
487
511
  margin-bottom: 0;
512
+ padding-bottom: 0;
488
513
  }
489
514
 
490
515
  /* Select Component */
@@ -519,23 +544,18 @@
519
544
  }
520
545
 
521
546
  /* Big Tablet */
522
- @media screen and (min-width: 768px) {
523
- /* Quiz */
524
- .cio-quiz {
525
- font-size: 18px;
526
- }
527
-
547
+ @container quiz (min-width: 768px) {
528
548
  /* Container */
529
549
  .cio-container {
530
550
  align-items: center;
531
551
  margin-top: 0;
532
552
  }
533
553
  .cio-container--with-image {
534
- padding: 6rem 2rem;
554
+ padding: 6% 2%;
535
555
  align-items: center;
536
556
  flex-direction: row;
537
557
  }
538
-
558
+
539
559
  /* Input */
540
560
  .cio-question-input-text {
541
561
  margin-bottom: 1rem;
@@ -543,7 +563,7 @@
543
563
 
544
564
  /* Image */
545
565
  .cio-question-image-container {
546
- max-height: 1000px;
566
+ max-height: 100%;
547
567
  }
548
568
  .cio-cover-question-container--with-image .cio-question-image-container {
549
569
  max-height: unset;
@@ -587,6 +607,7 @@
587
607
  padding: 1rem 5rem;
588
608
  }
589
609
  .cio-select-question-container {
610
+ justify-content: center;
590
611
  margin: 0;
591
612
  padding: 2rem;
592
613
  padding-bottom: 0;
@@ -612,11 +633,8 @@
612
633
  }
613
634
 
614
635
  /* Desktop */
615
- @media screen and (min-width: 1280px) {
636
+ @container quiz (min-width: 1280px) {
616
637
  /* Container */
617
- .cio-container--with-image {
618
- padding: 6rem 2rem;
619
- }
620
638
  .cio-cover-question-container--with-image {
621
639
  padding: 0;
622
640
  }
@@ -632,7 +650,6 @@
632
650
  padding: 2.5rem 0rem;
633
651
  }
634
652
 
635
-
636
653
  /* Results component */
637
654
  .cio-results-container {
638
655
  margin-top: 3rem;
@@ -3,6 +3,7 @@ export declare const quizId = "coffee-quiz";
3
3
  export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `onAddToCartClick` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `onQuizResultClick` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `onQuizResultsLoaded` is an optional callback function that will be called when the quiz results are loaded\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price\n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
4
4
  export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
5
5
  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)";
6
+ 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";
6
7
  export declare enum RequestStates {
7
8
  Stale = 0,
8
9
  Loading = 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -61,15 +61,15 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@cspell/eslint-plugin": "^6.18.1",
64
- "@storybook/addon-a11y": "^7.0.0-beta.40",
65
- "@storybook/addon-actions": "7.0.0-beta.40",
66
- "@storybook/addon-essentials": "7.0.0-beta.40",
67
- "@storybook/addon-interactions": "^7.0.0-beta.40",
68
- "@storybook/addon-links": "7.0.0-beta.40",
69
- "@storybook/jest": "^0.0.11-next.0",
70
- "@storybook/react-webpack5": "7.0.0-beta.40",
71
- "@storybook/test-runner": "0.10.0-next.8",
72
- "@storybook/testing-library": "^0.0.14-next.1",
64
+ "@storybook/addon-a11y": "^7.0.11",
65
+ "@storybook/addon-actions": "7.0.11",
66
+ "@storybook/addon-essentials": "7.0.11",
67
+ "@storybook/addon-interactions": "^7.0.11",
68
+ "@storybook/addon-links": "7.0.11",
69
+ "@storybook/jest": "^0.1.0",
70
+ "@storybook/react-webpack5": "7.0.11",
71
+ "@storybook/test-runner": "0.10.0",
72
+ "@storybook/testing-library": "^0.1.0",
73
73
  "@types/react": "^18.0.26",
74
74
  "@types/react-dom": "^18.0.9",
75
75
  "@typescript-eslint/eslint-plugin": "^5.47.0",
@@ -83,13 +83,13 @@
83
83
  "eslint-plugin-prettier": "^4.2.1",
84
84
  "eslint-plugin-react": "^7.31.11",
85
85
  "eslint-plugin-react-hooks": "^4.6.0",
86
- "eslint-plugin-storybook": "^0.6.8",
86
+ "eslint-plugin-storybook": "^0.6.12",
87
87
  "husky": "^8.0.1",
88
88
  "license-checker": "^25.0.1",
89
89
  "react": "^18.2.0",
90
90
  "react-dom": "^18.2.0",
91
91
  "start-server-and-test": "^2.0.0",
92
- "storybook": "7.0.0-beta.40",
92
+ "storybook": "7.0.11",
93
93
  "typescript": "^4.9.4",
94
94
  "webpack": "^5.75.0",
95
95
  "vite": "^4.2.1",