diff --git a/types/react-highlight-words/index.d.ts b/types/react-highlight-words/index.d.ts index 669a600dc9..de71c72c17 100644 --- a/types/react-highlight-words/index.d.ts +++ b/types/react-highlight-words/index.d.ts @@ -1,34 +1,55 @@ -// Type definitions for react-highlight-words 0.6 +// Type definitions for react-highlight-words 0.11 // Project: https://github.com/bvaughn/react-highlight-words#readme // Definitions by: Mohamed Hegazy +// Diogo CorrĂȘa // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 import * as React from "react"; -export = Highlighter; - interface HighlighterProps { - /** Escape characters which are meaningful in regular expressions */ - autoEscape?: boolean; - /** Escape characters which are meaningful in regular expressions */ + /** The class name to be applied to an active match. Use along with activeIndex */ activeClassName?: string; /** Specify the match index that should be actively highlighted. Use along with activeClassName */ activeIndex?: string; + /** The inline style to be applied to an active match. Use along with activeIndex */ + activeStyle?: React.CSSProperties; + /** Escape characters in searchWords which are meaningful in regular expressions */ + autoEscape?: boolean; + /** CSS class name applied to the outer/wrapper */ + className?: string; + /** Search should be case sensitive; defaults to false */ + caseSensitive?: boolean; + /** + * Use a custom function to search for matching chunks. This makes it possible to use arbitrary logic + * when looking for matches. See the default findChunks function in highlight-words-core for signature. + * Have a look at the custom findChunks example on how to use it. + */ + findChunks?: () => void; /** CSS class name applied to highlighted text */ highlightClassName?: string; /** Inline styles applied to highlighted text */ - highlightStyle?: any; - /** Type of tag to wrap around highlighted matches; defaults to mark */ + highlightStyle?: React.CSSProperties; + /** + * Type of tag to wrap around highlighted matches; defaults to mark but can also be a React element + * (class or functional) + */ highlightTag?: string; - /** Process each search word and text to highlight before comparing (eg remove accents); signature (text: string): string */ - sanitize?(text: string): string; - /** Array of search words */ + /** + * Process each search word and text to highlight before comparing (eg remove accents); signature + * (text: string): string + */ + sanitize?: (text: string) => string; + /** Array of search words. The search terms are treated as RegExps unless autoEscape is set. */ searchWords: string[]; /** Text to highlight matches in */ textToHighlight: string; + /** CSS class name applied to unhighlighted text */ + unhighlightClassName?: string; + /** Inline styles applied to unhighlighted text */ + unhighlightStyle?: React.CSSProperties; } -declare class Highlighter extends React.Component { - static propTypes: any; -} +declare class Highlighter extends React.Component {} + +export default Highlighter; diff --git a/types/react-highlight-words/react-highlight-words-tests.tsx b/types/react-highlight-words/react-highlight-words-tests.tsx index a63e9b877b..11b1e79137 100644 --- a/types/react-highlight-words/react-highlight-words-tests.tsx +++ b/types/react-highlight-words/react-highlight-words-tests.tsx @@ -1,8 +1,32 @@ import * as React from "react"; -import Highlighter = require("react-highlight-words"); +import Highlighter from "react-highlight-words"; -; +class HighlighterTest extends React.Component { + render() { + return ( +
+ + {}} + highlightClassName="highlightClassName" + highlightStyle={{ color: "red" }} + highlightTag="span" + sanitize={(text: string) => text} + searchWords={["el", "or"]} + textToHighlight="Hello World" + unhighlightClassName="unhighlightClassName" + unhighlightStyle={{ color: "red" }} + /> +
+ ); + } +} diff --git a/types/react-highlight-words/tsconfig.json b/types/react-highlight-words/tsconfig.json index 1617289fa7..96ae2a73a9 100644 --- a/types/react-highlight-words/tsconfig.json +++ b/types/react-highlight-words/tsconfig.json @@ -1,5 +1,10 @@ { + "files": [ + "index.d.ts", + "react-highlight-words-tests.tsx" + ], "compilerOptions": { + "jsx": "react", "module": "commonjs", "lib": [ "es6", @@ -14,12 +19,7 @@ "../" ], "types": [], - "jsx": "react", "noEmit": true, "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "react-highlight-words-tests.tsx" - ] -} \ No newline at end of file + } +}