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

@swup/forms-plugin

v3.5.1

Published

A swup plugin for submitting forms

Downloads

7,414

Readme

Swup Forms Plugin

A swup plugin for submitting forms.

  • Serialize and submit forms with animated page transitions
  • Opt-in with a configurable selector, by default form[data-swup-form]
  • Respects custom animations set on the form element

Note: This plugin is meant for simple scenarios like search or contact forms. For complex requirements like custom serialization, it is recommended to use the swup API directly.

Installation

Install the plugin from npm and import it into your bundle.

npm install @swup/forms-plugin
import SwupFormsPlugin from '@swup/forms-plugin';

Or include the minified production file from a CDN:

<script src="https://unpkg.com/@swup/forms-plugin@3"></script>

Usage

To run this plugin, include an instance in the swup options.

const swup = new Swup({
  plugins: [new SwupFormsPlugin()]
});

Server response

Action, method and encoding type attributes set on the form are respected.

The server response must be a valid page with all containers to be replaced by swup.

Custom animations

The plugin respects custom animations set on the form using the data-swup-animation attribute:

<!-- Animate with an 'overlay' custom animation -->
<form action="/" data-swup-form data-swup-animation="overlay">

Inline Forms

If you give a form an additional attribute [data-swup-inline-form], swup will:

  • update only that form when being submitted, ignoring the default containers.
  • scroll back to the beginning of the form
  • scope animations to the form itself

Note If you mark a form as an inline form, the form must have an id attribute

Example

HTML

<form id="form-1" class="transition-form" data-swup-form data-swup-inline-form method="POST">
  <input name="test"></input> <input type="submit"></input>
</form>

CSS

.transition-form.is-changing {
  transition: opacity 200ms;
}
.transition-form.is-animating {
  opacity: 0;
}

Options

formSelector

Type: String, Default: form[data-swup-form]

Customize the selector for forms which should be handled by swup.

inlineFormSelector

Type: String, Default: form[data-swup-inline-form]

Customize the selector for inline forms

stripEmptyParams

Type: Boolean, Default: false

Strip empty parameters from forms with action="GET" before submitting.

  • Before: ?foo=&bar=baz&bat=
  • After: ?bar=baz

Hooks

The plugin adds two new hooks to swup.

form:submit

Triggered when a form is submitted.

swup.hooks.on('form:submit', (visit, { el, event }) => {
  console.log(el);
});

form:submit:newtab

Triggered when a form is submitted to a new tab or window. This will happen if the user has pressed either the Command (Mac), Control (Windows) or Shift key while submitting the form. The plugin normalizes that behavior across browsers.