zim-fuzzysearch
Version:
Client side fuzzy search combined with seperate configurable result highlighting.
14 lines (13 loc) • 1.36 kB
JavaScript
import React from "react";
var FuzzyInputCtx = React.createContext(null);
export var FuzzyInputProvider = function (_a) {
var inputVal = _a.inputVal, placeHolder = _a.placeHolder, clickMode = _a.clickMode, handleInput = _a.handleInput, doSearch = _a.doSearch, data = _a.data, onSearch = _a.onSearch, toggleFuseKey = _a.toggleFuseKey, fuseKeyMap = _a.fuseKeyMap, fuseKeyAllLabel = _a.fuseKeyAllLabel, fuseStateOptions = _a.fuseStateOptions, setSelTag = _a.setSelTag, suggestions = _a.suggestions, children = _a.children;
if (!FuzzyInputCtx)
throw new ReferenceError("FuzzyIinput context validated false. There must be an error inside the useFuzzyInput custom hook");
return (React.createElement(FuzzyInputCtx.Provider, { value: { inputVal: inputVal, clickMode: clickMode, doSearch: doSearch, handleInput: handleInput, placeHolder: placeHolder, onSearch: onSearch, data: data, fuseKeyMap: fuseKeyMap, fuseKeyAllLabel: fuseKeyAllLabel, fuseStateOptions: fuseStateOptions, toggleFuseKey: toggleFuseKey, setSelTag: setSelTag, suggestions: suggestions } }, children));
};
export var useFuzzyInput = function () {
if (!FuzzyInputCtx)
throw new ReferenceError("FuzzyInputCtx is still null. Make sure to call the correct FuzzyInputProvider somewhere in the parent components.");
return React.useContext(FuzzyInputCtx);
};