Skip to content

Commit 8577f01

Browse files
committed
feat(scroll in sync): added ability to toggle in sync scroll
1 parent 8b94c0d commit 8577f01

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

components/RTStickyCopyButton.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'bg-gray-100 dark:bg-gray-600': !copied,
77
'bg-green-500': copied,
88
}"
9+
:aria-label="ariaLabel"
910
@click="handleClick"
1011
>
1112
<svg
@@ -49,6 +50,10 @@ export default {
4950
type: Function,
5051
default: () => {},
5152
},
53+
ariaLabel: {
54+
type: String,
55+
default: 'Copy to clipboard',
56+
},
5257
},
5358
data() {
5459
return {

components/navbar.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</div>
4747

4848
<div class="flex items-center justify-between flex-1">
49-
<div class="items-center">
49+
<div class="items-center w-1/2">
5050
<a
5151
href="https://github.com/technikhil314/offline-diff-viewer/stargazers"
5252
title="github stars on this open source project"
@@ -58,15 +58,16 @@
5858
</a>
5959
<slot name="left" />
6060
</div>
61-
<div class="items-center">
61+
<div class="flex items-center justify-end w-1/2 gap-4">
6262
<slot name="right" />
6363
<button
6464
type="button"
6565
class="inline-flex items-center justify-center ml-4 bg-transparent border-2 border-gray-700 rounded-full shadow-lg w-9 h-9 active:scale-y-75"
66+
aria-label="Toggle Dark Mode"
6667
@click="toggleDarkMode"
6768
>
6869
<svg
69-
v-if="!darkMode"
70+
v-if="darkMode"
7071
fill="none"
7172
stroke="currentColor"
7273
class="w-6 h-6"
@@ -81,7 +82,7 @@
8182
></path>
8283
</svg>
8384
<svg
84-
v-if="darkMode"
85+
v-if="!darkMode"
8586
fill="none"
8687
class="w-6 h-6"
8788
stroke="currentColor"

pages/index.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
placeholder="Add label to this text block"
2525
value="Original Text"
2626
/>
27+
<span class="sr-only"
28+
>Add label to this original text bloack</span
29+
>
2730
</label>
2831
<textarea
2932
id="lhs"
@@ -33,14 +36,19 @@
3336
></textarea>
3437
</div>
3538
<div class="flex flex-col w-1/2 gap-4">
36-
<input
37-
id="rhsLabel"
38-
name="rhsLabel"
39-
type="text"
40-
class="flex-1 flex-grow-0 w-full bg-transparent rounded-md"
41-
placeholder="Add label to this text block"
42-
value="Changed text"
43-
/>
39+
<label for="lhsLabel" class="relative">
40+
<input
41+
id="rhsLabel"
42+
name="rhsLabel"
43+
type="text"
44+
class="flex-1 flex-grow-0 w-full bg-transparent rounded-md"
45+
placeholder="Add label to this text block"
46+
value="Changed text"
47+
/>
48+
<span class="sr-only"
49+
>Add label to this original text bloack</span
50+
>
51+
</label>
4452
<textarea
4553
id="rhs"
4654
rows="28"
@@ -52,6 +60,7 @@
5260
<div class="self-end flex-grow-0 w-full text-center">
5361
<button
5462
class="inline-flex items-center justify-center w-48 px-4 py-2 transition-transform transform bg-blue-600 rounded-md shadow-lg outline-none text-gray-50 focus:ring-4 active:scale-y-75"
63+
aria-label="Click here to compare the inputted text blocks"
5564
>
5665
Compare
5766
</button>

pages/v1/diff.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
<div class="page-contents">
33
<Navbar :show-back-button="true">
44
<template #right>
5+
<div class="inline-flex items-center gap-1">
6+
<label for="toggleScrollInSync" class="select-none"
7+
>Scroll in sync</label
8+
>
9+
<input
10+
id="toggleScrollInSync"
11+
type="checkbox"
12+
:checked="scrollInSync"
13+
class="form-checkbox filter mix-blend-luminosity"
14+
@click="toggleInSyncScroll"
15+
/>
16+
</div>
517
<button
618
type="button"
719
class="inline-flex justify-center px-4 py-2 transition-transform transform rounded-md shadow outline-none copy-uri-button align-center focus:ring-4 active:scale-y-75"
20+
aria-label="Copy url to clipboard"
821
:class="{
922
'bg-blue-500 text-white': !copied,
1023
'bg-green-500 text-gray-800': copied,
@@ -57,9 +70,15 @@
5770
{{ lhsLabel }}
5871
</p>
5972
<div
60-
class="relative flex-1 px-4 py-2 overflow-y-auto border-2 rounded-md dark:border-gray-500 max-h-screen--nav line-number-gutter min-h-80"
73+
class="relative flex-1 px-4 py-2 border-2 rounded-md dark:border-gray-500 line-number-gutter min-h-80"
74+
:class="{
75+
'overflow-y-auto max-h-screen--nav': !scrollInSync,
76+
}"
6177
>
62-
<RTStickyCopyButton :click-handler="copyTextToClipboard" />
78+
<RTStickyCopyButton
79+
:aria-label="'Copy the content to clipboard'"
80+
:click-handler="copyTextToClipboard"
81+
/>
6382
<div
6483
v-for="(lineDiff, index) in lhsDiff"
6584
:key="index"
@@ -71,15 +90,20 @@
7190
</div>
7291
</div>
7392
</div>
74-
7593
<div class="flex flex-col w-1/2 gap-2">
7694
<p class="flex-grow-0 text-lg font-bold text-center capitalize">
7795
{{ rhsLabel }}
7896
</p>
7997
<div
80-
class="relative flex-1 px-4 py-2 overflow-y-auto border-2 rounded-md dark:border-gray-500 min-h-80 line-number-gutter max-h-screen--nav"
98+
class="relative flex-1 px-4 py-2 border-2 rounded-md dark:border-gray-500 line-number-gutter min-h-80"
99+
:class="{
100+
'overflow-y-auto max-h-screen--nav': !scrollInSync,
101+
}"
81102
>
82-
<RTStickyCopyButton :click-handler="copyTextToClipboard" />
103+
<RTStickyCopyButton
104+
:click-handler="copyTextToClipboard"
105+
:aria-label="'Copy the content to clipboard'"
106+
/>
83107
<div
84108
v-for="(lineDiff, index) in rhsDiff"
85109
:key="index"
@@ -109,6 +133,7 @@ export default {
109133
rhsLabel: this.rhsLabel,
110134
lhsLabel: this.lhsLabel,
111135
copied: false,
136+
scrollInSync: this.scrollInSync,
112137
}
113138
},
114139
mounted() {
@@ -118,6 +143,7 @@ export default {
118143
const { diff, lhsLabel, rhsLabel } = diffData
119144
this.lhsLabel = lhsLabel
120145
this.rhsLabel = rhsLabel
146+
this.scrollInSync = true
121147
this.lhsDiff = diff
122148
.map((item) => {
123149
const hunkState = item[0]
@@ -197,6 +223,9 @@ export default {
197223
'Text copied to your clipboard'
198224
)
199225
},
226+
toggleInSyncScroll() {
227+
this.scrollInSync = !this.scrollInSync
228+
},
200229
},
201230
}
202231
</script>

0 commit comments

Comments
 (0)