All files / ts/components/misc highlight.tsx

100% Statements 19/19
100% Branches 17/17
100% Functions 2/2
100% Lines 17/17

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 52 53 54 55 56 57 58 59 60 61 62 63 64 6532x 32x 32x 32x                                               32x 32x 4x 4x 4x 8x 8x 8x 8x 4x     4x                                           32x   32x  
import * as classNames from 'classnames';
import * as React from 'react';
import { HTMLProps, PureComponent } from 'react';
import * as CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import { ComponentProps } from '../../types';
 
export interface HighlightProps extends ComponentProps, HTMLProps<HTMLElement> {
  /**
   * Displays the overlay
   * @default false
   */
  open?: boolean;
  /**
   * Disables any interactions with highlighted area
   * @default false
   */
  disabled?: boolean;
  /**
   * Background colour
   * @default undefined
   */
  backgroundColor?: string | undefined;
}
 
/**
 * This highlight component is used to display a single element while shading everything else out.
 */
export class Highlight extends PureComponent<HighlightProps, {}> {
  public render() {
    const {
      className,
      children,
      open = false,
      disabled = false,
      backgroundColor = null,
      component: Component = 'div',
      ...remainingProps
    } = this.props;
 
    return (
      <Component
        {...remainingProps}
        className={classNames('highlight', className)}
      >
        <CSSTransitionGroup
          transitionName="highlight-transition"
          transitionEnterTimeout={300}
          transitionLeaveTimeout={200}
        >
          {open && <div className="highlight-overlay" />}
        </CSSTransitionGroup>
        <div
          className={classNames('highlight-content', open && 'open')}
          style={backgroundColor ? { backgroundColor } : undefined}
        >
          {children}
          {open && disabled && <div className="highlight-overlay-disabled" />}
        </div>
      </Component>
    );
  }
}
 
export default Highlight;