All files FakeCodeTyping.jsx

100% Statements 14/14
100% Branches 0/0
100% Functions 2/2
100% Lines 14/14
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 52 53 54 55 56 57 58 59 60 61 62 63 64                1x 1x   1x   1x 1x 1x 1x   1x       1x 1x 1x   1x                                           1x                 1x            
/* eslint-disable react/no-array-index-key */
 
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import FakeCodeTypingLine from './FakeCodeTypingLine';
 
class FakeCodeTyping extends Component {
  render() {
    const { children, speed } = this.props;
    let { className } = this.props;
 
    const lines = children.props.children.split('\n');
 
    className += ' fake-code-typing';
    let delay = 0;
    let duration = 0;
    const lineLen = lines.length;
 
    return (
      <div className={className.trim()}>
        <pre>
          {lines.map((line, i) => {
            const count = line.length;
            delay += duration;
            duration = count / speed;
 
            return (
              <div key={i}>
                <FakeCodeTypingLine
                  keepBorder={lineLen === i + 1}
                  count={count}
                  duration={duration}
                  delay={delay}
                >
                  {line}
                </FakeCodeTypingLine>
                {'\n'}
              </div>
 
            );
          }
          )}
        </pre>
      </div>
    );
  }
}
 
FakeCodeTyping.propTypes = {
  children: PropTypes.oneOfType([
    PropTypes.arrayOf(PropTypes.node),
    PropTypes.node
  ]).isRequired,
  className: PropTypes.string,
  speed: PropTypes.number
};
 
FakeCodeTyping.defaultProps = {
  speed: 12,
  className: ''
};
 
export default FakeCodeTyping;