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

simple-search-dropdown

v0.2.1

Published

<h3 align="center">Simple Search Dropdown</h3>

Downloads

294

Readme

Status GitHub Issues GitHub Pull Requests License


Instalação

Instalando simple-search-dropdown:

npm install simple-search-dropdown
# OU
yarn add simple-search-dropdown
# OU
pnpm add simple-search-dropdown

Uso/Exemplos

[!IMPORTANT]
Caso queira usar somente o componente SearchSelect, é necessário importar o CSS como mostrado abaixo:

@import url('../node_modules/simple-search-dropdown/dist/style.css');

Dados como Array

import { SearchSelect } from 'simple-search-dropdown'

function App() {
  const data = [
    {value: 1, label: "Abacaxi"},
    {value: 2, label: "Banana"},
    {value: 3, label: "Avião"},
    {value: 4, label: "Bola"},
    {value: 5, label: "Lula"},
    {value: 6, label: "Faca"},
    {value: 7, label: "Magnus"},
    {value: 8, label: "Xadrez"},
  ]

  return (
    <main className="flex flex-col justify-center items-center ">
      <div className="flex flex-col mt-2">
        <SearchSelect data={data} placeholder="Pesquisar"} />
      </div>
    </main>
  )
}

export default App

Dados como função Async

import { SearchSelect } from 'simple-search-dropdown'

function App() {
  const promiseOptions = () =>
    new Promise((resolve) => {
      setTimeout(() => {
        const data = [
          {value: 1, label: "Abacaxi"},
          {value: 2, label: "Banana"},
          {value: 3, label: "Avião"},
          {value: 4, label: "Bola"},
          {value: 5, label: "Lula"},
          {value: 6, label: "Faca"},
          {value: 7, label: "Magnus"},
          {value: 8, label: "Xadrez"},
        ]
        resolve(data);
      }, 1000);
    });

  return (
    <main className="flex flex-col justify-center items-center ">
      <div className="flex flex-col mt-2">
        <SearchSelect data={promiseOptions} placeholder="Pesquisar"} />
      </div>
    </main>
  )
}

export default App

Usando react-hook-form

import { useForm } from 'react-hook-form'
import { SearchSelect } from 'simple-search-dropdown'

function App() {
  const { handleSubmit, register } = useForm()
  const promiseOptions = () =>
    new Promise((resolve) => {
      setTimeout(() => {
        const data = [
          { value: 1, label: 'Abacaxi' },
          { value: 2, label: 'Banana' },
          { value: 3, label: 'Avião' },
          { value: 4, label: 'Bola' },
          { value: 5, label: 'Lula' },
          { value: 6, label: 'Faca' },
          { value: 7, label: 'Magnus' },
          { value: 8, label: 'Xadrez' },
        ]
        resolve(data)
      }, 1000)
    })

  return (
    <main className="flex flex-col justify-center items-center ">
      <form className="flex flex-col mt-2" onSubmit={handleSubmit((data) => console.log(data))}>
        <SearchSelect data={promiseOptions} placeholder="Pesquisar" {...register('abc')} />
        <button type="submit" className="p-2 bg-blue-500 text-white mt-2">
          Submit
        </button>
      </form>
    </main>
  )
}

export default App

Criando seu próprio

É possível fazer seu próprio componente usando o Select e useDataSearch do pacote.

[!NOTE]
O uso do CSS presente na dependência se torna totalmente OPCIONAL aqui.

import { Select, useDataSearch } from 'simple-search-dropdown'

function YourSelectComponent({ data, name }) {
  const itemFiltered = useDataSearch(data, name)

  return (
    <Select name={name}>
      <Select.Trigger>
        <Select.Search />
      </Select.Trigger>
      <Select.Panel>
        {itemFiltered.length > 0 &&
          itemFiltered.map((item, idx) => <Select.Item key={idx} value={item.value} label={item.label} />)}
      </Select.Panel>
    </Select>
  )
}

export default YourSelectComponent

[!WARNING]
Os dados vindo do parâmetro data precisa ser uma lista com o seguinte formato: { label: "", value: 0 || "" }. E o parâmetro name servirá para vincular o campo com os dados filtrados.

Funcionalidades

  • Faz a menor quantidade de requisições possível.
  • Aceita lista de dados ou uma função assíncrona.
  • Componente primitivo para customização pessoal.
  • Compatível com react-hook-form.
  • Sistema de pesquisa e dropdown em um só.

Para Desenvolvedores

Contribuições são sempre bem-vindas!

Conhecimento

É necessário o entendimento de TypeScript para contribuições envolvendo os componentes. Além do TypeScript, entender como funciona o react e ref são essenciais.

Pré requisito

  • Git
  • Node.js
  • IDE (VSCode/Zed)

Contribuindo

  1. Crie um fork do projeto clicando no botão localizado a direita do nome do repositório.
  2. Clone o repositório que está na sua conta do github. (Siga os passos do próximo tópico)
  3. Faça suas alterações.
  4. Commit e abra um Pull Request.
  5. Espere a aprovação de algum desenvolvedor.

Rodando localmente

Clone o projeto

git clone https://github.com/KingTimer12/simple-search-dropdown.git

Entre no diretório do projeto

cd simple-search-dropdown

Instale as dependências

pnpm install

Rodando os testes

Para rodar os testes, rode o seguinte comando

npm run test
# OU
yarn test
# OU
pnpm test

Tecnologias

Licença

MIT

Autores