Sha256: 8a3d65c56fe3d0b49b198e62e88ca1d62c9a0a1a38980737ca078214baf6cbc4

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

import React from 'react';
import classNames from 'classnames';

/**
 * Display an element with a background image.
 */
export default class BackgroundImage extends React.Component {
  static propTypes = {
    /** The id of the image file to display */
    imageFileId: React.PropTypes.number,

    /** Background position */
    position: React.PropTypes.arrayOf(React.PropTypes.number),

    /** Additional CSS classes. */
    className: React.PropTypes.string,

    /** Used to lazy load images. */
    loaded: React.PropTypes.bool
  }

  static defaultProps = {
    position: [50, 50]
  }

  render() {
    return (
      <div className={this.cssClass()} style={this.style()}>
      </div>
    );
  }

  cssClass() {
    return classNames(
      this.props.className,
      this.props.loaded ? 'load_image' : null,
      this.imageCssClass()
    );
  }

  imageCssClass() {
    return ['image', this.props.imageFileId || 'none'].join('_');
  }

  style() {
    return {
      backgroundPosition: `${this.positionCoordinate(0)}% ${this.positionCoordinate(1)}%`
    };
  }

  positionCoordinate(index) {
    var coordinate = this.props.position[index];

    if (typeof coordinate === 'undefined') {
      return 50;
    }

    return coordinate;
  }
};

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pageflow-react-0.1.1 js/src/components/background_image.jsx
pageflow-react-0.1.0 js/src/components/background_image.jsx