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

Added useEuiTextDiff hook #3288

Merged
merged 59 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ed16415
Added EuiTextDiff component
anishagg17 Apr 7, 2020
2a84497
fixed sass-linting
anishagg17 Apr 10, 2020
7c553dd
removed unwanted exports
anishagg17 Apr 30, 2020
6c2a4b7
improved Examples, exported all data from component
anishagg17 Apr 30, 2020
ad11dd4
used useMemo
anishagg17 Apr 30, 2020
4be06fd
exported props,used for loop
anishagg17 May 6, 2020
c6cca37
allow user to pass components
anishagg17 May 6, 2020
295375d
yarn.lock updated and deletion component used for example
anishagg17 May 6, 2020
0de0e0b
used id as key, useMemos combined
anishagg17 May 6, 2020
faa8259
removed disableTimeout prop
anishagg17 May 6, 2020
2f798d8
used useMemo for renderedHtml
anishagg17 May 6, 2020
5da5eb8
Changed slider steps to display result
anishagg17 May 7, 2020
5c4e9a7
tranformed to hook
anishagg17 May 7, 2020
d8dca69
removed padding , fontSize controll from euiText
anishagg17 May 7, 2020
5f44db0
removed unnecessay props
anishagg17 May 11, 2020
792775b
used EuiTextDiffProps and removed Funcion def
anishagg17 May 11, 2020
0760d25
used ElementType
anishagg17 May 11, 2020
51a41d5
Used diff inside useMemo
anishagg17 May 11, 2020
cb7f3ef
populated text-diff module defination
anishagg17 May 11, 2020
4fce6e7
Update src-docs/src/views/code/code_example.js
anishagg17 May 12, 2020
c27cc01
used _colors and eui_colors_dark.scss for text diff, changed slider p…
anishagg17 May 12, 2020
126f1f5
valueAppend used
anishagg17 May 12, 2020
3896b5c
more detailed timeout description
anishagg17 May 12, 2020
4869248
insertions/dels are recalculated, improved custom components desc
anishagg17 May 12, 2020
251ac01
console.log removed
anishagg17 May 12, 2020
cc81248
created separate section for text diff
anishagg17 May 12, 2020
8c7e879
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 14, 2020
17bc834
setDel , setIns to zero on value change
anishagg17 May 14, 2020
058309d
Update src-docs/src/views/text_diff/text_diff_timeout.js
anishagg17 May 20, 2020
cb2d2d2
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
b5b9ac3
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
fca53cb
Update src-docs/src/views/text_diff/text_diff_custom_components.js
anishagg17 May 20, 2020
1082578
Update src/components/code/text_diff.tsx
anishagg17 May 20, 2020
0ca7ff3
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
85fc0ec
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
fee4259
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
231bdf7
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
7998222
Update src-docs/src/views/text_diff/text_diff_example.js
anishagg17 May 20, 2020
3220821
updated custom-components name, added clasName prop, updated text for…
anishagg17 May 20, 2020
a17b697
moved to own folder
anishagg17 May 20, 2020
a5c343f
handled props directly
anishagg17 May 20, 2020
bb69275
over rides eslint
anishagg17 May 20, 2020
b43effe
resolved conflicts
anishagg17 May 20, 2020
7f43118
Merge branch 'master' into text
anishagg17 May 20, 2020
a69e4c8
Update .eslintrc.js
anishagg17 May 20, 2020
b135497
added licence
anishagg17 May 21, 2020
833bb0a
used license for all files
anishagg17 May 21, 2020
1b15f0b
removed default wraper from
anishagg17 May 21, 2020
85564c4
removed timeout example
anishagg17 Jun 3, 2020
cbb4308
Some design/docs additions (#11)
cchaos Jun 4, 2020
dd68031
Mt pull mine text
anishagg17 Jun 5, 2020
8904525
Merge branch 'text' of https://github.com/anishagg17/eui into text
anishagg17 Jun 5, 2020
c8ecd82
added test, CL, updated branch
anishagg17 Jun 5, 2020
d9367f9
updated test
anishagg17 Jun 5, 2020
ae5f408
fixed snaps
anishagg17 Jun 5, 2020
04218ea
snaps
anishagg17 Jun 5, 2020
fdf02c8
linting fixed
anishagg17 Jun 5, 2020
bbb5df6
Update CHANGELOG.md
anishagg17 Jun 5, 2020
de94ef8
Merge branch 'master' into text
anishagg17 Jun 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"classnames": "^2.2.5",
"highlight.js": "^9.12.0",
"html": "^1.0.0",
"html-react-parser": "^0.10.3",
"keymirror": "^0.1.1",
"lodash": "^4.17.11",
"numeral": "^2.0.6",
Expand All @@ -69,6 +70,7 @@
"react-virtualized": "^9.21.2",
"resize-observer-polyfill": "^1.5.0",
"tabbable": "^3.0.0",
"text-diff": "^1.0.1",
"uuid": "^3.1.0"
},
"devDependencies": {
Expand Down
54 changes: 53 additions & 1 deletion src-docs/src/views/code/code_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';

import { EuiCode, EuiCodeBlockImpl } from '../../../../src/components';
import {
EuiCode,
EuiCodeBlockImpl,
EuiTextDiff,
} from '../../../../src/components';

import Code from './code';
const codeSource = require('!!raw-loader!./code');
Expand All @@ -23,6 +27,14 @@ import CodeBlockPre from './code_block_pre';
const codeBlockPreSource = require('!!raw-loader!./code_block_pre');
const codeBlockPreHtml = renderToHtml(CodeBlockPre);

import TextDiff from './text_diff';
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const textDiffSource = require('!!raw-loader!./text_diff');
const textDiffHtml = renderToHtml(TextDiff);

import NoDeletion from './text_diff_no_deletions';
const noDeletionSource = require('!!raw-loader!./text_diff_no_deletions');
const noDeletionHtml = renderToHtml(NoDeletion);

export const CodeExample = {
title: 'Code',
sections: [
Expand Down Expand Up @@ -95,5 +107,45 @@ export const CodeExample = {
props: { EuiCodeBlockImpl },
demo: <CodeBlockPre />,
},
{
title: 'Text Diff',
source: [
{
type: GuideSectionTypes.JS,
code: textDiffSource,
},
{
type: GuideSectionTypes.HTML,
code: textDiffHtml,
},
],
text: (
<p>
<strong>EuiTextDiff</strong> is for making text comparisions.
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
</p>
),
demo: <TextDiff />,
props: { EuiTextDiff },
},
{
title: 'Text Diff without deletions',
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
source: [
{
type: GuideSectionTypes.JS,
code: noDeletionSource,
},
{
type: GuideSectionTypes.HTML,
code: noDeletionHtml,
},
],
text: (
<p>
<EuiCode>showDeletion</EuiCode> is used for hiding/showing deletions.
</p>
),
demo: <NoDeletion />,
props: { EuiTextDiff },
},
],
};
23 changes: 23 additions & 0 deletions src-docs/src/views/code/text_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

import { EuiTextDiff } from '../../../../src/components';

export default () => {
const initialText =
'One difference is that interface creates a new name that is used everywhere. Type aliases do create a new name — for instance, error text won’t use the alias name. In the code below, hovering over interfaced in code editor will show that it returns an Interface, but will show that aliased returns object literal type.Wish you happy';
const currentText =
'One difference is that interfaces create a new name that is used everywhere. Type aliases don’t create a new name — for instance, error messages won’t use the alias name. In the code below, hovering over interfaced in an editor will show that it returns an Interface, but will show that aliased returns object literal type.Hope you will be happy every day';

const onGetDataFormat = data => console.log(data);

return (
<EuiTextDiff
fontSize="m"
paddingSize="m"
initialText={initialText}
currentText={currentText}
showDeletion={true}
getDataFormat={onGetDataFormat}
/>
);
};
23 changes: 23 additions & 0 deletions src-docs/src/views/code/text_diff_no_deletions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

import { EuiTextDiff } from '../../../../src/components';

export default () => {
const initialText =
'One difference is that interface creates a new name that is used everywhere. Type aliases do create a new name — for instance, error text won’t use the alias name. In the code below, hovering over interfaced in code editor will show that it returns an Interface, but will show that aliased returns object literal type.Wish you happy';
const currentText =
'One difference is that interfaces create a new name that is used everywhere. Type aliases don’t create a new name — for instance, error messages won’t use the alias name. In the code below, hovering over interfaced in an editor will show that it returns an Interface, but will show that aliased returns object literal type.Hope you will be happy every day';

const onGetDataFormat = data => console.log(data);

return (
<EuiTextDiff
fontSize="m"
paddingSize="m"
initialText={initialText}
currentText={currentText}
showDeletion={false}
getDataFormat={onGetDataFormat}
/>
);
};
6 changes: 4 additions & 2 deletions src/components/code/_code_block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ import { EuiInnerText } from '../inner_text';
import { keysOf } from '../common';
import { FontSize, PaddingSize } from './code';

const fontSizeToClassNameMap = {
export const fontSizeToClassNameMap = {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
s: 'euiCodeBlock--fontSmall',
m: 'euiCodeBlock--fontMedium',
l: 'euiCodeBlock--fontLarge',
};

export const FONT_SIZES = keysOf(fontSizeToClassNameMap);

const paddingSizeToClassNameMap: { [paddingSize in PaddingSize]: string } = {
export const paddingSizeToClassNameMap: {
[paddingSize in PaddingSize]: string
} = {
none: '',
s: 'euiCodeBlock--paddingSmall',
m: 'euiCodeBlock--paddingMedium',
Expand Down
1 change: 1 addition & 0 deletions src/components/code/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'code_block';
@import 'text_diff';
43 changes: 43 additions & 0 deletions src/components/code/_text_diff.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.euiTextDiff {
display: block;
position: relative;
background: $euiCodeBlockBackgroundColor;
color: $euiCodeBlockColor;
box-sizing: border-box;
line-height: $euiLineHeight;
font-size: inherit;
font-family: inherit;
font-weight: $euiFontWeightRegular;

del {
color: $euiColorDanger;
}

ins {
color: $euiColorSecondary;
}
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
}

.euiTextDiff--paddingMedium {
padding: $euiSize;
}

.euiTextDiff--paddingLarge {
padding: $euiSizeL;
}

.euiTextDiff--paddingSmall {
padding: $euiSizeS;
}

.euiTextDiff--fontSmall {
font-size: $euiFontSizeXS;
}

.euiTextDiff--fontMedium {
font-size: $euiFontSizeS;
}

.euiTextDiff--fontLarge {
font-size: $euiFontSize;
}
1 change: 1 addition & 0 deletions src/components/code/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { EuiCode, EuiCodeProps } from './code';
export { EuiCodeBlock, EuiCodeBlockProps } from './code_block';
export { EuiCodeBlockImpl } from './_code_block';
export { EuiTextDiff } from './text_diff';
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/components/code/text-diff.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'text-diff';
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
107 changes: 107 additions & 0 deletions src/components/code/text_diff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { CommonProps } from '../common';

import React, { FunctionComponent, HTMLAttributes } from 'react';
import Diff from 'text-diff';
import classNames from 'classnames';
import parse from 'html-react-parser';
import { FontSize, PaddingSize } from './code';

export const fontSizeToClassNameMap = {
s: 'euiTextDiff--fontSmall',
m: 'euiTextDiff--fontMedium',
l: 'euiTextDiff--fontLarge',
};

export const paddingSizeToClassNameMap: {
[paddingSize in PaddingSize]: string
} = {
none: '',
s: 'euiTextDiff--paddingSmall',
m: 'euiTextDiff--paddingMedium',
l: 'euiTextDiff--paddingLarge',
};

export interface EuiTextDiffSharedProps {
paddingSize?: PaddingSize;

/**
* Sets the syntax highlighting for a specific language
* @see http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html#language-names-and-aliases
* for options
*/
language?: string;
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
overflowHeight?: number;
fontSize?: FontSize;
transparentBackground?: boolean;
isCopyable?: boolean;
}
interface DataFormat {
type: string;
content: any;
}

interface Props extends EuiTextDiffSharedProps {
inline?: true;
fontSize: FontSize;
paddingSize: PaddingSize;
currentText: string;
initialText: string;
showDeletion?: boolean;
getDataFormat?: (data: DataFormat[]) => void;
}

export type EuiTextDiffProps = CommonProps &
Props &
HTMLAttributes<HTMLElement>;

export const EuiTextDiff: FunctionComponent<EuiTextDiffProps> = ({
inline,
fontSize,
paddingSize,
initialText,
currentText,
showDeletion = true,
getDataFormat,
...rest
}) => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const diff = new Diff(); // options may be passed to constructor; see below
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const textDiff = diff.main(initialText, currentText); // produces diff array
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

const dataFormat = () => {
return [...textDiff]
.filter(el => el[0] !== 0)
.map(el => {
if (el[0] === -1) {
return {
type: 'delete',
content: el[1],
};
} else {
return {
type: 'insert',
content: el[1],
};
}
});
};

const classes = classNames(
'euiTextDiff',
fontSizeToClassNameMap[fontSize],
paddingSizeToClassNameMap[paddingSize]
);
let htmlString = diff.prettyHtml(textDiff);
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

if (!showDeletion) {
htmlString = htmlString.replace(/<del>[A-z]*<\/del>/g, '');
}
const rendereredHtml = parse(htmlString);

if (getDataFormat) getDataFormat(dataFormat());
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className={classes} {...rest}>
{rendereredHtml}
</div>
);
};
2 changes: 1 addition & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export { EuiCallOut } from './call_out';

export { EuiCard, EuiCheckableCard } from './card';

export { EuiCode, EuiCodeBlock, EuiCodeBlockImpl } from './code';
export { EuiCode, EuiCodeBlock, EuiCodeBlockImpl, EuiTextDiff } from './code';

export { EuiCodeEditor } from './code_editor';

Expand Down
Loading