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

vue3-search-select

v1.0.10

Published

A lightweight and versatile Vue search and select package allowing for efficient searching, selection, and modification of items

Downloads

42

Readme

Vue 3 Search Select Component

A light-weight, flexible and easy-to-use Vue 3 Search and Select component that allows users to search and select options from a dynamic or static list.

Installation

Install the package via npm:

npm i vue3-search-select

Demo

Check out the live demonstration to see the package in action.

QUICK PREVIEW

Search Select

Search Select

Dynamic Multi Select

Dynamic Multi Select

Components in this package

  • Search Select
  • Dynamic Multi Select

Search Select

✨ Key Features 🗂 Custom Display Order Arrange options in any order, helping users easily find frequently selected or high-priority items.

🔢 Conditional Count Display Display options dynamically based on specific conditions, so users see only relevant choices.

🔍 Search Functionality Integrated search allows users to quickly filter options by typing, ideal for large lists.

🔑 Primary Key Tracking Each option is linked to a unique identifier (primary key), ensuring accurate selection and tracking of values.

⭐ Default Value Selection Pre-select default values to highlight the most relevant choice, improving the initial user experience.

Search Select Usage

import { SearchSelect } from 'vue3-search-select'
import "vue3-search-select/Vue-Search-Select.css";
 <SearchSelect
    :data="pseudoEmployeeData"
    placeholderName="Employee" // optional
    displayKey="firstName lastName - employeeId"
    :selectMax="2" // optional
    v-model="employee"
    primaryKey="employeeId"
    :defaultValue="['emp-0001']" // optional
  />

Dynamic Multi Select

The DynamicMultiSelect component is packed with advanced functionality, allowing users to select multiple options from a dynamic list with ease and flexibility.

🚀 Key Features 🎛️ Slot Manipulation Customize component slots to control how each item selected will be displayed, allowing for unique visual arrangements.

🗂️ Custom Display Order Easily reorder options to prioritize frequently selected or high-importance items at the top of the list.

🔑 Primary Key Tracking Each item is uniquely identified by a primary key, ensuring consistent data handling and accurate selections.

🔢 Conditional Count Display Apply conditions to dynamically control the visibility of options based on specific counts, improving list relevance.

🔍 Multi-Select Search Built-in search functionality enables users to filter multiple selections, making large lists more manageable.

🖼️ Image Prefix for Options Add an image prefix to each list option, creating a visually rich experience and making options more recognizable.

⭐ Default Value Selection Set default values to highlight recommended or commonly selected options, enhancing the user experience from the start.

🚫 Auto-Close on Maximum Selection Automatically close the dropdown when the maximum number of selections is reached, ensuring users know their selection limit.

import { DynamicMultiSelect } from 'vue3-search-select'
import "vue3-search-select/Vue-Search-Select.css";
  <DynamicMultiSelect
    v-model="anotherEmploye"
    :data="pseudoEmployeeData"
    display-key="firstName lastName - employeeId"
    primary-key="employeeId"
    imgPrefix="src" // (optional) to add prefix to the list for each item, src is the key in the object of each array
    :select-max="3" // optional
    :defaultValue="['APN999000', 'APN0001']" // optional
    :closeAfterMax="true" // optional
  >
    <template #listClassPrefix="{ item }"> // optional slot manipulation to add prefix to each item in a list
      <div :class="item.tag === 'tech' ? 'red-circle' : 'blue-circle'"></div>
    </template>
    <template #dynamicAction="{ item }">
      {{ fullNameList(item) }}
    </template>
  </DynamicMultiSelect>

  const fullNameList = (item: Person[]) => { // show fullname after the picked
    let allItems = item?.map((obj) => `${obj.firstName} ${obj.lastName}`).join(', ')
    return allItems
  }

Explanations of All Props

  • data: This is where you pass your data to, it houses/consumes your data.

  • placeholderName: This is what is attached to the count of the things you will pick in the input box e.g 2 Employee Selected. Take note of the "Employee that was passed to the component". You can change it to whatever you want. This is optional prop. If you exclude the placeholderName prop, once you pick items what will show in the input will be e.g "1 item selected"

  • displayKey: This is what will be displayed from the data you are passing. You can decide to add a separator. From the example component you can decide to use

firstName lastName // coming from the api/json you are consuing

OR

firstName lastName | employeeId // coming from the api/json you are consuing
  • selectMax: This is an optional prop, if you want to pick from the list inifintely, you can take off the selectMax prop from the component. But if you have need to cap the number of items to be picked from the list then add the selectMax prop. Once it is met, all other items will be disabled.

  • v-model: of course we know what v-model is.

  • primaryKey: Primary key is an essential part of this component, because it tells the component to keep track of a particular key in the array that is being passed to it and this is what v-model will be keep track of. If your primary key is employeeId, as you keeping picking from the list, it will keep adding employeeId to v-model as an array e.g [00000, 22222, 44444].

  • defaultValue: This is an optional prop. This is the prop you will use if you need to pass default value that matches the primaryKey. E.g in an edit page, you will certainly be passing default value.

  • imgPrefix: This is an optional prop for Dynamic Multi Select. All that is needed is to reference key in the object from the data you are sending to the dynamic multiselect. The key can be src, image, link etc. What is important is that, it must be an image.

  • slots: Only two slots are available for Dyamic Multi Select and they are:

  1. List Prefix: You can add a prefix to the list being displayed in the drop down, e.g you want to add a blue circle/banner to the prefix of each item if their tag is tech and blue circle for others. NOTE: To use this slot, make sure the imgPrefix is taken off the component because it will take precedence over this list class prefix prop.

EXAMPLE

  <template #listClassPrefix="{ item }">
    <div :class="item.tag === 'tech' ? 'red-circle' : 'blue-circle'"></div>
  </template>
  1. Dynamic Action: This is the slot you can use to manipulate the display of the items you have picked. By using this slot you can add only images to slot, show the name of items piacked, add banners etc. All you need to do make use of the item that passed down to the slot template.

EXAMPLE

  <template #dynamicAction="{ item }">
    {{ fullNameList(item) }}
  </template>

  const fullNameList = (item: Person[]) => { // show fullname after the picked
    let allItems = item?.map((obj) => `${obj.firstName} ${obj.lastName}`).join(', ')
    return allItems
  }
  • closeAfterMax: If you added selectMax to any of the components. Once there is a closeAfterMax is added to your component, it will close the selection dropdown once selectMax is true.

Other Search Select optional props

| Prop | Description | Default Value | | --------------------- | ----------------------------------------------------------------------------------------------------- | ----------------- | | listBackgroundColor | This is the background of the dropdown list. | #e5e7eb | | inputBorderColour | This is the input border colour. | 1px solid gray | | inputFocusBorderColor | When the input is active or focused on, what colour do you want to show. this is where to specify it. | 1px solid #6a7ada | | closeAfterMax | Close the selection field once the selectMax condition/count specified is met. | false |

Other Dynamic Multi Select optional props

| Prop | Description | Default Value | | ---------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------- | | dynamicListBackgroundColor | This is the background of the dropdown list. | #e5e7eb | | dynamicInputBorderColour | This is the input border colour. | 1px solid gray | | dynamicInputFocusBorderColor | When the input is active or focused on, what colour do you want to show. this is where to specify it. | 1px solid #6a7ada | | closeAfterMax | Close the selection field once the selectMax condition/count specified is met. | false |

License

This package is open-source software licensed under the MIT license.

Happing coding!