Commit 8b2ee742 authored by Julien Bouquillon's avatar Julien Bouquillon 🐫

feat: allow sentences diff

parent af05de41
// adapted from https://github.com/davidmason/react-stylable-diff/blob/master/lib/react-diff.js
import React from "react";
import React, { useState, useMemo } from "react";
import jsdiff from "diff";
const fnMap = {
......@@ -11,7 +11,11 @@ const fnMap = {
};
export const Diff = ({ style, className, type, inputA, inputB }) => {
const diff = fnMap[type](inputA, inputB);
const [mode, setMode] = useState(type)
const diff = fnMap[mode](inputA, inputB);
const groupName = useMemo(() => Math.random())
const result = diff.map((part, index) => {
if (part.added) {
return <ins key={index}>{part.value}</ins>;
......@@ -23,6 +27,11 @@ export const Diff = ({ style, className, type, inputA, inputB }) => {
});
return (
<div style={style} className={className}>
<div style={{marginBottom:20}}>
Diff mode :
<input type="radio" name={groupName} onClick={() => setMode("words")} style={{marginLeft:10}} checked={mode==="words"}/> Mots
<input type="radio" name={groupName} onClick={() => setMode("sentences")} style={{marginLeft:10}} checked={mode==="sentences"}/> Phrases
</div>
{result}
</div>
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment