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 🙏

© 2025 – Pkg Stats / Ryan Hefner

survey-tool-lib

v0.1.7

Published

A powerful, flexible, and designer-friendly React survey library. Create beautiful surveys with a drag-and-drop builder, run them in your app, and export results with ease.

Readme

Survey Tool Library

A powerful, flexible, and designer-friendly React survey library. Create beautiful surveys with a drag-and-drop builder, run them in your app, and export results with ease.

Features

🎨 Survey Creator

  • Drag-and-Drop Interface: Easily add and arrange questions.
  • Inline Editing: Click and type to edit titles and choices directly on the canvas.
  • Logic Builder: Visual interface to set up "Visible If" conditional logic (e.g., show a question only if the previous answer was "Yes").
  • Property Panel: Fine-tune question settings, names, and required flags.
  • JSON Preview & Simulation: View the underlying JSON or test the survey in a built-in simulator.
  • Real-time Updates: Sync survey state with your app using onJsonChange.

📝 Survey Runner

  • Responsive Rendering: Automatically renders the survey based on the JSON model.
  • Pagination: Supports multi-page surveys with "Next" and "Previous" navigation.
  • Validation: Built-in required field validation.
  • Conditional Visibility: Automatically evaluates logic rules to show/hide questions.
  • Theming: Customizable brand color to match your application's design.

🛠 Supported Question Types

  • Text: Single line input.
  • Comment: Multi-line text area.
  • Radiogroup: Single choice selection.
  • Checkbox: Multiple choice selection.
  • Dropdown: Select from a list.
  • Boolean: Yes/No radio buttons.

Installation

npm install survey-tool-lib
# or
pnpm add survey-tool-lib
# or
yarn add survey-tool-lib

Usage Guide

1. Survey Creator (Builder)

Use the SurveyCreator component to let users build or edit surveys.

import { useState } from "react";
import { SurveyCreator } from "survey-tool-lib";
import "survey-tool-lib/style.css"; // Don't forget to import styles!

function CreatorPage() {
  const [surveyJson, setSurveyJson] = useState({
    title: "My New Survey",
    pages: [{ name: "page1", elements: [] }],
  });

  return (
    <div style={{ height: "100vh", width: "100%" }}>
      <SurveyCreator
        json={surveyJson}
        onSave={(finalJson) => console.log("Saved!", finalJson)}
        onJsonChange={(newJson) => setSurveyJson(newJson)} // Keep local state in sync
        brandColor="#007bff" // Customize the primary color
      />
    </div>
  );
}

2. Survey Runner (Renderer)

Use the Survey component and Model class to display and run the survey for end-users.

import { Survey, Model } from "survey-tool-lib";
import "survey-tool-lib/style.css";

const surveyJson = {
  title: "Customer Feedback",
  pages: [
    {
      name: "page1",
      elements: [
        {
          type: "text",
          name: "name",
          title: "What is your name?",
          isRequired: true,
        },
      ],
    },
  ],
};

function SurveyPage() {
  // 1. Create a Model instance
  const model = new Model(surveyJson);

  // 2. Define completion handler
  const handleComplete = (sender) => {
    // 'sender' is the Model instance
    const results = sender.data;
    console.log("Survey Results:", results);

    // You can also access the full JSON if needed
    // console.log("Survey Definition:", sender.json);
  };

  return (
    <div className="my-survey-container">
      <Survey model={model} onComplete={handleComplete} brandColor="#007bff" />
    </div>
  );
}

3. PDF Export

You can export survey definitions or results to PDF.

import { generateSurveyPDF } from "survey-tool-lib";

// ... inside your component
const handleExport = () => {
  // Pass the model (which contains both JSON and data) and a filename
  generateSurveyPDF(model, "survey-results.pdf");
};

Props & API

SurveyCreator Props

| Prop | Type | Description | | -------------- | ---------- | ---------------------------------------------------------------------- | | json | object | The initial survey JSON object. | | onSave | function | Callback triggered when the "Save" button (if implemented) is clicked. | | onJsonChange | function | Callback triggered whenever the survey structure changes. | | brandColor | string | Hex color code for buttons and highlights. |

Survey Props

| Prop | Type | Description | | ------------ | ---------- | ---------------------------------------------------------------------------------------------- | | model | Model | The survey model instance created with new Model(json). | | onComplete | function | Callback triggered when the survey is completed. Receives the model instance as an argument. | | brandColor | string | Hex color code for the "Complete" button and other accents. |

Model Class

  • constructor(json): Initializes the model.
  • data: Getter for the current survey response data.
  • setValue(name, value): Programmatically set a question value.
  • getValue(name): Get a question value.
  • validate(): Triggers validation for visible questions.

License

MIT