Skip to content

Commit f18e9b5

Browse files
committed
feat: added dark mode support
1 parent b076366 commit f18e9b5

File tree

7 files changed

+110
-18
lines changed

7 files changed

+110
-18
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The simplest solution in my opinion will be
3434
In the chase of one such tool I ended up creating one as I did not find any that satisfied my requirements.
3535
This is open source and has very easy user interface. Here is the link to the tool https://diffviewer.vercel.app/
3636
It has following benefits
37+
3738
1. Since the tool does not store your data on its server there is no server required in the tool
3839
2. The tool is blazing fast
3940
3. Most importantly the link can be shared with anyone without security concerns(Unless you share link itself over some insecure network)
@@ -65,3 +66,4 @@ For detailed explanation on how things work, check out the [documentation](https
6566
- [ ] Auto detect language
6667
- [ ] Add small shadow to line numbers
6768
- [x] Fix toast issue. (Click on copy button while toast is on)
69+
- [ ] Handle line gutter issue when last line in data is empty

components/RTStickyCopyButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@click="handleClick"
55
class="absolute top-0 right-0 p-2 transition-all transform rounded-full shadow z-1 hover:shadow-lg hover:scale-110 hover:rotate-12"
66
v-bind:class="{
7-
'bg-gray-100': !copied,
7+
'bg-gray-100 dark:bg-gray-600': !copied,
88
'bg-green-500': copied,
99
}"
1010
>

components/navbar.vue

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<template>
2-
<header class="fixed top-0 left-0 right-0 shadow-lg bg-gray-50 z-100">
2+
<header
3+
class="fixed top-0 left-0 right-0 shadow-lg dark:shadow-dark bg-gray-50 dark:bg-gray-900 z-100 dark:text-gray-50"
4+
>
35
<div class="container flex items-center h-full py-4 m-auto">
46
<div v-if="showBackButton" class="mr-4">
57
<NuxtLink to="/">
@@ -24,7 +26,9 @@
2426
<svg
2527
height="40px"
2628
width="40px"
29+
class="dark:text-white"
2730
fill="#000000"
31+
stroke="currentColor"
2832
xmlns="http://www.w3.org/2000/svg"
2933
xmlns:xlink="http://www.w3.org/1999/xlink"
3034
version="1.1"
@@ -55,6 +59,42 @@
5559
</div>
5660
<div class="items-center">
5761
<slot name="right" />
62+
<button
63+
type="button"
64+
class="inline-flex items-center justify-center ml-4 text-gray-800 bg-transparent border-2 border-gray-700 rounded-full shadow-lg dark:text-gray-50 w-9 h-9 active:scale-y-75"
65+
@click="toggleDarkMode"
66+
>
67+
<svg
68+
fill="none"
69+
stroke="currentColor"
70+
class="w-6 h-6"
71+
viewBox="0 0 24 24"
72+
v-if="!darkMode"
73+
xmlns="http://www.w3.org/2000/svg"
74+
>
75+
<path
76+
stroke-linecap="round"
77+
stroke-linejoin="round"
78+
stroke-width="2"
79+
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"
80+
></path>
81+
</svg>
82+
<svg
83+
fill="none"
84+
class="w-6 h-6"
85+
stroke="currentColor"
86+
viewBox="0 0 24 24"
87+
v-if="darkMode"
88+
xmlns="http://www.w3.org/2000/svg"
89+
>
90+
<path
91+
stroke-linecap="round"
92+
stroke-linejoin="round"
93+
stroke-width="2"
94+
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"
95+
></path>
96+
</svg>
97+
</button>
5898
</div>
5999
</div>
60100
<!-- buttons -->
@@ -113,5 +153,34 @@
113153
<script>
114154
export default {
115155
props: ['showBackButton'],
156+
data() {
157+
return {
158+
darkMode: false,
159+
}
160+
},
161+
mounted() {
162+
const cookies = document.cookie.split(';')
163+
const cookieMap = {}
164+
cookies.forEach((element) => {
165+
const [name, val] = element.split('=')
166+
cookieMap[name] = val
167+
})
168+
if (
169+
window.matchMedia('(prefers-color-scheme: dark)').matches &&
170+
(cookieMap.darkMode === undefined || cookieMap.darkMode === 'true')
171+
) {
172+
this.toggleDarkMode(null, true)
173+
}
174+
},
175+
methods: {
176+
toggleDarkMode(e, val) {
177+
e && e.preventDefault()
178+
this.darkMode = val || !this.darkMode
179+
document.documentElement.classList[this.darkMode ? 'add' : 'remove'](
180+
'dark'
181+
)
182+
document.cookie = `darkMode=${this.darkMode}; Secure; max-age=31536000;`
183+
},
184+
},
116185
}
117186
</script>

pages/diff/_diff.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<button
66
type="button"
77
@click="copyUrlToClipboard"
8-
class="inline-flex justify-center px-4 py-2 transition-transform transform rounded-md shadow-lg outline-none copy-uri-button align-center focus:ring-4 active:scale-y-75"
8+
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"
99
v-bind:class="{
10-
'bg-blue-600 text-white': !copied,
10+
'bg-blue-500 text-white': !copied,
1111
'bg-green-500 text-gray-800': copied,
1212
}"
1313
>
@@ -49,17 +49,17 @@
4949
</template>
5050
</Navbar>
5151
<main>
52-
<div class="flex items-start w-full gap-4 font-mono">
52+
<div class="flex items-start w-full gap-4 font-mono dark:text-gray-50">
5353
<div
54-
class="relative flex-1 px-4 py-2 overflow-y-auto border-2 rounded-sm max-h-screen--nav line-number-gutter min-h-80"
54+
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"
5555
>
5656
<RTStickyCopyButton :clickHandler="copyTextToClipboard" />
5757
<div v-for="(lineDiff, index) in lhsDiff" :key="index">
5858
<p class="break-all whitespace-pre-wrap" v-html="lineDiff"></p>
5959
</div>
6060
</div>
6161
<div
62-
class="relative flex-1 px-4 py-2 overflow-y-auto border-2 rounded-sm min-h-80 line-number-gutter max-h-screen--nav"
62+
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"
6363
>
6464
<RTStickyCopyButton :clickHandler="copyTextToClipboard" />
6565
<div v-for="(lineDiff, index) in rhsDiff" :key="index">
@@ -84,7 +84,8 @@ export default {
8484
.map((item) => {
8585
const hunkState = item[0]
8686
if (hunkState === -1 || hunkState === 0) {
87-
const className = hunkState === -1 ? 'bg-red-400' : ''
87+
const className =
88+
hunkState === -1 ? 'bg-red-400 dark:bg-yellow-700' : ''
8889
return `<span class="break-all inline p-0 m-0 ${className}">${item[1]}</span>`
8990
}
9091
return false
@@ -96,7 +97,8 @@ export default {
9697
.map((item) => {
9798
const hunkState = item[0]
9899
if (hunkState === 1 || hunkState === 0) {
99-
const className = hunkState === 1 ? 'bg-green-400' : ''
100+
const className =
101+
hunkState === 1 ? 'bg-green-400 dark:bg-green-700' : ''
100102
return `<span class="break-all inline p-0 m-0 ${className}">${item[1]}</span>`
101103
}
102104
return false
@@ -183,13 +185,13 @@ export default {
183185
line-height: 1.65;
184186
@apply relative;
185187
&:hover {
186-
@apply bg-gray-200;
188+
@apply bg-gray-200 dark:bg-gray-700;
187189
}
188190
&::before {
189191
counter-increment: line-numbers;
190192
content: counter(line-numbers);
191193
width: var(--line-number-gutter-width);
192-
@apply absolute left-0 top-0 -mx-4 bottom-0 text-center bg-gray-200 text-gray-500 flex justify-center items-center text-sm;
194+
@apply absolute left-0 top-0 -mx-4 bottom-0 text-center bg-gray-200 dark:bg-gray-700 dark:text-gray-50 text-gray-500 flex justify-center items-center text-sm;
193195
}
194196
&:first-of-type {
195197
&::before {

pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="contents">
33
<Navbar />
4-
<main>
4+
<main class="text-gray-800 dark:text-gray-50">
55
<h1 class="w-full mb-2 text-xl text-center">
66
Find difference in any two text blocks and get easy sharable link
77
</h1>
@@ -20,7 +20,7 @@
2020
></textarea>
2121
<div class="self-end w-full text-center">
2222
<button
23-
class="inline-flex items-center justify-center w-48 px-4 py-2 text-white transition-transform transform bg-blue-600 rounded-md shadow-lg outline-none focus:ring-4 active:scale-y-75"
23+
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"
2424
>
2525
Compare
2626
</button>

styles/global.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/* Basic layout */
2+
:root {
3+
color-scheme: dark light;
4+
}
25
html,
36
body,
47
#__nuxt,
58
#__layout,
69
.page-root,
710
main {
811
@apply h-full;
9-
@apply bg-gray-50;
12+
@apply bg-gray-50 dark:bg-gray-900;
1013
}
1114

1215
body {
@@ -27,11 +30,11 @@ main {
2730
width: 10px;
2831
}
2932
::-webkit-scrollbar-track {
30-
background: #f1f1f1;
33+
@apply bg-gray-50 dark:bg-gray-700;
3134
}
3235
::-webkit-scrollbar-thumb {
33-
background: #888;
36+
@apply bg-gray-500 dark:bg-gray-500;
3437
}
3538
::-webkit-scrollbar-thumb:hover {
36-
background: #555;
39+
@apply bg-gray-400 dark:bg-gray-400;
3740
}

tailwind.config.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
module.exports = {
22
mode: 'jit',
33
darkMode: 'class',
4+
variants: {
5+
extend: {
6+
boxShadow: ['dark']
7+
},
8+
},
49
theme: {
510
maxHeight: {
611
'screen--nav': 'calc(100vh - 7rem)',
@@ -17,7 +22,18 @@ module.exports = {
1722
},
1823
translate: {
1924
'-screen': '-100vh',
20-
}
25+
},
26+
boxShadow: {
27+
DEFAULT: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
28+
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
29+
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
30+
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
31+
'2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
32+
'3xl': '0 35px 60px -15px rgba(0, 0, 0, 0.3)',
33+
inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
34+
dark: '0 5px 10px -3px rgba(255, 255, 255, 0.1), 0 4px 6px -2px rgba(255, 255, 255, 0.05)',
35+
none: 'none',
36+
},
2137
},
2238
plugins: [
2339
require('@tailwindcss/forms'),

0 commit comments

Comments
 (0)