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

@zachleat/filter-container

v4.0.0

Published

Filtering visible child elements based on form field values.

Downloads

147

Readme

Filter Container

A themeless zero-dependency web component to filter visible child elements based on form field values.

Installation

npm install @zachleat/filter-container

Please see the demo for sample code. Use:

  • <filter-container>
    • <select data-filter-key="KEY_NAME"> for the form element and <option value="CATEGORY_VALUE"> for categories.
    • (New in v3) <input value="CATEGORY_VALUE" data-filter-key="KEY_NAME"> (try text, radio, checkbox, etc)
  • Add a data-filter-KEY_NAME="CATEGORY_VALUE" attribute to any child element of <filter-container> to assign both a filter key and category to match on.

Optional Features

  • You can add the CSS for each KEY_NAME yourself if you’re server rendering (or not happy with the browser support of replaceSync). Prepopulate the server-rendered content on each individual item using this too if you’d like (maybe your page has a server-rendered filter applied).
.filter-KEY_NAME--hide {
  display: none;
}
  • This component will not filter on initialization unless you use <filter-container oninit>. By default the form field needs to change for filtering to take place.
  • Add the data-filter-results attribute to any child element of the component if you’d like us to populate it with the number of results.
    • Add a string to this attribute value to customize your Results labels (delimited by /). e.g. data-filter-results="Country/Countries"
    • Add aria-live="polite" to this element and screen readers will announce when the text changes.
  • Use <filter-container delimiter=","> if your content elements may have more than one filter value assigned (in this example delimited by a comma).
    • For example, Egypt is in both Africa and Asia: <li data-filter-continent="africa,asia">Egypt</li>

Changelog

v3.0.4

  • Add support for filter-mode="all" on <filter-container> to enable AND-ing filters for all multi-select form elements (checkboxes). Use filter-mode-KEY_NAME="any" to override back to the default.

v3.0.3

  • Add support for AND-ing filters across multiple checkboxes. Previously only OR operations were supported.
    • Use filter-mode-KEY_NAME="all" on <filter-container> to enable.

v3.0.0

  • Added support for radio and checkbox inputs for filtering.
  • Renamed attributes:
    • data-oninit renamed to oninit
    • data-filter-delimiter renamed to delimiter (only supported on <filter-container>)
    • data-filter-skip-url renamed to leave-url-alone (only supported on <filter-container>)

Credits