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

htmx-ext-loading-states

v2.0.0

Published

This extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Downloads

3,932

Readme

This extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Install

<script src="https://unpkg.com/[email protected]/loading-states.js"></script>

Usage

Add the hx-ext="loading-states" attribute to the body tag or to any parent element containing your htmx attributes.

Add the following class to your stylesheet to make sure elements are hidden by default:

[data-loading] {
  display: none;
}

Supported attributes

  • data-loading

    Shows the element. The default style is inline-block, but it's possible to use any display style by specifying it in the attribute value.

    <div data-loading>loading</div>
    
    <div data-loading="block">loading</div>
    
    <div data-loading="flex">loading</div>
  • data-loading-class

    Adds, then removes, CSS classes to the element:

    <div class="transition-all ease-in-out duration-600" data-loading-class="bg-gray-100 opacity-80">
    ...
    </div>
  • data-loading-class-remove

    Removes, then adds back, CSS classes from the element.

    <div class="p-8 bg-gray-100 transition-all ease-in-out duration-600" data-loading-class-remove="bg-gray-100">
    ...
    </div>
  • data-loading-disable

    Disables an element for the duration of the request.

    <button data-loading-disable>Submit</button>
  • data-loading-aria-busy

    Add aria-busy="true" attribute to the element for the duration of the request

    <button data-loading-aria-busy>Submit</button>
  • data-loading-delay

    Some actions may update quickly and showing a loading state in these cases may be more of a distraction. This attribute ensures that the loading state changes are applied only after 200ms if the request is not finished. The default delay can be modified through the attribute value and expressed in milliseconds:

    <button type="submit" data-loading-disable data-loading-delay="1000">Submit</button>

    You can place the data-loading-delay attribute directly on the element you want to disable, or in any parent element.

  • data-loading-target

    Allows setting a different target to apply the loading states. The attribute value can be any valid CSS selector. The example below disables the submit button and shows the loading state when the form is submitted.

    <form hx-post="/save"
      data-loading-target="#loading"
      data-loading-class-remove="hidden">
    
      <button type="submit" data-loading-disable>Submit</button>
    
    </form>
    
    <div id="loading" class="hidden">Loading ...</div>
  • data-loading-path

    Allows filtering the processing of loading states only for specific requests based on the request path.

    <form hx-post="/save">
      <button type="submit" data-loading-disable data-loading-path="/save">Submit</button>
    </form>

    You can place the data-loading-path attribute directly on the loading state element, or in any parent element.

    <form hx-post="/save" data-loading-path="/save">
      <button type="submit" data-loading-disable>Submit</button>
    </form>
  • data-loading-states

    This attribute is optional and it allows defining a scope for the loading states so only elements within that scope are processed.

    <div data-loading-states>
      <div hx-get=""></div>
      <div data-loading>loading</div>
    </div>
    
    <div data-loading-states>
      <div hx-get=""></div>
      <div data-loading>loading</div>
    </div>
    
    <form data-loading-states hx-post="">
      <div data-loading>loading</div>
    </form>