1.3.2 • Published 4 months ago

select-components v1.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

📦 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:

PropertyTypeDescriptionDefault
renderfunctionFunction to render each item in a custom way.undefined
namestringComponent name, useful in forms.undefined
funtionSearchfunctionFunction executed to perform custom search.() => {}
onSelectfunctionFunction executed when an item is selected.() => {}
isCategorybooleanDisplays categories within items.undefined
defaultValuestringDefault value displayed initially.""
searchPropertystringObject property used to execute search or setter in the field."name"
placeholderstringText displayed in the empty field.""
isSearchbooleanEnables the search function.false
isFilterbooleanEnables filtering of items (recommended when isSearch is false).true
requiredbooleanDefines if selection is mandatory.true
isMultiplebooleanEnables multiple selection.false
customFormatfunctionCustom function to render each item, using the item as an argument.undefined
disabledbooleanDisables the component when true.false
disabledClassNamestringCustom CSS class when disabled..undefined
classNamestringCustom CSS class to style the component.""
selectedClassNamestringCustom CSS class for selected option.undefined
dropClassNamestringCustom CSS class for dropdown.undefined
dropHoverstringCustom CSS hover class for dropdownundefined

Property Added for Controller

PropertyTypeDescriptionDefault
returnStringbooleanControls if a string or the object is returned.false
1.2.0

6 months ago

1.2.8

6 months ago

1.2.7

6 months ago

1.2.6

6 months ago

1.2.5

6 months ago

1.2.4

6 months ago

1.2.3

6 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.30

7 months ago

1.0.34

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.3.2

4 months ago

1.1.4

7 months ago

1.3.1

5 months ago

1.1.3

7 months ago

1.3.0

6 months ago

1.1.2

7 months ago

1.2.9

6 months ago

1.0.27

8 months ago

1.0.26

8 months ago

1.0.25

8 months ago

1.0.24

8 months ago

1.0.23

8 months ago

1.0.22

8 months ago

1.0.21

8 months ago

1.0.20

8 months ago

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago