├── .eslintignore
├── .eslintrc.json
├── .gitignore
├── .size-limit.js
├── .size-snapshot.json
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── LICENSE.md
├── README.md
├── index.js
├── jest.config.js
├── lint-staged.config.js
├── package.json
├── prettier.config.js
├── rollup.config.js
├── src
├── FilterResults.tsx
├── InputFilter.tsx
├── behaviorStore.ts
└── index.ts
├── test
├── FilterResults.test.tsx
├── InputFilter.test.tsx
├── __snapshots__
│ └── InputFilter.test.tsx.snap
├── behaviorStore.test.ts
├── index.test.tsx
└── types.test.tsx
├── tsconfig.base.json
├── tsconfig.json
└── yarn.lock
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "plugin:@typescript-eslint/recommended",
4 | "plugin:react/recommended",
5 | "prettier",
6 | "prettier/@typescript-eslint"
7 | ],
8 | "parser": "@typescript-eslint/parser",
9 | "parserOptions": {
10 | "ecmaFeatures": {
11 | "jsx": true
12 | },
13 | "useJSXTextNode": true,
14 | "project": "./tsconfig.json"
15 | },
16 | "plugins": ["@typescript-eslint", "react-hooks"],
17 | "rules": {
18 | "react-hooks/rules-of-hooks": "error",
19 | "react-hooks/exhaustive-deps": "warn",
20 | "@typescript-eslint/array-type": ["error", "array-simple"],
21 | "@typescript-eslint/no-unused-vars": [
22 | "error",
23 | {
24 | "argsIgnorePattern": "^_",
25 | "caughtErrorsIgnorePattern": "^_"
26 | }
27 | ],
28 | "@typescript-eslint/explicit-function-return-type": "off"
29 | },
30 | "settings": {
31 | "react": {
32 | "version": "detect"
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
3 | .DS_Store
4 | dist
5 | compiled
6 |
--------------------------------------------------------------------------------
/.size-limit.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | path: "./dist/react-fuzzy-filter.esm.js",
4 | limit: "5 kB",
5 | },
6 | {
7 | path: "./dist/react-fuzzy-filter.umd.production.js",
8 | limit: "5 kB",
9 | },
10 | ];
11 |
--------------------------------------------------------------------------------
/.size-snapshot.json:
--------------------------------------------------------------------------------
1 | {
2 | "./dist/react-fuzzy-filter.umd.production.js": {
3 | "bundled": 20556,
4 | "minified": 13997,
5 | "gzipped": 5019
6 | },
7 | "./dist/react-fuzzy-filter.umd.development.js": {
8 | "bundled": 20556,
9 | "minified": 13997,
10 | "gzipped": 5019
11 | },
12 | "./dist/react-fuzzy-filter.cjs.production.js": {
13 | "bundled": 4771,
14 | "minified": 2270,
15 | "gzipped": 937
16 | },
17 | "./dist/react-fuzzy-filter.cjs.development.js": {
18 | "bundled": 4771,
19 | "minified": 2270,
20 | "gzipped": 937
21 | },
22 | "dist/react-fuzzy-filter.esm.js": {
23 | "bundled": 4129,
24 | "minified": 2068,
25 | "gzipped": 876,
26 | "treeshaked": {
27 | "rollup": {
28 | "code": 179,
29 | "import_statements": 75
30 | },
31 | "webpack": {
32 | "code": 1295
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | script: npm run $TEST_SUITE
3 | sudo: false
4 | cache:
5 | directories:
6 | - node_modules
7 | node_js:
8 | - 10
9 | env:
10 | matrix:
11 | - TEST_SUITE=lint
12 | - TEST_SUITE=test
13 | - TEST_SUITE=size-limit
14 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 5.0.1 (2019-4-1)
4 |
5 | Fixed:
6 |
7 | - Removed arrow functions from UMD builds to support older browsers. Thanks @rburak for contributing!
8 |
9 | ## 5.0.0 (2019-3-16)
10 |
11 | Changed:
12 |
13 | - Using react hooks internally. **Breaking:** React peer dependency is now 16.8.0
14 | - 4.x.x branch will continue to release patches, etc. for older versions of React
15 | - Smaller bundle!
16 |
17 | ## 4.3.0 (2019-2-22)
18 |
19 | Added:
20 |
21 | Add typescript definitions and rewrite library with typescript.
22 |
23 | ## 4.2.1 (2019-2-14)
24 |
25 | Fixed:
26 |
27 | - An internal bug was preventing subscriptions from unsubscribing due to `behaviorStore` not returning the unsubscribe function. This bug was introduced in `4.2.0`. Thanks @quietshu for the fix!
28 |
29 | ## 4.2.0 (2019-1-21)
30 |
31 | Improved:
32 |
33 | - Wrapped `valoo` store to store current value so that subscribers can replay the latest event (and have the current state) regardless of component render order. This will also help with async react.
34 |
35 | ## 4.1.0 (2019-1-15)
36 |
37 | Added:
38 |
39 | - `changeInputValue` function is now a named export from the library. This will trigger changing the `InputFilter` input value as well as affect the rendered `FilterResults`. eg. `changeInputValue("new input")`
40 |
41 | ## 4.0.0 (2018-7-24)
42 |
43 | Changed:
44 |
45 | - Use [valoo](https://www.npmjs.com/package/valoo) instead of [rxjs](https://github.com/ReactiveX/rxjs) for state management.
46 |
47 | ## 3.2.0 (2017-5-30)
48 |
49 | Added:
50 |
51 | - Added support for React ^15.5 by using `prop-types` package and prepares for deprecation of PropTypes from React.
52 |
53 | ## 3.1.0 (2017-5-23)
54 |
55 | Added:
56 |
57 | - Allow updating `initialSearch` prop. This provides an escape hook in situations where the `initialSearch` might not be known until right after the first render.
58 |
59 | ## 3.0.0 (2017-4-10)
60 |
61 | Changed:
62 |
63 | - Updated API to remove props and simplify usage. `FilterResults` now expects a function as a child, which receives the matching items as an argument. This provides more flexibility without needing to pass "configuration props".
64 |
65 | Removed:
66 |
67 | - Removed the following props in the API change: `classPrefix`, `wrapper`, `wrapperProps`, and `renderContainer`.
68 |
69 | ## 2.3.0 (2016-8-26)
70 |
71 | Added:
72 |
73 | - Added `debounceTime` prop to `InputFilter`. This specifies the time in milliseconds to debounce the `onChange` event on the input field. [196de58](../../commit/196de58)
74 |
75 | ## 2.2.0 (2016-8-26)
76 |
77 | Added:
78 |
79 | - Added `prefilters` prop to `FilterResults`. Enables prefiltering the items on matching regular expressions. The return of the callback is the list of items to fuzzy search on. This enables "commands" that toggle state or change what is being fuzzy searched on. [bb7d688](../../commit/bb7d688)
80 |
81 | ## 2.1.0 (2016-8-3)
82 |
83 | Added:
84 |
85 | - `renderContainer` callback function on `FilterResults` receives a second argument with the raw filtered items. [commit](../../commit/4f7552f)
86 |
87 | ## 2.0.0 (2016-8-2)
88 |
89 | Changed:
90 |
91 | - Removed `initialSearch` prop from `FilterResults`. It now syncs with `initialSearch` prop from `InputFilter`. [commit](../../commit/eb200b5)
92 | - `onChange` callback for `InputFilter` now can optionally return a string (instead of a boolean). The string overrides the search value passed to `FilterResults`. [commit](../../commit/eb200b5)
93 |
94 | ## 1.1.0 (2016-8-1)
95 |
96 | Added:
97 |
98 | - Optional prop, `renderContainer` added to `FilterResults` component. This is an alternative to using `wrapper`/`wrapperProps` and provides more fine grained control over what is ultimately rendered from `FilterResults`. [commit](../../commit/b2d5866)
99 |
100 | ## 1.0.0 (2016-7-29)
101 |
102 | Initial release
103 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4 |
5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6 |
7 | Examples of unacceptable behavior by participants include:
8 |
9 | * The use of sexualized language or imagery
10 | * Personal attacks
11 | * Trolling or insulting/derogatory comments
12 | * Public or private harassment
13 | * Publishing other's private information, such as physical or electronic
14 | addresses, without explicit permission
15 | * Other unethical or unprofessional conduct
16 |
17 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
18 |
19 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
20 |
21 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
22 |
23 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
24 |
25 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version]
26 |
27 | [homepage]: http://contributor-covenant.org
28 | [version]: http://contributor-covenant.org/version/1/3/0/
29 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2019 Jonathan Lehman
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://yarnpkg.com/en/package/react-fuzzy-filter) [](https://travis-ci.org/jdlehman/react-fuzzy-filter) [](LICENSE.md)
2 |
3 | # react-fuzzy-filter
4 |
5 | Fuzzy filter a list of data based on the search value typed in the input field. The list of matching items is made available as an argument to the FilterResults component's child function.
6 |
7 | ReactFuzzyFilter is powered by [`fuse.js`](https://github.com/krisk/Fuse).
8 |
9 | ## Installation
10 |
11 | **npm**
12 |
13 | ```sh
14 | npm install -S react-fuzzy-filter
15 | ```
16 |
17 | **yarn**
18 |
19 | ```sh
20 | yarn add react-fuzzy-filter
21 | ```
22 |
23 | ## Example Usage
24 |
25 | The default export of ReactFuzzyFilter is a factory function that returns two components, `InputFilter` and `FilterResults`. `FilterResults` receives the data typed into the `InputFilter` and uses it to fuzzy filter matches in its items. Each item is then rendered via a custom render function. Each invocation of the factory function creates two new "linked" components that can be used anywhere. The components do not need to live in the same component or part of the page.
26 |
27 | ```js
28 | import React, { Component } from "react";
29 | import fuzzyFilterFactory, { onChangeInputValue } from "react-fuzzy-filter";
30 |
31 | // these components share state and can even live in different components
32 | const { InputFilter, FilterResults, changeInputValue } = fuzzyFilterFactory();
33 |
34 | class MyComponent extends Component {
35 | render() {
36 | const items = [
37 | { name: "first", meta: "first|123", tag: "a" },
38 | { name: "second", meta: "second|443", tag: "b" },
39 | { name: "third", meta: "third|623", tag: "a" },
40 | ];
41 | const fuseConfig = {
42 | keys: ["meta", "tag"],
43 | };
44 | const setInputText = () => onChangeInputValue("hello");
45 | return (
46 |