1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-22 01:03:37 +01:00

copy button component

This commit is contained in:
Matthias Kretschmann 2019-11-18 21:59:20 +01:00
parent 9083830e06
commit e948d48df7
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 66 additions and 49 deletions

View File

@ -0,0 +1,35 @@
@import 'variables';
.button {
margin: 0;
position: absolute;
right: 0;
top: 0;
bottom: 0;
border: 0;
box-shadow: none;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
background: rgba($brand-grey, 0.3);
padding: $spacer / 3;
svg {
stroke: $brand-grey-light;
transition: 0.15s ease-out;
}
&:hover {
svg {
stroke: $brand-grey-dimmed;
}
}
}
.copied {
background: green;
// stylelint-disable-next-line no-descending-specificity
svg {
stroke: $brand-grey-dimmed;
}
}

View File

@ -0,0 +1,22 @@
import React from 'react'
import Clipboard from 'react-clipboard.js'
import styles from './Copy.module.scss'
import Icon from './Icon'
const onCopySuccess = (e: any) => {
e.trigger.classList.add(styles.copied)
}
export default function Copy({ text }: { text: string }) {
return (
<Clipboard
data-clipboard-text={text}
button-title="Copy to clipboard"
onSuccess={e => onCopySuccess(e)}
className={styles.button}
>
<Icon name="Copy" />
</Clipboard>
)
}

View File

@ -17,37 +17,3 @@
text-align: center;
}
}
.button {
margin: 0;
position: absolute;
right: 0;
top: 0;
bottom: 0;
border: 0;
box-shadow: none;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
background: rgba($brand-grey, 0.3);
padding: $spacer / 3;
svg {
stroke: $brand-grey-light;
transition: 0.15s ease-out;
}
&:hover {
svg {
stroke: $brand-grey-dimmed;
}
}
}
.copied {
background: green;
// stylelint-disable-next-line no-descending-specificity
svg {
stroke: $brand-grey-dimmed;
}
}

View File

@ -1,13 +1,7 @@
import React from 'react'
import { QRCode } from 'react-qr-svg'
import Clipboard from 'react-clipboard.js'
import styles from './Qr.module.scss'
import Icon from './Icon'
const onCopySuccess = (e: any) => {
e.trigger.classList.add(styles.copied)
}
import Copy from './Copy'
export default function Qr({
address,
@ -30,14 +24,7 @@ export default function Qr({
<pre className={styles.code}>
<code>{address}</code>
<Clipboard
data-clipboard-text={address}
button-title="Copy to clipboard"
onSuccess={e => onCopySuccess(e)}
className={styles.button}
>
<Icon name="Copy" />
</Clipboard>
<Copy text={address} />
</pre>
</>
)

View File

@ -2,6 +2,13 @@
@import 'mixins';
.buttonBack {
margin-bottom: $spacer;
display: block;
@media (min-width: $screen-md) {
margin-top: -($spacer);
}
svg {
stroke: $brand-grey-light;
display: inline-block;