0.4.0 • Published 1 year ago

react-search-crow v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-search-crow

React Search Crow

SearchCrow Component

The SearchCrow component is a React component that provides a search functionality with a dropdown list of results. It allows you to customize various aspects of the search behavior and appearance.

Features

  • It is capable of searching for any type of array and any nesting
  • Allows you to pass your own list of items to search through
  • Supports searching excluding certain keys, and displaying specific keys in the dropdown list
  • Provides callbacks for search results, item selection, loading state, focus/blur events, and clear events
  • Supports buttonless search, disabled selection, closing the list on selection, and showing/hiding various UI elements
  • Allows customizing the placeholder, label, button text, loader text, and no results text
  • Supports changing the dropdown position if it rests at the bottom of the window

Install

npm install react-search-crow

Usage

import { SearchCrow } from 'react-search-crow'

const MyComponent = () => {
  const handleSearchResults = (results) => {
    // Handle {search} results
  }
  const handleSelect = (item) => {
    // Handle {item} selection
  }

  return (
    <SearchCrow
      items={[...]}
      onSearchResults={handleSearchResults}
      onSelect={handleSelect}
      // ...props
    />
  )
}

Props

The SearchCrow component accepts the following props:

PropTypeDefaultDescription
childrenReact.ReactNodenullCustom content to be rendered inside the component.
itemsany[][]Array of items to search through.
keyIdstring''Key to use as the unique identifier for each item.
excludesKeysstring[][]Array of keys to exclude from the search.
keysShowValuestring[][]Array of keys whose values should be displayed in the dropdown list.
searchByKeyAfterSelectstring''Key to use for searching after an item is selected. The key must not match a key from the excludesKeys list.
separatorValuestring', 'Separator to use for displaying multiple values in the input field. Space must not be used and if children is used - use the same separator as in children.
valuestring''Initial value of the search input.
debouncenumber0Delay time (in milliseconds) for the search results.
onSearchResultsfunction() => {}Callback that returns the search results.
onSelectfunction() => {}Callback that returns the selected item.
onLoadfunction() => {}Callback that returns the loading state.
onFocusfunction() => {}Callback that is executed on input focus.
onBlurfunction() => {}Callback that is executed on input blur.
onClearfunction() => {}Callback that is executed on clear.
onlyVertexSearchbooleanfalseWhether to search only by vertices, excluding nested arrays.
autoSearchbooleanfalseWhether to perform the search automatically without a button.
disabledSelectbooleanfalseWhether to disable selection of items.
closeOnSelectbooleanfalseWhether to close the dropdown list when an item is selected.
withClearbooleantrueWhether to show the clear button.
withBtnbooleantrueWhether to show the search button.
withDropdownbooleantrueWhether to show the dropdown list of results.
withLoaderbooleantrueWhether to show the loader.
disabledbooleanfalseWhether to disable the search input.
autoFocusbooleanfalseWhether to focus the search input on mount.
changeDropdownPositionbooleantrueWhether to change the dropdown position if it rests at the bottom.
placeholderstring'text...'Placeholder text for the search input.
labelstring'Search'Label text for the search input.
btnTextstring'Search'Text for the search button.
loaderTextstring'Loading'Text for the loader.
noResultsTextstring'No results:'Text to display when there are no search results.
addClassesaddClassesTypes{}Custom CSS classes to apply to the component.

addClassesTypes

ClassTypeDefault
wrapperstring''
labelstring''
inputFormstring''
inputstring''
clearstring''
buttonstring''
loaderstring''
dropdownWrapperstring''
dropdownstring''
dropdownItemstring''

SearchCrow Function

The onSearchCrow function is a utility function that can be used to perform a search on a list of items. It takes the following parameters:

Usage

import { onSearchCrow } from 'react-search-crow'

onSearchCrow([...], 'search text' ['id'], false)
ArgumentsTypeDefaultDescription
listany[][]An array of elements of any type and nesting.
valuestring''The search query.
excludesKeysstring[][]An optional array of keys to exclude from the search.
onlyVertexSearchbooleanfalseA boolean indicating whether to search only by vertices, excluding nested arrays.

The function returns an array of items that match the search query.

You can use this function for your own search or sort arrays by found values.

Engines

react: 18.3.1
typescript: 4.9.5
node: >=14.0.0

Contribution

If you find any problems or have suggestions for improvement:

  • Feel free to submit a pull request.
  • Create issues.
  • Email me at german.work11@gmail.com
0.4.0

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago