Skip to content

Commit 7b12675

Browse files
committed
feat: added comparator diff component
1 parent 7d6e3f8 commit 7b12675

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/components/ComparatorDiff.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as Diff from "diff";
2+
import "../styles/ComparatorDiff.css";
3+
4+
type Props = {
5+
previous: string;
6+
current: string;
7+
};
8+
9+
export const ComparatorDiff = (props: Props) => {
10+
const diff = Diff.diffWordsWithSpace(props.previous, props.current);
11+
return (
12+
<>
13+
{diff.map((part: any, i: number) => (
14+
<span
15+
key={`${part.value}-${i}`}
16+
className={
17+
part.added ? "text-addition" : part.removed ? "text-removal" : ""
18+
}
19+
>
20+
{part.value}
21+
</span>
22+
))}
23+
</>
24+
);
25+
};

src/styles/ComparatorDiff.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.text-addition {
2+
background-color: #acf2bd;
3+
}
4+
5+
.text-removal {
6+
background-color: #fdb8c0;
7+
text-decoration: line-through;
8+
text-decoration-thickness: -2px;
9+
}

0 commit comments

Comments
 (0)