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

class ThemeSwitch extends Component {
  constructor(props) {
    super(props);

    this.store = typeof localStorage === 'undefined' ? null : localStorage;

    this.css = `
      html { filter: invert(100%); background: #fefefe; }
      * { background-color: inherit }
    `;

    if (this.props.preserveRasters) {
      this.css += 'img:not([src*=".svg"]), video, [style*="url("] { filter: invert(100%) }';
    }

    this.state = {
      active: false,
      supported: true
    };

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

  invertSupported (property, value) {
    var prop = property + ':',
        el = document.createElement('test'),
        mStyle = el.style;
    el.style.cssText = prop + value;
    return mStyle[property];
  }

  toggle() {
    this.setState({
      active: !this.state.active
    });
  }

  componentDidMount() {
    if (this.store) {
      this.setState({
        supported: this.invertSupported('filter', 'invert(100%)'),
        active: this.store.getItem('ThemeSwitch') || false
      });
    }
  }

  componentDidUpdate() {
    if (this.store) {
      this.store.setItem('ThemeSwitch', this.state.active);
    }
  }

  render() {
    if (!this.state.supported) {
      return null;
    }

    return (
      <div>
        <button aria-pressed={this.state.active} onClick={this.toggle}>
          inverted theme: <span aria-hidden="true">{this.state.active ? 'on' : 'off'}</span>
        </button>
        <style media={this.state.active ? 'screen' : 'none'}>
          {this.state.active ? this.css.trim() : this.css}
        </style>
      </div>
    );
  }
}

ThemeSwitch.defaultProps = { preserveRasters: 'true' }

export default ThemeSwitch;<commit_msg>Make ThemeSwitch the default ofa storeKey prop<commit_after>import React, { Component } from 'react';

class ThemeSwitch extends Component {
  constructor(props) {
    super(props);

    this.store = typeof localStorage === 'undefined' ? null : localStorage;

    this.css = `
      html { filter: invert(100%); background: #fefefe; }
      * { background-color: inherit }
    `;

    if (this.props.preserveRasters) {
      this.css += 'img:not([src*=".svg"]), video, [style*="url("] { filter: invert(100%) }';
    }

    this.state = {
      active: false,
      supported: true
    };

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

  invertSupported (property, value) {
    var prop = property + ':',
        el = document.createElement('test'),
        mStyle = el.style;
    el.style.cssText = prop + value;
    return mStyle[property];
  }

  toggle() {
    this.setState({
      active: !this.state.active
    });
  }

  componentDidMount() {
    if (this.store) {
      this.setState({
        supported: this.invertSupported('filter', 'invert(100%)'),
        active: this.store.getItem(this.props.storeKey) || false
      });
    }
  }

  componentDidUpdate() {
    if (this.store) {
      this.store.setItem(this.props.storeKey, this.state.active);
    }
  }

  render() {
    if (!this.state.supported) {
      return null;
    }

    return (
      <div>
        <button aria-pressed={this.state.active} onClick={this.toggle}>
          inverted theme: <span aria-hidden="true">{this.state.active ? 'on' : 'off'}</span>
        </button>
        <style media={this.state.active ? 'screen' : 'none'}>
          {this.state.active ? this.css.trim() : this.css}
        </style>
      </div>
    );
  }
}

ThemeSwitch.defaultProps = {
  preserveRasters: 'true',
  storeKey: 'ThemeSwitch'
}

export default ThemeSwitch;
{'fraction_non_alphanumeric': 0.16238839285714285, 'fraction_numerical': 0.005022321428571429, 'mean_word_length': 2.5250737463126844, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3457691', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1134, 'n_words': 219}