Skip to content

Commit

Permalink
feat(clayui.com): add feedback for when code content is copied
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceosterhaus committed Feb 21, 2020
1 parent 1680408 commit a443210
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
22 changes: 22 additions & 0 deletions clayui.com/plugins/gatsby-remark-use-clipboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ module.exports = ({markdownAST}) => {
}

node.value = `
<div class="copied-alert alert alert-fluid alert-info d-none" role="alert">
<div class="container">
<div class="alert-autofit-row autofit-row">
<div class="autofit-col inline-item-before">
<div class="autofit-section">
<span class="alert-indicator">
<svg class="lexicon-icon lexicon-icon-info-circle" role="presentation">
<use xlink:href="/images/icons/icons.svg#info-circle"></use>
</svg>
</span>
</div>
</div>
<div class="autofit-col autofit-col-expand">
<div class="autofit-section">
<strong class="lead">Copied!</strong>
</div>
</div>
</div>
</div>
</div>
<div class="code-container">
<button class="btn btn-sm btn-copy btn-monospaced btn-unstyled" title="Copy">
<svg class="lexicon-icon">
Expand Down
18 changes: 18 additions & 0 deletions clayui.com/src/components/CodeClipboard/CodeClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ export default props => {
clayClipboard = new Clipboard(selector, {
text: delegateTarget => {
const codeContentParentNode = delegateTarget.parentNode;
const gatsbyHighlightContainer =
codeContentParentNode.parentNode;
let codeContent;
const buttonContent = delegateTarget.innerHTML;

delegateTarget.innerHTML = delegateTarget.innerHTML.replace(
/paste/g,
'check'
);

delegateTarget.setAttribute('title', 'Copied');

gatsbyHighlightContainer
.querySelector('.copied-alert')
.classList.toggle('d-none');

setTimeout(() => {
delegateTarget.setAttribute('title', 'Copy');

delegateTarget.innerHTML = buttonContent;

gatsbyHighlightContainer
.querySelector('.copied-alert')
.classList.toggle('d-none');
}, 2000);

if (codeContentParentNode.querySelector('pre code')) {
Expand Down
11 changes: 10 additions & 1 deletion clayui.com/src/components/clay/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import {ClayButtonWithIcon} from '@clayui/button/src';
import ClayAlert from '@clayui/alert';
import {ClayButtonWithIcon} from '@clayui/button';
import parserBabylon from 'prettier/parser-babylon';
import prettier from 'prettier/standalone';
import React, {useState} from 'react';
Expand Down Expand Up @@ -117,6 +118,14 @@ const Editor = ({code, disabled = false, imports, preview = true, scope}) => {
)}

<div className="gatsby-highlight">
<ClayAlert
className="copied-alert d-none"
displayType="info"
spritemap={spritemap}
title="Copied!"
variant="stripe"
/>

<div style={{padding: '10px'}}>
<ClayButtonWithIcon
className="btn-copy"
Expand Down
1 change: 1 addition & 0 deletions clayui.com/src/styles/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
}

.lexicon-icon {
pointer-events: none;
vertical-align: baseline;
}
}
Expand Down

0 comments on commit a443210

Please sign in to comment.