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

swift-select

v1.1.3

Published

A customizable select component for modern web applications.

Downloads

18

Readme

SwiftSelect

SwiftSelect is a customizable plugin to enhance select elements with support for multi-selection, searching, custom events, and keyboard navigation.

Installation

Install via npm:

npm install swift-select

Usage

Initialization

To initialize SwiftSelect, pass in the wrapper element, options array, and (optionally) settings and events.

import SwiftSelect from 'swift-select';

const options = [
  { label: 'Option 1', value: 'option1' },
  { label: 'Option 2', value: 'option2' },
  { label: 'Option 3', value: 'option3' }
];

const settings = {
  multiple: true,             // Enables multi-selection
  searchable: true,           // Adds a search input field
  placeholder: 'Select...',   // Placeholder text
};

const events = {
  onSelectChange: (value) => {
    console.log('Selected value:', value);
  }
};

// Initialization
const selectWrapper = document.querySelector('#select-wrapper');
const swiftSelect = new SwiftSelect(selectWrapper, options, settings, events);

HTML Structure

Ensure the element you want to transform into a select has a wrapper:

<div id="select-wrapper"></div>

Options

SwiftSelect supports the following settings:

| Option | Type | Description | Default | |--------------------------|---------|---------------------------------------------------------------------------------------------------------|-------------------| | multiple | Boolean | If set to true, allows selecting multiple options. If set to false, only a single option can be selected. | false | | searchable | Boolean | If set to true, adds a search input field in the dropdown, allowing users to filter options by typing. | false | | placeholder | String | Placeholder text displayed when no option is selected. This provides guidance for the user on what to do. | 'Select an option' | | withDefaultOption | Boolean | If set to true, displays a default option when the dropdown is opened. Useful for prompting user action. | false | | selectVisibleOptions | Number | Determines how many options are visible in the dropdown at a time. This helps manage space and usability. | 7 | | searchPlaceholder | String | Placeholder text for the search input field. This informs users what they can enter in the search box. | 'Search...' | | searchNotFoundText | String | Text displayed when no options match the search query. This provides feedback to users when their search yields no results. | 'Not found' | | searchDefaultOption | String | A specific option value that should always be visible in the dropdown, even if it doesn't match the search query. | null | | disabled | Boolean | If set to true, disables the select component, preventing user interaction. Useful for managing form states. | false |

Events

You can hook into different events by passing an events object during initialization. For example:

  • onSelectChange: Triggered when an option is selected or deselected.
const events = {
  onSelectChange: (value) => {
    console.log('Current selected value:', value);
  }
};

License

This project is licensed under the MIT License. See the LICENSE file for details.