diff --git a/README.md b/README.md
index 134273f..32e4990 100644
--- a/README.md
+++ b/README.md
@@ -1,181 +1,241 @@
-# TSDX React w/ Storybook User Guide
+# react-search-highlight
-Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
+
-> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
+react-search-highlight is a light weight react package to highlight static/dynamic search for auto completion
-> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
+
+
+
+
+
+
-## Commands
+## Installation
-TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
+install it using npm or yarn to include it in your own React project
-The recommended workflow is to run TSDX in one terminal:
+You will also need to import css modules in root your project before using it. `dist/react-search-highlight.cjs.development.css`
```bash
-npm start # or yarn start
+npm install react-search-highlight
```
-This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
-
-Then run either Storybook or the example playground:
-
-### Storybook
-
-Run inside another terminal:
+or:
```bash
-yarn storybook
+yarn add react-search-highlight
```
-This loads the stories from `./stories`.
-
-> NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.
-
-### Example
-
-Then run the example inside another:
-
-```bash
-cd example
-npm i # or yarn to install dependencies
-npm start # or yarn start
+## Usage
+
+You can either use the hook:
+
+```tsx static
+import {
+ PopOverList,
+ PopOverOption,
+ PopOverOptionText,
+ Props,
+ ReactSearchHighlightProvider,
+ SearchBar,
+ STRING_MATCHING,
+ useReactSearchHighlight,
+ Wrapper
+} from 'react-search-highlight';
+import 'react-search-highlight/dist/react-search-highlight.cjs.development.css';
+
+import TEST_DATA from '../data.json';
+
+const Template = () => {
+ const {suggestions, isResultsEmpty} = useReactSearchHighlight();
+ return (
+
+
+
+ {suggestions?.map((item, index) => (
+ alert(index)}
+ >
+ ⚡️
+
+
+
+ ))}
+ {isResultsEmpty &&
No results found
}
+
+
+ );
+};
+
+export const Custom = () => {
+ return (
+
+
+
+ );
+};
```
-The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
-
-To do a one-off build, use `npm run build` or `yarn build`.
-
-To run tests, use `npm test` or `yarn test`.
-
-## Configuration
-
-Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
-
-### Jest
-
-Jest tests are set up to run with `npm test` or `yarn test`.
-
-### Bundle analysis
-
-Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
-
-#### Setup Files
-
-This is the folder structure we set up for you:
-
-```txt
-/example
- index.html
- index.tsx # test your component here in a demo app
- package.json
- tsconfig.json
-/src
- index.tsx # EDIT THIS
-/test
- blah.test.tsx # EDIT THIS
-/stories
- Thing.stories.tsx # EDIT THIS
-/.storybook
- main.js
- preview.js
-.gitignore
-package.json
-README.md # EDIT THIS
-tsconfig.json
+Or with the wrapper component
+
+```tsx
+import {
+ PopOverList,
+ PopOverOption,
+ PopOverOptionText,
+ Props,
+ SearchBar,
+ Wrapper
+} from 'react-search-highlight';
+import 'react-search-highlight/dist/react-search-highlight.cjs.development.css';
+
+import TEST_DATA from '../data.json';
+
+export const Default = args => {
+ return (
+
+ {({suggestions}) => {
+ return (
+ <>
+
+
+ {suggestions?.map((item, index) => (
+ alert(index)}
+ >
+ ⚡️
+
+
+
+ ))}
+
+ >
+ );
+ }}
+
+ );
+};
```
-#### React Testing Library
+If you want to use it with modal
+
+```tsx static
+import {Modal} from 'react-search-highlight';
+
+export const WithModal = () => {
+ return (
+
+
Modal is open
+
+
+
+
+ );
+};
+```
-We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
+🔨 API
+`useReactSearchHighlight` can be used with `ReactSearchHighlightProvider` and it can be used throughout the component to access the context values. Note that whenever you are using it you must wrap the entire component using `ReactSearchHighlightProvider`.
+
+```tsx static
+const {
+ suggestions,
+ isLoading,
+ input,
+ startLoading,
+ endLoading,
+ isResultsEmpty,
+ resetState
+} = useReactSearchHighlight();
+```
-### Rollup
+You can also access these values using wrapper component
-TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
+```tsx static
+
+ {({suggestions, isLoading, input, startLoading, endLoading, isResultsEmpty, resetState}) => {
+ return (
+ .....
+ );
+ }}
+
+```
-### TypeScript
+### `` Props:
-`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
+```tsx
+ // Data to perform search operation
+ data: any[];
-## Continuous Integration
+ // Determines which keys to search from the data object
+ keysToSearch?: string[];
-### GitHub Actions
+ // Determines input box behaviour it accepts three values DEBOUNCE, THROTTLE or DEFAULT
+ inputAlgorithm?: typeof DEBOUNCE | typeof THROTTLE | typeof DEFAULT;
-Two actions are added by default:
+ // Optional: Determines the input algorithm timeout for debounce and throttle
+ inputAlgorithmTimeout?: number;
-- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
-- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit)
+ // Determines matching algorithm to search over data, it accepts two values CHARACTER_MATCHING or STRING_MATCHING
+ // CHARACTER_MATCHING matches each character from the data to highlight it
+ // STRING_MATCHING matches each word from the data to highlight it
+ matchingAlgorithm?: typeof CHARACTER_MATCHING | typeof STRING_MATCHING;
-## Optimizations
+ // Optional: input value, it is recommended not to pass any in general case
+ value?: string;
-Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
+ // Optional: input value onChange event handler
+ onChange?: (e:React.ChangeEvent) => void
-```js
-// ./types/index.d.ts
-declare var __DEV__: boolean;
+ // Optional: Determines initial input value
+ initialValue?: string
-// inside your code...
-if (__DEV__) {
- console.log('foo');
-}
+ // Optional: It can be used to change search bar icon
+ PrefixIcon?: React.FC
```
-You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
-
-## Module Formats
-
-CJS, ESModules, and UMD module formats are supported.
-
-The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
+### `` Props:
-## Deploying the Example Playground
+```ts
+ // React element node
+ children: ReactNode;
+
+ // Determines the navigation index used for internal list navigation
+ optionIndex: number;
-The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
-
-```bash
-cd example # if not already in the example folder
-npm run build # builds to dist
-netlify deploy # deploy the dist folder
```
-Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
-
-```bash
-netlify init
-# build command: yarn build && cd example && yarn && yarn build
-# directory to deploy: example/dist
-# pick yes for netlify.toml
-```
+### `` Props:
-## Named Exports
+```ts
+ // Determines text value to render with highlight
+ value: string;
-Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
-
-## Including Styles
-
-There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
-
-For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
-
-## Publishing to NPM
-
-We recommend using [np](https://github.com/sindresorhus/np).
-
-## Usage with Lerna
-
-When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
+ // Determine type of html element ex: p, h1, h2
+ as: string;
+```
-The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
+### 🐛 Bug Reporting
+`The Library is in developing stage`
+- Feel free to Open an [issue on GitHub](https://github.com/Abusayid693/react-search-highlight/issues) to request any additional features you might need for your use case.
+- Connect with me on [LinkedIn](https://www.linkedin.com/in/rehan-choudhury-66842a164/). I'd love ❤️️ to hear where you are using this library.
-Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
-```diff
- "alias": {
-- "react": "../node_modules/react",
-- "react-dom": "../node_modules/react-dom"
-+ "react": "../../../node_modules/react",
-+ "react-dom": "../../../node_modules/react-dom"
- },
-```
+### 📜 License
-An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
+This software is open source, licensed under the [MIT License](./LICENSE).
\ No newline at end of file
diff --git a/example/.npmignore b/example/.npmignore
deleted file mode 100644
index 587e4ec..0000000
--- a/example/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-node_modules
-.cache
-dist
\ No newline at end of file
diff --git a/example/index.html b/example/index.html
deleted file mode 100644
index 547e2e0..0000000
--- a/example/index.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
- Playground
-
-
-
-
-
-
-
diff --git a/example/index.tsx b/example/index.tsx
deleted file mode 100644
index 73387c6..0000000
--- a/example/index.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import 'react-app-polyfill/ie11';
-import * as React from 'react';
-import * as ReactDOM from 'react-dom';
-import { Thing } from '../.';
-
-const App = () => {
- return (
-
-
-
- );
-};
-
-ReactDOM.render(, document.getElementById('root'));
diff --git a/example/package.json b/example/package.json
deleted file mode 100644
index a50960f..0000000
--- a/example/package.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "name": "example",
- "version": "1.0.0",
- "main": "index.js",
- "license": "MIT",
- "scripts": {
- "start": "parcel index.html",
- "build": "parcel build index.html"
- },
- "dependencies": {
- "react-app-polyfill": "^1.0.0"
- },
- "alias": {
- "react": "../node_modules/react",
- "react-dom": "../node_modules/react-dom/profiling",
- "scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
- },
- "devDependencies": {
- "@types/react": "^16.9.11",
- "@types/react-dom": "^16.8.4",
- "parcel": "^1.12.3",
- "typescript": "^3.4.5"
- }
-}
diff --git a/example/tsconfig.json b/example/tsconfig.json
deleted file mode 100644
index 1e2e4fd..0000000
--- a/example/tsconfig.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "compilerOptions": {
- "allowSyntheticDefaultImports": false,
- "target": "es5",
- "module": "commonjs",
- "jsx": "react",
- "moduleResolution": "node",
- "noImplicitAny": false,
- "noUnusedLocals": false,
- "noUnusedParameters": false,
- "removeComments": true,
- "strictNullChecks": true,
- "preserveConstEnums": true,
- "sourceMap": true,
- "lib": ["es2015", "es2016", "dom"],
- "types": ["node"]
- }
-}
diff --git a/package.json b/package.json
index 81d0502..0ac80e8 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "version": "0.1.3",
+ "version": "0.1.4",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
diff --git a/resources/logo.svg b/resources/logo.svg
new file mode 100644
index 0000000..8d276cd
--- /dev/null
+++ b/resources/logo.svg
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/src/container/SearchBar/index.tsx b/src/container/SearchBar/index.tsx
index c33a751..15d4e57 100644
--- a/src/container/SearchBar/index.tsx
+++ b/src/container/SearchBar/index.tsx
@@ -7,7 +7,7 @@ import {
import { useReactSearchHighlight } from '../../context';
import { Stack } from '../../elements/flexBox';
import { useKeyDown, useRefComposition } from '../../hooks';
-import searchIcon from '../../icons/search.svg';
+import SearchIcon from '../../icons/search';
import { InternalContext } from '../main';
import {
@@ -28,27 +28,65 @@ export const matchingAlgorithms: Record = {
};
export interface Props extends React.InputHTMLAttributes {
+ // Data to perform search operation
data: any[];
+
+ // Determines which keys to search from the data object
keysToSearch?: string[];
+
+ // Determines input box behaviour it accepts three values DEBOUNCE, THROTTLE or DEFAULT
inputAlgorithm?: typeof DEBOUNCE | typeof THROTTLE | typeof DEFAULT;
+
+ // Optional: Determines the input algorithm timeout for debounce and throttle
inputAlgorithmTimeout?: number;
+
+ // Determines matching algorithm to search over data, it accepts two values CHARACTER_MATCHING or STRING_MATCHING
+ // CHARACTER_MATCHING matches each character from the data to highlight it
+ // STRING_MATCHING matches each word from the data to highlight it
matchingAlgorithm?: typeof CHARACTER_MATCHING | typeof STRING_MATCHING;
+
+ // Optional: input value, it is recommended not to pass any in general case
value?: string;
+
+ // Optional: input value onChange event handler
onChange?: (e:React.ChangeEvent) => void
+
+ // Optional: Determines initial input value
initialValue?: string
+
+ // Optional: It can be used to change search bar icon
PrefixIcon?: React.FC
}
export const SearchBar = React.forwardRef(({
+ // Determines which keys to search from the data object
keysToSearch,
+
+ // Determines input box behaviour it accepts three values DEBOUNCE, THROTTLE or DEFAULT
inputAlgorithm = DEBOUNCE,
+
+ // Determines matching algorithm to search over data, it accepts two values CHARACTER_MATCHING or STRING_MATCHING
+ // CHARACTER_MATCHING matches each character from the data to highlight it
+ // STRING_MATCHING matches each word from the data to highlight it
matchingAlgorithm = CHARACTER_MATCHING,
+
+ // Data to perform search operation
data,
+
+ // Optional: input value, it is recommended not to pass any in general case
value: controlledValue,
+
+ // Optional: Determines the input algorithm timeout for debounce and throttle
inputAlgorithmTimeout = 500,
+
+ // Optional: onChange event handler
onChange,
+
+ // Optional: Determines initial input value
initialValue,
+
+ // Optional: It can be used to change search bar icon
PrefixIcon,
...any
}: Props, forwardedRef) => {
@@ -104,7 +142,7 @@ export const SearchBar = React.forwardRef(({
cursor={'text'}
>
(
export interface PopOverOptionProps
extends React.LiHTMLAttributes {
+ // React element node
children: ReactNode;
+
+ // Determines the navigation index used for internal list navigation
optionIndex: number;
}
@@ -207,7 +210,11 @@ export const PopOverOption: React.FC = ({
export interface PopOverOptionTextProps
extends React.HTMLAttributes {
className?: string;
+
+ // Determines text value to render with highlight
value: string;
+
+ // Determine type of html element ex: p, h1, h2
as: string;
}
diff --git a/src/icons/search.tsx b/src/icons/search.tsx
new file mode 100644
index 0000000..a0745de
--- /dev/null
+++ b/src/icons/search.tsx
@@ -0,0 +1,10 @@
+import React from "react";
+const SearchIcon = () => {
+ return (
+
+ );
+};
+
+export default SearchIcon
\ No newline at end of file
diff --git a/stories/custom.stories.tsx b/stories/custom.stories.tsx
index daa388c..153fdd3 100644
--- a/stories/custom.stories.tsx
+++ b/stories/custom.stories.tsx
@@ -34,8 +34,6 @@ const Template = args => {
const {suggestions, isResultsEmpty} = useReactSearchHighlight();
const ref = useRef();
- console.log('ref :', ref);
-
return (
{
- it('renders without crashing', () => {
- const div = document.createElement('div');
- ReactDOM.render(, div);
- ReactDOM.unmountComponentAtNode(div);
- });
-});