{"size": 2199, "ext": "js", "max_stars_repo_path": "src/components/app/draft/options/Bool.js", "max_stars_repo_name": "freesewing-bot/website", "max_stars_repo_stars_event_min_datetime": "2018-11-16T02:12:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-30T17:23:47.000Z", "max_issues_repo_path": "src/components/app/draft/options/Bool.js", "max_issues_repo_name": "freesewing-bot/website", "max_issues_repo_issues_event_min_datetime": "2018-10-03T12:06:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-27T18:23:38.000Z", "max_forks_repo_path": "src/components/app/draft/options/Bool.js", "max_forks_repo_name": "freesewing-bot/website", "max_forks_repo_forks_event_min_datetime": "2018-10-07T12:34:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-24T19:26:09.000Z"}
{"max_stars_count": 6, "max_issues_count": 48, "max_forks_count": 11, "avg_line_length": 29.7162162162, "max_line_length": 69, "alphanum_fraction": 0.5175079582}
import React from "react";
import Radio from "@material-ui/core/Radio";
import RadioGroup from "@material-ui/core/RadioGroup";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import Button from "@material-ui/core/Button";
import { FormattedMessage } from "react-intl";
import CloseIcon from "@material-ui/icons/Close";

class Bool extends React.Component {
  state = {
    value: this.props.value
  };

  toggleOption = () => {
    let value = "false";
    if (this.state.value === "false") value = "true";
    this.setState({ value });
    this.props.updateOption(this.props.option, value);
  };

  render() {
    let { desc, display, updateDisplay, dflt, intl } = this.props;
    return (
      <div className="option-wrapper">
        <p className="option-desc">{desc}</p>
        <RadioGroup
          name="units"
          onChange={this.toggleOption}
          value={this.state.value}
        >
          <FormControlLabel
            control={<Radio color="primary" />}
            value="false"
            checked={this.state.value === "false" ? true : false}
            label={intl.formatMessage({ id: "app.no" })}
          />
          <FormControlLabel
            control={<Radio color="primary" />}
            checked={this.state.value === "true" ? true : false}
            value="true"
            label={intl.formatMessage({ id: "app.yes" })}
          />
        </RadioGroup>
        <p className="option-actions">
          {this.state.value === "" + dflt ? (
            ""
          ) : (
            <Button
              variant="outlined"
              onClick={this.toggleOption}
              className="mr1"
            >
              <FormattedMessage id="app.reset" />
            </Button>
          )}
          <Button
            variant="outlined"
            onClick={
              display === "docs"
                ? () => updateDisplay("draft")
                : () => updateDisplay("docs", this.props.option)
            }
          >
            {display === "docs" ? <CloseIcon className="mr1" /> : ""}
            <FormattedMessage id="app.docs" />
          </Button>
        </p>
      </div>
    );
  }
}

export default Bool;
