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

dha-cpg-reader

v1.4.1

Published

A component to render JSON serialized flowcharts in an interactive way.

Downloads

6

Readme

dha-cpg-reader

A component to render JSON serialized flowcharts in an interactive way.

Getting Started

Install

Install from npm:

  • npm i dha-cpg-reader

If you plan on using this module in the pwa-starter, make sure to edit the starter's 'tailwind.config.cjs' file with the following code (to tell tailwind to scan dha-cpg-reader for tailwind classes):

module.exports = {
  content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}', './node_modules/dha-cpg-reader/**/*.js'],
};

Usage

To use the CPG reader, import the component and pass in the JSON serialized flowchart.

import React from 'react';
import { CPGReader } from 'dha-cpg-reader';

import sampleCPG from './sampleCpg.json';

const Home = () => {
  return <CPGReader cpg={sampleCPG} />;
};

export default Home;

Type Definitions

Props


The CPG reader accepts the following props:

export interface ICPGReaderProps {
  cpg: CPG;
  spacer?: string;.
  customStyles?: ICPGReaderStyleProps;
}

The spacer prop is used in the multi list to divide each line of text. The default value is -- OR --.

The customStyles prop is used to pass in custom styles to the CPG reader. The type definition for the customStyles prop is as follows:

export interface ICPGReaderStyleProps {
  container?: ClassNameValue;
  nextButton?: ClassNameValue;
  backButton?: ClassNameValue;
}

where ClassNameValue is defined as:

type ClassNameValue = ClassNameArray | string | null | undefined | 0 | false;

see https://github.com/dcastil/tailwind-merge for more information on how we handle passing in custom styles.

CPG Interface


The CPG reader accepts a JSON serialized flowchart as a prop in the form of a CPG interface. The type definition for the flowchart is as follows:

export interface CPG {
  id: number;
  name: string;
  root: string;
  nodes: { [key: string]: Node };
  edges: Edge[];
}

As long as your JSON conforms to the CPG interface this module will have no problem rendering it.

Nodes and Edges


This Module is designed for JSON files to be structured in a graph like manner, with nodes and edges. The nodes and edges are defined as follows:

export interface Edge {
  source: string;
  target: string;
  label: string;
}

export interface Node {
  type: string;
  text: string;
  supplemental: string[];
}

The role of a node is to hold information about a specific step in the flowchart. The role of an edge is to connect two nodes together. The source and target of an edge are the ids of the nodes that the edge connects. The label of an edge is the text that is displayed on the edge, in the case of this module they are used to render buttons for navigation between each node.

There are currently four types of nodes that should be passed into type. These are:

  • info: The Info node displays a string of text as well as multiple supplemental text
  • list: The list node is used to display an ordered list of text
  • multi: The Multi node that is used to display multiple lines of text in a single node, each supplemental text is then divided by an -- OR -- line, or the value passed into the spacer prop
  • question: A question node that is used to display singular text

NPM

https://www.npmjs.com/package/dha-cpg-reader