npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@constructor-io/constructorio-ui-quizzes

v1.17.18

Published

Constructor.io Quizzes UI library for web applications

Downloads

1,342

Readme

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.