Skip to content

Commit ce2f471

Browse files
committed
Refactor the styling of SuperDebug to be based on css variables for user customization
1 parent ad66e8f commit ce2f471

File tree

2 files changed

+76
-21
lines changed

2 files changed

+76
-21
lines changed

src/lib/client/SuperDebug.svelte

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
return json.replace(
3636
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
3737
function (match: string) {
38-
let cls = 'num';
38+
let cls = 'number';
3939
if (/^"/.test(match)) {
4040
if (/:$/.test(match)) {
4141
cls = 'key';
@@ -133,13 +133,14 @@
133133
}
134134
135135
.super-debug {
136+
--_sd-bg-color: var(--sd-bg-color, rgb(30, 41, 59));
136137
position: relative;
137-
background-color: #1e293b;
138+
background-color: var(--_sd-bg-color);
138139
border-radius: 0.5rem;
139140
overflow: hidden;
140141
}
141142
142-
.super-debug .super-debug--status {
143+
.super-debug--status {
143144
display: flex;
144145
padding: 1em;
145146
justify-content: space-between;
@@ -148,66 +149,90 @@
148149
}
149150
150151
.super-debug--label {
151-
color: white;
152+
color: var(--sd-label-color, white);
152153
}
153154
154155
.super-debug pre {
155-
color: #999;
156-
background-color: #1e293b;
156+
color: var(--sd-code-default, #999);
157+
background-color: var(--_sd-bg-color);
157158
margin-bottom: 0px;
158159
/** Sakura is doing 0.9em, turn font-size back to 1em **/
159160
font-size: 1em;
160161
}
161162
162163
.info {
163-
color: rgb(85, 85, 255);
164+
color: var(--sd-info, rgb(85, 85, 255));
164165
}
165166
166167
.success {
167-
color: #2cd212;
168+
color: var(--sd-success, #2cd212);
168169
}
169170
170171
.redirect {
171-
color: #03cae5;
172+
color: var(--sd-redirect, #03cae5);
172173
}
173174
174175
.error {
175-
color: #ff475d;
176+
color: var(--sd-error, #ff475d);
176177
}
177178
178179
:global(.super-debug--code .key) {
179-
color: #eab308;
180+
color: var(--sd-code-key, #eab308);
180181
}
181182
182183
:global(.super-debug--code .string) {
183-
color: #6ec687;
184+
color: var(--sd-code-string, #6ec687);
184185
}
185186
186187
:global(.super-debug--code .date) {
187-
color: #f06962;
188+
color: var(--sd-code-date, #f06962);
188189
}
189190
190191
:global(.super-debug--code .boolean) {
191-
color: #79b8ff;
192+
color: var(--sd-code-boolean, #79b8ff);
192193
}
193194
194-
:global(.super-debug--code .num) {
195-
color: #af77e9;
195+
:global(.super-debug--code .number) {
196+
color: var(--sd-code-number, #af77e9);
196197
}
197198
198199
:global(.super-debug--code .bigint) {
199-
color: #af77e9;
200+
color: var(--sd-code-bigint, #af77e9);
200201
}
201202
202203
:global(.super-debug--code .null) {
203-
color: #238afe;
204+
color: var(--sd-code-null, #238afe);
204205
}
205206
206207
:global(.super-debug--code .nan) {
207-
color: #af77e9;
208+
color: var(--sd-code-nan, #af77e9);
208209
}
209210
210211
:global(.super-debug--code .undefined) {
211-
color: #238afe;
212+
color: var(--sd-code-undefined, #238afe);
213+
}
214+
215+
:global(.super-debug--code .function) {
216+
color: var(--sd-code-function, #f06962);
217+
}
218+
219+
.super-debug pre::-webkit-scrollbar {
220+
width: var(--sd-sb-width, 1.25rem);
221+
height: var(--sd-sb-height, 1.25rem);
222+
opacity: 0.5;
223+
}
224+
225+
.super-debug pre::-webkit-scrollbar-track {
226+
background-color: var(--sd-sb-track-color, hsl(0, 0%, 40%, 0.2));
227+
}
228+
.super-debug:is(:focus-within, :hover) pre::-webkit-scrollbar-track {
229+
background-color: var(--sd-sb-track-color-focus, hsl(0, 0%, 50%, 0.2));
230+
}
231+
232+
.super-debug pre::-webkit-scrollbar-thumb {
233+
background-color: var(--sd-sb-thumb-color, hsl(217, 50%, 50%, 0.5));
234+
}
235+
.super-debug:is(:focus-within, :hover) pre::-webkit-scrollbar-thumb {
236+
background-color: var(--sd-sb-thumb-color-focus, hsl(217, 50%, 50%));
212237
}
213238
</style>

src/routes/super-debug/+page.svelte

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,40 @@
9999
<p>Svelte's <code>$page</code> data in all its glory.</p>
100100
<SuperDebug label="$page data" data={$page} />
101101
</section>
102+
<section>
103+
<h4>Super Debug custom styling 😎</h4>
104+
<p>Bugs are easier to solve if they look familiar.</p>
105+
<SuperDebug
106+
data={$form}
107+
label="VS Code like theme"
108+
--sd-bg-color="#1f1f1f"
109+
--sd-label-color="#cccccc"
110+
--sd-code-default="#8c8a89"
111+
--sd-code-key="#9cdcfe"
112+
--sd-code-string="#ce9171"
113+
--sd-code-number="#b5c180"
114+
--sd-code-boolean="#4a9cd6"
115+
--sd-code-null="#4a9cd6"
116+
--sd-code-undefined="#4a9cd6"
117+
--sd-sb-thumb-color="#35373a"
118+
--sd-sb-thumb-color-focus="#4b4d50"
119+
/>
120+
<p
121+
style:margin-top="1em"
122+
style:padding-left="4px"
123+
style:background-color="#1f1f1f0f"
124+
>
125+
<strong>Note:</strong> styling the component produces de side effect
126+
described at the
127+
<a href="https://svelte.dev/docs/component-directives#style-props"
128+
>Svelte docs</a
129+
>.
130+
</p>
131+
</section>
102132
</main>
103133

104134
<style>
105135
:global(.space-y-4 > * + *) {
106136
margin-top: 1rem;
107137
}
108-
</style>
138+
</style>

0 commit comments

Comments
 (0)