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

@michael-brauner/choosy

v1.1.1

Published

A lightweight choice-picker written in vanilla javascript.

Downloads

3

Readme

Choosy

Choosy

A lightweight vanilla-js choice-picker written in typescript.

Setup

npm i @michael-brauner/choosy
yarn add @michael-brauner/choosy
import Choosy from "@michael-brauner/choosy";

new Choosy(document.getElementById("cars"));
<!-- import this inside of the `head` of your html document -->
<link rel="stylesheet" href="/dist/choosy.min.css">

<select name="cars" id="cars" multiple>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
</select>

Be aware that Choosy automatically restricts the input limit to 1 as soon as the multiple attribute is not set onto the select element.

Options

Your choosy widget can be configured with some options.
Just pass your options object as second argument into the Choosy constructor.

After the widget got initialized the full Choosy object got stored inside a __x variable. This way you can access all public methods even after initialisation.

enabled

Enable or disable your Choosy.

This causes that no input is possible anymore, the widget is locked at the current state and can't be focused anymore. A greyed-out effect visualizes this behavior and the cursor shows not-allowed.

new Choosy(document.getElementById("cars_disabled"), {
    enabled: false
});

It is possible to enable / disable the whole widget after initialisation:

// enable the widget
getElementById("cars_disabled").__x.enable()

// disable the widget again
getElementById("cars_disabled").__x.disable()

limit

Limits the items you can select with your Choosy widget.

new Choosy(document.getElementById("cars_limited_2"), {
    limit: 2
})

Contributing

Since Choosy is an open-source project you are very welcome to contribute by sending a PR.

Compiling

To apply the latest changes and compile it to a ready-to-go package into the dist folder you can use the following commands:

postcss ./src/style/choosy.css -o ./dist/choosy.min.css
rollup -c 

Testing

Choosy uses Cypress for testing.
So you are able to start the testsuite with this command:

yarn tests 

If you want to use the cypress client to debug your tests in a real browser, you have to start the http-server first then you can open the cypress-suite:

yarn http-server -c-1 &
yarn cypress open

Actually you can use the test script for testing:

sh test

Don't forget to stop the server after you are done:

CTRL + c # to stop the cypress suite
fg # to bring the http-server in the foreground
CTRL + c # stop the http-server