1.0.3 • Published 2 years ago

search-select-react v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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!