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

vue-virtual-selector

v1.1.1

Published

Blazing fast scrolling for any amount of data (based on : Akryum/vue-virtual-scroller)

Downloads

235

Readme

vue-virtual-selector

npm npm vue2

⚡️ Blazing fast scrolling for any amount of data (based on : Akryum/vue-virtual-scroller)

normal

Demo : Select PK

Installation

npm install --save vue-virtual-selector

Import

Install the component :

import Vue from "vue";
import VueVirtualSelector from "vue-virtual-selector";

Vue.use(VueVirtualSelector);

Usage

Basic usage

<VirtualSelector
  :list="list"
  :option="listOption">
</VirtualSelector>

or

<virtual-selector
  :list="list"
  :option="listOption">
</virtual-selector>

The list and option props are required.

Using all props, events and slots as follows.

<virtual-selector
  :loading="loading"
  label="virtual selector"
  placeholder="please select"
  v-model="selected"
  :list="list"
  :option="listOption"
  @focus="handleFocus"
  @search="handleSearch"
  @select="handleSelect">
  <div slot="loading">loading...</div>
  <div slot="item" slot-scope="{ item }">
    {{ item.name }}
  </div>
</virtual-selector>
. . .
<script>
export default {
  data() {
    return {
      loading: false,
      selected: {},
      list: [],
      listOption: {
        itemNameKey: "name",
        itemValueKey: "value",
        itemPageSize: 8,
        itemGap: 5,
      },
    };
  },
  methods: {
    handleFocus( { id, focus } ) {
      console.log("focus : ", { id, focus });
    },
    handleSearch( { id, search } ) {
      this.selected = search;
      console.log("search : ", { id, search });
    },
    handleSelect( { id, select } ) {
      this.selected = select;
      console.log("select : ", { id, select });
    },
  },
}
</script>

"list" data example :

[
  {
    name: "aaa",
    value: "1",
  },
  {
    name: "bbb",
    value: "2",
  },
  {
    name: "ccc",
    value: "3",
  },
];

In this example, "itemNameKey" of "listOption" is "name", "itemValueKey" of "listOption" is "value", which are specifing dropdown item display and value.

If you want to select a value by default, selected data should be assigned like below

this.selected = { name: "aaa", value: "1" };

Props

  • v-model (Object) : vue directive, to create two-way data bindings.
  • list (Array) : list of items display in the selector dropdown.
  • label (String) : when you want to show what the selector is, give this option.
  • placeholder (String) : input element's placeholder.
  • loading (Boolean) : this option works with slot.
  • option (Object) : this option use with list prop, and contain some properties.
    • itemNameKey (String) : specify selector dropdown item display.
    • itemValueKey (String) : specify selector dropdown item value.
    • itemPageSize (Number) : specify how many items display in the dropdown box (default is 8).
    • itemGap (Number) : specify interval between the items (default is 0).

Events

  • focus : emitted when the input focused.
  • search : emitted when the input changed.
  • select : emitted when the dropdown item is selected.

Every event callback function will get a emitted data, which is object type, contain component id and event data named with event name.

Slots

You can set loading like below

<virtual-selector>
  <div slot="loading">loading...</div>
</virtual-selector>

The display effect is as follows :

loading

Usually, we need to customize the selector dropdown item. for this purpose, there is item slot to use.

<virtual-selector>
  <div slot="item" slot-scope="{ item }">
    {{ item.name }} ({{ item.value }})
  </div>
</virtual-selector>

In this case, if you want to select a value by default, and display with the customize pattern, please complete this job at selected name (itemNameKey) property.

For example, customized selector dropdown item like this "aaa (1)", "bbb (2)", "ccc (3)" (under the above list data example). the default setted value display should be like this.

this.selected = { name: "aaa (1)", value: "1" };