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

@felte/reporter-element

v0.4.11

Published

An error reporter for Felte using custom elements

Downloads

282

Readme

@felte/reporter-element

Tests Bundle size NPM Version codecov

A Felte reporter that uses a custom element to report errors.

WARNING: This package is under development, things might break on updates and documentation is almost non-existent besides this README.

Installation

# npm
npm i -S @felte/reporter-element

# yarn
yarn add @felte/reporter-element

Usage

The package exports a reporter function. Pass the reporter function to the extend option of createForm or useForm.

You can import side effects from @felte/reporter-element/felte-validation-message to define the <felte-validation-message> element globally. You can add this wherever you want your validation message for the specified field to be displayed. It accepts the following attributes:

  • for: (required) the name of the field you want to display the validation messages for.
  • max: (optional) the maximun amount of validation messages to display for the given field. Useful if you can get multiple validation messages but you only want to display a few at a time.
  • level: (optional) the kind of validation messages this element should display. Set it to warning to display warning messages. Default: error.
  • templateid or templateId: (optional) the id of the template element to be used for this element.

It expects a <template> element as its child (or assigned using templateid), which will be used as the template for your validation messages. This template will be cloned into the as a child of <felte-validation-message> and updated when validation messages change. The template must have an element with an attribute data-part="item". This element is the one that will contain the validation message, and it will be appended for each message. Optionally you can add an element with data-part="message" deeper within the item element if you want your message somewhere else.

An example of its usage:

<felte-validation-message for="email" max="2">
  <template>
    <ul aria-live="polite">
      <li data-part="item">
        <em data-part="message"></em>
      </li>
    </ul>
  </template>
</felte-validation-message>

When using templateid, this package expects the template to be either on the light DOM, or on the immediate parent's shadow root. If it's somewhere else, it will not find it.

<template id="message-template">
  <ul aria-live="polite">
    <li data-part="item">
      <em data-part="message"></em>
    </li>
  </ul>
</template>

<felte-validation-message
  for="email"
  templateid="message-template"
></felte-validation-message>

<felte-validation-message
  for="password"
  templateid="message-template"
></felte-validation-message>

A more complete example using @felte/element:

<script type="module">
  import '@felte/element/felte-form';
  import '@felte/reporter-element/felte-validation-message';
  import { reporter } from '@felte/reporter-element';

  const felteForm = document.querySelector('felte-form');
  felteForm.configuration = {
    // ...
    extend: reporter,
    // ...
  };
</script>

<felte-form>
  <form>
    <input id="email" type="text" name="email" />
    <!-- For the first element, we assume there will only be a single message at all times -->
    <felte-validation-message for="email" max="1">
      <template>
        <span data-part="message" />
      </template>
    </felte-validation-message>
    <input type="password" name="password" />
    <felte-validation-message for="password">
      <template>
        <ul aria-live="polite">
          <li data-part="item" />
        </ul>
      </template>
    </felte-validation-message>
    <input type="submit" value="Sign in" />
  </form>
</felte-form>

Warnings

This reporter can help you display your warning messages as well. If you want your felte-validation-message component to display the warnings for a field you'll need to set the level prop to the value warning. By default this prop has a value of error.

<felte-validation-message level="warning" for="email">
  <template>
    <ul aria-live="polite">
      <li data-part="item">
        <em data-part="message"></em>
      </li>
    </ul>
  </template>
</felte-validation-message>

Framework compatibility

This element should work nicely with any framework except React due to an issue on how React renders <template> elements (although anyway a specific package for React exists for this same purpose.