21
21
:fileType =" fileType"
22
22
>{{ fileName }}
23
23
</Filename >
24
- <div class =" container-general" ref = " scrollContainer " >
24
+ <div class =" container-general" >
25
25
<button
26
26
v-if =" copyToClipboard"
27
- v-show =" showCopyButton"
28
27
class =" copy-button"
29
- ref =" copyButton"
30
- :class =" { copied: isCopied, visible: buttonPositioned }"
28
+ :class =" { copied: isCopied }"
31
29
@click =" copyCodeToClipboard"
32
- @update =" handleScroll"
33
30
aria-label =" Copy code to clipboard"
34
31
>
35
32
<svg
72
69
</template >
73
70
74
71
<script >
75
- import debounce from ' docc-render/utils/debounce' ;
76
72
import { escapeHtml } from ' docc-render/utils/strings' ;
77
73
import Language from ' docc-render/constants/Language' ;
78
74
import CodeBlock from ' docc-render/components/CodeBlock.vue' ;
@@ -87,20 +83,8 @@ export default {
87
83
return {
88
84
syntaxHighlightedLines: [],
89
85
isCopied: false ,
90
- showCopyButton: true ,
91
- buttonPositioned: false ,
92
- scrollTimeout: null ,
93
86
};
94
87
},
95
- mounted () {
96
- this .$nextTick (() => {
97
- this .updateCopyButtonPosition ();
98
- const container = this .$refs .scrollContainer ;
99
- if (container) {
100
- container .addEventListener (' scroll' , this .handleScroll , { passive: true });
101
- }
102
- });
103
- },
104
88
props: {
105
89
fileName: String ,
106
90
isFileNameActionable: {
@@ -170,29 +154,6 @@ export default {
170
154
line === ' ' ? ' \n ' : line
171
155
));
172
156
},
173
- updateCopyButtonPosition () {
174
- const container = this .$refs .scrollContainer ;
175
- const button = this .$refs .copyButton ;
176
-
177
- if (! container || ! button) return ;
178
-
179
- const { scrollLeft } = container;
180
-
181
- button .style .transform = ` translateX(${ scrollLeft} px)` ;
182
- this .buttonPositioned = true ;
183
- },
184
- handleScroll: debounce (function handleScroll () {
185
- this .showCopyButton = false ;
186
- this .updateCopyButtonPosition ();
187
-
188
- if (this .scrollTimeout ) {
189
- clearTimeout (this .scrollTimeout );
190
- }
191
-
192
- this .scrollTimeout = window .setTimeout (() => {
193
- this .showCopyButton = true ;
194
- }, 500 );
195
- }, 100 ),
196
157
copyCodeToClipboard () {
197
158
const lines = this .content ;
198
159
const text = lines .join (' \n ' );
@@ -272,6 +233,7 @@ code {
272
233
flex-direction : column ;
273
234
border-radius : var (--code-border-radius , $border-radius );
274
235
overflow : hidden ;
236
+ position : relative ;
275
237
// we need to establish a new stacking context to resolve a Safari bug where
276
238
// the scrollbar is not clipped by this element depending on its border-radius
277
239
@include new-stacking-context ;
@@ -283,7 +245,6 @@ code {
283
245
284
246
.container-general {
285
247
overflow : auto ;
286
- position : relative ;
287
248
}
288
249
289
250
.container-general ,
@@ -301,13 +262,8 @@ pre {
301
262
border-radius : 6px ;
302
263
padding : 7px 6px ;
303
264
cursor : pointer ;
304
- display : none ;
305
- opacity : 0 ;
306
- transition : all 0.2s ease-in-out ;
307
- }
308
-
309
- .copy-button.visible {
310
265
opacity : 1 ;
266
+ transition : all 0.2s ease-in-out ;
311
267
}
312
268
313
269
.copy-button svg {
@@ -328,8 +284,4 @@ pre {
328
284
color : var (--color-figure-blue );
329
285
}
330
286
331
- .container-general :hover .copy-button {
332
- display : flex ;
333
- }
334
-
335
287
</style >
0 commit comments