{"size": 1225, "ext": "js", "max_stars_repo_path": "src/StaticComponent.js", "max_stars_repo_name": "BadCoder1337/react-mathquill", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/StaticComponent.js", "max_issues_repo_name": "BadCoder1337/react-mathquill", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/StaticComponent.js", "max_forks_repo_name": "BadCoder1337/react-mathquill", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.1206896552, "max_line_length": 109, "alphanum_fraction": 0.6253061224}
import React from 'react'
import PropTypes from 'prop-types'
import { MathQuill } from './mathquill-loader'

class MathQuillStaticComponent extends React.Component {
  constructor(props) {
    super(props)

    this.element = null
    this.mathField = null
  }

  componentDidMount() {
    this.mathField = MathQuill.StaticMath(this.element)
    this.mathField.latex(this.props.latex || '')

    if (this.props.mathquillDidMount) {
      this.props.mathquillDidMount(this.mathField)
    }
  }

  componentWillReceiveProps(nextProps) {
    this.mathField.latex(nextProps.latex || '')
  }

  render() {
    const {
      latex,
      mathquillDidMount,
      className,
      ...otherProps
    } = this.props

    if (this.element) {
      this.element.classList.remove(...[...this.element.classList.values()].filter(c => !c.startsWith('mq')))
      try {
        this.element.classList.add(...className.split(' '))
      } catch (error) {/* */}
    }

    return (
      <div
        {...otherProps}
        ref={x => {
          this.element = x
        }}
      />
    )
  }
}

MathQuillStaticComponent.propTypes = {
  latex: PropTypes.string,
  mathquillDidMount: PropTypes.func,
}

export default MathQuillStaticComponent
