<commit_before>import React, { Component } from 'react'
import classNames from 'classnames'

import styles from './index.styl'

const AUTOCLOSE_DELAY = 2000

class Alerter extends Component {

  constructor (props) {
    super()
    this.state = {
      hidden: true
    }
    this.shouldAutoClose = !props.buttonText
    this.closeTimer = null
  }

  componentDidMount () {
    if (this.shouldAutoClose) {
      this.closeTimer = setTimeout(() => {
        this.setState({ hidden: true })
      }, AUTOCLOSE_DELAY)
    }
    // Delay to trigger CSS transition after the first render.
    // Totally open for a better way to achieve this.
    setTimeout(() => {
      this.setState({ hidden: false })
    }, 20)
  }

  componentWillUnmount () {
    this.setState({ hidden: false })
    if (this.closeTimer) {
      clearTimeout(this.closeTimer)
    }
  }
<commit_msg>[feat] added optional alerter close callback<commit_after>import React, { Component } from 'react'
import classNames from 'classnames'

import styles from './index.styl'

const AUTOCLOSE_DELAY = 2000

class Alerter extends Component {

  constructor (props) {
    super()
    this.state = {
      hidden: true
    }
    this.shouldAutoClose = !props.buttonText
    this.closeTimer = null
  }

  componentDidMount () {
    if (this.shouldAutoClose) {
      this.closeTimer = setTimeout(() => {
        this.setState({ hidden: true })
        if (this.props.onClose && typeof this.props.onClose === 'function') this.props.onClose()
      }, AUTOCLOSE_DELAY)
    }
    // Delay to trigger CSS transition after the first render.
    // Totally open for a better way to achieve this.
    setTimeout(() => {
      this.setState({ hidden: false })
    }, 20)
  }

  componentWillUnmount () {
    this.setState({ hidden: false })
    if (this.closeTimer) {
      clearTimeout(this.closeTimer)
    }
  }

{'fraction_non_alphanumeric': 0.11654135338345864, 'fraction_numerical': 0.00644468313641246, 'mean_word_length': 2.756048387096774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3590400', 'n_tokens_mistral': 575, 'n_tokens_neox': 565, 'n_words': 149}