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

select-components

v1.1.4

Published

**`SelectComponent`** is a versatile selection component in React. It includes search, filtering, multi-select, and custom formatting options, making it easy to integrate and customize to fit your needs.

Downloads

2,224

Readme

📦 SelectComponent

SelectComponent is a versatile selection component in React. It includes search, filtering, multi-select, and custom formatting options, making it easy to integrate and customize to fit your needs.

📥 Installation

To install the package, use the following command in your terminal:

npm install select-components

Usage Examples

Basic Selection

The render prop should be an array of objects containing the name property.

const urgency = [
  { name: "Alta" },
  { name: "Media" },
  { name: "Baja" },
]);
<SelectComponent
  render={urgency}
  name="simpleSelect"
  placeholder="Seleccione una opción"
  onSelect={(value) => console.log("Seleccionado:", value)}
/>

Compatibility with react-hook-form

Use ControllerSelectComponent to integrate SelectComponent with react-hook-form.

Basic Controller

<ControllerSelectComponent
  name={"urgency"}
  control={control}
  required={true}
  render={[{ name: "Alta" }, { name: "Media" }, { name: "Baja" }]}
  placeholder="Elija la urgencia"
/>

Enable Search

Enable real-time search using an endpoint to fetch data.

  <ControllerSelectComponent
    {...{
      name: "Sparepart_order",
      onSelect: handleOnSelect,
      placeholder: "Escribe el nombre repuesto",
      isSearch: true, // Activar búsqueda
      funtionSearch: getSpareParts,  Endpoint para la búsqueda
      control: control,
    }}
  />

Custom Formatting

Define a custom format for each option.

<SelectComponent
  name="formattedSelect"
  render={[{ name: "Alta" }, { name: "Media" }, { name: "Baja" }]}
  customFormat={(item) => <span>{item.customLabel}</span>}
/>

Multi-Select

Enable the selection of multiple options.

<SelectComponent
  name="multipleSelect"
  render={[{ name: "Alta" }, { name: "Media" }, { name: "Baja" }]}
  isMultiple={true}
  placeholder="Seleccione varias opciones"
/>

By Category

Create sub-options organized by categories:

  const unitOptions = [
    {
      title: "Adimensional",
      options: [{ name: "u" }]
    },
    {
      title: "Volumen",
      options: [
        { name: "m3" },
        { name: "cm3" },
        { name: "L" },
        { name: "ml" },
      ],
    },
    {
      title: "Masa",
      options: [
        { name: "kg" },
        { name: "g" },
        { name: "mg" },
      ],
    },
]
<SelectComponent
  name="advancedSelect"
  render = {unitOptions}
  searchProperty="title"
  isCategory={true}
  defaultValue="Option1"
/>

⚙️ Propiedades Disponibles

A continuación, se detallan las propiedades que puedes utilizar para configurar el componente según tus necesidades:

| Property | Type | Description | Default | | ----------------- | -------- | ----------------------------------------------------------------------------------- | -------------------- | | render | function | Function to render each item in a custom way. | undefined | | name | string | Component name, useful in forms. | undefined | | funtionSearch | function | Function executed to perform custom search. | () => {} | | onSelect | function | Function executed when an item is selected. | () => {} | | isCategory | boolean | Displays categories within items. | undefined | | defaultValue | string | Default value displayed initially. | "" | | searchProperty | string | Object property used to execute search or setter in the field. | "name" | | placeholder | string | Text displayed in the empty field. | "" | | isSearch | boolean | Enables the search function. | false | | isFilter | boolean | Enables filtering of items (recommended when isSearch is false). | true | | required | boolean | Defines if selection is mandatory. | true | | isMultiple | boolean | Enables multiple selection. | false | | customFormat | function | Custom function to render each item, using the item as an argument. | undefined | | disabled | boolean | Disables the component when true. | false | | disabledClassName | string | Custom CSS class when disabled.. | undefined | | className | string | Custom CSS class to style the component. | "" | | selectedClassName | string | Custom CSS class for selected option. | undefined | | dropClassName | string | Custom CSS class for dropdown. | undefined | | dropHover | string | Custom CSS hover class for dropdown | undefined |

Property Added for Controller

| Property | Type | Description | Default | | ----------------- | -------- | ----------------------------------------------------------------------------------- | -------------------- | | returnString | boolean | Controls if a string or the object is returned. | false |