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

prototype-kit

v1.13.2

Published

A toolkit for rapid prototyping of govuk themed services in react.

Downloads

13

Readme

prototype-kit

A toolkit for rapid prototyping of govuk themed services in react.

Prerequisites

Using the toolkit requires at least version 8 of node. You can install it here.

Getting started

Create a folder for your prototype

Inside that folder, run the following command:

npx prototype-kit init

This will install all of the code you need to run the prototype kit.

You should now see you have a directory named pages in your folder.

Create a file inside that folder and name it index.jsx, then give it the following content:

import React from 'react';
import { Page } from 'prototype-kit';

class Index extends Page {

  content() {
    return <h1>Hello World!!</h1>
  }

}

export default Index;

Now run the following command to start your prototype:

npx prototype-kit run --watch

This will start your prototype running at http://localhost:3000. Open that page in a browser to see your prototype.

Any changes you make will be automatically compiled, so there's no need to do anything except refresh the page in the browser when you make changes.

Adding pages

To add a new page easily, you can run the following command:

npx prototype-kit page <page-name>

This will create a new page for you at http://localhost:3000/<page-name> by creating a template file in your pages directory. You can then edit the content of this file as you require.

Any .jsx files you create in your pages directory will be automatically served, with the file names mapped to urls. So if you create a new file my-page.jsx then it will be visible at http://localhost:3000/my-page.

Any content returns by the content method of your page component will be rendered into the page.

Pages are react components, and can include any other local or third party components as required.

Custom CSS

The prototype kit uses sass to compile css files. You can create sass files in your assets/css directory and they will be automatically compiled and included in pages as follows:

  • All pages will load assets/css/default.scss
  • Pages will also attempt to load page-specific css from assets/css/<page>.scss

You can also include all of the govuk frontend toolkit, and govuk elements by adding the following line to the top of your css files.

@import "prototype-kit";

Static assets

Any files in your assets directory will be available to be served as static files.

Forms

You can create form pages by creating a page that extends the Form base component as follows:

import React from 'react';
import { Form } from 'prototype-kit';

class FormPage extends Form {

  pageTitle() {
    return 'Form Page';
  }

  button() {
    return 'Submit form';
  }

  fields() {
    return [
      { label: 'A text field' },
      { label: 'Another text field' }
    ];
  }

}

export default FormPage;

Data

You can load mock data into your prototypes by adding CSV or JSON files to a data directory in your prototype.

This data will then be parsed and exposed into your prototype as a data prop, with sub-objects corresponding to the file names.

For example, if you add data/user.json to your project with the following content:

{
  "name": "Joe Bloggs",
  "dob": "1990-01-01"
}

Then you can use the data in your page as follows:

import React from 'react';
import { Page } from 'prototype-kit';

class Index extends Page {

  content() {
    const user = this.props.data.user;
    return <h1>User { user.name } was born on { user.dob }.</h1>
  }

}

export default Index;

Components

Documentation for built-in components

Roadmap

  • [ ] Add some persistent state so that form inputs can be re-used later on
  • [ ] Convert some of the built-in components from the original prototyping kit
  • [ ] More components
  • [ ] Add option to easily put prototype behind basic auth