Skip to content

Commit be65437

Browse files
authored
Fix code block buttons overlapping content (#2772)
* Add temporary fix: Padding top to avoid content overlap not the prettiest solution, though * Only show codeblock buttons on hover * Re-add top padding on mobile * Align code block buttons on left on mobile * Fix again positioning and background color in most cases * Fix ApiCalls * Ensure buttonGroups are properly aligned on mobile
1 parent a1fd654 commit be65437

File tree

2 files changed

+201
-17
lines changed

2 files changed

+201
-17
lines changed

docusaurus/src/scss/api-call.scss

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898

9999
--custom-code-block-background-color: var(--custom-api-call-response-content-background-color);
100100
}
101-
102101
}
103102

104103
.theme-code-block {
@@ -107,6 +106,123 @@
107106
&-highlighted-line {
108107
background-color: var(--strapi-neutral-150) !important;
109108
}
109+
110+
.clean-btn {
111+
background-color: white;
112+
position: relative;
113+
top: -12px;
114+
115+
svg,
116+
i::before {
117+
color: black;
118+
}
119+
120+
span {
121+
color: black;
122+
}
123+
}
124+
125+
&:has([class*="codeBlockTitle"]) {
126+
.clean-btn {
127+
top: -50px;
128+
}
129+
}
130+
}
131+
132+
133+
[class*="buttonGroup"],
134+
.ai-button-group {
135+
opacity: 0;
136+
transition: opacity 0.2s ease;
137+
}
138+
139+
.theme-code-block:hover {
140+
[class*="buttonGroup"],
141+
.ai-button-group {
142+
opacity: 1;
143+
144+
.clean-btn {
145+
opacity: 1 !important;
146+
147+
svg,
148+
i::before,
149+
span {
150+
opacity: 0.6;
151+
transition: opacity 0.2s ease;
152+
}
153+
}
154+
}
155+
}
156+
157+
.clean-btn:hover {
158+
svg,
159+
i::before,
160+
span {
161+
opacity: 1 !important;
162+
}
163+
}
164+
}
165+
166+
@include medium-up {
167+
.api-call__request {
168+
[class*="buttonGroup"] {
169+
right: -24px;
170+
top: -66px;
171+
}
172+
}
173+
174+
.api-call__response {
175+
[class*="buttonGroup"] {
176+
right: 0;
177+
top: -51px;
178+
}
179+
}
180+
}
181+
182+
@include medium-down {
183+
.api-call {
184+
.theme-code-block {
185+
[class*="buttonGroup"],
186+
[class*="buttonGroup"] .clean-btn,
187+
.ai-button-group,
188+
.ai-button-group .clean-btn {
189+
opacity: 1 !important;
190+
}
191+
192+
[class*="buttonGroup"],
193+
.ai-button-group {
194+
.clean-btn {
195+
svg,
196+
i::before,
197+
span {
198+
opacity: 1 !important;
199+
}
200+
}
201+
}
202+
203+
[class*="buttonGroup"],
204+
.ai-button-group {
205+
right: auto;
206+
left: 0;
207+
}
208+
209+
[class*="codeBlockTitle"] {
210+
padding-right: 84px;
211+
}
212+
213+
&[class*="codeBlockContainer"],
214+
[class*="codeBlockContainer"] {
215+
[class*="codeBlockContent"] {
216+
padding-top: 48px;
217+
}
218+
}
219+
220+
&:has([class*="codeBlockTitle"]) {
221+
.clean-btn {
222+
top: 8px;
223+
}
224+
}
225+
}
110226
}
111227
}
112228

@@ -127,5 +243,17 @@
127243
border: solid 1px transparent !important;
128244
}
129245
}
246+
247+
.theme-code-block {
248+
.clean-btn {
249+
background-color: var(--strapi-neutral-0);
250+
251+
svg,
252+
i::before,
253+
span {
254+
color: var(--strapi-neutral-900);
255+
}
256+
}
257+
}
130258
}
131-
}
259+
}

docusaurus/src/scss/code-block.scss

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pre.prism-code {
149149
&[class*="codeBlockContainer"],
150150
[class*="codeBlockContainer"] {
151151
background: var(--custom-code-block-background-color);
152+
position: relative;
152153

153154
&:not(:has([class*="codeBlockTitle"])) {
154155
padding: 24px !important;
@@ -208,7 +209,6 @@ pre.prism-code {
208209
position: relative;
209210
}
210211

211-
212212
[class*="codeBlockContent"] {
213213
border-radius: 0;
214214
border-color: transparent;
@@ -307,36 +307,92 @@ pre.prism-code {
307307
background-color: var(--strapi-neutral-200);
308308
position: absolute;
309309
top: -4px;
310-
left: 62px
310+
left: 62px;
311311
}
312312
}
313313
}
314314
}
315315

316-
// Make code block buttons always visible with reduced opacity
317-
[class*="buttonGroup"] {
318-
opacity: 0.7; // Always visible with slight transparency
316+
// Desktop: Button opacity behavior
317+
[class*="buttonGroup"],
318+
.ai-button-group {
319+
opacity: 0;
319320
transition: opacity 0.2s ease;
320-
321-
&:hover {
322-
opacity: 1; // Full opacity on hover
323-
}
324321
}
325322

326-
[class*="buttonGroup"] .clean-btn {
327-
opacity: inherit; // Inherit from parent buttonGroup
323+
[class*="codeBlock"]:hover {
324+
[class*="buttonGroup"],
325+
.ai-button-group {
326+
opacity: 1;
327+
328+
.clean-btn {
329+
opacity: 1 !important;
330+
331+
svg,
332+
i::before,
333+
span {
334+
opacity: 0.6;
335+
transition: opacity 0.2s ease;
336+
}
337+
}
338+
}
328339
}
329340

341+
.clean-btn:hover {
342+
svg,
343+
i::before,
344+
span {
345+
opacity: 1 !important;
346+
}
347+
}
330348

349+
// Mobile: Always visible
331350
@include medium-down {
332351
[class*="buttonGroup"],
333-
[class*="buttonGroup"] .clean-btn {
334-
opacity: 1;
352+
[class*="buttonGroup"] .clean-btn,
353+
.ai-button-group,
354+
.ai-button-group .clean-btn {
355+
opacity: 1 !important;
356+
}
357+
358+
[class*="buttonGroup"],
359+
.ai-button-group {
360+
.clean-btn {
361+
svg,
362+
i::before,
363+
span {
364+
opacity: 1 !important;
365+
}
366+
}
367+
}
368+
369+
// Align buttons to the left on mobile
370+
[class*="buttonGroup"],
371+
.ai-button-group {
372+
right: auto;
373+
left: 16px;
335374
}
336375

337376
[class*="codeBlockTitle"] {
338377
padding-right: 84px;
339378
}
379+
380+
// On mobile: always add padding-top (with or without title)
381+
.theme-code-block {
382+
&[class*="codeBlockContainer"],
383+
[class*="codeBlockContainer"] {
384+
[class*="codeBlockContent"] {
385+
padding-top: 48px;
386+
}
387+
}
388+
389+
// Reset button position on mobile (don't put them in title bar)
390+
&:has([class*="codeBlockTitle"]) {
391+
.clean-btn {
392+
top: 8px;
393+
}
394+
}
395+
}
340396
}
341397

342398
/** Dark theme */
@@ -361,7 +417,7 @@ pre.prism-code {
361417
}
362418

363419
.clean-btn {
364-
background-color: transparent;
420+
background-color: var(--strapi-neutral-0);
365421

366422
svg,
367423
i::before,
@@ -394,4 +450,4 @@ pre.prism-code {
394450
}
395451
}
396452
}
397-
}
453+
}

0 commit comments

Comments
 (0)