# All files / composer/utils/draft-js-custom-plugins/short-link ShortLink.jsx

0% Statements 0/7
100% Branches 0/0
0% Functions 0/3
0% Lines 0/7

    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

     import React from 'react';
    import PropTypes from 'prop-types';

    import styles from './ShortLink.css';

    class ShortLink extends React.Component {
      static propTypes = {
        onMouseOver: PropTypes.func.isRequired,
        onMouseOut: PropTypes.func.isRequired,
        entityKey: PropTypes.string.isRequired,
        contentState: PropTypes.object.isRequired,
        children: PropTypes.node,
      };

      onMouseOver = () => {
        const { contentState, entityKey } = this.props;
        const { unshortenedLink, shortLink } = contentState.getEntity(entityKey).getData();
        const el = this.refs.shortLink;

        const relativePosition = {
          top: el.offsetTop,
          left: el.offsetLeft,
          width: el.offsetWidth,
          height: el.offsetHeight,
        };

        this.props.onMouseOver({ entityKey, unshortenedLink, shortLink, relativePosition });
      };

      onMouseOut = () => this.props.onMouseOut();

      render = () => (
        <span
          onMouseOver={this.onMouseOver} onMouseOut={this.onMouseOut}
          className={styles.link} ref="shortLink"
        >
          {this.props.children}
        </span>
      );
    }

    export default ShortLink;