Skip to content

Instantly share code, notes, and snippets.

@gardun0
Last active August 3, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gardun0/2f968acd73d77064947e7d1da174acd7 to your computer and use it in GitHub Desktop.
Save gardun0/2f968acd73d77064947e7d1da174acd7 to your computer and use it in GitHub Desktop.
Image component to prevent dragging and user select
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