Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-highlight-words: Add type information for new unhighlightTag property #69523

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions types/react-highlight-words/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface HighlighterProps {
unhighlightClassName?: string | undefined;
/** Inline styles applied to unhighlighted text */
unhighlightStyle?: React.CSSProperties | undefined;
/**
* Type of tag to wrap around unhighlighted matches; defaults to span but can also be a React element
* (class or functional)
*/
unhighlightTag?: string | React.ComponentType<any> | undefined;
/** Allows to pass through any parameter to wrapped component */
[index: string]: any;
}
Expand Down
2 changes: 1 addition & 1 deletion types/react-highlight-words/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/react-highlight-words",
"version": "0.16.9999",
"version": "0.20.9999",
"projects": [
"https://github.com/bvaughn/react-highlight-words#readme"
],
Expand Down
19 changes: 19 additions & 0 deletions types/react-highlight-words/react-highlight-words-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const findChunks = ({
}: FindChunks) => [];

const CustomHighlight: React.FC<{ children?: React.ReactNode }> = ({ children }) => <span>{children}</span>;
const CustomUnhighlight: React.FC<{ children?: React.ReactNode }> = ({ children }) => <span>{children}</span>;

class HighlighterTest extends React.Component {
render() {
Expand Down Expand Up @@ -41,6 +42,24 @@ class HighlighterTest extends React.Component {
unhighlightClassName="unhighlightClassName"
unhighlightStyle={{ color: "red" }}
/>
<Highlighter
activeClassName="activeClassName"
activeIndex={1}
activeStyle={{ color: "red" }}
autoEscape={true}
className="className"
caseSensitive={true}
findChunks={findChunks}
highlightClassName="highlightClassName"
highlightStyle={{ color: "red" }}
highlightTag={CustomHighlight}
sanitize={(text: string) => text}
searchWords={["el", "or"]}
textToHighlight="Hello World"
unhighlightClassName="unhighlightClassName"
unhighlightStyle={{ color: "red" }}
unhighlightTag={CustomUnhighlight}
/>
</div>
);
}
Expand Down