Socket
Book a DemoInstallSign in
Socket

search-select-react

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

search-select-react

A React component that accepts data Array of Objects and headers to search on multiple conditions and perform actions on select using click and keyboard events

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
6
200%
Maintainers
1
Weekly downloads
 
Created
Source

search-select-react

A React component that accepts data Array of Objects and headers to search on multiple conditions and perform actions on select using click and keyboard events

Installation

npm install search-select-react
yarn add search-select-react

Usage

import React from 'react';
import {SearchSelect} from 'search-select-react';

const data = [
                {
                id: 1,
                name: 'John Doe',
                email: 'john@mail.com',
                phone: '1234567890',
              },
              {
                id: 2,
                name: 'Jane Doe',
                email: 'jane@mail.com',
                phone: '0987654321',
              },
];

const searchBy = ['name', 'email', 'phone'];

const display = ['name', 'email'];

const onSelectAction = (selected) => {
  console.log(selected);
};

const onNoResultAction = () => {
  console.log('No result found');
};

const App = () => {
  return (
    <div>
      <SearchSelect
        data={data}
        search={searchBy}
        display={display}
        select={onSelectAction}
        noResults={onNoResultAction}
        noResultsText='No Results Found! Click to Add New.'
        placeholder='Search'
        label='Search'
        name={'search'}
        helperText='Search for a user'
      />
    </div>
  );
};

export default App;

Styling

The component by default has no styling. You can style it using your own CSS or any css library like tailwindcss using the different class props available.

List of styling class props

Prop NameDescriptionDefaultNotes
wrapperClassClass for the wrapper div''
labelClassClass for the label''
inputClassClass for the input''
helperTextClassClass for the helper text''
resultContainerClassClass for the result container''
resultItemClassClass for the result item''
resultItemActiveClassClass for the active result item''Active State should be handled in the CSS
resultItemHoverClassClass for the hovered result item''Hover State should be handled in the CSS

All Props

Prop NameTypeDescriptionRequiredDefault
dataArrayArray of Objects to search onYes[ ]
searchArrayArray of keys to search onYes[ ]
displayArrayArray of keys to display in the listYes[ ]
selectFunctionFunction to perform on selectYes() => {}
noResultsFunctionFunction to perform on no resultsNo() => {}
noResultsTextStringText to display on no resultsNo'No Results Found! Click to Add New'
placeholderStringPlaceholder for the inputNo---
labelStringLabel for the inputNo---
showLabelBooleanShow label for the inputNotrue
nameStringName for the inputNo---
helperTextStringHelper text for the inputNo---
showHelperTextBooleanShow helper textNotrue
disabledBooleanDisable the inputNofalse
requiredBooleanMake the input requiredNofalse
readOnlyBooleanMake the input read onlyNofalse
wrapperClassStringClass for the wrapperNo---
labelClassStringClass for the labelNo---
inputClassStringClass for the inputNo---
helperTextClassStringClass for the helper textNo---
resultContainerClassStringClass for the result containerNo---
resultItemClassStringClass for the result itemNo---
resultItemActiveClassStringClass for the active result itemNo---
resultItemHoverClassStringClass for the hover result itemNo---
enterToSelectBooleanSelect on enter key pressNofalse
onChangeFunctionFunction to perform on change in the input boxNo() => {}
...props---Props for the inputNo---

License

MIT © trehansangpriya

Author

👤 Trehan Sangpriya

Website LinkedIn Twitter GitHub

Show your support

Give a ⭐️ if this project helped you!

Keywords

react

FAQs

Package last updated on 18 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.