<commit_before>/**
 * TagSpaces - universal file and folder organizer
 * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License (version 3) as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @flow
 */

import React from 'react';
import Button from '@material-ui/core/Button';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import { withStyles } from '@material-ui/core/styles';
import { SketchPicker } from 'react-color';
import GenericDialog, { onEnterKeyHandler } from './GenericDialog';
import i18n from '../../services/i18n';

const presetColors = ['#ffffff', '#000000', '#ac725e', '#d06b64', '#f83a22', '#fa573c',
  '#ff7537', '#ffad46', '#42d692', '#008000', '#7bd148', '#fad165', '#FFCC24',
  '#92e1c0', '#9fe1e7', '#9fc6e7', '#4986e7', '#9a9cff', '#b99aff', '#c2c2c2',
  '#cabdbf', '#cca6ac', '#f691b2', '#cd74e6', '#a47ae2'];

type Props = {
  open: boolean,
  color: string,
  setColor: (color: string) => void,
  onClose: () => void
};

type State = {
  color: string
};

const styles = {
  noBorder: {
    padding: '0 !important',
    boxShadow: 'none !important'
  }
};

class ColorPickerDialog extends React.Component<Props, State> {
  state = {
    color: ''
  };

  componentWillReceiveProps = (nextProps: any) => {
    if (this.props.color !== nextProps.color) {
      this.setState({
        color: nextProps.color
      });
    }
  };

  onConfirm = () => {
    if (this.state.color && this.state.color.length > 2) {
      this.props.setColor(this.state.color);
    }
    this.props.onClose();
  };

  handleChangeComplete = (color) => {
    this.setState({ color: color.hex });
  };

  renderTitle = () => (
    <DialogTitle>{i18n.t('core:colorPickerDialogTitle')}</DialogTitle>
  );

  renderContent = () => (
    <DialogContent
      style={{
        marginLeft: 'auto',
        marginRight: 'auto'<commit_msg>TSN49 - adding data-tid to colorPickerDialogTitle<commit_after>/**
 * TagSpaces - universal file and folder organizer
 * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License (version 3) as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @flow
 */

import React from 'react';
import Button from '@material-ui/core/Button';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import { withStyles } from '@material-ui/core/styles';
import { SketchPicker } from 'react-color';
import GenericDialog, { onEnterKeyHandler } from './GenericDialog';
import i18n from '../../services/i18n';

const presetColors = ['#ffffff', '#000000', '#ac725e', '#d06b64', '#f83a22', '#fa573c',
  '#ff7537', '#ffad46', '#42d692', '#008000', '#7bd148', '#fad165', '#FFCC24',
  '#92e1c0', '#9fe1e7', '#9fc6e7', '#4986e7', '#9a9cff', '#b99aff', '#c2c2c2',
  '#cabdbf', '#cca6ac', '#f691b2', '#cd74e6', '#a47ae2'];

type Props = {
  open: boolean,
  color: string,
  setColor: (color: string) => void,
  onClose: () => void
};

type State = {
  color: string
};

const styles = {
  noBorder: {
    padding: '0 !important',
    boxShadow: 'none !important'
  }
};

class ColorPickerDialog extends React.Component<Props, State> {
  state = {
    color: ''
  };

  componentWillReceiveProps = (nextProps: any) => {
    if (this.props.color !== nextProps.color) {
      this.setState({
        color: nextProps.color
      });
    }
  };

  onConfirm = () => {
    if (this.state.color && this.state.color.length > 2) {
      this.props.setColor(this.state.color);
    }
    this.props.onClose();
  };

  handleChangeComplete = (color) => {
    this.setState({ color: color.hex });
  };

  renderTitle = () => (
    <DialogTitle data-tid="colorPickerDialogTitle" >
      {i18n.t('core:colorPickerDialogTitle')}
    </DialogTitle>
  );

  renderContent = () => (
    <DialogContent
      style={{
        marginLeft: 'auto',
        marginRight: 'auto'
{'fraction_non_alphanumeric': 0.15135556855861126, 'fraction_numerical': 0.03627852545348157, 'mean_word_length': 3.726267281105991, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1777868', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1638, 'n_words': 468}