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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cpepin/haunted-forms

v0.0.1

Published

A lightweight form library for haunted-js

Downloads

3

Readme

haunted-forms 👻

A lightweight form library for haunted-js

Installation

npm install @cpepin/haunted-forms

Examples below show components build with haunted and lit-html for templating.

IE11

This library requires the polyfills outlined in here, as well as a CustomEvent polyfill which you can find here.

Getting Started

In order to use the components exposed in this library, you will first need to register them using the register function.

// your entry point
import { register } from '@cpepin/haunted-forms';

/*
 * 'defines' the custom elements in the DOM
 */
register();

Components

hf-form

hf-form creates a FormContext, which child form elements using usField will register with.

Usage

<hf-form>
  <!-- Form Elements -->
</hf-form>

Attributes

  • dont-prevent-default: (boolean) will trigger typical form submission behavior (refresh page)
  • on-submit: ((values) => void) function invoked with the values from the form
  • on-value-change: ((values) => void) function invoked with the form values, when a value has changed
  • api-ref: ({ current: any }) accepts a ref provided by useRef, gives access to form api

Form API

  • setValue: ((field, value) => void) updates a given form value
  • getValue: ((field) => value) retrieves a form value
  • getError: ((field) => error) retrieves a form error
  • setError: ((field, error) => void) updates a given field's form error
  • validate: (() => void) manually triggers form validation
  • getState: (() => formState) retrieves the current state of the form

Form State

{
  hasError: boolean,
  fields: [
    {
      [field]: { value, error },
    },
  ],
}

useField

Hook for creating form fields.

Usage

import { useField } from '@cpepin/haunted-forms';

const MyTextInput = ({
  field,
  initialValue = '',
  validate,
  validateOnBlur,
  validateOnChange,
  validateOnRender,
}) => {
  const { error, handleBlur, handleChange, render } = useField({
    field,
    initialValue,
    validate,
    validateOnBlur,
    validateOnChange,
    validateOnRender,
  });

  return render(html`
    <input
      id="my-input"
      type="text"
      value=${initialValue}
      @input=${handleChange}
      @blur=${handleBlur}
    ></input>
    <div>${error}</div>
  `);
};

Params

  • field: (string, required) name of the field (must be unique)
  • initialValue: (any, default="") initial value of the field
  • onValueChange: ((value) => void, default=() => {}) invoked when value has changed
  • validate: ((value) => undefined | string, default=() => undefined) validation function to be run against the input. Returns undefined if no error exists.
  • validateOnBlur: (boolean, default=false) run field validation on blur
  • validateOnChange: (boolean, default=false) run field validation on change
  • validateOnRender: (boolean, default=false) run field validation on render

useSubmitDispatcher

Hook used to dispatch a customer submit event from a form button. This is necessary, as normal submit events can not bubble up outside of the shadowRoot.

Usage

import { useSubmitDispatcher } from '@cpepin/haunted-forms';

const MySubmitButton = () => {
  const { dispatch } = useSubmitDispatcher();

  const handleClick = e => dispatch(e);

  return html`
    <button @click=${handleClick}>Submit</button>
  `;
};