<commit_before>// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import CSSClassnames from '../utils/CSSClassnames';
import Props from '../utils/Props';
import Box from './Box';

const CLASS_ROOT = CSSClassnames.HEADER;

export default class Header extends Component {

  constructor(props, context) {
    super(props, context);

    this._onResize = this._onResize.bind(this);
  }

  componentDidMount () {
    if (this.props.fixed) {
      this._alignMirror();
      window.addEventListener('resize', this._onResize);
    }
  }

  componentDidUpdate () {
    if (this.props.fixed) {
      this._alignMirror();
    }
  }

  componentWillUnmount () {
    if (this.props.fixed) {
      window.removeEventListener('resize', this._onResize);
    }
  }

  _onResize () {
    this._alignMirror();
  }

  _alignMirror () {
    var contentElement = ReactDOM.findDOMNode(this.contentRef);
    var mirrorElement = this.mirrorRef;

    // constrain fixed content to the width of the mirror
    var mirrorRect = mirrorElement.getBoundingClientRect();
    contentElement.style.width = `${Math.floor(mirrorRect.width)}px`;

    // align the mirror height with the content's height
    var contentRect = contentElement.getBoundingClientRect();
    mirrorElement.style.height = `${Math.floor(contentRect.height)}px`;
  }

  render () {
    const {
      children, className, colorIndex, fixed, float, role, size, splash
    } = this.props;
    const classes = classnames(
      CLASS_ROOT, {
        [`${CLASS_ROOT}--${size}`]: (size && typeof size === 'string'),
        [`${CLASS_ROOT}--float`]: float,
        [`${CLASS_ROOT}--splash`]: splash
      },
      className
    );
    const containerClasses = classnames(
      `${CLASS_ROOT}__container`, {
        [`${CLASS_ROOT}__container--fixed`]: fixed,<commit_msg>Changed Header to delay aligning a fixed mirror just a bit. Fixes GitHub issue #1114.<commit_after>// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import CSSClassnames from '../utils/CSSClassnames';
import Props from '../utils/Props';
import Box from './Box';

const CLASS_ROOT = CSSClassnames.HEADER;

export default class Header extends Component {

  constructor(props, context) {
    super(props, context);

    this._onResize = this._onResize.bind(this);
    this._alignMirror = this._alignMirror.bind(this);
  }

  componentDidMount () {
    if (this.props.fixed) {
      window.addEventListener('resize', this._onResize);
      this._onResize();
    }
  }

  componentDidUpdate () {
    if (this.props.fixed) {
      this._onResize();
    }
  }

  componentWillUnmount () {
    if (this.props.fixed) {
      clearTimeout(this._resizeTimer);
      window.removeEventListener('resize', this._onResize);
    }
  }

  _onResize () {
    // give just a little time for the DOM to stabilize
    clearTimeout(this._resizeTimer);
    this._resizeTimer = setTimeout(this._alignMirror, 10);
  }

  _alignMirror () {
    var contentElement = ReactDOM.findDOMNode(this.contentRef);
    var mirrorElement = this.mirrorRef;

    // constrain fixed content to the width of the mirror
    var mirrorRect = mirrorElement.getBoundingClientRect();
    contentElement.style.width = `${Math.floor(mirrorRect.width)}px`;

    // align the mirror height with the content's height
    var contentRect = contentElement.getBoundingClientRect();
    mirrorElement.style.height = `${Math.floor(contentRect.height)}px`;
  }

  render () {
    const {
      children, className, colorIndex, fixed, float, role, size, splash
    } = this.props;
    const classes = classnames(
      CLASS_ROOT, {
        [`${CLASS_ROOT}--${size}`]: (size && typeof size === 'string'),
        [`${CLASS_ROOT}--float`]: float,
        [`${CLASS_ROOT}--splash`]: splash
      },
      className
    );
    const containerClasses = classnames(
      `${CLASS_ROOT}__container`, {
        [`${CLASS_ROOT}__container--fixed`]: fixed,
{'fraction_non_alphanumeric': 0.13175514108082256, 'fraction_numerical': 0.0052606408417025345, 'mean_word_length': 3.3482328482328483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257895', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1228, 'n_words': 293}