Skip to content

Commit 0a9ee14

Browse files
committed
Refactor color variables and theme handling
1 parent bf79827 commit 0a9ee14

5 files changed

Lines changed: 53 additions & 38 deletions

File tree

packages/comment-widget/src/comment-editor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ export class CommentEditor extends LitElement {
207207
...baseStyles,
208208
unsafeCSS(contentStyles),
209209
css`
210-
@unocss-placeholder;
211210
212211
:host {
213212
display: block;
@@ -225,16 +224,18 @@ export class CommentEditor extends LitElement {
225224
}
226225
227226
.tiptap p.is-editor-empty:first-child::before {
228-
color: var(--halo-cw-text-3-color, #6B7280);
229227
content: attr(data-placeholder);
230228
float: left;
231229
height: 0;
232230
pointer-events: none;
231+
color: var(--halo-cw-text-3-color, #334155);
233232
}
234233
235234
.tiptap code br {
236235
display: block;
237236
}
237+
238+
@unocss-placeholder;
238239
`,
239240
];
240241
}

packages/comment-widget/src/styles/content.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
-ms-text-size-adjust: 100%;
1010
-webkit-text-size-adjust: 100%;
1111
margin: 0;
12-
color: var(--halo-cw-text-1-color, #111827);
1312
font-family: var(--base-font-family);
1413
font-size: var(--base-font-size);
1514
line-height: var(--base-line-height);
1615
word-wrap: break-word;
16+
@apply text-text-1;
1717
}
1818

1919
.markdown-body details,
@@ -39,7 +39,7 @@
3939

4040
.markdown-body mark {
4141
background-color: var(--bgColor-attention-muted);
42-
color: var(--halo-cw-text-1-color, #111827);
42+
@apply text-text-1;
4343
}
4444

4545
.markdown-body sub,
@@ -78,12 +78,11 @@
7878
box-sizing: content-box;
7979
overflow: hidden;
8080
background: transparent;
81-
border-bottom: 1px solid var(--halo-cw-muted-1-color, #d1d5db);
8281
height: 0.25em;
8382
padding: 0;
8483
margin: 1.4em 0;
85-
background-color: var(--halo-cw-muted-1-color, #d1d5db);
8684
border: 0;
85+
@apply bg-muted-1;
8786
}
8887

8988
.markdown-body a:hover {
@@ -134,8 +133,9 @@
134133
.markdown-body blockquote {
135134
margin: 0;
136135
padding: 0 1em;
137-
color: var(--halo-cw-text-1-color, #111827);
138-
border-left: 0.25em solid var(--halo-cw-muted-1-color, #d1d5db);
136+
border-left: 0.25em;
137+
border-style: solid;
138+
@apply text-text-1 border-muted-1;
139139
}
140140

141141
.markdown-body ul,
@@ -256,8 +256,8 @@
256256
margin: 0;
257257
font-size: 85%;
258258
white-space: break-spaces;
259-
background-color: var(--halo-cw-muted-2-color, #e5e7eb);
260259
border-radius: 6px;
260+
@apply bg-muted-2;
261261
}
262262

263263
.markdown-body code br {

packages/comment-widget/uno.config.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { defineConfig, definePreset, presetIcons, presetWind3 } from 'unocss';
1+
import {
2+
defineConfig,
3+
definePreset,
4+
presetIcons,
5+
presetWind3,
6+
transformerDirectives,
7+
} from 'unocss';
28

39
const remRE = /(-?[.\d]+)rem/g;
410

@@ -26,14 +32,14 @@ export default defineConfig({
2632
},
2733
background: 'var(--halo-cw-background-color, transparent)',
2834
text: {
29-
1: 'var(--halo-cw-text-1-color, #111827)',
30-
2: 'var(--halo-cw-text-2-color, #374151)',
31-
3: 'var(--halo-cw-text-3-color, #6B7280)',
35+
1: 'var(--halo-cw-text-1-color, #0f172a)',
36+
2: 'var(--halo-cw-text-2-color, #1e293b)',
37+
3: 'var(--halo-cw-text-3-color, #334155)',
3238
},
3339
muted: {
34-
1: 'var(--halo-cw-muted-1-color, #D1D5DB)',
35-
2: 'var(--halo-cw-muted-2-color, #E5E7EB)',
36-
3: 'var(--halo-cw-muted-3-color, #F3F4F6)',
40+
1: 'var(--halo-cw-muted-1-color, #cbd5e1)',
41+
2: 'var(--halo-cw-muted-2-color, #e2e8f0)',
42+
3: 'var(--halo-cw-muted-3-color, #f1f5f9)',
3743
},
3844
},
3945
},
@@ -50,4 +56,5 @@ export default defineConfig({
5056
avatar:
5157
'rounded-full size-9 overflow-hidden inline-flex items-center justify-center bg-muted-2',
5258
},
59+
transformers: [transformerDirectives()],
5360
});

packages/comment-widget/var.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
--halo-cw-primary-3-color: #065f46; /* green-800 */
106106

107107
--halo-cw-text-1-color: #f9fafb; /* gray-50 */
108-
--halo-cw-text-2-color: #e5e7eb; /* gray-200 */
109-
--halo-cw-text-3-color: #9ca3af; /* gray-400 */
108+
--halo-cw-text-2-color: #e2e8f0; /* gray-200 */
109+
--halo-cw-text-3-color: #94a3b8; /* gray-400 */
110110

111-
--halo-cw-muted-1-color: #4b5563; /* gray-600 */
112-
--halo-cw-muted-2-color: #374151; /* gray-700 */
113-
--halo-cw-muted-3-color: #1f2937; /* gray-800 */
111+
--halo-cw-muted-1-color: #64748b; /* gray-600 */
112+
--halo-cw-muted-2-color: #475569; /* gray-700 */
113+
--halo-cw-muted-3-color: #334155; /* gray-800 */
114114
}

packages/example/index.html

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,35 @@
88
<script src="/src/main.ts" type="module"></script>
99

1010
<style>
11-
body {
12-
display: flex;
13-
justify-content: center;
11+
#toggle-theme {
12+
margin-bottom: 1rem;
1413
}
14+
</style>
1515

16-
:root {
17-
color-scheme: dark;
18-
--halo-cw-primary-1-color: #059669; /* green-600 */
19-
--halo-cw-primary-2-color: #047857; /* green-700 */
20-
--halo-cw-primary-3-color: #065f46; /* green-800 */
21-
22-
--halo-cw-text-1-color: #f9fafb; /* gray-50 */
23-
--halo-cw-text-2-color: #e5e7eb; /* gray-200 */
24-
--halo-cw-text-3-color: #9ca3af; /* gray-400 */
16+
<script>
17+
document.addEventListener("DOMContentLoaded", () => {
18+
const button = document.getElementById("toggle-theme");
19+
button.addEventListener("click", () => {
20+
document.documentElement.classList.toggle("dark");
21+
// save the theme to local storage
22+
localStorage.setItem(
23+
"theme",
24+
document.documentElement.classList.contains("dark")
25+
? "dark"
26+
: "light"
27+
);
28+
});
2529

26-
--halo-cw-muted-1-color: #4b5563; /* gray-600 */
27-
--halo-cw-muted-2-color: #374151; /* gray-700 */
28-
--halo-cw-muted-3-color: #1f2937; /* gray-800 */
29-
}
30-
</style>
30+
// get the theme from local storage
31+
const theme = localStorage.getItem("theme");
32+
if (theme) {
33+
document.documentElement.classList.add(theme);
34+
}
35+
});
36+
</script>
3137
</head>
3238
<body>
39+
<button id="toggle-theme">Dark / Light</button>
3340
<comment-widget
3441
baseUrl="http://127.0.0.1:8090"
3542
group="content.halo.run"

0 commit comments

Comments
 (0)