@constructor-io/constructorio-ui-quizzes

中文文档
1.21.1发布于 2026/09/03MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5087

Constructor.io Quizzes UI library for web applications

原始使用文档
文档目录15 节
  1. Introduction
  2. Installation
  3. Usage
  4. Using the React Component
  5. Using the Javascript Bundle
  6. Custom Styling
  7. Library defaults
  8. Troubleshooting
  9. Known Issues
  10. Local Development
  11. Development scripts
  12. Publishing new versions
  13. New Storybook Version
  14. Supporting Docs
  15. Demoing quizzes in a sandbox environment

Constructor.io Quizzes UI Library

npm MIT licensed

A UI Library that provides React components to manage the fetching and rendering logic for Constructor.io's Quizzes.

Introduction

Constructor.io's Quizzes are interactive experiences that personalize the shopping journey for each of your customers. This UI library simplifies the integration process by providing React Components that handle the fetching and rendering logic for Quizzes. Typescript support is available.

Our storybook docs are the best place to explore the behavior and the available configuration options for this UI Library.

Quizzes-UI-Example

Installation

npm i @constructor-io/constructorio-ui-quizzes

Usage

Using the React Component

The CioQuiz component handles state management, data fetching, and rendering logic for the entire quiz.

import CioQuiz from '@constructor-io/constructorio-ui-quizzes';

function YourComponent() {
  return (
    <div>
      <CioQuiz quizId='coffee-quiz' apiKey='key_n4SkMH5PFWLdStQZ' />
    </div>
  );
}

Using the Javascript Bundle

This is a framework agnostic method that can be used in any JavaScript project. The CioQuiz function provides a simple interface to inject an entire Quizzes UI into the provided selector. In addition to Quiz component props, this function also accepts selector and includeCSS.

import CioQuiz from '@constructor-io/constructorio-ui-quizzes/constructorio-ui-quizzes-bundled';

CioQuiz({
  selector: '#quiz-container',
  quizId: 'coffee-quiz',
  apiKey: 'key_n4SkMH5PFWLdStQZ',
  includeCSS: true, // Include the default CSS styles. Defaults to true.
  resultCardOptions: {
    resultCardRegularPriceKey: 'price',
  },
  questionsPageOptions: {
    skipQuestionButtonText: 'Skip',
  },
  // ... additional arguments
});

Custom Styling

Library defaults

By default, importing React components from this library does not pull any css into your project.

If you wish to use some starter styles from this library, add an import statement similar to the example import statement below:

import '@constructor-io/constructorio-ui-quizzes/styles.css';
  • These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
  • To opt out of all default styling, do not import the styles.css stylesheet.
  • All starter styles in this library are scoped within the .cio-quiz css selector.
  • These starter styles are intended to be extended by layering in your own css rules
  • If you import the starter styles, CioQuiz component will take up the full width and height of its parent container

Please note the starter styles utilize @container queries and enable responsive styles for our quizzes based on the size of their container element. Since this feature is supported by modern browsers, polyfills have not been included in this library. However, if you want to support older browsers, you can add fallback styles or use a polyfill.

Troubleshooting

Known Issues

Older Javascript environments

The library provides two different builds. CommonJS (cjs) and ECMAScript Modules (mjs)

For ECMAScript Modules (mjs) build. The Javascript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.

Module parse failed: Unexpected token (15:32) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file

To solve this you can import the CommonJS (cjs) build which supports ES6 (ES2015) syntax:

import CioQuiz from '@constructor-io/constructorio-ui-quizzes/cjs'

ESLint

There is a known issue with ESLint where it fails to resolve the paths exposed in the exports statement of NPM packages. If you are receiving the following error, you can safely disable ESLint using // eslint-disable-line for that line.

Unable to resolve path to module '@constructor-io/constructorio-ui-quizzes/styles.css'

Relevant open issues:

Issue 1868

Issue 1810

Local Development

Development scripts

npm ci                  # install dependencies for local dev
npm run dev             # start a local dev server for Storybook
npm run lint            # run linter

Publishing new versions

Dispatch the Publish workflow in GitHub Actions. You're required to provide two arguments:

  • Version Strategy: major, minor, or patch.
  • Title: A title for the release.

This workflow will automatically:

  1. Bump the library version using the provided strategy.
  2. Create a new git tag.
  3. Create a new GitHub release.
  4. Compile the library.
  5. Publish the new version to NPM.
  6. Deploy the Storybook docs to GitHub Pages.
  7. Report the progress on the relevant Slack channel.

ℹ️ Note: Please don't manually increase the package.json version or create new git tags.

The library version is tracked by releases and git tags. We intentionally keep the package.json version at 0.0.0 to avoid pushing changes to the main branch. This solves many security concerns by avoiding the need for branch-protection rule exceptions.

New Storybook Version

Dispatch the Deploy Storybook workflow in GitHub Actions.

ℹ️ Note: This is already done automatically when publishing a new version.

Supporting Docs

Demoing quizzes in a sandbox environment

Please fork from the following code sandboxes to experiment with the quizzes UI library integrated in various approaches.

版本与发布记录

@constructor-io/constructorio-ui-quizzes 共发布 120 个版本,首次发布于 2023/04/19;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.21.1latest2026/09/032 个月前
1.21.02026/06/264 个月前
1.20.12026/06/025 个月前
1.19.142026/03/307 个月前
1.19.132026/03/177 个月前
1.19.122026/03/118 个月前

关于 @constructor-io/constructorio-ui-quizzes 的常见问题

@constructor-io/constructorio-ui-quizzes 是什么?

Constructor.io Quizzes UI library for web applications

如何安装 @constructor-io/constructorio-ui-quizzes?

在项目目录运行 npm install @constructor-io/constructorio-ui-quizzes,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.12.0)、tslib(^2.4.0)、react-dom(>=16.12.0)、@constructor-io/constructorio-client-javascript(^2.86.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@constructor-io/constructorio-ui-quizzes 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@constructor-io/constructorio-ui-quizzes 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@constructor-io/constructorio-ui-quizzes 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@constructor-io/constructorio-ui-quizzes 可以商用吗?

@constructor-io/constructorio-ui-quizzes 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@constructor-io/constructorio-ui-quizzes 的下载量有多少?

根据 npm 官方下载统计,@constructor-io/constructorio-ui-quizzes 在 2026/10/11 – 2026/11/09 这 30 天内被下载 5,087 次,日均约 170 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@constructor-io/constructorio-ui-quizzes 还在维护吗?

最新版本 1.21.1 发布于 2026/09/03(2 个月前);至今共发布 120 个版本,其中过去 12 个月发布了 14 个;首次发布于 2023/04/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。