Skip to content

Commit 0bb66bf

Browse files
committed
Fixing table width on split and inline view
1 parent 75fe855 commit 0bb66bf

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,20 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
523523

524524
const title = (leftTitle || rightTitle)
525525
&& <tr>
526-
<td colSpan={splitView ? 3 : 5} className={this.styles.titleBlock}>{leftTitle}</td>
526+
<td colSpan={splitView ? 3 : 5} className={this.styles.titleBlock}>
527+
<pre className={this.styles.contentText}>
528+
{leftTitle}
529+
</pre>
530+
</td>
527531
{splitView
528-
&& <td colSpan={3} className={this.styles.titleBlock}>{rightTitle}</td>
532+
&& <td colSpan={3} className={this.styles.titleBlock}>
533+
<pre className={this.styles.contentText}>{rightTitle}</pre>
534+
</td>
529535
}
530536
</tr>;
531537

532538
return (
533-
<table className={this.styles.diffContainer}>
539+
<table className={cn(this.styles.diffContainer, { [this.styles.splitView]: splitView })}>
534540
<tbody>
535541
{title}
536542
{nodes}

src/styles.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ReactDiffViewerStyles {
2121
codeFold?: string;
2222
titleBlock?: string;
2323
content?: string;
24+
splitView?: string;
2425
[key: string]: string | undefined;
2526
}
2627

@@ -74,6 +75,7 @@ export interface ReactDiffViewerStylesOverride {
7475
emptyLine?: Interpolation;
7576
content?: Interpolation;
7677
titleBlock?: Interpolation;
78+
splitView?: Interpolation;
7779
}
7880

7981
export default (
@@ -148,6 +150,18 @@ export default (
148150

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

153+
const content = css({
154+
width: '100%',
155+
label: 'content',
156+
});
157+
158+
const splitView = css({
159+
[`.${content}`]: {
160+
width: '50%',
161+
},
162+
label: 'split-view',
163+
});
164+
151165
const diffContainer = css({
152166
width: '100%',
153167
background: variables.diffViewerBackground,
@@ -158,32 +172,30 @@ export default (
158172
},
159173
label: 'diff-container',
160174
borderCollapse: 'collapse',
175+
161176
});
162177

163178
const codeFoldContent = css({
164179
color: variables.codeFoldContentColor,
165180
label: 'code-fold-content',
166181
});
167182

183+
const contentText = css({
184+
color: variables.diffViewerColor,
185+
label: 'content-text',
186+
});
187+
168188
const titleBlock = css({
169-
color: variables.diffViewerTitleColor,
170189
background: variables.diffViewerTitleBackground,
171190
padding: 10,
172191
borderBottom: `1px solid ${variables.diffViewerTitleBorderColor}`,
173192
label: 'title-block',
174193
':last-child': {
175194
borderLeft: `1px solid ${variables.diffViewerTitleBorderColor}`,
176195
},
177-
});
178-
179-
const content = css({
180-
width: '50%',
181-
label: 'content',
182-
});
183-
184-
const contentText = css({
185-
color: variables.diffViewerColor,
186-
label: 'content-text',
196+
[`.${contentText}`]: {
197+
color: variables.diffViewerTitleColor,
198+
},
187199
});
188200

189201
const lineNumber = css({
@@ -260,6 +272,7 @@ export default (
260272
const marker = css({
261273
width: 25,
262274
paddingLeft: 10,
275+
paddingRight: 10,
263276
userSelect: 'none',
264277
label: 'marker',
265278
[`&.${diffAdded}`]: {
@@ -334,6 +347,7 @@ export default (
334347
diffContainer,
335348
diffRemoved,
336349
diffAdded,
350+
splitView,
337351
marker,
338352
highlightedGutter,
339353
highlightedLine,

0 commit comments

Comments
 (0)