Skip to content

UI fixes, added prefix argument to onLineNumberClick #5

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

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ examples
test
*.svg
src
/.github
/.storybook
/.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br/>

[![Build Status](https://travis-ci.com/praneshr/react-diff-viewer.svg?branch=master)](https://travis-ci.com/praneshr/react-diff-viewer)
[![npm version](https://badge.fury.io/js/%40chunxei%2Freact-diff-viewer.svg)](https://badge.fury.io/js/%40chunxei%2Freact-diff-viewer.svg)
[![npm version](https://badge.fury.io/js/%40chunxei%2Freact-diff-viewer.svg)](https://badge.fury.io/js/%40chunxei%2Freact-diff-viewer)
[![GitHub license](https://img.shields.io/github/license/Chunxei/react-diff-viewer)](https://github.com/chunxei/react-diff-viewer/blob/master/LICENSE)

**NOTE: This is a fork of Pranesh Ravi's [react-diff-viewer](https://github.com/praneshr/react-diff-viewer) with added hooks and features that allow for more fluid multilline selection and enable commenting.**
Expand Down
10 changes: 6 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface ReactDiffViewerProps {
onLineNumberClick?: (
lineId: string,
isNewSelection: boolean,
prefix: string,
event: React.MouseEvent<HTMLTableCellElement>,
) => void;
// Comments for the left and right panels
Expand Down Expand Up @@ -299,7 +300,7 @@ ReactDiffViewerState
*
* @param id Line id of a line.
*/
private onLineNumberClickProxy = (id: string): any => {
private onLineNumberClickProxy = (id: string, prefix: string): any => {
if (this.props.onLineNumberClick) {
return (e: any): void => {
const {
Expand All @@ -316,7 +317,7 @@ ReactDiffViewerState
});

const isNewSelection = !highlightLines.includes(id);
onLineNumberClick(id, isNewSelection, e);
onLineNumberClick(id, isNewSelection, prefix, e);
}
};
}
Expand Down Expand Up @@ -488,7 +489,7 @@ ReactDiffViewerState
{!this.props.hideLineNumbers && (
<td
onClick={lineNumber && canSelectLines[prefix]
? this.onLineNumberClickProxy(lineNumberTemplate)
? this.onLineNumberClickProxy(lineNumberTemplate, prefix)
: (): void => {}
}
onMouseEnter={lineNumber && canSelectLines[prefix]
Expand Down Expand Up @@ -526,6 +527,7 @@ ReactDiffViewerState
onClick={additionalLineNumber && canSelectLines[prefix]
? this.onLineNumberClickProxy(
additionalLineNumberTemplate,
additionalPrefix,
)
: (): void => {}
}
Expand Down Expand Up @@ -592,7 +594,7 @@ ReactDiffViewerState
)}

<button
className={cn(this.styles.clearHighlightButton)}
className={cn(this.styles.addCommentButton, this.styles.clearHighlightButton)}
onClick={onClearHighlights}
>
Clear
Expand Down
17 changes: 12 additions & 5 deletions src/stories/DiffViewer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const comments = {
isUrgent: true,
target: {
createdAt: '2021-07-09T14:36:49.542Z',
description: 'line-1,line-2,line-3,line-4',
description: 'line-2,line-3,line-4',
id: '60e85bc129eea948453cd3ad',
type: 'code-fragment',
updatedAt: '2021-07-09T14:36:49.542Z',
Expand All @@ -43,7 +43,7 @@ const comments = {
subscribed: [] as Record<string, any>[],
target: {
createdAt: '2021-07-09T14:36:49.542Z',
description: 'line-3,line-4',
description: 'line-2,line-4',
id: '60e85bc129eea948453cd3ad',
type: 'code-fragment',
updatedAt: '2021-07-09T14:36:49.542Z',
Expand All @@ -63,13 +63,13 @@ const comments = {
comment: "* check's pulse *",
createdAt: '2021-07-09T14:36:49.542Z',
module: '60e859d3b267df4bc3c6159d',
replies: [1,2,3],
replies: [1, 2, 3],
resolved: false,
subscribed: [] as Record<string, any>[],
isUrgent: true,
target: {
createdAt: '2021-07-09T14:36:49.542Z',
description: 'line-3,line-4',
description: 'line-1,line-3,line-4',
id: '60e85bc129eea948453cd3ad',
type: 'code-fragment',
updatedAt: '2021-07-09T14:36:49.542Z',
Expand All @@ -94,7 +94,7 @@ const comments = {
subscribed: [] as Record<string, any>[],
target: {
createdAt: '2021-07-09T14:36:49.542Z',
description: 'line-3,line-4',
description: 'line-1',
id: '60e85bc129eea948453cd3ad',
type: 'code-fragment',
updatedAt: '2021-07-09T14:36:49.542Z',
Expand Down Expand Up @@ -237,9 +237,14 @@ if(a === 10) {
}
`;

const leftTitle = 'Left Title';
const rightTitle = 'Right Title';

SplitView.args = {
oldValue: oldCode,
newValue: newCode,
leftTitle,
rightTitle,
splitView: true,
canSelectLines: {
L: false,
Expand All @@ -250,6 +255,8 @@ SplitView.args = {
InlineView.args = {
oldValue: oldCode,
newValue: newCode,
leftTitle,
rightTitle,
splitView: false,
canSelectLines: {
L: false,
Expand Down
40 changes: 24 additions & 16 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export default (

const variables = useDarkTheme ? themeVariables.dark : themeVariables.light;

const interpolateClassname = (classname: string): string => `.${classname}`;

const content = css({
position: 'relative',
width: '100%',
Expand Down Expand Up @@ -411,7 +413,6 @@ export default (
});

const clearHighlightButton = css`
${addCommentButton};
label: clear-highlight-button;
background: #de3838;
&:hover {
Expand All @@ -429,14 +430,15 @@ export default (
display: flex;
justify-content: center;
align-items: center;
height: min(100%, 25px);
min-width: 30px;
height: min(100%, 20px);
min-width: 25px;
font-family: Monospace, sans-serif;
font-size: 10px;
color: #fff;
border: none;
background: #00a4db;
opacity: 0.7;
background: rgba(0, 164, 219, 0.7);
opacity: 1;
//opacity: 0.7;
border-radius: 5px;
padding: 0 5px;
cursor: pointer;
Expand All @@ -462,16 +464,21 @@ export default (
}

&:hover {
opacity: 1 !important;
//opacity: 1 !important;
background: rgb(0, 164, 219);
}

&:focus {
outline: 0;
}

&._urgent {
font-weight: 700;
background: red;
background: rgba(255, 0, 0, 0.7);
&:hover {
//opacity: 1 !important;
background: rgba(255, 0, 0, 1);
}
}
`;

Expand All @@ -492,28 +499,29 @@ export default (
transition: 0.2s;

&._stacked {
.${viewCommentButton} {
${interpolateClassname(viewCommentButton)} {
&:last-of-type {
//border-top-right-radius: 5px;
//border-bottom-right-radius: 5px;
//box-shadow: -2px -2px 0 rgba(17, 65, 82, 0.7), -4px -4px 0 rgba(17, 65, 82, 0.7);
&::after {
z-index: 9;
position: absolute;
right: 0;
bottom: -7px;
bottom: -6px;
content: attr(data-hidden-comments-count);
display: flex;
justify-content: center;
align-items: center;
min-width: 10px;
height: 10px;
height: 9px;
background: #fff;
opacity: 1;
color: #00a4db;
font-size: 8px;
font-weight: 800;
border: 1px solid #00a4db;
border-radius: 2px;
background-color: #fff;
padding: 0 2px;
transform: translateX(0);
transition: 0.2s;
Expand All @@ -522,7 +530,7 @@ export default (
}

&._urgent {
.${viewCommentButton} {
${interpolateClassname(viewCommentButton)} {
&:last-of-type {
&::after {
color: red;
Expand All @@ -534,10 +542,10 @@ export default (
}

&:hover {
.${viewCommentButton} {
${interpolateClassname(viewCommentButton)} {
//display: flex;
position: relative;
opacity: 0.7;
opacity: 1;
pointer-events: all;
transform: translateX(0);

Expand Down