Skip to content

Commit ec4b4da

Browse files
authored
feat!: remove clipboard button inline opacity transition (#523)
1 parent 8617d1e commit ec4b4da

File tree

4 files changed

+79
-12
lines changed

4 files changed

+79
-12
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ Using `markdown` component and/or directive, you will be able to use the `clipbo
406406

407407
The `clipboard` plugin provide an unstyled default button with a default behavior out of the box if no alternative is used.
408408

409+
#### Customize button toolbar
410+
411+
The clipboard button is placed inside a wrapper element that can be customize using the `.markdown-clipboard-toolbar` CSS selector in your global `styles.css/scss` file.
412+
413+
This allows to override the default positionning of the clipboard button and play with the visibility of the button using the `.hover` CSS selector that is applied on the toolbar when the mouse cursor enters and leaves the code block element.
414+
415+
#### Customize default button
416+
409417
To customize the default button styling, use the `.markdown-clipboard-button` CSS selector in your global `styles.css/scss` file. You can also customized the "copied" state happening after the button is clicked using the `.copied` CSS selector.
410418

411419
#### Using global configuration

demo/src/app/plugins/plugins.component.html

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ <h2 id="emoji">Emoji plugin</h2>
1515
```javascript
1616
node_modules/emoji-toolkit/lib/js/joypixels.min.js
1717
```
18+
1819
#### Directive
1920
`emoji` - activate emoji plugin
21+
2022
### Example
2123
</markdown>
2224

@@ -53,10 +55,13 @@ <h2 id="line-numbers">Line Numbers plugin</h2>
5355
node_modules/prismjs/plugins/line-numbers/prism-line-numbers.css
5456
node_modules/prismjs/plugins/line-numbers/prism-line-numbers.js
5557
```
58+
5659
#### Directive
5760
`lineNumbers` - activate line numbers plugin
61+
5862
#### Attributes
5963
`start` - offset number for the first display line
64+
6065
### Example
6166
</markdown>
6267

@@ -117,11 +122,14 @@ <h2 id="line-highlight">Line Highlight plugin</h2>
117122
node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css
118123
node_modules/prismjs/plugins/line-highlight/prism-line-highlight.js
119124
```
125+
120126
#### Directive
121127
`lineHighlight` - activate line highlight plugin
128+
122129
#### Attributes
123130
`line` - lines to highlight (i.e.: 6, 11-15)<br>
124-
`lineOffset` - starting offset for line numbers
131+
`lineOffset` - starting offset for line numbers<br>
132+
125133
### Example
126134
</markdown>
127135

@@ -166,14 +174,17 @@ <h2 id="command-line">Command Line plugin</h2>
166174
node_modules/prismjs/plugins/command-line/prism-command-line.css
167175
node_modules/prismjs/plugins/command-line/prism-command-line.min.js
168176
```
177+
169178
#### Directive
170179
`commandLine` - activate command-line display
180+
171181
#### Attributes
172182
`host` - host name<br>
173183
`output` - lines to be presented as output (optional)<br>
174184
`filterOutput` - prefix to automatically present lines as output (optional)<br>
175185
`prompt` - data prompt<br>
176186
`user` - user name<br>
187+
177188
### Example
178189
</markdown>
179190

@@ -275,10 +286,13 @@ <h2 id="katex">KaTeX plugin</h2>
275286
node_modules/katex/dist/katex.min.js
276287
node_modules/katex/dist/contrib/auto-render.min.js
277288
```
289+
278290
#### Directive
279291
`katex` - activate KaTeX plugin
292+
280293
#### Attributes
281294
`katexOptions` - combine [KaTeX options](https://katex.org/docs/options.html) and [Auto-Renderer options](https://katex.org/docs/autorender.html#api)<br>
295+
282296
### Example
283297
</markdown>
284298

@@ -331,10 +345,13 @@ <h2 id="mermaid">Mermaid plugin</h2>
331345
```javascript
332346
node_modules/mermaid/dist/mermaid.min.js
333347
```
348+
334349
#### Directive
335350
`mermaid` - activate mermaid plugin
351+
336352
#### Attributes
337353
`mermaidOptions` - mermaid [configuration options](https://mermaid.js.org/config/schema-docs/config.html#mermaid-config-properties)<br>
354+
338355
### Example
339356
</markdown>
340357

@@ -387,14 +404,24 @@ <h2 id="clipboard">Clipboard plugin</h2>
387404

388405
<markdown ngPreserveWhitespaces>
389406
#### Clipboard file(s) to include
407+
390408
```javascript
391409
node_modules/clipboard/dist/clipboard.min.js
392410
```
411+
393412
#### Directive
394413
`clipboard` - activate copy-to-clipboard plugin
414+
395415
#### Attributes
396-
`clipboardButtonComponent` - component `Type&lt;any>` to use as copy-to-clipboard button
397-
`clipboardButtonTemplate` - template reference `TemplateRef&lt;T>` to use as copy-to-clipboard button
416+
`clipboardButtonComponent` - component `Type&lt;any>` to use as copy-to-clipboard button<br>
417+
`clipboardButtonTemplate` - template reference `TemplateRef&lt;T>` to use as copy-to-clipboard button<br>
418+
419+
#### CSS Selectors
420+
`markdown-clipboard-toolbar` - toolbar wrapper<br>
421+
`markdown-clipboard-toolbar.hover` - toolbar wrapper during mouse hover<br>
422+
`markdown-clipboard-button` - default button<br>
423+
`markdown-clipboard-button.copied` - default button during "copied" state<br>
424+
398425
### Example
399426
</markdown>
400427

@@ -404,14 +431,35 @@ <h2 id="clipboard">Clipboard plugin</h2>
404431
The `clipboard` plugin provide an unstyled default button with a default behavior out of the box if no alternative is used.
405432

406433
```javascript
407-
const example = 'rollover me to see the default clipboard button appears!';
434+
const example = 'the default clipboard button with default behavior';
435+
```
436+
</markdown>
437+
438+
<markdown class="btn-clipboard-toolbar" clipboard ngPreserveWhitespaces>
439+
#### Customize toolbar
440+
441+
The clipboard button is placed inside a wrapper element that can be customize using the `.markdown-clipboard-toolbar` CSS selector in your global `styles.css/scss` file.
442+
443+
This allows to override the default positionning of the clipboard button and play with the visibility of the button using the `.hover` CSS selector that is applied on the toolbar when the mouse cursor enters and leaves the code block element.
444+
445+
```css
446+
.markdown-clipboard-toolbar &#123;
447+
top: 16px;
448+
right: 16px;
449+
opacity: 0;
450+
transition: opacity 250ms ease-out;
451+
&#125;
452+
453+
.markdown-clipboard-toolbar.hover &#123;
454+
opacity: 1;
455+
&#125;
408456
```
409457
</markdown>
410458

411-
<markdown class="btn-clipboard-default" emoji clipboard ngPreserveWhitespaces>
459+
<markdown class="btn-clipboard-default" clipboard ngPreserveWhitespaces>
412460
#### Customize default button
413461

414-
To customize the default button styling, use the `.markdown-clipboard-button` CSS selector in your global `styles.css/scss` file. You can also customized the "copied" state happening after the button is clicked using the `.copied` CSS selector.
462+
The default button can be customized using the `.markdown-clipboard-button` CSS selector in your global `styles.css/scss` file. You can also customized the "copied" state happening after the button is clicked using the `.copied` CSS selector.
415463

416464
```css
417465
.markdown-clipboard-button &#123;

demo/src/app/plugins/plugins.component.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ textarea {
66
min-height: 180px;
77
}
88

9-
// Clipboard default button
9+
// Clipboard toolbar styling
10+
11+
.btn-clipboard-toolbar ::ng-deep .markdown-clipboard-toolbar {
12+
top: 16px;
13+
right: 16px;
14+
opacity: 0;
15+
transition: opacity 250ms ease-out;
16+
17+
&.hover {
18+
opacity: 1;
19+
}
20+
}
21+
22+
// Clipboard default button styling
1023

1124
.btn-clipboard-default ::ng-deep .markdown-clipboard-button {
1225
background-color: rgba(255, 255, 255, 0.07);

lib/src/markdown.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,16 @@ export class MarkdownService {
387387

388388
// create toolbar element
389389
const toolbarWrapperElement = document.createElement('div');
390+
toolbarWrapperElement.classList.add('markdown-clipboard-toolbar');
390391
toolbarWrapperElement.style.position = 'absolute';
391392
toolbarWrapperElement.style.top = '.5em';
392393
toolbarWrapperElement.style.right = '.5em';
393-
toolbarWrapperElement.style.opacity = '0';
394-
toolbarWrapperElement.style.transition = 'opacity 250ms ease-out';
395394
toolbarWrapperElement.style.zIndex = '1';
396395
preWrapperElement.insertAdjacentElement('beforeend', toolbarWrapperElement);
397396

398397
// register listener to show/hide toolbar
399-
preElement.onmouseover = () => toolbarWrapperElement.style.opacity = '1';
400-
preElement.onmouseout = () => toolbarWrapperElement.style.opacity = '0';
398+
preWrapperElement.onmouseenter = () => toolbarWrapperElement.classList.add('hover');
399+
preWrapperElement.onmouseleave = () => toolbarWrapperElement.classList.remove('hover');
401400

402401
// declare embeddedViewRef holding variable
403402
let embeddedViewRef: EmbeddedViewRef<unknown>;
@@ -425,7 +424,6 @@ export class MarkdownService {
425424

426425
// attach clipboard.js to root node
427426
embeddedViewRef.rootNodes.forEach((node: HTMLElement) => {
428-
node.onmouseover = () => toolbarWrapperElement.style.opacity = '1';
429427
toolbarWrapperElement.appendChild(node);
430428
clipboardInstance = new ClipboardJS(node, { text: () => preElement.innerText });
431429
});

0 commit comments

Comments
 (0)