You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
carbon/components/ExportButton.js

47 lines
1.1 KiB
JavaScript

import React from 'react'
import { withRouter } from 'next/router'
import CopyButton from './CopyButton'
const toIFrame = url =>
`<iframe
src="https://carbon.now.sh/embed${url}"
style="transform:scale(0.7); width:1024px; height:473px; border:0; overflow:hidden;"
sandbox="allow-scripts allow-same-origin">
</iframe>
`
function ExportButton({ router, children, color }) {
return (
<React.Fragment>
{children === 'COPY EMBED' ? (
<CopyButton text={toIFrame(router.asPath)}>
{({ copied }) => <button>{copied ? 'COPIED!' : 'COPY EMBED'}</button>}
</CopyButton>
) : (
<button>{children}</button>
)}
<style jsx>
{`
button {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
vertical-align: baseline;
color: ${color};
background: transparent;
cursor: pointer;
}
&:active {
outline: none;
}
`}
</style>
</React.Fragment>
)
}
export default withRouter(ExportButton)