component2canvas
guide
- add your index html portal element
<div id='crop-portal'></div>
- use as below
const ComponentToBeCrop = () => (
<div
style={{
width: 250,
height: 250,
backgroundColor: '#ff44d9',
color: '#fff',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
Crop me if you can
</div>
)
<div>
<ComponentToBeCrop />
<CropComponent
portalId='crop-portal'
canvasConfigs={{
width: 250,
height: 250,
innerWidth: 250,
innerHeight: 250,
}}
Component={ComponentToBeCrop}
/>
</div>
type
defaultValue
prop object
buttonGroupStyle {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}
object
modalStyle {
position: 'fixed',
left: 0,
top: 0,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
bottom: 0,
right: 0,
background: 'rgba(49, 73, 177, 0.5)',
zIndex: 9999,
}
string
canvas-portal
portalId ReactElement
null
Component object
null
canvasConfigs object
null
imgStyle object
buttonStyle {
padding: 8,
margin: 8,
background: '#273CAF',
color: '#fff',
border: 'none',
outline: 'none',
}
string
'download.png'
filename object
downloadStyle {
padding: 8,
margin: 8,
background: '#36C2CE',
color: '#fff',
}
function
DownloadButton ({ canvasElement, #### onClick }) => (
<a
onClick={onClick}
href={canvasElement && canvasElement.toDataURL()}
download={filename}
style={downloadStyle}
>
DOWNLOAD
</a>
)
function
CancelButton ;({ onClick }) => (
<button style={buttonStyle} onClick={onClick}>
CANCEL
</button>
)
function
CropButton ;({ onClick }) => (
<button style={buttonStyle} onClick={onClick}>
Crop Component
</button>
)
Dependency html2canvas
This project was bootstrapped with Create React App.
Available Scripts
In the project directory, you can run:
npm start
development env
npm run build
production script
npm run npmbuild
creates node_module output file