<commit_before>import React from 'react';
import { findDOMNode } from 'react-dom';
import {shouldComponentUpdate} from 'react/lib/ReactComponentWithPureRenderMixin';
import Collapse from '../../Collapse';
import text from './text.json';
import * as style from './style';
import scroll from 'scroll';

const page = /Firefox/.test(navigator.userAgent) ?
    document.documentElement :
    document.body

const getText = num => text.slice(0, num).map((p, i) => <p key={i}>{p}</p>);


const Hooks = React.createClass({
    getInitialState() {
        return {isOpened: false, keepContent: false, scrollHook: true, paragraphs: 0};
    },

    scroll(height) {
        if (this.state.scrollHook) {
            const collapsable = findDOMNode(this).querySelector('.collapsable');
            const bottom = collapsable.getBoundingClientRect().top + height;

            if (bottom > window.innerHeight) {
                scroll.top(page, bottom);
            }
        }
    },

    shouldComponentUpdate,


    render() {
        const {isOpened, keepContent, scrollHook, paragraphs} = this.state;

        return (
            <div>
                <div style={style.config}>
                    <label style={style.label}>
                        Opened:
                        <input style={style.input}
                               type="checkbox"
                               checked={isOpened}
                               onChange={({target: {checked}}) => this.setState({isOpened: checked})} />
                    </label>

                    <label style={style.label}>
                        Keep content:
                        <input style={style.input}
                               type="checkbox"
                               checked={keepContent}
                               onChange={({target: {checked}}) => this.setState({keepContent: checked})} />
                    </label>

                    <label style={style.label}>
                        Auto-scroll:
                        <input style={style.input}
                               type="checkbox"
                               checked={scrollHook}
                               onChange={({target: {checked}}) => this.setState({scrollHook: checked})} />
                    </label>

                    <label style={style.label}>
                        Paragraphs:
                        <input style={style.input}
                               type="range"
                               value={paragraphs} step={1} min={0} max={4}
                               onChange={({target: {value}}) => this.setState({paragraphs: parseInt(value, 10)})} />
                        {paragraphs}
                    </label>
                </div>
                <Collapse
                    className="collapsable"
                    style={style.container}
                    isOpened={isOpened}
                    keepCollapsedContent={keepContent}
                    onHeightReady={this.scroll}
                >
                    <div style={{padding: 10}}>{paragraphs ? getText(paragraphs) : <p>No text</p>}</div>
                </Collapse>
            </div>
        );
    }
});


export default Hooks;
<commit_msg>Formatting off<commit_after>import React from 'react';
import {findDOMNode} from 'react-dom';
import {shouldComponentUpdate} from 'react/lib/ReactComponentWithPureRenderMixin';
import Collapse from '../../Collapse';
import text from './text.json';
import * as style from './style';
import scroll from 'scroll';

const page = /Firefox/.test(navigator.userAgent) ?
  document.documentElement :
  document.body;

const getText = num => text.slice(0, num).map((p, i) => <p key={i}>{p}</p>);


const Hooks = React.createClass({
  getInitialState() {
    return {isOpened: false, keepContent: false, scrollHook: true, paragraphs: 0};
  },


  scroll(height) {
    if (this.state.scrollHook) {
      const collapsable = findDOMNode(this).querySelector('.collapsable');
      const bottom = collapsable.getBoundingClientRect().top + height;

      if (bottom > window.innerHeight) {
        scroll.top(page, bottom);
      }
    }
  },


  shouldComponentUpdate,


  render() {
    const {isOpened, keepContent, scrollHook, paragraphs} = this.state;

    return (
      <div>
        <div style={style.config}>
          <label style={style.label}>
            Opened:
            <input style={style.input}
              type="checkbox"
              checked={isOpened}
              onChange={({target: {checked}}) => this.setState({isOpened: checked})} />
          </label>

          <label style={style.label}>
            Keep content:
            <input style={style.input}
              type="checkbox"
              checked={keepContent}
              onChange={({target: {checked}}) => this.setState({keepContent: checked})} />
          </label>

          <label style={style.label}>
            Auto-scroll:
            <input style={style.input}
              type="checkbox"
              checked={scrollHook}
              onChange={({target: {checked}}) => this.setState({scrollHook: checked})} />
          </label>

          <label style={style.label}>
            Paragraphs:
            <input style={style.input}
              type="range"
              value={paragraphs} step={1} min={0} max={4}
              onChange={({target: {value}}) => this.setState({paragraphs: parseInt(value, 10)})} />
            {paragraphs}
          </label>
        </div>
        <Collapse
          className="collapsable"
          style={style.container}
          isOpened={isOpened}
          keepCollapsedContent={keepContent}
          onHeightReady={this.scroll}>
          <div style={{padding: 10}}>{paragraphs ? getText(paragraphs) : <p>No text</p>}</div>
        </Collapse>
      </div>
    );
  }
});


export default Hooks;

{'fraction_non_alphanumeric': 0.13486786018755328, 'fraction_numerical': 0.003069053708439898, 'mean_word_length': 1.6724373576309794, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 65, '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': '4977741', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1504, 'n_words': 309}