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 7 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
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
78 changes: 77 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,18 @@ 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);

import TextDiffTimeOut from './text_diff_timeout';
const TextDiffTimeOutSource = require('!!raw-loader!./text_diff_timeout');
const TextDiffTimeOutHtml = renderToHtml(TextDiffTimeOut);

export const CodeExample = {
title: 'Code',
sections: [
Expand Down Expand Up @@ -95,5 +111,65 @@ 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 },
},
{
title: 'Text Diff with timeout',
source: [
{
type: GuideSectionTypes.JS,
code: TextDiffTimeOutSource,
},
{
type: GuideSectionTypes.HTML,
code: TextDiffTimeOutHtml,
},
],
text: (
<p>
<EuiCode>timeout</EuiCode> is used for setting timeout.
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
</p>
),
demo: <TextDiffTimeOut />,
props: { EuiTextDiff },
},
],
};
42 changes: 42 additions & 0 deletions src-docs/src/views/code/text_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState } from 'react';

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

export default () => {
const [del, setDel] = useState(0);
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const [ins, setIns] = useState(0);

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 => {
setDel([...data].filter(el => el.type === 'delete').length);
setIns([...data].filter(el => el.type === 'insert').length);
};

return (
<>
<EuiTextDiff
fontSize="m"
paddingSize="m"
initialText={initialText}
currentText={currentText}
getDataFormat={onGetDataFormat}
disableTimeout={true}
/>
<EuiSpacer />
<EuiCode>
<EuiTextColor color="secondary"> {ins} </EuiTextColor> Insertions,
<EuiTextColor color="danger"> {del} </EuiTextColor>
Deletions
</EuiCode>
</>
);
};
42 changes: 42 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,42 @@
import React, { useState } from 'react';

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

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

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 => {
setDel([...data].filter(el => el.type === 'delete').length);
setIns([...data].filter(el => el.type === 'insert').length);
};

return (
<>
<EuiTextDiff
fontSize="m"
paddingSize="m"
initialText={initialText}
currentText={currentText}
disableTimeout={true}
getDataFormat={onGetDataFormat}
/>
<EuiSpacer />
<EuiCode>
<EuiTextColor color="secondary">{ins} </EuiTextColor> Insertions,
<EuiTextColor color="danger"> {del} </EuiTextColor>
Deletions
</EuiCode>
</>
);
};
57 changes: 57 additions & 0 deletions src-docs/src/views/code/text_diff_timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from 'react';

import {
EuiTextDiff,
EuiCode,
EuiSpacer,
EuiTextColor,
EuiRange,
} from '../../../../src/components';
import { htmlIdGenerator } from '../../../../src/services';

export default () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example is better served with:

bigger diff, showing the effect of the timeout

import initialText from '!!raw-loader!../../../../src/global_styling/variables/_colors.scss';
import currentText from '!!raw-loader!../../../../src/themes/eui/eui_colors_dark.scss';

more tuned values

  • initial timeout of 0.5
  • timeout range of 0 -> 1 with step of 0.1

example structure
moving the range slider to the top of the example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about using our actual SASS vars to emulate a text diff. I think this could be confusing to users if they don't realize what page they've landed on. I also don't want to misconstrue any actual code that we ship. I'd much rather use fake content here.

We have a large text content block we use in both the scaling and text component docs that we could probably make a global constant for. I'd much rather use those than importing shippable code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make separate file for initialText and currentText specifically for this example ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would probably be fine!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that change is too long; it'd likely cause too much lag while rendering (size of dom updates), and is just lengthy in terms of looking at an example. I'll keep thinking on this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, my current thoughts here are finding the right-sized diff from our JS->TS conversion process. @cchaos if we label the example as such would that work for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think as long as the example has some sort of preamble about showing the diff of a JS to TS conversion, that would be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I thought about it some more. My worry about using any code for any of these examples is that I think consumers will start thinking it should be as robust as a real code diff. Should it indicate white space changes, or look like a code editor with line numbers and such? If we're ok indicating that this could eventually be a full fledged code-diff, that's one thing. Otherwise, I'd stick to simple text.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great, future-thinking point. I'm gonna explore a little bit more before leaving any real thoughts here.

const [del, setDel] = useState(0);
const [ins, setIns] = useState(0);
const [value, setValue] = useState(5);
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 inerfaces 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', data);
setDel([...data].filter(el => el.type === 'delete').length);
setIns([...data].filter(el => el.type === 'insert').length);
};

return (
<>
<EuiTextDiff
fontSize="m"
paddingSize="m"
initialText={initialText}
currentText={currentText}
getDataFormat={onGetDataFormat}
timeout={value}
/>
<EuiSpacer />
<EuiCode>
<EuiTextColor color="secondary">{ins} </EuiTextColor> Insertions,
<EuiTextColor color="danger"> {del} </EuiTextColor>
Deletions
</EuiCode>
<EuiSpacer />
<EuiRange
id={htmlIdGenerator()()}
min={0}
max={20}
value={value}
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
onChange={e => setValue(e.target.value)}
showLabels
showValue
aria-label="An example of EuiRange with showValue prop"
/>
</>
);
};
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, EuiTextDiffProps } from './text_diff';
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
Loading