0.0.7 • Published 5 years ago

react-histories-search v0.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

Search Like Google In React

npm version npm npm bundle size David

This is my component supported:

exmple for react-histories-search

features

  • Save search histories to local storage
  • Suggest histories searched

Usage/Examples

Example 1: No options

import React from "react";
import { Provider, History, Trigger } from 'react-histories-search';
import 'react-histories-search/dist/index.css'; // import css

export const Main: React.FC = () => {
  const handleSearch = (value: string) => {
    alert(`Call some API to handle search keyword: ${value}`);
  };
  return (
    <>
      <History onClick={handleSearch}>
        <input id="some_unique_id"/>
      </History>
      <Trigger dataId="some_unique_id">
        <button onClick={handleSearch}>Search</button>
      </Trigger>
    </>
  );
};

Example 2: Full options (recommend)

import React from "react";
import { Provider, History, Trigger } from 'react-histories-search';
import 'react-histories-search/dist/index.css'; // import css

export const Main: React.FC = () => {
  const handleSearch = (value: string) => {
    alert(`Call some API to handle search keyword: ${value}`);
  };
  return (
    <Provider value={{
      // pass options in here
      LocalStorageKey: 'key_in_local_storage',
      limitHistories: 5,
      handleSearch,
      isEnableEnterDown: true,
    }}>
      <History.Hint>
        <input id="some_unique_id"/>
      </History.Hint>
      <Trigger dataId="some_unique_id">
        <button>Search</button>
      </Trigger>
    </Provider>
  );
};

Options

nametypedefalutoptionaldescription
LocalStorageKeystringsearchKeywordstrueKey will save on local storage
limitHistoriesnumber5truelimit histories will save in local storage
handleSearchFunctionnotruecallback return your keyword, you will handle search in here
isEnableEnterDownbooleanfalsetruepress enter to search

Components

Namedescriptionprops
HistoryInsert history tableonClick={(keyword) => // handle your action search}
History.HintInsert hints to input tag, hints based on previous keywordonClick (like <History />) allowTabFill: type is boolean, allow you type tab to fill text on input by hint
TriggerWork like a button search. Tips: you can't not necessary use it, if you use option isEnableEnterDowndataId (requried) is must same with id of input tag

Example

You can download example

Thanks to