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 57 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
52 changes: 28 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,35 @@ const APACHE_2_0_LICENSE_HEADER = `
`;

module.exports = {
parser: "@typescript-eslint/parser",
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true
}
jsx: true,
},
},
settings: {
"import/resolver": {
node: {
extensions: [".ts", ".tsx", ".js", ".json"]
'import/resolver': {
node: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
webpack: {
config: "./src-docs/webpack.config.js"
}
config: './src-docs/webpack.config.js',
},
},
react: {
version: "detect"
}
version: 'detect',
},
},
extends: [
"@elastic/eslint-config-kibana",
"plugin:@typescript-eslint/recommended",
'@elastic/eslint-config-kibana',
'plugin:@typescript-eslint/recommended',
// Prettier options need to come last, in order to override other style
// rules.
"prettier/react",
"prettier/standard",
"plugin:prettier/recommended"
],
plugins: [
"jsx-a11y",
"prettier",
"local",
"react-hooks"
'prettier/react',
'prettier/standard',
'plugin:prettier/recommended',
],
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'],
rules: {
"prefer-template": "error",
"local/i18n": "error",
Expand All @@ -67,7 +62,6 @@ module.exports = {
],
"no-use-before-define": "off",
"quotes": ["warn", "single", "avoid-escape"],

"jsx-a11y/accessible-emoji": "error",
"jsx-a11y/alt-text": "error",
"jsx-a11y/anchor-has-content": "error",
Expand Down Expand Up @@ -118,6 +112,16 @@ module.exports = {
"@typescript-eslint/no-inferrable-types": "off",
},
env: {
jest: true
}
jest: true,
},
overrides: [
{
files: ['*.d.ts'],
rules: {
'react/no-multi-comp': 'off',
'react/prefer-es6-class': 'off',
'react/prefer-stateless-function': 'off',
cchaos marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
};
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `25.0.0`.
- Added `EuiTextDiff` component ([#3288](https://github.com/elastic/eui/pull/3288))
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

## [`25.0.0`](https://github.com/elastic/eui/tree/v25.0.0)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
4 changes: 4 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ import { TableInMemoryExample } from './views/tables/tables_in_memory_example';

import { TabsExample } from './views/tabs/tabs_example';

import { TextDiffExample } from './views/text_diff/text_diff_example';

import { TextExample } from './views/text/text_example';

import { TitleExample } from './views/title/title_example';
Expand Down Expand Up @@ -383,6 +385,7 @@ const navigation = [
LoadingExample,
ProgressExample,
StatExample,

TextExample,
TitleExample,
ToastExample,
Expand Down Expand Up @@ -444,6 +447,7 @@ const navigation = [
PrettyDurationExample,
ResizeObserverExample,
ResponsiveExample,
TextDiffExample,
ToggleExample,
WindowEventExample,
].map(example => createExample(example)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const PrefixSufixHtml = renderToHtml(PrefixSufix);
const prefixSuffixSnippet = " htmlIdGenerator('prefix')('suffix')";

export const HtmlIdGeneratorExample = {
title: 'HTML ID Generator',
title: 'HTML ID generator',
sections: [
{
source: [
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/overlay_mask/overlay_mask_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const overlayMaskSnippet = `<EuiOverlayMask>
</EuiOverlayMask>`;

export const OverlayMaskExample = {
title: 'Overlay Mask',
title: 'Overlay mask',
sections: [
{
source: [
Expand Down
7 changes: 7 additions & 0 deletions src-docs/src/views/text_diff/props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { FunctionComponent } from 'react';

import { EuiTextDiffProps } from '../../../../src/components/text_diff';

export const useEuiTextDiffProp: FunctionComponent<EuiTextDiffProps> = () => {
return <div />;
};
49 changes: 49 additions & 0 deletions src-docs/src/views/text_diff/text_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useState, useEffect } from 'react';

import {
useEuiTextDiff,
EuiCode,
EuiSpacer,
EuiTextColor,
EuiText,
} from '../../../../src/components';

export default () => {
const [del, setDel] = useState(0);
const [ins, setIns] = useState(0);

const beforeText =
'Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue green planet whose ape- descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.';
const afterText =
'Orbiting those at a distance of roughly ninety-nine billion yards is not insignificant dwaf red green planet whose ape- ascended life forms are so amazingly primitive that they still think digital clocks are a pretty neat idea.';

const [rendered, textDiffObject] = useEuiTextDiff({
beforeText,
afterText,
});

useEffect(() => {
textDiffObject.forEach(el => {
if (el[0] === 1) {
setIns(add => add + 1);
} else if (el[0] === -1) {
setDel(sub => sub + 1);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
<EuiText>
<p>{rendered}</p>
</EuiText>
<EuiSpacer />
<EuiCode>
<EuiTextColor color="secondary"> {ins} </EuiTextColor> Insertions,
<EuiTextColor color="danger"> {del} </EuiTextColor>
Deletions
</EuiCode>
</>
);
};
22 changes: 22 additions & 0 deletions src-docs/src/views/text_diff/text_diff_custom_components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

import { useEuiTextDiff, EuiCodeBlock } from '../../../../src/components';

export default () => {
const beforeText =
'Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue green planet whose ape- descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.';
const afterText =
'Orbiting those at a distance of roughly ninety-nine billion yards is not insignificant dwaf red green planet whose ape- ascended life forms are so amazingly primitive that they still think digital clocks are a pretty neat idea.';
const [rendered] = useEuiTextDiff({
beforeText,
afterText,
insertComponent: 'strong',
deleteComponent: 's',
});

return (
<EuiCodeBlock fontSize="m" paddingSize="m">
{rendered}
</EuiCodeBlock>
);
};
108 changes: 108 additions & 0 deletions src-docs/src/views/text_diff/text_diff_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React from 'react';
import { Link } from 'react-router-dom';

import { renderToHtml } from '../../services';

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

import { EuiCode } from '../../../../src/components';
import { useEuiTextDiffProp } from './props';
import TextDiff from './text_diff';
const textDiffSource = require('!!raw-loader!./text_diff');
const textDiffHtml = renderToHtml(TextDiff);

import TextDiffCustomComponents from './text_diff_custom_components';
const customComponentsSource = require('!!raw-loader!./text_diff_custom_components');
const customComponentsHtml = renderToHtml(TextDiffCustomComponents);

export const TextDiffExample = {
title: 'Text diff',
isNew: true,
sections: [
{
source: [
{
type: GuideSectionTypes.JS,
code: textDiffSource,
},
{
type: GuideSectionTypes.HTML,
code: textDiffHtml,
},
],
text: (
<>
<p>
The hook, <strong>useEuiTextDiff</strong>, generates a set of
changes between two strings. It returns both React elements for
displaying the diff and an object representing the identified
changes. The <EuiCode>timeout</EuiCode> prop is used to set how many
seconds any diff&apos;s exploration phase may take. The default
value is 0.1, a value of 0 disables the timeout and lets diff run
until completion. The higher the timeout, the more detailed the
comparison.
</p>
<p>
<EuiCode language="tsx">
{
'const [rendered, textDiffObject] = useEuiTextDiff({ beforeText, afterText })'
}
</EuiCode>
</p>
</>
),
demo: <TextDiff />,
props: { useEuiTextDiffProp },
snippet: `const [rendered, textDiffObject] = useEuiTextDiff({ beforeText, afterText })

<EuiText><p>{rendered}</p></EuiText>`,
},
{
title: 'Custom rendered elements',
source: [
{
type: GuideSectionTypes.JS,
code: customComponentsSource,
},
{
type: GuideSectionTypes.HTML,
code: customComponentsHtml,
},
],
text: (
<>
<p>
By default, the hook will wrap deletions with{' '}
<EuiCode>{'<del>'}</EuiCode> and insertions with{' '}
<EuiCode>{'<ins>'}</EuiCode> elements. You can replace these
elements with the <EuiCode>deleteComponent</EuiCode> and{' '}
<EuiCode>insertComponent</EuiCode>
props respectively.
</p>
<p>
Also, since <EuiCode>rendered</EuiCode> is simple html string, you
can wrap it in any contextual element like{' '}
<Link to="/display/text">
<strong>EuiText</strong>
</Link>{' '}
or{' '}
<Link to="/display/code">
<strong>EuiCodeBlock</strong>
</Link>
.
</p>
</>
),
demo: <TextDiffCustomComponents />,
snippet: `const [rendered] = useEuiTextDiff({
beforeText,
afterText,
insertComponent: 'strong',
});

<EuiCodeBlock fontSize="m" paddingSize="m">
{rendered}
</EuiCodeBlock>`,
},
],
};
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ export { EuiTab, EuiTabs, EuiTabbedContent } from './tabs';

export { EuiText, EuiTextColor, EuiTextAlign } from './text';

export { useEuiTextDiff } from './text_diff';

export { EuiTitle } from './title';

export { EuiGlobalToastList, EuiGlobalToastListItem, EuiToast } from './toast';
Expand Down
1 change: 1 addition & 0 deletions src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
@import 'suggest/index';
@import 'table/index';
@import 'tabs/index';
@import 'text_diff/index';
@import 'title/index';
@import 'toast/index';
@import 'token/index';
Expand Down
Loading