@@ -14,4 +14,52 @@ export const CompareText = () => {
14
14
)
15
15
}
16
16
```
17
+ ## Customizing the ` useTextComparison ` Hook
18
+ The ` useTextComparison ` hook now allows you to customize the colors used to highlight common, removed, and added words when comparing two texts.
17
19
20
+ ``` js
21
+ import { useTextComparison } from ' text-compare' ;
22
+
23
+ const TextDiffer = () => {
24
+ const text1 = ' The quick brown fox jumps over the lazy dog' ;
25
+ const text2 = ' The quick blue fox leaps over the happy dog' ;
26
+
27
+ // Define custom colors for comparison
28
+ const customColors = {
29
+ commonColor: ' #1E90FF' , // DodgerBlue for common words
30
+ removedColor: ' #FF6347' , // TomatoRed for removed words
31
+ addedColor: ' #32CD32' , // LimeGreen for added words
32
+ };
33
+
34
+ // Pass custom colors to the hook
35
+ const { comparisonResult , similarity } = useTextComparison (text1, text2, customColors);
36
+
37
+ return (
38
+ < div>
39
+ < div className= ' comparison' > {comparisonResult}< / div>
40
+ < div> Similarity: {similarity .toFixed (2 )}% < / div>
41
+ < / div>
42
+ );
43
+ };
44
+
45
+ export default TextDiffer ;
46
+
47
+ ```
48
+
49
+ ## Available Customization Options
50
+ When using the useTextComparison hook, you can pass an optional object to customize the colors:
51
+
52
+ - ** commonColor** (default: "gray"): Color for common words between the two texts.
53
+ - ** removedColor** (default: "red"): Color for words that are in text1 but not in text2.
54
+ - ** addedColor** (default: "green"): Color for words that are in text2 but not in text1.
55
+
56
+ ### Example Customization:
57
+
58
+ ``` js
59
+ const customColors = {
60
+ commonColor: ' #1E90FF' , // DodgerBlue for common words
61
+ removedColor: ' #FF6347' , // TomatoRed for removed words
62
+ addedColor: ' #32CD32' , // LimeGreen for added words
63
+ };
64
+ ```
65
+ These options allow for more flexible styling to match the look and feel of your project.
0 commit comments