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

25 lines
668 B
JavaScript
Raw Normal View History

2017-03-17 05:32:01 +00:00
import React, { Component, PropTypes } from 'react'
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>
}
}