All files / src/ui EditorButtons.js

71.43% Statements 10/14
100% Branches 4/4
66.67% Functions 4/6
71.43% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 521x 1x 1x   6x                       10x 10x 10x 10x                       6x                 6x                      
import React, {Component} from 'react';
import PropTypes from 'prop-types/prop-types';
import {logResults} from '../utils';
 
export class ToggleButton extends Component {
  static propTypes = {
    setBlockMode: PropTypes.func.isRequired,
    blockMode: PropTypes.bool.isRequired
  }
 
  // call setBlockMode on the opposite of the current mode
  handleToggle = () => {
    this.props.setBlockMode(!this.props.blockMode);
  }
 
  render() {
    const modeName   = this.props.blockMode ? "text" : "blocks";
    const buttonAria = "Switch to " + modeName + " mode";
    const buttonIcon = this.props.blockMode? "✏️" : "🧱";
    return (
      <button className="blocks-toggle-btn btn btn-default btn-sm"
              aria-label={buttonAria}
              title={buttonAria}
              onClick={this.handleToggle}
              tabIndex="0">
        <span>{buttonIcon}</span>
      </button>
    );
  }
}
 
export class BugButton extends Component {
 
  handleBugReport = () => {
    const history = JSON.stringify(window.reducerActivities);
    const description = prompt("Briefly describe what happened");
    logResults(history, "user-generated bug report", description);
  }
 
  render() {
    return (
      <button className="bug-btn btn btn-default btn-sm"
              aria-label="Report a bug"
              title="Report a bug"
              onClick={this.handleBugReport}
              tabIndex="0">
        <span>&#128030;</span>
      </button>
    );
  }
}