Last active
August 3, 2018 21:15
-
-
Save gardun0/2f968acd73d77064947e7d1da174acd7 to your computer and use it in GitHub Desktop.
Image component to prevent dragging and user select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
const Image = ({ | |
width = 'auto', | |
height = 'auto', | |
src, | |
...rest | |
}) => ( | |
<div | |
{...rest} | |
style={{ | |
width, | |
height, | |
backgroundImage: `url(${src})`, | |
backgroundSize: 'contain', | |
backgroundRepeat: 'no-repeat', | |
userSelect: 'none' | |
}} | |
> | |
<img | |
{...rest} | |
draggable='false' | |
style={{ | |
opacity: 0, | |
userSelect: 'none', | |
pointerEvents: 'none' | |
}} | |
width={width} | |
height={height} | |
src={src} | |
/> | |
</div> | |
) | |
export default Image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment