Skip to content

Commit

Permalink
feat: Use inline svg rather than background image for copy icon in co…
Browse files Browse the repository at this point in the history
…de snippet
  • Loading branch information
jerelmiller committed Jun 11, 2020
1 parent df680e2 commit d601774
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/components/CodeSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import Highlight, { defaultProps } from 'prism-react-renderer';
import github from 'prism-react-renderer/themes/github';
import styles from './CodeSnippet.module.scss';
import cx from 'classnames';
import useFormattedCode from '../hooks/useFormattedCode';
import FeatherIcon from './FeatherIcon';

const copyCode = (code, setCopied) => {
const textArea = document.createElement('textarea');
Expand Down Expand Up @@ -47,8 +47,9 @@ const CodeSnippet = ({ children, copy, className, lineNumbers }) => {
</Highlight>
</div>
{copy !== 'false' && (
<div className={cx({ [styles.copied]: copied }, styles.copyBar)}>
<div className={styles.copyBar}>
<button type="button" onClick={() => copyCode(children, setCopied)}>
<FeatherIcon name="copy" size="1rem" className={styles.copyIcon} />
{copied ? 'Copied!' : 'Copy output'}
</button>
</div>
Expand Down
11 changes: 2 additions & 9 deletions src/components/CodeSnippet.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@
justify-content: flex-end;
align-items: center;
background: var(--color-neutrals-200);
height: 35px;
background-image: url('../images/copy.svg');
background-size: 1rem;
background-repeat: no-repeat;
background-position: 83% 50%;

button {
padding-right: 1rem;
font-size: 0.75rem;
font-family: var(--primary-font-family);
color: var(--color-brand-800);
background: none;
border: none;
outline: none;
}
}

.copied {
background-position: 88% 50%;
.copyIcon {
margin-right: 0.5rem;
}

0 comments on commit d601774

Please sign in to comment.