metamaps--metamaps/src/components/Sprite.js

26 lines
692 B
JavaScript
Raw Normal View History

import React, { Component } from 'react'
import PropTypes from 'prop-types'
2017-03-17 05:32:01 +00:00
export default class Sprite extends Component {
static propTypes = {
src: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number,
xIndex: PropTypes.number,
yIndex: PropTypes.number
}
render () {
const { src, width, height, xIndex, yIndex } = this.props
const styles = {
overflow: 'hidden',
backgroundImage: `url(${src})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: `-${xIndex * width}px -${yIndex * height}px`,
width: `${width}px`,
height: `${height}px`
}
return <div className='sprite' style={styles}></div>
}
}